ungenerated chunks are now filled with 0xFFFF

This commit is contained in:
minjaesong
2024-07-11 16:02:57 +09:00
parent d8e6a01735
commit 7b6d7f2b93
13 changed files with 45 additions and 28 deletions

View File

@@ -156,6 +156,7 @@
"4094";"N/A";"N/A";"ACTORBLOCK_NO_PASS_RIGHT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"N/A";"0";"0";"4";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0";"INTERNAL,ACTORBLOCK,NORANDTILE"
"4095";"N/A";"N/A";"ACTORBLOCK_NO_PASS_LEFT";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"N/A";"0";"0";"4";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0";"INTERNAL,ACTORBLOCK,NORANDTILE"
"-1";"N/A";"N/A";"BLOCK_NULL";"4.0000";"4.0000";"4.0000";"4.0000";"-1";"2600";"NULL";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"INTERNAL,NORANDTILE"
"-2";"N/A";"N/A";"BLOCK_NULL";"4.0000";"4.0000";"4.0000";"4.0000";"-1";"2600";"NULL";"1";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"INTERNAL,NORANDTILE"
## Notes ##
Can't render this file because it contains an unexpected character in line 18 and column 2.

View File

@@ -132,5 +132,6 @@ object Block {
const val WATER = "basegame:4095"
const val NULL = "basegame:-1"
const val NOT_GENERATED = "basegame:-2"
}

View File

@@ -12,5 +12,4 @@ object Fluid {
val WATER = "fluid@basegame:1"
val LAVA = "fluid@basegame:2"
}

View File

