fix: fixtures not placing actorblocks

This commit is contained in:
minjaesong
2021-08-11 18:01:34 +09:00
parent 7bb921321f
commit 740eab3e84
7 changed files with 45 additions and 40 deletions

View File

@@ -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"
1 id drop name shdr shdg shdb shduv str dsty mate solid plat wall grav dlfn fv fr lumr lumg lumb lumuv colour vscs refl
103 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
104 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
105 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
106 4091 0 ACTORBLOCK_NO_COLLISION 0.0312 0.0312 0.0312 0.0312 1 1 NULL 0 0 0 N/A 0 0 0 4 0.0 0.0 0.0 0.0 N/A N/A 0.0
107 4092 0 ACTORBLOCK_FULL_COLLISION 0.0312 0.0312 0.0312 0.0312 1 1 NULL 0 0 0 N/A 0 0 0 16 0.0 0.0 0.0 0.0 N/A N/A 0.0
108 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 16 0.0 0.0 0.0 0.0 N/A N/A 0.0
109 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 4 0.0 0.0 0.0 0.0 N/A N/A 0.0
110 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 4 0.0 0.0 0.0 0.0 N/A N/A 0.0
111 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
112 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
113 -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

View File

@@ -70,9 +70,10 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
val actorContainerActive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val actorContainerInactive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
protected val terrainChangeQueue = Queue<BlockChangeQueueItem>()
protected val wallChangeQueue = Queue<BlockChangeQueueItem>()
protected val wireChangeQueue = Queue<BlockChangeQueueItem>() // 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<BlockChangeQueueItem>()
protected val wallChangeQueue = ArrayList<BlockChangeQueueItem>()
protected val wireChangeQueue = ArrayList<BlockChangeQueueItem>() // 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))
}

View File

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

View File

@@ -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, "------------------------------------------")
}
}

View File

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

View File

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

View File

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