Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colour blending in the wilderness #75

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/main/kotlin/models/scene/SceneRegionBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SceneRegionBuilder constructor(
if (xr >= -blend && xr < REGION_SIZE + blend) {
val r: RegionDefinition? = regionLoader.findRegionForWorldCoordinates(baseX + xr, baseY + yi)
if (r != null) {
val underlayId: Int = r.tiles[z][convert(xr)][convert(yi)].underlayId.toInt()
val underlayId: Int = r.tiles[z][xr and 0x3F][yi and 0x3F].underlayId.toInt() and 0xff
if (underlayId > 0) {
val underlay: UnderlayDefinition = underlayLoader.get(underlayId - 1) ?: continue
hues[yi + blend] += underlay.hue
Expand All @@ -101,7 +101,7 @@ class SceneRegionBuilder constructor(
if (xl >= -blend && xl < REGION_SIZE + blend) {
val r: RegionDefinition? = regionLoader.findRegionForWorldCoordinates(baseX + xl, baseY + yi)
if (r != null) {
val underlayId: Int = r.tiles[z][convert(xl)][convert(yi)].underlayId.toInt()
val underlayId: Int = r.tiles[z][xl and 0x3F][yi and 0x3F].underlayId.toInt() and 0xff
if (underlayId > 0) {
val underlay: UnderlayDefinition = underlayLoader.get(underlayId - 1) ?: continue
hues[yi + blend] -= underlay.hue
Expand Down Expand Up @@ -389,14 +389,6 @@ class SceneRegionBuilder constructor(
companion object {
val sceneRegionCache = hashMapOf<Int, SceneRegion>()

fun convert(d: Int): Int {
return if (d >= 0) {
d % 64
} else {
64 - -(d % 64) - 1
}
}

private fun multiplyHslBrightness(hsl: Int, brightness: Int): Int {
val adjustedBrightness = ((hsl and 0x7f) * brightness) / 0x80
return (hsl and 0xff80) + adjustedBrightness.clamp(2, 126)
Expand Down