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

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