mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
bugs on fluid sim, Type is NULL but fill isn't 0/new temporary fluid draw
This commit is contained in:
@@ -108,7 +108,7 @@ object BlockCodex {
|
||||
prop.friction = intVal(record, "friction")
|
||||
prop.viscosity = intVal(record, "vscs")
|
||||
|
||||
prop.isFluid = Fluid.isThisTileFluid(prop.id)//boolVal(record, "fluid")
|
||||
prop.isFluid = boolVal(record, "fluid")
|
||||
prop.isSolid = boolVal(record, "solid")
|
||||
prop.isClear = boolVal(record, "clear")
|
||||
prop.isWallable = boolVal(record, "wall")
|
||||
|
||||
@@ -359,6 +359,11 @@ open class GameWorld {
|
||||
}*/
|
||||
|
||||
|
||||
if (fluidType == Fluid.NULL && fill != 0f) {
|
||||
throw Error("Illegal fluid at ($x,$y): ${FluidInfo(fluidType, fill)}")
|
||||
}
|
||||
|
||||
|
||||
val addr = LandUtil.getBlockAddr(this, x, y)
|
||||
// fluid completely drained
|
||||
if (fill <= WorldSimulator.FLUID_MIN_MASS) {
|
||||
@@ -396,7 +401,9 @@ open class GameWorld {
|
||||
return if (type == null) FluidInfo(Fluid.NULL, 0f) else FluidInfo(type, fill!!)
|
||||
}
|
||||
|
||||
data class FluidInfo(val type: FluidType, val amount: Float)
|
||||
data class FluidInfo(val type: FluidType, val amount: Float) {
|
||||
override fun toString() = "Fluid type: ${type.value}, amount: $amount"
|
||||
}
|
||||
|
||||
|
||||
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {
|
||||
|
||||
@@ -76,8 +76,8 @@ object WorldSimulator {
|
||||
fun moveFluids(delta: Float) {
|
||||
makeFluidMapFromWorld()
|
||||
|
||||
simCompression()
|
||||
/*for (y in 1 until fluidMap.size - 1) {
|
||||
//simCompression()
|
||||
for (y in 1 until fluidMap.size - 1) {
|
||||
for (x in 1 until fluidMap[0].size - 1) {
|
||||
val worldX = x + updateXFrom
|
||||
val worldY = y + updateYFrom
|
||||
@@ -98,7 +98,7 @@ object WorldSimulator {
|
||||
fluidNewMap[y + 1][x] += remainingMass
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
fluidmapToWorld()
|
||||
}
|
||||
@@ -299,9 +299,9 @@ object WorldSimulator {
|
||||
fluidNewMap[y][x] = fluidData.amount
|
||||
fluidNewTypeMap[y][x] = fluidData.type
|
||||
|
||||
if (x + updateXFrom == 60 && y + updateYFrom == 256) {
|
||||
/*if (x + updateXFrom == 60 && y + updateYFrom == 256) {
|
||||
printdbg(this, "making array amount ${fluidData.amount} for (60,256)")
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,18 @@ import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.blockproperties.Fluid
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.gameworld.MapLayer
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_TILES
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.zip.GZIPInputStream
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
/**
|
||||
@@ -311,39 +315,9 @@ internal object BlocksDrawer {
|
||||
* will blend colour using colour multiplication
|
||||
* i.e. red hues get lost if you dive into the water
|
||||
*/
|
||||
private val TILES_BLEND_MUL = hashSetOf(-1
|
||||
/*Block.WATER,
|
||||
Block.WATER_1,
|
||||
Block.WATER_2,
|
||||
Block.WATER_3,
|
||||
Block.WATER_4,
|
||||
Block.WATER_5,
|
||||
Block.WATER_6,
|
||||
Block.WATER_7,
|
||||
Block.WATER_8,
|
||||
Block.WATER_9,
|
||||
Block.WATER_10,
|
||||
Block.WATER_11,
|
||||
Block.WATER_12,
|
||||
Block.WATER_13,
|
||||
Block.WATER_14,
|
||||
Block.WATER_15,
|
||||
Block.LAVA,
|
||||
Block.LAVA_1,
|
||||
Block.LAVA_2,
|
||||
Block.LAVA_3,
|
||||
Block.LAVA_4,
|
||||
Block.LAVA_5,
|
||||
Block.LAVA_6,
|
||||
Block.LAVA_7,
|
||||
Block.LAVA_8,
|
||||
Block.LAVA_9,
|
||||
Block.LAVA_10,
|
||||
Block.LAVA_11,
|
||||
Block.LAVA_12,
|
||||
Block.LAVA_13,
|
||||
Block.LAVA_14,
|
||||
Block.LAVA_15*/
|
||||
private val TILES_BLEND_MUL = hashSetOf(
|
||||
Block.WATER,
|
||||
Block.LAVA
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -387,6 +361,7 @@ internal object BlocksDrawer {
|
||||
|
||||
drawTiles(TERRAIN, true) // blendmul tiles
|
||||
renderUsingBuffer(TERRAIN, projectionMatrix)
|
||||
renderFluids(projectionMatrix)
|
||||
|
||||
|
||||
|
||||
@@ -454,6 +429,9 @@ internal object BlocksDrawer {
|
||||
for (y in for_y_start..for_y_end) {
|
||||
for (x in for_x_start..for_x_end) {
|
||||
|
||||
val bufferX = x - for_x_start
|
||||
val bufferY = y - for_y_start
|
||||
|
||||
val thisTile: Int?
|
||||
if (mode % 3 == WALL)
|
||||
thisTile = world.getTileFromWall(x, y)
|
||||
@@ -516,29 +494,39 @@ internal object BlocksDrawer {
|
||||
// so obviously when we caught not eligible tile, we need to skip that by marking as Tile No. zero
|
||||
|
||||
if (isBlendMul(thisTile)) {
|
||||
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage)
|
||||
if (BlockCodex[thisTile].isFluid) {
|
||||
val fluid = world.getFluid(x, y)
|
||||
|
||||
if (fluid.type == Fluid.NULL && fluid.amount != 0f) {
|
||||
throw Error("Illegal fluid at ($x,$y): $fluid")
|
||||
}
|
||||
|
||||
if (fluid.amount >= WorldSimulator.FLUID_MIN_MASS) {
|
||||
val fluidLevel = fluid.amount.coerceIn(0f,1f).times(PairedMapLayer.RANGE - 1).roundToInt()
|
||||
val baseTileID = (GameWorld.TILES_SUPPORTED) - fluid.type.abs()
|
||||
val tileX = fluidLevel + (baseTileID % 16) * PairedMapLayer.RANGE
|
||||
val tileY = baseTileID / 16
|
||||
|
||||
printdbg(this, "$fluid")
|
||||
printdbg(this, "$fluidLevel, $baseTileID, $tileX, $tileY")
|
||||
|
||||
writeToBuffer(mode, bufferX, bufferY, tileX, tileY, 0)
|
||||
}
|
||||
}
|
||||
else {
|
||||
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, breakingStage)
|
||||
}
|
||||
}
|
||||
else {
|
||||
writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0, 0)
|
||||
writeToBuffer(mode, bufferX, bufferY, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// do NOT add "if (!isBlendMul(thisTile))"!
|
||||
// or else they will not look like they should be when backed with wall
|
||||
writeToBuffer(mode, x - for_x_start, y - for_y_start, thisTileX, thisTileY, breakingStage)
|
||||
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, breakingStage)
|
||||
}
|
||||
|
||||
// draw a breakage
|
||||
/*if (mode == TERRAIN || mode == WALL) {
|
||||
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
|
||||
val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength
|
||||
val stage = (breakage / maxHealth).times(breakAnimSteps).roundInt()
|
||||
// actual drawing
|
||||
if (stage > 0) {
|
||||
writeToBuffer(mode, x - for_x_start, y - for_y_start, 5 + stage, 0)
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
//} // end if (is illuminated)
|
||||
//} // end if (not an air)
|
||||
@@ -762,6 +750,10 @@ internal object BlocksDrawer {
|
||||
//tilesBufferAsTex.dispose()
|
||||
}
|
||||
|
||||
private fun renderFluids(projectionMatrix: Matrix4) {
|
||||
|
||||
}
|
||||
|
||||
private var oldScreenW = 0
|
||||
private var oldScreenH = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user