diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 61ea48d1a..5dba3b23c 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -320,7 +320,9 @@ open class ActorWithBody : Actor { var isChronostasis = false /** - * if set to TRUE, the ingame will not move the actor into the active list + * if set to TRUE, the ingame will not move the actor into the active list. + * + * This flag will override `chunkAnchoring` flag (in this case, the chunk will be anchored but the actor will be dormant) */ var forceDormant = false @@ -410,12 +412,14 @@ open class ActorWithBody : Actor { * ... * n: (2n-1)x(2n-1) */ - @Transient val chunkAnchorRange: Int = 0 + @Transient open val chunkAnchorRange: Int = 0 /** * Should nearby chunks be kept in the chunk pool even if the player is far away. + * + * `ActorWithBody.forceDormant` will IGNORE this flag. */ - @Transient var chunkAnchoring = false + @Transient open var chunkAnchoring = false init { // some initialiser goes here... diff --git a/src/net/torvald/terrarum/gameworld/ChunkPool.kt b/src/net/torvald/terrarum/gameworld/ChunkPool.kt index f0bcf99ec..a6733babe 100644 --- a/src/net/torvald/terrarum/gameworld/ChunkPool.kt +++ b/src/net/torvald/terrarum/gameworld/ChunkPool.kt @@ -111,4 +111,36 @@ open class ChunkPool( return numIn } + companion object { + fun getRenameFunTerrain(world: GameWorld): (Int) -> Int { + // word size: 2 + return { oldTileNum -> + val oldOreName = world.oldTileNumberToNameMap[oldTileNum.toLong()] + + world.tileNameToNumberMap[oldOreName]!! + } + } + + fun getRenameFunOres(world: GameWorld): (Int) -> Int { + // word size: 3 + return { oldTileNumRaw -> + val oldOreNum = oldTileNumRaw and 0x0000FFFF + val oldOrePlacement = oldTileNumRaw and 0xFFFF0000.toInt() + val oldOreName = world.oldTileNumberToNameMap[oldOreNum.toLong()]!! + + world.tileNameToNumberMap[oldOreName]!! or oldOrePlacement + } + } + + fun getRenameFunFluids(world: GameWorld): (Int) -> Int { + // word size: 4 + return { oldTileNumRaw -> + val oldFluidNum = oldTileNumRaw and 0x0000FFFF + val oldFluidFill = oldTileNumRaw and 0xFFFF0000.toInt() + val oldFluidName = world.oldTileNumberToNameMap[oldFluidNum.toLong()] + + world.tileNameToNumberMap[oldFluidName]!! or oldFluidFill + } + } + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index f063f1074..97f9a4f47 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -163,6 +163,7 @@ open class GameWorld( it[1] = Block.UPDATE it[65535] = Block.NOT_GENERATED // unlike Block.NULL, this one is solid } + @Transient internal lateinit var oldTileNumberToNameMap: Map // this is a caching variable, refreshed on every (initial) load /*val fluidNumberToNameMap = HashArray().also { it[0] = Fluid.NULL it[65535] = Fluid.NULL // 65535 denotes "not generated" @@ -275,7 +276,7 @@ open class GameWorld( tileNumberToNameMap[1] = Block.UPDATE tileNumberToNameMap[65535] = Block.NOT_GENERATED // before the renaming, update the name maps - val oldTileNumberToNameMap: Map = tileNumberToNameMap.toMap() + oldTileNumberToNameMap = tileNumberToNameMap.toMap() tileNumberToNameMap.forEach { l, s -> printdbg(this, " afterload oldMapping tileNumber $l <-> $s") diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index b1ed081fb..c0922e88c 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -1365,7 +1365,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { var i = 0 while (i < actorContainerSize) { // loop through actorContainerInactive val actor = actorContainerInactive[i] - if (actor is ActorWithBody && actor.inUpdateRange(world) && !actor.forceDormant) { + if (actor is ActorWithBody && (actor.chunkAnchoring || actor.inUpdateRange(world)) && !actor.forceDormant) { activateDormantActor(actor) // duplicates are checked here actorContainerSize -= 1 i-- // array removed 1 elem, so we also decrement counter by 1 @@ -1392,7 +1392,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { i-- // array removed 1 elem, so we also decrement counter by 1 } // inactivate distant actors - else if (actor is ActorWithBody && (!actor.inUpdateRange(world) || actor.forceDormant)) { + else if (actor is ActorWithBody && (!actor.chunkAnchoring && !actor.inUpdateRange(world) || actor.forceDormant)) { if (actor !is Projectile) { // if it's a projectile, don't inactivate it; just kill it. actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt index 1de094df8..e5a180d0c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/IngamePlayer.kt @@ -42,6 +42,8 @@ class IngamePlayer : ActorHumanoid, HasAssembledSprite, NoSerialise { /** ADL for glow sprite. Optional. */ @Transient override var animDescEmissive: ADProperties? = null + @Transient override val chunkAnchorRange = 3 + @Transient override var chunkAnchoring = true private constructor()