mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixing random terragen crash? (was it block change event too big?)
This commit is contained in:
@@ -144,7 +144,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
*/
|
||||
open fun queueTerrainChangedEvent(old: ItemID, new: ItemID, position: Long) {
|
||||
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) {
|
||||
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) {
|
||||
val (x, y) = LandUtil.resolveBlockAddr(world, position)
|
||||
wireChangeQueue.addFirst(BlockChangeQueueItem(old, new, x, y))
|
||||
wireChangeQueue.addLast(BlockChangeQueueItem(old, new, x, y))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ open class GameWorld : Disposable {
|
||||
* *
|
||||
* @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 tilenum = tileNameToNumberMap[itemID]!!
|
||||
|
||||
@@ -277,7 +277,8 @@ open class GameWorld : Disposable {
|
||||
layerWall.unsafeSetTile(x, y, tilenum)
|
||||
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!
|
||||
*/
|
||||
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 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
|
||||
|
||||
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) {
|
||||
@@ -431,7 +433,7 @@ open class GameWorld : Disposable {
|
||||
|
||||
// remove tile from the world
|
||||
if (terrainDamages[addr] ?: 0f >= BlockCodex[getTileFromTerrain(x, y)].strength) {
|
||||
setTileTerrain(x, y, Block.AIR)
|
||||
setTileTerrain(x, y, Block.AIR, false)
|
||||
terrainDamages.remove(addr)
|
||||
return true
|
||||
}
|
||||
@@ -460,7 +462,7 @@ open class GameWorld : Disposable {
|
||||
|
||||
// remove tile from the world
|
||||
if (wallDamages[addr]!! >= BlockCodex[getTileFromWall(x, y)].strength) {
|
||||
setTileWall(x, y, Block.AIR)
|
||||
setTileWall(x, y, Block.AIR, false)
|
||||
wallDamages.remove(addr)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -84,19 +84,19 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
println("[BuildingMaker] Generating builder world...")
|
||||
|
||||
for (y in 0 until gameWorld.height) {
|
||||
gameWorld.setTileWall(0, y, Block.ILLUMINATOR_RED)
|
||||
gameWorld.setTileWall(gameWorld.width - 1, y, Block.ILLUMINATOR_RED)
|
||||
gameWorld.setTileTerrain(0, y, Block.ILLUMINATOR_RED_OFF)
|
||||
gameWorld.setTileTerrain(gameWorld.width - 1, y, Block.ILLUMINATOR_RED_OFF)
|
||||
gameWorld.setTileWall(0, y, Block.ILLUMINATOR_RED, true)
|
||||
gameWorld.setTileWall(gameWorld.width - 1, y, Block.ILLUMINATOR_RED, true)
|
||||
gameWorld.setTileTerrain(0, y, Block.ILLUMINATOR_RED_OFF, true)
|
||||
gameWorld.setTileTerrain(gameWorld.width - 1, y, Block.ILLUMINATOR_RED_OFF, true)
|
||||
}
|
||||
|
||||
for (y in 150 until gameWorld.height) {
|
||||
for (x in 1 until gameWorld.width - 1) {
|
||||
// wall layer
|
||||
gameWorld.setTileWall(x, y, Block.DIRT)
|
||||
gameWorld.setTileWall(x, y, Block.DIRT, true)
|
||||
|
||||
// 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
|
||||
PENMODE_PENCIL -> {
|
||||
if (palSelection.startsWith("wall@"))
|
||||
world.setTileWall(x, y, palSelection.substring(5))
|
||||
world.setTileWall(x, y, palSelection.substring(5), true)
|
||||
else
|
||||
world.setTileTerrain(x, y, palSelection)
|
||||
world.setTileTerrain(x, y, palSelection, true)
|
||||
}
|
||||
PENMODE_PENCIL_ERASE -> {
|
||||
if (currentPenTarget and PENTARGET_WALL != 0)
|
||||
world.setTileWall(x, y, Block.AIR)
|
||||
world.setTileWall(x, y, Block.AIR, true)
|
||||
else
|
||||
world.setTileTerrain(x, y, Block.AIR)
|
||||
world.setTileTerrain(x, y, Block.AIR, true)
|
||||
}
|
||||
PENMODE_EYEDROPPER -> {
|
||||
uiPaletteSelector.fore = if (world.getTileFromTerrain(x, y) == Block.AIR)
|
||||
|
||||
@@ -78,10 +78,10 @@ open class FixtureBase(
|
||||
// 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)
|
||||
world.setTileTerrain(x, y, if (y == posY) BlockBox.ALLOW_MOVE_DOWN else BlockBox.NO_COLLISION, false)
|
||||
}
|
||||
else
|
||||
world.setTileTerrain(x, y, blockBox.collisionType)
|
||||
world.setTileTerrain(x, y, blockBox.collisionType, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ open class FixtureBase(
|
||||
// remove filler block
|
||||
for (x in posX until posX + blockBox.width) {
|
||||
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 (y in posY until posY + blockBox.height) {
|
||||
if (world.getTileFromTerrain(x, y) == blockBox.collisionType) {
|
||||
world.setTileTerrain(x, y, Block.AIR)
|
||||
world.setTileTerrain(x, y, Block.AIR, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ object PlayerBuilderSigrid {
|
||||
try {
|
||||
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
|
||||
|
||||
@@ -56,14 +56,16 @@ object BlockBase {
|
||||
ingame.world.setTileWall(
|
||||
mouseTile.x,
|
||||
mouseTile.y,
|
||||
itemID.substring(5)
|
||||
itemID.substring(5),
|
||||
false
|
||||
)
|
||||
}
|
||||
else {
|
||||
ingame.world.setTileTerrain(
|
||||
mouseTile.x,
|
||||
mouseTile.y,
|
||||
itemID
|
||||
itemID,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -208,8 +208,8 @@ object WorldSimulator {
|
||||
// process the gradual falling of the selected "stack"
|
||||
if (!fallableStackProcessed && fallDownCounter != 0 && isFallable) {
|
||||
// replace blocks
|
||||
world.setTileTerrain(x, y, Block.AIR)
|
||||
world.setTileTerrain(x, y + fallDownCounter, currentTile)
|
||||
world.setTileTerrain(x, y, Block.AIR, true)
|
||||
world.setTileTerrain(x, y + fallDownCounter, currentTile, true)
|
||||
|
||||
fallableStackProcessed = true
|
||||
}
|
||||
|
||||
@@ -86,17 +86,17 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
when (control) {
|
||||
0 -> { // woodlands
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -109,8 +109,8 @@ class Biomegen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
}*/
|
||||
4 -> { // rockylands
|
||||
if (tileThis == Block.DIRT) {
|
||||
world.setTileTerrain(x, y, Block.STONE)
|
||||
world.setTileWall(x, y, Block.STONE)
|
||||
world.setTileTerrain(x, y, Block.STONE, true)
|
||||
world.setTileWall(x, y, Block.STONE, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ->
|
||||
ThreadExecutor.submit {
|
||||
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
|
||||
synchronized(localLock) { // also see: https://stackoverflow.com/questions/28818494/threads-stopping-prematurely-for-certain-values
|
||||
//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
|
||||
for (x in xs) {
|
||||
for (y in 0 until world.height) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
val wallBlock = groundDepthBlock[terr]
|
||||
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.setTileWall(x, y, wallBlock)
|
||||
world.setTileTerrain(x, y, terrBlock, true)
|
||||
world.setTileWall(x, y, wallBlock, true)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user