actor update control by chunkAnchoring flag

This commit is contained in:
minjaesong
2024-09-07 19:01:03 +09:00
parent ab31986cf2
commit 11cdcbe2fc
5 changed files with 45 additions and 6 deletions

View File

@@ -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...

View File

@@ -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
}
}
}
}

View File

@@ -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<Long, ItemID> // this is a caching variable, refreshed on every (initial) load
/*val fluidNumberToNameMap = HashArray<ItemID>().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<Long, ItemID> = tileNumberToNameMap.toMap()
oldTileNumberToNameMap = tileNumberToNameMap.toMap()
tileNumberToNameMap.forEach { l, s ->
printdbg(this, " afterload oldMapping tileNumber $l <-> $s")

View File

@@ -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
}

View File

@@ -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()