fluids separated from blocks

This commit is contained in:
minjaesong
2023-10-09 17:35:26 +09:00
parent dd1e53f761
commit d9218a2dd6
15 changed files with 89 additions and 79 deletions

View File

@@ -245,29 +245,6 @@ internal object BlocksDrawer {
}*/
}
/**
* Returns a tile number as if we're addressing tile number in the main atlas. That is, returning int of
* 18 means will point to the tile (32, 1) of the fluid atlas.
*
* This behaviour is to keep compatibility with World.getTile() method, this method need to mimic the World's
* behaviour to return "starting point" of the tile, so nearby information (int 0..15) can simply be added to
* the X-position that can be deduced from the tile number.
*
* As a consequence, fluids.tga must have the same width as tiles.tga.
*/
private fun GameWorld.FluidInfo.toTileInFluidAtlas(): Int {
val fluidNum = this.type.abs()
if (this.amount >= WorldSimulator.FLUID_MIN_MASS) {
val fluidLevel = this.amount.coerceIn(0f,1f).times(15).roundToInt()
return fluidLevel * 16 + fluidNum
}
else {
return 0
}
}
/**
* Turns bitmask-with-single-bit-set into its bit index. The LSB is counted as 1, and thus the index starts at one.
* @return 0 -> -1, 1 -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16 -> 4, ...
@@ -288,6 +265,8 @@ 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
@@ -326,9 +305,9 @@ internal object BlocksDrawer {
val nearbyTilesInfo = if (mode == OCCLUSION) {
getNearbyTilesInfoFakeOcc(x, y)
}
else if (mode == FLUID) {
/*else if (mode == FLUID) {
getNearbyTilesInfoFluids(x, y)
}
}*/
else if (isPlatform(thisTile)) {
getNearbyTilesInfoPlatform(x, y)
}
@@ -347,9 +326,9 @@ 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
// if (mode == FLUID)
// App.tileMaker.fluidToTileNumber(world.getFluid(x, y))
// else
renderTag.tileNumber
var tileNumber = if (thisTile == Block.AIR) 0
// special case: actorblocks and F3 key
@@ -451,7 +430,7 @@ 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) }
@@ -464,7 +443,7 @@ internal object BlocksDrawer {
}
return ret
}
}*/
private fun getNearbyTilesInfoWallSticker(x: Int, y: Int): Int {
val nearbyTiles = arrayOf(Block.NULL, Block.NULL, Block.NULL, Block.NULL)

View File

@@ -273,14 +273,6 @@ class CreateTileAtlas {
return tags.getOrDefault(blockID, defaultRenderTag)
}
fun fluidFillToTileLevel(fill: Float) = fill.times(8).roundToInt().coerceIn(0, 8)
fun fluidToTileNumber(fluid: GameWorld.FluidInfo): Int {
val fluidLevel = fluidFillToTileLevel(fluid.amount)
return if (fluid.type == Fluid.NULL || fluidLevel == 0) 0 else
16 + (376 * (fluid.type.abs() - 1)) + (47 * (fluidLevel - 1))
}
val nullTile = Pixmap(TILE_SIZE * 16, TILE_SIZE * 16, Pixmap.Format.RGBA8888)
private fun fileToAtlantes(modname: String, matte: FileHandle, glow: FileHandle?) {

View File

@@ -9,9 +9,7 @@ import net.torvald.gdx.graphics.UnsafeCvecArray
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.blockproperties.BlockProp
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.blockproperties.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
@@ -451,7 +449,7 @@ object LightmapRenderer {
private val _thisTileLuminosity = Cvec(0)
private var _thisTerrainProp: BlockProp = BlockProp()
private var _thisWallProp: BlockProp = BlockProp()
private var _thisFluidProp: BlockProp = BlockProp()
private var _thisFluidProp: FluidProp = FluidProp()
private fun precalculate(rawx: Int, rawy: Int) {
val lx = rawx.convX(); val ly = rawy.convY()
@@ -470,7 +468,7 @@ object LightmapRenderer {
_thisWall = world.getTileFromWallRaw(worldX, worldY)
_thisWallProp = BlockCodex[world.tileNumberToNameMap[_thisWall.toLong()]]
_thisFluid = world.getFluid(worldX, worldY)
_thisFluidProp = BlockCodex[_thisFluid.type]
_thisFluidProp = FluidCodex[_thisFluid.type]
// regarding the issue #26
@@ -500,7 +498,7 @@ object LightmapRenderer {
_fluidAmountToCol.set(_thisFluid.amount, _thisFluid.amount, _thisFluid.amount, _thisFluid.amount)
_thisTileLuminosity.set(_thisTerrainProp.getLumCol(worldX, worldY))
_thisTileLuminosity.maxAndAssign(_thisFluidProp.getLumCol(worldX, worldY).mul(_fluidAmountToCol))
_thisTileLuminosity.maxAndAssign(_thisFluidProp.lumCol.mul(_fluidAmountToCol))
_mapThisTileOpacity.setVec(lx, ly, _thisTerrainProp.opacity)
_mapThisTileOpacity.max(lx, ly, _thisFluidProp.opacity.mul(_fluidAmountToCol))
}