@@ -30,7 +30,7 @@ open class BlockLayerI16(override val width: Int, override val height: Int) : Bl
get() = ptr.destroyed
init {
ptr.fillWith(0)
ptr.fillWith(-1)
}
/**

View File

@@ -29,7 +29,7 @@ class BlockLayerI16F16(override val width: Int, override val height: Int) : Bloc
get() = ptr.destroyed
init {
ptr.fillWith(0)
ptr.fillWith(-1)
}
/**

View File

@@ -13,7 +13,7 @@ import net.torvald.unsafe.UnsafePtr
* where a_n is a tile number, p_n is a placement index
* Created by minjaesong on 2023-10-10.
*/
class BlockLayerI16I8 (override val width: Int, override val height: Int) : BlockLayer {
class BlockLayerOresI16I8 (override val width: Int, override val height: Int) : BlockLayer {
override val bytesPerBlock = BYTES_PER_BLOCK
// for some reason, all the efforts of saving the memory space were futile.
@@ -25,7 +25,7 @@ class BlockLayerI16I8 (override val width: Int, override val height: Int) : Bloc
get() = ptr.destroyed
init {
ptr.fillWith(0)
ptr.fillWith(0) // there is no NOT-GENERATED for ores, keep it as 0
}
/**

View File

@@ -86,7 +86,7 @@ open class GameWorld(
//layers
@Transient open lateinit var layerWall: BlockLayerI16
@Transient open lateinit var layerTerrain: BlockLayerI16
@Transient open lateinit var layerOres: BlockLayerI16I8 // damage to the block follows `terrainDamages`
@Transient open lateinit var layerOres: BlockLayerOresI16I8 // damage to the block follows `terrainDamages`
@Transient open lateinit var layerFluids: BlockLayerI16F16
val wallDamages = HashArray<Float>()
val terrainDamages = HashArray<Float>()
@@ -146,22 +146,25 @@ open class GameWorld(
)
@Transient private val forcedTileNumberToNames = hashSetOf(
Block.AIR, Block.UPDATE
Block.AIR, Block.UPDATE, Block.NOT_GENERATED
)
@Transient private val forcedFluidNumberToTiles = hashSetOf(
Fluid.NULL
)
val tileNumberToNameMap = HashArray<ItemID>().also {
it[0] = Block.AIR
it[2] = Block.UPDATE
it[1] = Block.UPDATE
it[65535] = Block.NOT_GENERATED // unlike Block.NULL, this one is solid
}
val fluidNumberToNameMap = HashArray<ItemID>().also {
it[0] = Fluid.NULL
it[65535] = Fluid.NULL // 65535 denotes "not generated"
}
// does not go to the savefile
@Transient val tileNameToNumberMap = HashMap<ItemID, Int>().also {
it[Block.AIR] = 0
it[Block.UPDATE] = 2
it[Block.UPDATE] = 1
it[Block.NOT_GENERATED] = 65535 // unlike Block.NULL, this one is solid
}
@Transient val fluidNameToNumberMap = HashMap<ItemID, Int>().also {
it[Fluid.NULL] = 0
@@ -221,7 +224,7 @@ open class GameWorld(
layerTerrain = BlockLayerI16(width, height)
layerWall = BlockLayerI16(width, height)
layerOres = BlockLayerI16I8(width, height)
layerOres = BlockLayerOresI16I8(width, height)
layerFluids = BlockLayerI16F16(width, height)
chunkFlags = Array(height / CHUNK_H) { ByteArray(width / CHUNK_W) }
@@ -252,8 +255,13 @@ open class GameWorld(
fun coordInWorldStrict(x: Int, y: Int) = x in 0 until width && y in 0 until height // ROUNDWORLD implementation
fun renumberTilesAfterLoad() {
// patch the "old"map
tileNumberToNameMap[0] = Block.AIR
tileNumberToNameMap[1] = Block.UPDATE
tileNumberToNameMap[65535] = Block.NOT_GENERATED
// before the renaming, update the name maps
val oldTileNumberToNameMap: Map<Long, ItemID> = tileNumberToNameMap.toMap()
tileNumberToNameMap.clear()
tileNameToNumberMap.clear()
App.tileMaker.tags.forEach {
@@ -263,24 +271,29 @@ open class GameWorld(
tileNameToNumberMap[it.key] = it.value.tileNumber
}
// force this rule to the old saves
tileNumberToNameMap[0] = Block.AIR
tileNumberToNameMap[1] = Block.UPDATE
tileNumberToNameMap[65535] = Block.NOT_GENERATED
tileNameToNumberMap[Block.AIR] = 0
tileNameToNumberMap[Block.UPDATE] = 1
tileNameToNumberMap[Block.NOT_GENERATED] = 65535
fluidNumberToNameMap[0] = Fluid.NULL
fluidNumberToNameMap[65535] = Fluid.NULL
fluidNameToNumberMap[Fluid.NULL] = 0
// perform renaming of tile layers
for (y in 0 until layerTerrain.height) {
for (x in 0 until layerTerrain.width) {
layerTerrain.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerTerrain.unsafeGetTile(x, y).toLong()]]!!)
layerWall.unsafeSetTile(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerWall.unsafeGetTile(x, y).toLong()]]!!)
layerOres.unsafeSetTileKeepPlacement(x, y, tileNameToNumberMap[oldTileNumberToNameMap[layerOres.unsafeGetTile(x, y).toLong()]]!!)
val oldNum = layerOres.unsafeGetTile(x, y).toLong()
val oldName = oldTileNumberToNameMap[oldNum]
layerOres.unsafeSetTileKeepPlacement(x, y, oldName.let { tileNameToNumberMap[it] ?: throw NullPointerException("Unknown tile name: $oldName (<- $oldNum)") })
}
}
// force this rule to the old saves
tileNumberToNameMap[0] = Block.AIR
tileNumberToNameMap[2] = Block.UPDATE
tileNameToNumberMap[Block.AIR] = 0
tileNameToNumberMap[Block.UPDATE] = 2
fluidNumberToNameMap[0] = Fluid.NULL
fluidNameToNumberMap[Fluid.NULL] = 0
BlocksDrawer.rebuildInternalPrecalculations()
}

View File

@@ -53,6 +53,9 @@ internal object ExportMap : ConsoleCommand {
var mapDataPointer = 0
for ((terr, wall, ore) in world.terrainIterator()) {
val terr = if (terr == "basegame:-2") "basegame:-1" else terr
val wall = if (wall == "basegame:-2") "basegame:-1" else wall // world.getTileFromWall() returns item ID WITHOUT wall tag
val colOre = (oreColourMap.get(ore) ?: throw NullPointerException("nullore $ore")).toByteArray()
val colFore = (App.tileMaker.terrainTileColourMap.get(terr) ?: throw NullPointerException("nullterr $terr")).toByteArray()
val colWall = (App.tileMaker.terrainTileColourMap.get(wall) ?: throw NullPointerException("nullwall $wall")).cpy().mul(WALL_OVERLAY).toByteArray()

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameworld.BlockLayerI16
import net.torvald.terrarum.gameworld.BlockLayerI16F16
import net.torvald.terrarum.gameworld.BlockLayerI16I8
import net.torvald.terrarum.gameworld.BlockLayerOresI16I8
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.GameWorld.Companion.CHUNK_LOADED
import net.torvald.terrarum.langpack.Lang
@@ -150,7 +150,7 @@ object LoadSavegame {
world.layerTerrain = BlockLayerI16(world.width, world.height)
world.layerWall = BlockLayerI16(world.width, world.height)
world.layerOres = BlockLayerI16I8(world.width, world.height)
world.layerOres = BlockLayerOresI16I8(world.width, world.height)
world.layerFluids = BlockLayerI16F16(world.width, world.height)
world.chunkFlags = Array(world.height / LandUtil.CHUNK_H) { ByteArray(world.width / LandUtil.CHUNK_W) }

View File

@@ -4,8 +4,6 @@ import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.NoSerialise
import net.torvald.terrarum.gameworld.BlockLayer
import net.torvald.terrarum.gameworld.BlockLayerI16
import net.torvald.terrarum.gameworld.BlockLayerI16I8
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
@@ -14,7 +12,6 @@ import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.savegame.ByteArray64
import net.torvald.terrarum.savegame.ByteArray64Writer
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.serialise.toUint
import net.torvald.terrarum.utils.PlayerLastStatus
import net.torvald.terrarum.weather.WeatherMixer
import java.io.File

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum.serialise
import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.utils.JsonValue
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameitems.ItemID

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameworld.BlockLayerI16F16
import net.torvald.terrarum.gameworld.BlockLayerI16I8
import net.torvald.terrarum.gameworld.BlockLayerOresI16I8
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.SimpleGameWorld
import java.io.File
@@ -25,7 +25,7 @@ object ReadSimpleWorld {
world.tileNumberToNameMap.forEach { l, s ->
world.tileNameToNumberMap[s] = l.toInt()
}
world.layerOres = BlockLayerI16I8(world.width, world.height)
world.layerOres = BlockLayerOresI16I8(world.width, world.height)
world.layerFluids = BlockLayerI16F16(world.width, world.height)
ItemCodex.loadFromSave(origin, world.dynamicToStaticTable, world.dynamicItemInventory)

View File

@@ -11,6 +11,7 @@ import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.utils.HashArray
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.AtlasSource.*
@@ -310,6 +311,9 @@ class CreateTileAtlas {
)
}
// special colour
terrainTileColourMap[Block.NULL] = Cvec(1f, 0f, 0f, 1f)
itemTerrainTexture = Texture(itemTerrainPixmap)
itemTerrainTextureGlow = Texture(itemTerrainPixmapGlow)
itemTerrainTextureEmissive = Texture(itemTerrainPixmapEmissive)