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

@@ -130,8 +130,6 @@
"4093";"N/A";"N/A";"ACTORBLOCK_ALLOW_MOVE_DOWN";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"0";"N/A";"0";"0";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0";"INTERNAL,ACTORBLOCK,PLATFORM"
"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"
"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"
"65536";"N/A";"N/A";"BLOCK_WATER";"0.1016";"0.0744";"0.0508";"0.0826";"100";"1000";"WATR";"0";"0";"0";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"005599A6";"16";"0.0";"NATURAL"
"65537";"N/A";"N/A";"BLOCK_LAVA";"0.9696";"0.9696";"0.9696";"0.9696";"100";"2600";"ROCK";"0";"0";"0";"0";"0";"16";"0.7664";"0.2032";"0.0000";"0.0000";"FF4600E6";"32";"0.0";"NATURAL"
"-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"
1 id drop spawn name shdr shdg shdb shduv str dsty mate solid wall grav dlfn fv fr lumr lumg lumb lumuv colour vscs refl tags
130 65536 -1 N/A N/A BLOCK_WATER BLOCK_NULL 0.1016 4.0000 0.0744 4.0000 0.0508 4.0000 0.0826 4.0000 100 -1 1000 2600 WATR NULL 0 0 1 0 N/A 0 0 16 0.0000 0.0000 0.0000 0.0000 005599A6 N/A 16 N/A 0.0 NATURAL INTERNAL
131 65537 ## Notes ##
132 -1 #
## Notes ##
#
133 # Every block must have a shade value that is at least as dark as the air block's
134 #
135 # Lava/Water props are left for future references, do not delete them until FluidCodex is built #

View File

@@ -0,0 +1,3 @@
"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

