From 740eab3e84a1524f0032c94ef95673c639a07164 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 11 Aug 2021 18:01:34 +0900 Subject: [PATCH] fix: fixtures not placing actorblocks --- assets/mods/basegame/blocks/blocks.csv | 10 +++--- src/net/torvald/terrarum/IngameInstance.kt | 23 +++++++------- .../torvald/terrarum/gameworld/GameWorld.kt | 6 ++-- .../terrarum/gameworld/WorldSimulator.kt | 10 +++--- .../terrarum/modulebasegame/TerrarumIngame.kt | 4 ++- .../modulebasegame/gameactors/FixtureBase.kt | 31 +++++++++++-------- .../modulebasegame/gameitems/BlockBase.kt | 1 - 7 files changed, 45 insertions(+), 40 deletions(-) diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 6eef08fdb..f070635ef 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -103,11 +103,11 @@ "273";"273";"BLOCK_SCAFFOLDING_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1400";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" "274";"274";"BLOCK_SCAFFOLDING_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"670";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" "275";"275";"BLOCK_SCAFFOLDING_BLOODROSE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"900";"WOOD";"0";"1";"0";"6";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" -"4091";"0";"ACTORBLOCK_NO_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" -"4092";"0";"ACTORBLOCK_FULL_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" -"4093";"0";"ACTORBLOCK_ALLOW_MOVE_DOWN";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" -"4094";"0";"ACTORBLOCK_NO_PASS_RIGHT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" -"4095";"0";"ACTORBLOCK_NO_PASS_LEFT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"0";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +"4091";"0";"ACTORBLOCK_NO_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"4";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +"4092";"0";"ACTORBLOCK_FULL_COLLISION";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +"4093";"0";"ACTORBLOCK_ALLOW_MOVE_DOWN";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"0";"N/A";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +"4094";"0";"ACTORBLOCK_NO_PASS_RIGHT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"4";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +"4095";"0";"ACTORBLOCK_NO_PASS_LEFT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"0";"N/A";"0";"0";"4";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" "65536";"0";"BLOCK_WATER";"0.1016";"0.0744";"0.0508";"0.0826";"100";"1000";"WATR";"0";"0";"0";"0";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"005599A6";"16";"0.0" "65537";"0";"BLOCK_LAVA";"0.9696";"0.9696";"0.9696";"0.9696";"100";"2600";"ROCK";"0";"0";"0";"0";"0";"0";"16";"0.7664";"0.2032";"0.0000";"0.0000";"FF4600E6";"32";"0.0" "-1";"0";"BLOCK_NULL";"4.0000";"4.0000";"4.0000";"4.0000";"-1";"2600";"NULL";"0";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0" diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index ff5054b02..d635e6bca 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -70,9 +70,10 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { val actorContainerActive = SortedArrayList(ACTORCONTAINER_INITIAL_SIZE) val actorContainerInactive = SortedArrayList(ACTORCONTAINER_INITIAL_SIZE) - protected val terrainChangeQueue = Queue() - protected val wallChangeQueue = Queue() - protected val wireChangeQueue = Queue() // if 'old' is set and 'new' is blank, it's a wire cutter + // FIXME queues will not work; input processing (blocks will queue) and queue consuming cannot be synchronised + protected val terrainChangeQueue = ArrayList() + protected val wallChangeQueue = ArrayList() + protected val wireChangeQueue = ArrayList() // if 'old' is set and 'new' is blank, it's a wire cutter override fun hide() { } @@ -151,17 +152,16 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { * * Queueing schema is used to make sure things are synchronised. */ - open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, position: Long) { - val (x, y) = LandUtil.resolveBlockAddr(world, position) - terrainChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y)) + open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, x: Int, y: Int) { + printdbg(this, "Terrain change enqueued: ${BlockChangeQueueItem(old, new, x, y)}") + printdbg(this, terrainChangeQueue) } /** * Wall version of terrainChanged() event */ - open fun queueWallChangedEvent(old: ItemID, new: ItemID, position: Long) { - val (x, y) = LandUtil.resolveBlockAddr(world, position) - wallChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y)) + open fun queueWallChangedEvent(old: ItemID, new: ItemID, x: Int, y: Int) { + wallChangeQueue.add(BlockChangeQueueItem(old, new, x, y)) } /** @@ -170,9 +170,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { * @param old previous settings of conduits in bit set format. * @param new current settings of conduits in bit set format. */ - open fun queueWireChangedEvent(wire: ItemID, isRemoval: Boolean, position: Long) { - val (x, y) = LandUtil.resolveBlockAddr(world, position) - wireChangeQueue.addLast(BlockChangeQueueItem(if (isRemoval) wire else "", if (isRemoval) "" else wire, x, y)) + open fun queueWireChangedEvent(wire: ItemID, isRemoval: Boolean, x: Int, y: Int) { + wireChangeQueue.add(BlockChangeQueueItem(if (isRemoval) wire else "", if (isRemoval) "" else wire, x, y)) } diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 0726aefe7..73f6eb964 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -283,7 +283,7 @@ open class GameWorld : Disposable { wallDamages.remove(LandUtil.getBlockAddr(this, x, y)) if (!bypassEvent) - Terrarum.ingame?.queueWallChangedEvent(oldWall, itemID, LandUtil.getBlockAddr(this, x, y)) + Terrarum.ingame?.queueWallChangedEvent(oldWall, itemID, x, y) } /** @@ -313,7 +313,7 @@ open class GameWorld : Disposable { // fluid tiles-item should be modified so that they will also place fluid onto their respective map if (!bypassEvent) - Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, itemID, LandUtil.getBlockAddr(this, x, y)) + Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, itemID, x, y) } fun setTileWire(x: Int, y: Int, tile: ItemID, bypassEvent: Boolean) { @@ -328,7 +328,7 @@ open class GameWorld : Disposable { wirings[blockAddr]!!.wires.add(tile) if (!bypassEvent) - Terrarum.ingame?.queueWireChangedEvent(tile, false, LandUtil.getBlockAddr(this, x, y)) + Terrarum.ingame?.queueWireChangedEvent(tile, false, x, y) // figure out wiring graphs diff --git a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt index 9bb1f7f1a..bb71bbcff 100644 --- a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt +++ b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt @@ -496,7 +496,7 @@ object WorldSimulator { if (world.getAllWiresFrom(point.x, point.y)?.filter { WireCodex[it].accepts == wireType }?.isEmpty() != false) break - printdbg(this, branchesVisited) + //printdbg(this, branchesVisited) // get all wires that matches 'accepts' (such as Red/Green/Blue wire) and propagate signal for each of them world.getAllWiresFrom(point.x, point.y)?.filter { WireCodex[it].accepts == wireType }?.forEach { wire -> @@ -506,14 +506,14 @@ object WorldSimulator { val signal = node.emitState val cnx = node.connections.toInt() // 1-15 val nextDirBit = cnx and (15 - point.fromWhere) // cnx minus where the old cursur was; also 1-15 - printdbg(this, "(${point.x}, ${point.y}) from ${point.fromWhere} to $nextDirBit") + //printdbg(this, "(${point.x}, ${point.y}) from ${point.fromWhere} to $nextDirBit") // mark current position as visited branchesVisited.add(point.copy()) // termination condition 1 if (branchesVisited.linearSearch { it.x == point.x && it.y == point.y }!! < branchesVisited.lastIndex) { - printdbg(this, "(${point.x}, ${point.y}) was already visited") + //printdbg(this, "(${point.x}, ${point.y}) was already visited") dequeue() } else { @@ -549,10 +549,10 @@ object WorldSimulator { } } - printdbg(this, "Point = $point") + //printdbg(this, "Point = $point") } // end While - printdbg(this, "------------------------------------------") + //printdbg(this, "------------------------------------------") } } diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 1807c2fc7..5f5dc7284 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -636,7 +636,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { ingameController.update(delta) if (!paused) { - + printdbg(this, "Clear tile change queues") // completely consume block change queues because why not terrainChangeQueue.clear() wallChangeQueue.clear() @@ -877,7 +877,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { } if (it is CuedByTerrainChange) { + printdbg(this, "actor is CuedByTerrainChange: ${terrainChangeQueue}") terrainChangeQueue.forEach { cue -> + printdbg(this, "Ingame actors terrainChangeCue: ${cue}") it.updateForWorldChange(cue) } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index d2aebb883..a353512b4 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.IngameInstance import net.torvald.terrarum.Point2i import net.torvald.terrarum.Terrarum @@ -53,7 +54,7 @@ open class FixtureBase( } fun forEachBlockbox(action: (Int, Int) -> Unit) { - worldBlockPos?.let { (posX, posY) -> + worldBlockPos!!.let { (posX, posY) -> for (y in posY until posY + blockBox.height) { for (x in posX until posX + blockBox.width) { action(x, y) @@ -96,22 +97,25 @@ open class FixtureBase( if (hasCollision) return false - - // fill the area with the filler blocks - forEachBlockbox { x, y -> - if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) { - // if the collision type is allow_move_down, only the top surface tile should be "the platform" - // lower part must not have such property (think of the table!) - // TODO does this ACTUALLY work ?! - world!!.setTileTerrain(x, y, if (y == posY) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, false) - } - else - world!!.setTileTerrain(x, y, blockBox.collisionType, false) - } + printdbg(this, "spawn ${nameFun()}") // set the position of this actor worldBlockPos = Point2i(posX, posY) + // fill the area with the filler blocks + forEachBlockbox { x, y -> + printdbg(this, "fillerblock ${blockBox.collisionType} at ($x, $y)") + if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) { + // if the collision type is allow_move_down, only the top surface tile should be "the platform" + // lower part must not have such property (think of the table!) + // TODO does this ACTUALLY work ?! + world!!.setTileTerrain(x, y, if (y == posY) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, false) + } + else + world!!.setTileTerrain(x, y, blockBox.collisionType, false) + } + + this.isVisible = true this.hitbox.setFromWidthHeight(posX * TILE_SIZED, posY * TILE_SIZED, blockBox.width * TILE_SIZED, blockBox.height * TILE_SIZED) @@ -148,6 +152,7 @@ open class FixtureBase( * E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self. */ override fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) { + printdbg(this, "updateForWorldChange ${nameFun()}") // check for marker blocks. // if at least one of them is missing, destroy all the markers and drop self as an item diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index f3d891653..75bba85ac 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -40,7 +40,6 @@ object BlockBase { } // return false if the tile is already there - // FIXME doesn't work for WALLs? if (gameItem.inventoryCategory == GameItem.Category.BLOCK && gameItem.dynamicID == ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) || gameItem.inventoryCategory == GameItem.Category.WALL &&