fixing random terragen crash? (was it block change event too big?)

This commit is contained in:
minjaesong
2021-02-25 10:15:37 +09:00
parent ed0bec0ee8
commit 5f16f71b0a
9 changed files with 44 additions and 38 deletions

View File

@@ -144,7 +144,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
*/ */
open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, position: Long) { open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, position: Long) {
val (x, y) = LandUtil.resolveBlockAddr(world, position) val (x, y) = LandUtil.resolveBlockAddr(world, position)
terrainChangeQueue.addFirst(BlockChangeQueueItem(old, new, x, y)) terrainChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y))
} }
/** /**
@@ -152,7 +152,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
*/ */
open fun queueWallChangedEvent(old: ItemID, new: ItemID, position: Long) { open fun queueWallChangedEvent(old: ItemID, new: ItemID, position: Long) {
val (x, y) = LandUtil.resolveBlockAddr(world, position) val (x, y) = LandUtil.resolveBlockAddr(world, position)
wallChangeQueue.addFirst(BlockChangeQueueItem(old, new, x, y)) wallChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y))
} }
/** /**
@@ -163,7 +163,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
*/ */
open fun queueWireChangedEvent(old: ItemID, new: ItemID, position: Long) { open fun queueWireChangedEvent(old: ItemID, new: ItemID, position: Long) {
val (x, y) = LandUtil.resolveBlockAddr(world, position) val (x, y) = LandUtil.resolveBlockAddr(world, position)
wireChangeQueue.addFirst(BlockChangeQueueItem(old, new, x, y)) wireChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y))
} }

View File

