Fluid.NULL is identical to Block.AIR

This commit is contained in:
minjaesong
2024-07-15 00:48:52 +09:00
parent bddd871c9d
commit 5f1b860555
9 changed files with 74 additions and 63 deletions

View File

@@ -1,3 +0,0 @@
"id";"name";"shdr";"shdg";"shdb";"shduv";"str";"dsty";"mate";"lumr";"lumg";"lumb";"lumuv";"colour";"vscs";"refl";"tags"
"1";"BLOCK_WATER";"0.1016";"0.0744";"0.0508";"0.0826";"100";"1000";"WATR";"0.0000";"0.0000";"0.0000";"0.0000";"005599A6";"16";"0.0";"NATURAL"
"2";"BLOCK_LAVA";"0.9696";"0.9696";"0.9696";"0.9696";"100";"2600";"ROCK"; "0.7664";"0.2032";"0.0000";"0.0000";"FF4600E6";"32";"0.0";"NATURAL,MOLTEN"
1 id name shdr shdg shdb shduv str dsty mate lumr lumg lumb lumuv colour vscs refl tags
2 1 BLOCK_WATER 0.1016 0.0744 0.0508 0.0826 100 1000 WATR 0.0000 0.0000 0.0000 0.0000 005599A6 16 0.0 NATURAL
3 2 BLOCK_LAVA 0.9696 0.9696 0.9696 0.9696 100 2600 ROCK 0.7664 0.2032 0.0000 0.0000 FF4600E6 32 0.0 NATURAL,MOLTEN

View File

