From d315d61f68eb6660c71c972518a06ded864477e0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 21 Aug 2021 21:43:52 +0900 Subject: [PATCH] seemingly working #41 --- src/net/torvald/terrarum/IngameInstance.kt | 12 +++++---- .../terrarum/modulebasegame/TerrarumIngame.kt | 27 ++++++++++++++----- .../modulebasegame/gameactors/FixtureBase.kt | 15 ++++++++++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index 71d28809d..d62e5503b 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -71,9 +71,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { val actorContainerInactive = SortedArrayList(ACTORCONTAINER_INITIAL_SIZE) // 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 + 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() { } @@ -153,6 +153,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { * Queueing schema is used to make sure things are synchronised. */ open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, x: Int, y: Int) { + terrainChangeQueue.add(BlockChangeQueueItem(old, new, x, y)) //printdbg(this, terrainChangeQueue) } @@ -160,7 +161,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { * Wall version of terrainChanged() event */ open fun queueWallChangedEvent(old: ItemID, new: ItemID, x: Int, y: Int) { - //wallChangeQueue.add(BlockChangeQueueItem(old, new, x, y)) + wallChangeQueue.add(BlockChangeQueueItem(old, new, x, y)) } /** @@ -170,7 +171,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen { * @param new current settings of conduits in bit set format. */ open fun queueWireChangedEvent(wire: ItemID, isRemoval: Boolean, x: Int, y: Int) { - //wireChangeQueue.add(BlockChangeQueueItem(if (isRemoval) wire else "", if (isRemoval) "" else wire, x, y)) + wireChangeQueue.add(BlockChangeQueueItem(if (isRemoval) wire else "", if (isRemoval) "" else wire, x, y)) + //printdbg(this, wireChangeQueue) } diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 8e1f8814d..4119d6379 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -565,9 +565,9 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { // synchronised Ingame Input Updater + // will also queue up the block/wall/wire placed events ingameController.update(delta) - if (!paused) { //hypothetical_input_capturing_function_if_you_finally_decided_to_forgo_gdx_input_processor_and_implement_your_own_to_synchronise_everything() @@ -615,12 +615,12 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { } - /*if (!paused) { + if (!paused) { // completely consume block change queues because why not terrainChangeQueue.clear() wallChangeQueue.clear() wireChangeQueue.clear() - }*/ + } //////////////////////// @@ -859,13 +859,26 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) { } } - /*if (it is CuedByTerrainChange) { - printdbg(this, "actor is CuedByTerrainChange: ${terrainChangeQueue}") + if (it is CuedByTerrainChange) { terrainChangeQueue.forEach { cue -> printdbg(this, "Ingame actors terrainChangeCue: ${cue}") - it.updateForWorldChange(cue) + it.updateForTerrainChange(cue) } - }*/ + } + + if (it is CuedByWallChange) { + wallChangeQueue.forEach { cue -> + printdbg(this, "Ingame actors wallChangeCue: ${cue}") + it.updateForWallChange(cue) + } + } + + if (it is CuedByWireChange) { + wireChangeQueue.forEach { cue -> + printdbg(this, "Ingame actors wireChangeCue: ${cue}") + it.updateForWireChange(cue) + } + } } } actorNowPlaying?.update(delta) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index ec88a2f4a..c307be92c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -65,6 +65,10 @@ open class FixtureBase( } } + override fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) { + // TODO check for despawn code here + } + /** * Adds this instance of the fixture to the world * @@ -187,9 +191,18 @@ interface CuedByTerrainChange { * * E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self. */ - //fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) + fun updateForTerrainChange(cue: IngameInstance.BlockChangeQueueItem) } +interface CuedByWallChange { + fun updateForWallChange(cue: IngameInstance.BlockChangeQueueItem) +} + +interface CuedByWireChange { + fun updateForWireChange(cue: IngameInstance.BlockChangeQueueItem) +} + + /** * Standard 32-bit binary flags. *