Significantly reduce memory usage by cells

This commit is contained in:
DBotThePony 2023-10-19 08:13:57 +07:00
parent 8afef646ae
commit 8cd84a4501
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 10 additions and 12 deletions

View File

@ -55,19 +55,11 @@ class ClientWorld(
val renderRegionsY = size.y / renderRegionHeight val renderRegionsY = size.y / renderRegionHeight
fun isValidRenderRegionX(value: Int): Boolean { fun isValidRenderRegionX(value: Int): Boolean {
if (loopX) { return loopX || value in 0 .. renderRegionsX
return true
} else {
return value in 0 .. renderRegionsX
}
} }
fun isValidRenderRegionY(value: Int): Boolean { fun isValidRenderRegionY(value: Int): Boolean {
if (loopY) { return loopY || value in 0 .. renderRegionsY
return true
} else {
return value in 0 .. renderRegionsY
}
} }
inner class RenderRegion(val x: Int, val y: Int) { inner class RenderRegion(val x: Int, val y: Int) {

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.world.api
import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.Registries
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
import ru.dbotthepony.kstarbound.util.HashTableInterner
import java.io.DataInputStream import java.io.DataInputStream
sealed class AbstractLiquidState { sealed class AbstractLiquidState {

View File

@ -29,7 +29,10 @@ data class MutableCell(
} }
override fun immutable(): ImmutableCell { override fun immutable(): ImmutableCell {
return ImmutableCell(foreground.immutable(), background.immutable(), liquid.immutable(), dungeonId, biome, envBiome, isIndestructible) val result = ImmutableCell(foreground.immutable(), background.immutable(), liquid.immutable(), dungeonId, biome, envBiome, isIndestructible)
if (result == NULL) return NULL
if (result == EMPTY) return EMPTY
return result
} }
override fun mutable(): MutableCell { override fun mutable(): MutableCell {

View File

@ -23,6 +23,8 @@ data class MutableLiquidState(
} }
override fun immutable(): ImmutableLiquidState { override fun immutable(): ImmutableLiquidState {
return ImmutableLiquidState(def, level, pressure, isInfinite) val result = ImmutableLiquidState(def, level, pressure, isInfinite)
if (result == EMPTY) return EMPTY
return result
} }
} }