@@ -763,7 +763,7 @@ object ModMgr {
}
object GameFluidLoader {
const val fluidPath = "fluids/"
const val fluidPath = "fluid/"
init {
Terrarum.fluidCodex = FluidCodex()

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.gameitems.ItemID
*/
object Fluid {
val NULL = "fluid@basegame:0"
val NULL = Block.AIR
val WATER = "fluid@basegame:1"
val LAVA = "fluid@basegame:2"

View File

@@ -33,6 +33,9 @@ class FluidCodex {
}
}
fun getOrNull(blockID: ItemID?): FluidProp? {
return fluidProps[blockID]
}
/**
* Later entry (possible from other modules) will replace older ones

View File

@@ -145,30 +145,32 @@ open class GameWorld(
30L * WorldTime.MINUTE_SEC
)
// Terrain, ores and fluids all use the same number space
@Transient private val forcedTileNumberToNames = hashSetOf(
Block.AIR, Block.UPDATE, Block.NOT_GENERATED
)
@Transient private val forcedFluidNumberToTiles = hashSetOf(
/*@Transient private val forcedFluidNumberToTiles = hashSetOf(
Fluid.NULL
)
)*/
val tileNumberToNameMap = HashArray<ItemID>().also {
it[0] = Block.AIR
it[1] = Block.UPDATE
it[65535] = Block.NOT_GENERATED // unlike Block.NULL, this one is solid
}
val fluidNumberToNameMap = HashArray<ItemID>().also {
/*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] = 1
it[Block.NOT_GENERATED] = 65535 // unlike Block.NULL, this one is solid
}
@Transient val fluidNameToNumberMap = HashMap<ItemID, Int>().also {
/*@Transient val fluidNameToNumberMap = HashMap<ItemID, Int>().also {
it[Fluid.NULL] = 0
}
}*/
val extraFields = HashMap<String, Any?>()
@@ -248,12 +250,12 @@ open class GameWorld(
tileNameToNumberMap[it.key] = it.value.tileNumber
}
}
Terrarum.fluidCodex.fluidProps.entries.forEach {
/*Terrarum.fluidCodex.fluidProps.entries.forEach {
if (!forcedFluidNumberToTiles.contains(it.key)) {
fluidNumberToNameMap[it.value.numericID.toLong()] = it.key
fluidNameToNumberMap[it.key] = it.value.numericID
}
}
}*/
}
}
@@ -276,10 +278,10 @@ open class GameWorld(
tileNumberToNameMap[it.value.tileNumber.toLong()] = it.key
tileNameToNumberMap[it.key] = it.value.tileNumber
}
Terrarum.fluidCodex.fluidProps.entries.forEach {
/*Terrarum.fluidCodex.fluidProps.entries.forEach {
fluidNumberToNameMap[it.value.numericID.toLong()] = it.key
fluidNameToNumberMap[it.key] = it.value.numericID
}
}*/
// force this rule to the old saves
tileNumberToNameMap[0] = Block.AIR
@@ -288,9 +290,9 @@ open class GameWorld(
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
// fluidNumberToNameMap[0] = Fluid.NULL
// fluidNumberToNameMap[65535] = Fluid.NULL
// fluidNameToNumberMap[Fluid.NULL] = 0
// perform renaming of tile layers
for (y in 0 until layerTerrain.height) {
@@ -402,7 +404,7 @@ open class GameWorld(
terrainDamages.remove(blockAddr)
if (BlockCodex[itemID].isSolid) {
layerFluids.unsafeSetTile(x, y, fluidNameToNumberMap[Fluid.NULL]!!, 0f)
layerFluids.unsafeSetTile(x, y, tileNameToNumberMap[Fluid.NULL]!!, 0f)
// Terrarum.ingame?.modified(LandUtil.LAYER_FLUID, x, y)
}
// fluid tiles-item should be modified so that they will also place fluid onto their respective map
@@ -751,7 +753,7 @@ open class GameWorld(
wallDamages[LandUtil.getBlockAddr(this, x, y)] ?: 0f
fun setFluid(x: Int, y: Int, fluidType: ItemID, fill: Float) {
if (!fluidType.isFluid()) throw IllegalArgumentException("Fluid type is not actually fluid: $fluidType")
if (!fluidType.isFluid() && fluidType != Block.AIR) throw IllegalArgumentException("Fluid type is not actually fluid: $fluidType")
/*if (x == 60 && y == 256) {
printdbg(this, "Setting fluid $fill at ($x,$y)")
@@ -765,7 +767,7 @@ open class GameWorld(
// val addr = LandUtil.getBlockAddr(this, x, y)
val fluidNumber = fluidNameToNumberMap[fluidType]!!
val fluidNumber = tileNameToNumberMap[fluidType] ?: throw NullPointerException("No such fluid: $fluidType")
if (fill > WorldSimulator.FLUID_MIN_MASS) {
//setTileTerrain(x, y, fluidTypeToBlock(fluidType))
@@ -786,7 +788,10 @@ open class GameWorld(
fun getFluid(x: Int, y: Int): FluidInfo {
val (x, y) = coerceXY(x, y)
val (type, fill) = layerFluids.unsafeGetTile1(x, y)
val fluidID = fluidNumberToNameMap[type.toLong()] ?: throw NullPointerException("No such fluid: $type")
var fluidID = tileNumberToNameMap[type.toLong()] ?: throw NullPointerException("No such fluid: $type")
if (fluidID == Block.NULL || fluidID == Block.NOT_GENERATED)
fluidID = Fluid.NULL
return FluidInfo(fluidID, fill.let { if (it.isNaN()) 0f else it }) // hex FFFFFFFF (magic number for ungenerated tiles) is interpreted as Float.NaN
}

View File

@@ -451,10 +451,6 @@ object WorldSimulator {
fluidTypeMap[y][x] = fluidData.type
fluidNewMap[y][x] = fluidData.amount
fluidNewTypeMap[y][x] = fluidData.type
/*if (x + updateXFrom == 60 && y + updateYFrom == 256) {
printdbg(this, "making array amount ${fluidData.amount} for (60,256)")
}*/
}
}
}

View File

@@ -325,7 +325,7 @@ class BasicDebugInfoWindow : UICanvas() {
App.fontSmallNumbers.draw(batch, "$ccO$WIRE$ccG$wireCount ${ccY}X$ccO$mouseTileX ${ccY}Y$ccO$mouseTileY", gap + 7f*(tileCursX + 3), line(tileCursY + 3))
App.fontSmallNumbers.draw(batch, "$ccR$rawR $ccG$rawG $ccB$rawB $ccW$rawA", gap + 7f*(tileCursX + 3), line(tileCursY + 4))
App.fontSmallNumbers.draw(batch, "$ccO${TERRAIN}D $ccG$tdmg $ccO${WALL}D $ccG$wdmg", gap + 7f*(tileCursX + 3), line(tileCursY + 5))
App.fontSmallNumbers.draw(batch, "$ccO$LIQUID$ccG${fluid.type.substring(6).padEnd(15)}$ccO$BEAKER$ccG${fluid.amount.toIntAndFrac(2)}", gap + 7f*(tileCursX + 3), line(tileCursY + 6))
App.fontSmallNumbers.draw(batch, "$ccO$LIQUID$ccG${fluid.type.padEnd(16)}$ccO$BEAKER$ccG${fluid.amount.toIntAndFrac(2)}", gap + 7f*(tileCursX + 3), line(tileCursY + 6))
batch.draw(icons.get(4,0), gap + 7f*tileCursX, line(tileCursY + 1) + 7)
}

View File

@@ -16,6 +16,7 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.WorldSimulator.FLUID_MIN_MASS
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.serialise.toBig64
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR
@@ -218,7 +219,6 @@ internal object BlocksDrawer {
drawTiles(ORES)
drawTiles(FLUID)
drawTiles(OCCLUSION)
//drawTiles(WIRE)
}
}
}
@@ -330,8 +330,6 @@ internal object BlocksDrawer {
* @param wire coduitTypes bit that is selected to be drawn. Must be the power of two.
*/
private fun drawTiles(mode: Int) {
if (mode == FLUID) return
// can't be "WorldCamera.y / TILE_SIZE":
// ( 3 / 16) == 0
// (-3 / 16) == -1 <-- We want it to be '-1', not zero
@@ -363,7 +361,10 @@ internal object BlocksDrawer {
WALL -> world.layerWall.unsafeGetTile(wx, wy)
TERRAIN -> world.layerTerrain.unsafeGetTile(wx, wy)
ORES -> world.layerOres.unsafeGetTile(wx, wy)//.also { println(it) }
FLUID -> 0 // TODO need new wire storing format //world.getFluid(x, y).type.abs()
FLUID -> world.layerFluids.unsafeGetTile1(wx, wy).let { (number, fill) ->
if (fill < 1f/30f) 0
else number
}
OCCLUSION -> 0
else -> throw IllegalArgumentException()
}
@@ -379,9 +380,14 @@ internal object BlocksDrawer {
else if (mode == ORES) {
0
}
/*else if (mode == FLUID) {
getNearbyTilesInfoFluids(x, y)
}*/
else if (mode == FLUID) {
if (thisTile == 0)
0
else {
val fill = world.layerFluids.unsafeGetTile1(wx, wy).second.let { if (it.isNaN()) 0f else it }
(fill * 15f).roundToInt().coerceIn(0, 15)
}
}
else if (treeLeavesTiles.binarySearch(thisTile) >= 0) {
getNearbyTilesInfoTrees(x, y, mode).swizzle8(thisTile, hash)
}
@@ -408,18 +414,14 @@ internal object BlocksDrawer {
}
val renderTag = if (mode == OCCLUSION) occlusionRenderTag else App.tileMaker.getRenderTag(thisTile)
val tileNumberBase =
// if (mode == FLUID)
// App.tileMaker.fluidToTileNumber(world.getFluid(x, y))
// else
renderTag.tileNumber
val tileNumberBase = renderTag.tileNumber
var tileNumber = if (thisTile == 0 && mode != OCCLUSION) 0
// special case: actorblocks and F3 key
else if (renderOnF3Only.binarySearch(thisTile) >= 0 && !KeyToggler.isOn(Keys.F3))
0
// special case: fluids
else if (mode == FLUID)
tileNumberBase + connectLut47[nearbyTilesInfo]
tileNumberBase + nearbyTilesInfo
// special case: ores
else if (mode == ORES)
tileNumberBase + world.layerOres.unsafeGetTile1(wx, wy).second
@@ -438,12 +440,8 @@ internal object BlocksDrawer {
tileNumber = 2 // black solid
}
var thisTileX = tileNumber % App.tileMaker.TILES_IN_X
var thisTileY = tileNumber / App.tileMaker.TILES_IN_X
if (mode == FLUID && thisTileX == 22 && thisTileY == 3) {
//println("tileNumberBase = $tileNumberBase, tileNumber = $tileNumber, fluid = ${world.getFluid(x, y)}")
}
val thisTileX = tileNumber % App.tileMaker.TILES_IN_X
val thisTileY = tileNumber / App.tileMaker.TILES_IN_X
val breakage = if (mode == TERRAIN || mode == ORES) world.getTerrainDamage(x, y) else if (mode == WALL) world.getWallDamage(x, y) else 0f
if (breakage.isNaN()) throw IllegalStateException("Block breakage at ($x, $y) is NaN (mode=$mode)")
@@ -591,20 +589,20 @@ internal object BlocksDrawer {
/**
* Basically getNearbyTilesInfoConMutual() but connects mutually with all the fluids
*/
/*private fun getNearbyTilesInfoFluids(x: Int, y: Int): Int {
private fun getNearbyTilesInfoFluids(x: Int, y: Int): Int {
val nearbyPos = getNearbyTilesPos(x, y)
val nearbyTiles: List<ItemID> = nearbyPos.map { world.getTileFromTerrain(it.x, it.y) }
var ret = 0
for (i in nearbyTiles.indices) {
val fluid = world.getFluid(nearbyPos[i].x, nearbyPos[i].y)
if (BlockCodex[nearbyTiles[i]].isSolidForTileCnx || (fluid.isFluid() && 0 < App.tileMaker.fluidFillToTileLevel(fluid.amount))) {
if (BlockCodex[nearbyTiles[i]].isSolidForTileCnx || (fluid.isFluid() && fluid.amount > FLUID_MIN_MASS)) {
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
}
}
return ret
}*/
}
private fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int {
val nearbyTiles = arrayOf(Block.NULL, Block.NULL, Block.NULL, Block.NULL)

View File

@@ -161,15 +161,15 @@ class CreateTileAtlas {
// val tgaListOres = ArrayList<Pair<String, FileHandle>>()
val tgaList = HashMap<String, ArrayList<Pair<String, FileHandle>>>() // Key: directory name, value: pair of <modname, filehandle>
val dirList = listOf("blocks", "ores")
dirList.forEach { dirName ->
tgaList[dirName] = ArrayList()
ModMgr.getGdxFilesFromEveryMod(dirName).forEach { (modname, dir) ->
val prefixes = listOf("blocks", "ores", "fluid")
prefixes.forEach { prefix ->
tgaList[prefix] = ArrayList()
ModMgr.getGdxFilesFromEveryMod(prefix).forEach { (modname, dir) ->
if (!dir.isDirectory) {
throw Error("Path '${dir.path()}' is not a directory")
}
if (dirName == "blocks") {
if (prefix == "blocks") {
// filter files that do not exist on the blockcodex
dir.list()
.filter { tgaFile -> tgaFile.extension() == "tga" && !tgaFile.isDirectory && (BlockCodex.getOrNull("$modname:${tgaFile.nameWithoutExtension()}") != null) }
@@ -177,11 +177,11 @@ class CreateTileAtlas {
.forEach { tgaFile: FileHandle -> // toInt() to sort by the number, not lexicographically
// tgaFile be like: ./assets/mods/basegame/blocks/32.tga (which is not always .tga)
val newFile = ModMgr.GameRetextureLoader.altFilePaths.getOrDefault(tgaFile.path(), tgaFile)
tgaList[dirName]!!.add(modname to newFile)
tgaList[prefix]!!.add(modname to newFile)
// printdbg(this, "modname = $modname, file = $newFile")
}
}
else {
else if (prefix == "ores") {
// filter files that do not exist on the orecodex
dir.list()
.filter { tgaFile -> tgaFile.extension() == "tga" && !tgaFile.isDirectory && (OreCodex.getOrNull("ores@$modname:${tgaFile.nameWithoutExtension()}") != null) }
@@ -189,7 +189,19 @@ class CreateTileAtlas {
.forEach { tgaFile: FileHandle -> // toInt() to sort by the number, not lexicographically
// tgaFile be like: ./assets/mods/basegame/blocks/32.tga (which is not always .tga)
val newFile = ModMgr.GameRetextureLoader.altFilePaths.getOrDefault(tgaFile.path(), tgaFile)
tgaList[dirName]!!.add(modname to newFile)
tgaList[prefix]!!.add(modname to newFile)
// printdbg(this, "modname = $modname, file = $newFile")
}
}
else if (prefix == "fluid") {
// filter files that do not exist on the orecodex
dir.list()
.filter { tgaFile -> tgaFile.extension() == "tga" && !tgaFile.isDirectory && (FluidCodex.getOrNull("fluid@$modname:${tgaFile.nameWithoutExtension()}") != null) }
.sortedBy { it.nameWithoutExtension().toInt() }
.forEach { tgaFile: FileHandle -> // toInt() to sort by the number, not lexicographically
// tgaFile be like: ./assets/mods/basegame/blocks/32.tga (which is not always .tga)
val newFile = ModMgr.GameRetextureLoader.altFilePaths.getOrDefault(tgaFile.path(), tgaFile)
tgaList[prefix]!!.add(modname to newFile)
// printdbg(this, "modname = $modname, file = $newFile")
}
}
@@ -199,9 +211,9 @@ class CreateTileAtlas {
// Sift through the file list for blocks, but TGA format first
dirList.forEach { dirName ->
tgaList[dirName]!!.forEach { (modname, filehandle) ->
printdbg(this, "processing $dirName $modname:${filehandle.name()}")
prefixes.forEach { prefix ->
tgaList[prefix]!!.forEach { (modname, filehandle) ->
printdbg(this, "processing $prefix $modname:${filehandle.name()}")
try {
val glowFile = Gdx.files.internal(
@@ -214,7 +226,7 @@ class CreateTileAtlas {
modname, filehandle,
if (glowFile.exists()) glowFile else null,
if (emissiveFile.exists()) emissiveFile else null,
if (dirName == "blocks") null else dirName
if (prefix == "blocks") null else prefix
)
}
catch (e: GdxRuntimeException) {
@@ -337,12 +349,12 @@ class CreateTileAtlas {
val nullTile = Pixmap(TILE_SIZE * 16, TILE_SIZE * 16, Pixmap.Format.RGBA8888)
private fun fileToAtlantes(modname: String, diffuse: FileHandle, glow: FileHandle?, emissive: FileHandle?, mode: String?) {
private fun fileToAtlantes(modname: String, diffuse: FileHandle, glow: FileHandle?, emissive: FileHandle?, prefix: String?) {
val tilesPixmap = Pixmap(diffuse)
val tilesGlowPixmap = if (glow != null) Pixmap(glow) else nullTile
val tilesEmissivePixmap = if (emissive != null) Pixmap(emissive) else nullTile
val blockName = diffuse.nameWithoutExtension().split('-').last().toInt() // basically a filename
val blockID = if (mode != null) "$mode@$modname:$blockName" else "$modname:$blockName"
val blockID = if (prefix != null) "$prefix@$modname:$blockName" else "$modname:$blockName"
// determine the type of the block (populate tags list)