@@ -269,7 +269,7 @@ open class GameWorld : Disposable {
* * * *
* @param itemID Tile as in ItemID, with tag removed! * @param itemID Tile as in ItemID, with tag removed!
*/ */
fun setTileWall(x: Int, y: Int, itemID: ItemID) { fun setTileWall(x: Int, y: Int, itemID: ItemID, bypassEvent: Boolean) {
val (x, y) = coerceXY(x, y) val (x, y) = coerceXY(x, y)
val tilenum = tileNameToNumberMap[itemID]!! val tilenum = tileNameToNumberMap[itemID]!!
@@ -277,7 +277,8 @@ open class GameWorld : Disposable {
layerWall.unsafeSetTile(x, y, tilenum) layerWall.unsafeSetTile(x, y, tilenum)
wallDamages.remove(LandUtil.getBlockAddr(this, x, y)) wallDamages.remove(LandUtil.getBlockAddr(this, x, y))
Terrarum.ingame?.queueWallChangedEvent(oldWall, itemID, LandUtil.getBlockAddr(this, x, y)) if (!bypassEvent)
Terrarum.ingame?.queueWallChangedEvent(oldWall, itemID, LandUtil.getBlockAddr(this, x, y))
} }
/** /**
@@ -291,7 +292,7 @@ open class GameWorld : Disposable {
* * * *
* @param itemID Tile as in ItemID, with tag removed! * @param itemID Tile as in ItemID, with tag removed!
*/ */
fun setTileTerrain(x: Int, y: Int, itemID: ItemID) { fun setTileTerrain(x: Int, y: Int, itemID: ItemID, bypassEvent: Boolean) {
val (x, y) = coerceXY(x, y) val (x, y) = coerceXY(x, y)
val tilenum = tileNameToNumberMap[itemID]!! val tilenum = tileNameToNumberMap[itemID]!!
@@ -306,7 +307,8 @@ open class GameWorld : Disposable {
} }
// fluid tiles-item should be modified so that they will also place fluid onto their respective map // fluid tiles-item should be modified so that they will also place fluid onto their respective map
Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, itemID, LandUtil.getBlockAddr(this, x, y)) if (!bypassEvent)
Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, itemID, LandUtil.getBlockAddr(this, x, y))
} }
/*fun setTileWire(x: Int, y: Int, tile: Byte) { /*fun setTileWire(x: Int, y: Int, tile: Byte) {
@@ -431,7 +433,7 @@ open class GameWorld : Disposable {
// remove tile from the world // remove tile from the world
if (terrainDamages[addr] ?: 0f >= BlockCodex[getTileFromTerrain(x, y)].strength) { if (terrainDamages[addr] ?: 0f >= BlockCodex[getTileFromTerrain(x, y)].strength) {
setTileTerrain(x, y, Block.AIR) setTileTerrain(x, y, Block.AIR, false)
terrainDamages.remove(addr) terrainDamages.remove(addr)
return true return true
} }
@@ -460,7 +462,7 @@ open class GameWorld : Disposable {
// remove tile from the world // remove tile from the world
if (wallDamages[addr]!! >= BlockCodex[getTileFromWall(x, y)].strength) { if (wallDamages[addr]!! >= BlockCodex[getTileFromWall(x, y)].strength) {
setTileWall(x, y, Block.AIR) setTileWall(x, y, Block.AIR, false)
wallDamages.remove(addr) wallDamages.remove(addr)
return true return true
} }

View File

@@ -84,19 +84,19 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
println("[BuildingMaker] Generating builder world...") println("[BuildingMaker] Generating builder world...")
for (y in 0 until gameWorld.height) { for (y in 0 until gameWorld.height) {
gameWorld.setTileWall(0, y, Block.ILLUMINATOR_RED) gameWorld.setTileWall(0, y, Block.ILLUMINATOR_RED, true)
gameWorld.setTileWall(gameWorld.width - 1, y, Block.ILLUMINATOR_RED) gameWorld.setTileWall(gameWorld.width - 1, y, Block.ILLUMINATOR_RED, true)
gameWorld.setTileTerrain(0, y, Block.ILLUMINATOR_RED_OFF) gameWorld.setTileTerrain(0, y, Block.ILLUMINATOR_RED_OFF, true)
gameWorld.setTileTerrain(gameWorld.width - 1, y, Block.ILLUMINATOR_RED_OFF) gameWorld.setTileTerrain(gameWorld.width - 1, y, Block.ILLUMINATOR_RED_OFF, true)
} }
for (y in 150 until gameWorld.height) { for (y in 150 until gameWorld.height) {
for (x in 1 until gameWorld.width - 1) { for (x in 1 until gameWorld.width - 1) {
// wall layer // wall layer
gameWorld.setTileWall(x, y, Block.DIRT) gameWorld.setTileWall(x, y, Block.DIRT, true)
// terrain layer // terrain layer
gameWorld.setTileTerrain(x, y, if (y == 150) Block.GRASS else Block.DIRT) gameWorld.setTileTerrain(x, y, if (y == 150) Block.GRASS else Block.DIRT, true)
} }
} }
@@ -425,15 +425,15 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
// test paint terrain layer // test paint terrain layer
PENMODE_PENCIL -> { PENMODE_PENCIL -> {
if (palSelection.startsWith("wall@")) if (palSelection.startsWith("wall@"))
world.setTileWall(x, y, palSelection.substring(5)) world.setTileWall(x, y, palSelection.substring(5), true)
else else
world.setTileTerrain(x, y, palSelection) world.setTileTerrain(x, y, palSelection, true)
} }
PENMODE_PENCIL_ERASE -> { PENMODE_PENCIL_ERASE -> {
if (currentPenTarget and PENTARGET_WALL != 0) if (currentPenTarget and PENTARGET_WALL != 0)
world.setTileWall(x, y, Block.AIR) world.setTileWall(x, y, Block.AIR, true)
else else
world.setTileTerrain(x, y, Block.AIR) world.setTileTerrain(x, y, Block.AIR, true)
} }
PENMODE_EYEDROPPER -> { PENMODE_EYEDROPPER -> {
uiPaletteSelector.fore = if (world.getTileFromTerrain(x, y) == Block.AIR) uiPaletteSelector.fore = if (world.getTileFromTerrain(x, y) == Block.AIR)

View File

@@ -78,10 +78,10 @@ open class FixtureBase(
// if the collision type is allow_move_down, only the top surface tile should be "the platform" // 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!) // lower part must not have such property (think of the table!)
// TODO does this ACTUALLY work ?! // TODO does this ACTUALLY work ?!
world.setTileTerrain(x, y, if (y == posY) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION) world.setTileTerrain(x, y, if (y == posY) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, false)
} }
else else
world.setTileTerrain(x, y, blockBox.collisionType) world.setTileTerrain(x, y, blockBox.collisionType, false)
} }
} }
@@ -116,7 +116,7 @@ open class FixtureBase(
// remove filler block // remove filler block
for (x in posX until posX + blockBox.width) { for (x in posX until posX + blockBox.width) {
for (y in posY until posY + blockBox.height) { for (y in posY until posY + blockBox.height) {
world.setTileTerrain(x, y, Block.AIR) world.setTileTerrain(x, y, Block.AIR, false)
} }
} }
@@ -157,7 +157,7 @@ open class FixtureBase(
for (x in posX until posX + blockBox.width) { for (x in posX until posX + blockBox.width) {
for (y in posY until posY + blockBox.height) { for (y in posY until posY + blockBox.height) {
if (world.getTileFromTerrain(x, y) == blockBox.collisionType) { if (world.getTileFromTerrain(x, y) == blockBox.collisionType) {
world.setTileTerrain(x, y, Block.AIR) world.setTileTerrain(x, y, Block.AIR, false)
} }
} }
} }

View File

@@ -80,7 +80,9 @@ object PlayerBuilderSigrid {
try { try {
inventory.add("wall@"+t, 9995) inventory.add("wall@"+t, 9995)
} }
catch (e: Throwable) {} catch (e: Throwable) {
System.err.println("[PlayerBuilder] $e")
}
} }
// item ids are defined in <module>/items/itemid.csv // item ids are defined in <module>/items/itemid.csv

View File

@@ -56,14 +56,16 @@ object BlockBase {
ingame.world.setTileWall( ingame.world.setTileWall(
mouseTile.x, mouseTile.x,
mouseTile.y, mouseTile.y,
itemID.substring(5) itemID.substring(5),
false
) )
} }
else { else {
ingame.world.setTileTerrain( ingame.world.setTileTerrain(
mouseTile.x, mouseTile.x,
mouseTile.y, mouseTile.y,
itemID itemID,
false
) )
} }

View File

@@ -208,8 +208,8 @@ object WorldSimulator {
// process the gradual falling of the selected "stack" // process the gradual falling of the selected "stack"
if (!fallableStackProcessed && fallDownCounter != 0 && isFallable) { if (!fallableStackProcessed && fallDownCounter != 0 && isFallable) {
// replace blocks // replace blocks
world.setTileTerrain(x, y, Block.AIR) world.setTileTerrain(x, y, Block.AIR, true)
world.setTileTerrain(x, y + fallDownCounter, currentTile) world.setTileTerrain(x, y + fallDownCounter, currentTile, true)
fallableStackProcessed = true fallableStackProcessed = true
} }

View File

@@ -86,17 +86,17 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
when (control) { when (control) {
0 -> { // woodlands 0 -> { // woodlands
if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) { if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) {
world.setTileTerrain(x, y, Block.GRASS) world.setTileTerrain(x, y, Block.GRASS, true)
} }
} }
1 -> { // shrublands 1 -> { // shrublands
if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) { if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) {
world.setTileTerrain(x, y, Block.GRASS) world.setTileTerrain(x, y, Block.GRASS, true)
} }
} }
2, 3 -> { // plains 2, 3 -> { // plains
if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) { if (tileThis == Block.DIRT && nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }) {
world.setTileTerrain(x, y, Block.GRASS) world.setTileTerrain(x, y, Block.GRASS, true)
} }
} }
/*3 -> { // sands /*3 -> { // sands
@@ -109,8 +109,8 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
}*/ }*/
4 -> { // rockylands 4 -> { // rockylands
if (tileThis == Block.DIRT) { if (tileThis == Block.DIRT) {
world.setTileTerrain(x, y, Block.STONE) world.setTileTerrain(x, y, Block.STONE, true)
world.setTileWall(x, y, Block.STONE) world.setTileWall(x, y, Block.STONE, true)
} }
} }
} }

