diff --git a/assets/mods/basegame/fluid/1.tga b/assets/mods/basegame/fluid/1.tga index ef46626d4..f2f320991 100644 --- a/assets/mods/basegame/fluid/1.tga +++ b/assets/mods/basegame/fluid/1.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:844f0828124f0f20ddf23f06a5c454d35f0d71a193b14ef5b04eda14a4915da0 -size 18450 +oid sha256:a345ad105c6c97434f619e4035c10f62b0390ec43a7dc6ccad076bbe3792beac +size 55314 diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index f676b1d59..d763fd741 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -346,7 +346,7 @@ internal object BlocksDrawer { val (wx, wy) = world.coerceXY(x, y) - val thisTile: Int = when (mode) { + var thisTile: Int = when (mode) { WALL -> world.layerWall.unsafeGetTile(wx, wy) TERRAIN -> world.layerTerrain.unsafeGetTile(wx, wy) ORES -> world.layerOres.unsafeGetTile(wx, wy)//.also { println(it) } @@ -370,12 +370,36 @@ internal object BlocksDrawer { 0 } 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) + val solids = getNearbyTilesInfoTileCnx(x, y) + val notSolid = 15 - solids + val fluids = getNearbyFluidsInfo(x, y) + val fmask = getFluidMaskStatus(fluids) + + val tileToUse = fluidCornerLut[notSolid and fmask] and fluidCornerLut[solids] + + + val nearbyFluidType = fluids.filter { it.amount >= 0.5f / 16f }.map { it.type }.filter { it.startsWith("fluid@") }.sorted().firstOrNull() + + val fillThis = + world.layerFluids.unsafeGetTile1(wx, wy).second.let { if (it.isNaN()) 0f else it } + + val tile = + world.getTileFromTerrain(wx, wy) + + if (/*fluidCornerLut[solids] != 0 &&*/ BlockCodex[tile].isSolidForTileCnx && nearbyFluidType != null) { + thisTile = world.tileNameToNumberMap[nearbyFluidType]!! + 18 + tileToUse } + else if (thisTile == 0) + 0 + else if (fluids[3].amount >= 1.5f / 16f) + 17 + else if (fluids[3].amount >= 0.5f / 16f) + 16 + else if (fillThis < 0.5f / 16f) + 0 + else + (fillThis * 16f - 0.5f).roundToInt().coerceIn(0, 15) } else if (treeLeavesTiles.binarySearch(thisTile) >= 0) { getNearbyTilesInfoTrees(x, y, mode).swizzle8(thisTile, hash) @@ -469,6 +493,8 @@ internal object BlocksDrawer { arrayOf(0,2,1,5,6,3,4,7), ) + private val fluidCornerLut = arrayOf(15,12,9,8,3,0,1,0,6,4,0,0,2,0,0,0) + private fun Int.swizzleH2(tile: Int, hash: Int): Int { return h2lut[hash][this] } @@ -486,6 +512,15 @@ internal object BlocksDrawer { ) } + private fun getNearbyTilesPos4(x: Int, y: Int): Array { + return arrayOf( + Point2i(x + 1, y), + Point2i(x, y + 1), + Point2i(x - 1, y), + Point2i(x, y - 1), + ) + } + private fun getNearbyTilesInfoConSelf(x: Int, y: Int, mode: Int, mark: ItemID?): Int { val nearbyTiles = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) } @@ -553,6 +588,36 @@ internal object BlocksDrawer { return ret } + private fun getNearbyTilesInfoTileCnx(x: Int, y: Int): Int { + val nearbyTiles: List = getNearbyTilesPos4(x, y).map { world.getTileFromTerrain(it.x, it.y) } + + var ret = 0 + for (i in nearbyTiles.indices) { + if (BlockCodex[nearbyTiles[i]].isSolidForTileCnx) { + ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3 + } + } + + return ret + } + + private fun getNearbyFluidsInfo(x: Int, y: Int): List { + val nearbyTiles: List = getNearbyTilesPos4(x, y).map { world.getFluid(it.x, it.y) } + return nearbyTiles + } + + private val fluidSolidMaskLut = arrayOf(0b1010, 0b1000, 0b0010, 0b0000) + private fun getFluidMaskStatus(nearbyFluids: List): Int { + // TODO reverse gravity + + val D = (nearbyFluids[1].amount >= 15.5f / 16f) + val U = (nearbyFluids[3].amount >= 0.5f / 16f) + + val i = D.toInt(0) or U.toInt(1) + + return fluidSolidMaskLut[i] + } + private fun getNearbyTilesInfoTrees(x: Int, y: Int, mode: Int): Int { val tileThis = world.getTileFromTerrain(x, y) val nearbyTiles: List = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) } @@ -576,6 +641,8 @@ internal object BlocksDrawer { return ret } + private fun Int.popcnt() = Integer.bitCount(this) + /** * Basically getNearbyTilesInfoConMutual() but connects mutually with all the fluids */ diff --git a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt index 9c0ce6dc8..958cb81d3 100644 --- a/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt +++ b/src/net/torvald/terrarum/worlddrawer/CreateTileAtlas.kt @@ -392,7 +392,7 @@ class CreateTileAtlas { drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, RenderTag.MASK_FLUID) } // predefined by the image dimension: 288x16 - else if (tilesPixmap.width == TILE_SIZE * 18 && tilesPixmap.height == TILE_SIZE) { + else if (tilesPixmap.width == TILE_SIZE * 18 && tilesPixmap.height == TILE_SIZE * 3) { addTag(blockID, RenderTag.CONNECT_SELF, RenderTag.MASK_16X16) drawToAtlantes(tilesPixmap, tilesGlowPixmap, tilesEmissivePixmap, RenderTag.MASK_16X16) }