#12 event for world block change -- mainly meant for fixture updating itself

This commit is contained in:
minjaesong
2019-02-02 01:58:49 +09:00
parent 1e4e4d2b94
commit c476ca0d99
4 changed files with 96 additions and 2 deletions

View File

@@ -405,6 +405,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
itemOnGrip?.endSecondaryUse(delta)
}
private var firstTimeRun = true
///////////////
@@ -505,6 +507,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
CollisionSolver.process()
WorldCamera.update(gameworld, actorNowPlaying)
// completely consume block change queues because why not
terrainChangeQueue.clear()
wallChangeQueue.clear()
wireChangeQueue.clear()
}
@@ -665,6 +673,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
}
if (it is CuedByTerrainChange) {
terrainChangeQueue.forEach { cue ->
it.updateForWorldChange(cue)
}
}
}
}
actorNowPlaying?.update(delta)

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.ActorWBMovable
@@ -7,9 +8,9 @@ import net.torvald.terrarum.gameactors.ActorWBMovable
/**
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase(val blockBox: BlockBox) :
open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0)) :
// disabling physics (not allowing the fixture to move) WILL make things easier
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false) {
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false), CuedByTerrainChange {
/**
* Block-wise position of this fixture when it's placed on the world. Null if it's not on the world
@@ -32,6 +33,10 @@ open class FixtureBase(val blockBox: BlockBox) :
}
open fun updateSelf() {
}
/**
@@ -42,6 +47,33 @@ open class FixtureBase(val blockBox: BlockBox) :
}
}
interface CuedByTerrainChange {
/**
* Fired by world's BlockChanged event (fired when blocks are placed/removed).
* The flooding check must run on every frame. use updateSelf() for that.
*
* E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self.
*/
fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) {
}
}
/**
* Standard 32-bit binary flags.
*
* (LSB)
* - 0: fluid resist - when FALSE, the fixture will break itself to item/nothing. For example, crops has this flag FALSE.
* - 1: don't drop item when broken - when TRUE, the fixture will simply disappear instead of dropping itself. For example, crop has this flag TRUE.
*
* (MSB)
*
* In the savegame's JSON, this flag set should be stored as signed integer.
*/
inline class BlockBoxProps(val flags: Int) {
}
data class BlockBox(var collisionType: Int, var width: Int, var height: Int) {
fun redefine(collisionType: Int, width: Int, height: Int) {