View File

@@ -28,8 +28,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
(0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs -> (0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs ->
ThreadExecutor.submit { ThreadExecutor.submit {
val localJoise = getGenerator(seed, params as TerragenParams) val localJoise = getGenerator(seed, params as TerragenParams)
val localLock = java.lang.Object() // in an attempt to fix the "premature exit" issue of a thread run //val localLock = java.lang.Object() // in an attempt to fix the "premature exit" issue of a thread run
synchronized(localLock) { // also see: https://stackoverflow.com/questions/28818494/threads-stopping-prematurely-for-certain-values //synchronized(localLock) { // also see: https://stackoverflow.com/questions/28818494/threads-stopping-prematurely-for-certain-values
for (x in xs) { for (x in xs) {
for (y in 0 until world.height) { for (y in 0 until world.height) {
val sampleTheta = (x.toDouble() / world.width) * TWO_PI val sampleTheta = (x.toDouble() / world.width) * TWO_PI
@@ -43,7 +43,7 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
draw(x, y, noise, world) draw(x, y, noise, world)
} }
} }
} //}
} }
} }
@@ -71,8 +71,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
val wallBlock = groundDepthBlock[terr] val wallBlock = groundDepthBlock[terr]
val terrBlock = if (cave == 0) Block.AIR else wallBlock //wallBlock * cave // AIR is always zero, this is the standard val terrBlock = if (cave == 0) Block.AIR else wallBlock //wallBlock * cave // AIR is always zero, this is the standard
world.setTileTerrain(x, y, terrBlock) world.setTileTerrain(x, y, terrBlock, true)
world.setTileWall(x, y, wallBlock) world.setTileWall(x, y, wallBlock, true)
} }