@@ -18,6 +18,7 @@ import net.torvald.terrarum.App.*
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.FluidCodex
import net.torvald.terrarum.blockproperties.WireCodex
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorID
@@ -76,6 +77,7 @@ object Terrarum : Disposable {
var factionCodex = FactionCodex(); internal set
var craftingCodex = CraftingCodex(); internal set
var apocryphas = HashMap<String, Any>(); internal set
var fluidCodex = FluidCodex(); internal set
//////////////////////////////
@@ -761,6 +763,8 @@ val CraftingRecipeCodex: CraftingCodex
get() = Terrarum.craftingCodex
val Apocryphas: HashMap<String, Any>
get() = Terrarum.apocryphas
val FluidCodex: FluidCodex
get() = Terrarum.fluidCodex
class Codex : KVHashMap() {

View File

@@ -4,8 +4,6 @@ import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.ReferencingRanges.PREFIX_VIRTUALTILE
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.FluidType
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.utils.CSVFetcher
import net.torvald.util.SortedArrayList
import org.apache.commons.csv.CSVRecord
@@ -156,10 +154,10 @@ class BlockCodex {
}
}
operator fun get(fluidType: FluidType?): BlockProp {
/*operator fun get(fluidType: FluidType?): BlockProp {
// TODO fluid from other mods
if (fluidType == null || fluidType.value == 0) {
if (fluidType == null || fluidType == Fluid.NULL) {
return blockProps[Block.AIR]!!
}
@@ -169,7 +167,7 @@ class BlockCodex {
catch (e: NullPointerException) {
throw NullPointerException("Blockprop with id $fluidType does not exist.")
}
}
}*/
fun getOrNull(blockID: ItemID?): BlockProp? {//<O>
return blockProps[blockID]

View File

@@ -1,20 +1,14 @@
package net.torvald.terrarum.blockproperties
import net.torvald.terrarum.gameworld.FluidType
/**
* Created by minjaesong on 2016-08-06.
*/
object Fluid {
val NULL = FluidType(0)
val WATER = FluidType(1)
val STATIC_WATER = FluidType(-1)
val LAVA = FluidType(2)
val STATIC_LAVA = FluidType(-2)
val NULL = "fluid@basegame:0"
val WATER = "fluid@basegame:1"
val LAVA = "fluid@basegame:2"
val fluidRange = 1..2 // TODO MANUAL UPDATE
}

View File

@@ -0,0 +1,31 @@
package net.torvald.terrarum.blockproperties
import net.torvald.terrarum.gameitems.ItemID
/**
* Created by minjaesong on 2023-10-09.
*/
class FluidCodex {
@Transient val blockProps = HashMap<ItemID, FluidProp>()
@Transient private val nullProp = FluidProp()
operator fun get(fluidID: ItemID?): FluidProp {
if (fluidID == null || fluidID == Fluid.NULL) {
return nullProp
}
try {
return if (fluidID.startsWith("fluid@"))
blockProps[fluidID.substring(6)]!!
else
blockProps[fluidID]!!
}
catch (e: NullPointerException) {
throw NullPointerException("Fluidprop with id $fluidID does not exist.")
}
}
}

View File

@@ -0,0 +1,17 @@
package net.torvald.terrarum.blockproperties
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.gameitems.ItemID
/**
* Created by minjaesong on 2023-10-09.
*/
class FluidProp {
val opacity: Cvec = Cvec()
val lumCol: Cvec = Cvec()
var id: ItemID = ""
var nameKey: String = ""
}

View File

@@ -417,8 +417,9 @@ fun mouseInInteractableRangeTools(actor: ActorWithBody, item: GameItem?, reachMu
fun ItemID.isItem() = this.startsWith("item@")
fun ItemID.isWire() = this.startsWith("wire@")
fun ItemID.isDynamic() = this.startsWith("$PREFIX_DYNAMICITEM:")
fun ItemID.isDynamic() = this.startsWith("$PREFIX_DYNAMICITEM:") // aka module name 'dyn'
fun ItemID.isActor() = this.startsWith("$PREFIX_ACTORITEM@")
fun ItemID.isVirtual() = this.startsWith("$PREFIX_VIRTUALTILE@")
fun ItemID.isBlock() = !this.contains('@') && !this.isDynamic()
fun ItemID.isWall() = this.startsWith("wall@")
fun ItemID.isFluid() = this.startsWith("fluid@")

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.gameactors.ActorID
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isFluid
import net.torvald.terrarum.itemproperties.ItemRemapTable
import net.torvald.terrarum.itemproperties.ItemTable
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
@@ -651,7 +652,9 @@ open class GameWorld(
fun getWallDamage(x: Int, y: Int): Float =
wallDamages[LandUtil.getBlockAddr(this, x, y)] ?: 0f
fun setFluid(x: Int, y: Int, fluidType: FluidType, fill: Float) {
fun setFluid(x: Int, y: Int, fluidType: ItemID, fill: Float) {
if (!fluidType.isFluid()) throw IllegalArgumentException("Fluid type is not actually fluid: $fluidType")
/*if (x == 60 && y == 256) {
printdbg(this, "Setting fluid $fill at ($x,$y)")
}*/
@@ -690,17 +693,17 @@ open class GameWorld(
return if (type == null) FluidInfo(Fluid.NULL, 0f) else FluidInfo(type, fill!!)
}
private fun fluidTypeToBlock(type: FluidType) = when (type.abs()) {
/*private fun fluidTypeToBlock(type: FluidType) = when (type.abs()) {
Fluid.NULL.value -> Block.AIR
in Fluid.fluidRange -> GameWorld.TILES_SUPPORTED - type.abs()
else -> throw IllegalArgumentException("Unsupported fluid type: $type")
}
}*/
data class FluidInfo(val type: FluidType = Fluid.NULL, val amount: Float = 0f) {
data class FluidInfo(val type: ItemID = Fluid.NULL, val amount: Float = 0f) {
/** test if this fluid should be considered as one */
fun isFluid() = type != Fluid.NULL && amount >= WorldSimulator.FLUID_MIN_MASS
fun getProp() = BlockCodex[type]
override fun toString() = "Fluid type: ${type.value}, amount: $amount"
fun getProp(): Nothing = TODO()
override fun toString() = "Fluid type: ${type}, amount: $amount"
}
/**
@@ -776,10 +779,3 @@ infix fun Int.fmod(other: Int) = Math.floorMod(this, other)
infix fun Long.fmod(other: Long) = Math.floorMod(this, other)
infix fun Float.fmod(other: Float) = if (this >= 0f) this % other else (this % other) + other
infix fun Double.fmod(other: Double) = if (this >= 0.0) this % other else (this % other) + other
@JvmInline
value class FluidType(val value: Int) {
infix fun sameAs(other: FluidType) = this.value.absoluteValue == other.value.absoluteValue
fun abs() = this.value.absoluteValue
}

View File

@@ -178,12 +178,12 @@ object WorldSimulator {
fluidmapToWorld()
}
fun isFlowable(type: FluidType, worldX: Int, worldY: Int): Boolean {
fun isFlowable(type: ItemID, worldX: Int, worldY: Int): Boolean {
val fluid = world.getFluid(worldX, worldY)
val tile = world.getTileFromTerrain(worldX, worldY)
// true if target's type is the same as mine, or it's NULL (air)
return ((fluid.type sameAs type || fluid.type sameAs Fluid.NULL) && !BlockCodex[tile].isSolid)
return ((fluid.type == type || fluid.type == Fluid.NULL) && !BlockCodex[tile].isSolid)
}
/**

View File

@@ -253,7 +253,7 @@ class BasicDebugInfoWindow : UICanvas() {
App.fontSmallNumbers.draw(batch, "$ccO$TERRAIN$ccG$tileNum", gap + 7f*(tileCursX + 3), line(tileCursY))
App.fontSmallNumbers.draw(batch, "$ccO$WALL$ccG$wallNum", gap + 7f*(tileCursX + 3), line(tileCursY + 1))
App.fontSmallNumbers.draw(batch, "$ccO$LIQUID$ccG${fluid.type.value.toString().padEnd(3)}$ccO$BEAKER$ccG${fluid.amount.toIntAndFrac(2)}", gap + 7f*(tileCursX + 3), line(tileCursY + 2))
App.fontSmallNumbers.draw(batch, "$ccO$LIQUID$ccG${fluid.type.padEnd(3)}$ccO$BEAKER$ccG${fluid.amount.toIntAndFrac(2)}", gap + 7f*(tileCursX + 3), line(tileCursY + 2))
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))

View File

@@ -4,7 +4,6 @@ package net.torvald.terrarum.utils
import net.torvald.terrarum.gameactors.ActorValue
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.FluidType
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.PhysicalStatus
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
@@ -18,7 +17,7 @@ class HashArray<R>: HashMap<Long, R>() // primitives are working just fine tho
// Oh for the fucks sake fuck you everyone; json shit won't work with generics
class WiringGraphMap: HashMap<ItemID, GameWorld.WiringSimCell>()
class HashedFluidType: HashMap<BlockAddress, FluidType>()
class HashedFluidType: HashMap<BlockAddress, ItemID>()
class HashedWirings: HashMap<BlockAddress, GameWorld.WiringNode>()
class HashedWiringGraph: HashMap<BlockAddress, WiringGraphMap>()
class MetaModuleCSVPair: HashMap<String, ZipCodedStr>()

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