at least this fluid sim passes collection assertion codes

This commit is contained in:
Minjae Song
2018-12-16 02:55:12 +09:00
parent 8e6fcf0b8a
commit cd752bc763
2 changed files with 106 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.modulebasegame.gameworld package net.torvald.terrarum.modulebasegame.gameworld
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
@@ -88,18 +89,28 @@ object WorldSimulator {
if (isSolid(worldX, worldY)) continue if (isSolid(worldX, worldY)) continue
val remainingMass = fluidMap[y][x] val remainingMass = fluidMap[y][x]
val remainingType = fluidTypeMap[y][x]
if (remainingMass != 0f && remainingType == Fluid.NULL) throw InternalError("wtf? (Type: $remainingType, fill: $remainingMass)")
/*if (worldX == 60 && worldY == 256) { /*if (worldX == 60 && worldY == 256) {
printdbg(this, "remainimgMass: $remainingMass at ($worldX, $worldY)") printdbg(this, "remainimgMass: $remainingMass at ($worldX, $worldY)")
}*/ }*/
if (remainingMass == 0f) continue
if (!isSolid(worldX, worldY + 1)) { if (!isSolid(worldX, worldY + 1)) {
fluidNewMap[y][x] -= remainingMass fluidNewMap[y][x] -= remainingMass
fluidNewMap[y + 1][x] += remainingMass fluidNewMap[y + 1][x] += remainingMass
fluidNewTypeMap[y + 1][x] = remainingType
} }
} }
} }
if (AppLoader.IS_DEVELOPMENT_BUILD) {
monitorIllegalFluidSetup() // non-air non-zero fluid is kinda inevitable
}
fluidmapToWorld() fluidmapToWorld()
} }
@@ -288,6 +299,17 @@ object WorldSimulator {
} }
private fun monitorIllegalFluidSetup() {
for (y in 0 until fluidMap.size) {
for (x in 0 until fluidMap[0].size) {
val fluidData = world.getFluid(x + updateXFrom, y + updateYFrom)
if (fluidData.amount < 0f) {
throw InternalError("Negative amount of fluid at (${x + updateXFrom},${y + updateYFrom}): $fluidData")
}
}
}
}
private fun makeFluidMapFromWorld() { private fun makeFluidMapFromWorld() {
//printdbg(this, "Scan area: ($updateXFrom,$updateYFrom)..(${updateXFrom + fluidMap[0].size},${updateYFrom + fluidMap.size})") //printdbg(this, "Scan area: ($updateXFrom,$updateYFrom)..(${updateXFrom + fluidMap[0].size},${updateYFrom + fluidMap.size})")

View File

@@ -446,90 +446,109 @@ internal object BlocksDrawer {
// draw a tile, but only when illuminated // draw a tile, but only when illuminated
try { try {
//if (canIHazRender(mode, x, y)) { val nearbyTilesInfo: Int
if (isPlatform(thisTile)) {
//if (!hasLightNearby(x, y)) { nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y)
// // draw black patch }
// if (thisTile == 0) else if (isWallSticker(thisTile)) {
// writeToBuffer(mode, x - for_x_start, y - for_y_start, 0, 0) nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
// else }
// writeToBuffer(mode, x - for_x_start, y - for_y_start, 2, 0) else if (isConnectMutual(thisTile)) {
//} nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
//else { }
else if (isConnectSelf(thisTile)) {
val nearbyTilesInfo: Int nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
if (isPlatform(thisTile)) { }
nearbyTilesInfo = getNearbyTilesInfoPlatform(x, y) else {
} nearbyTilesInfo = 0
else if (isWallSticker(thisTile)) { }
nearbyTilesInfo = getNearbyTilesInfoWallSticker(x, y)
}
else if (isConnectMutual(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfoNonSolid(x, y, mode)
}
else if (isConnectSelf(thisTile)) {
nearbyTilesInfo = getNearbyTilesInfo(x, y, mode, thisTile)
}
else {
nearbyTilesInfo = 0
}
val thisTileX = if (!noDamageLayer) val thisTileX = if (!noDamageLayer)
PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo PairedMapLayer.RANGE * ((thisTile ?: 0) % PairedMapLayer.RANGE) + nearbyTilesInfo
else else
nearbyTilesInfo nearbyTilesInfo
val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE val thisTileY = (thisTile ?: 0) / PairedMapLayer.RANGE
val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y) val breakage = if (mode == TERRAIN) world.getTerrainDamage(x, y) else world.getWallDamage(x, y)
val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength val maxHealth = BlockCodex[world.getTileFromTerrain(x, y)].strength
val breakingStage = (breakage / maxHealth).times(breakAnimSteps).roundInt() val breakingStage = (breakage / maxHealth).times(breakAnimSteps).roundInt()
// draw a tile // draw a tile
if (drawModeTilesBlendMul) {
// while iterating through, only the some tiles are actually eligible to be drawn as MUL,
// so obviously when we caught not eligible tile, we need to skip that by marking as Tile No. zero
if (isBlendMul(thisTile)) { // I don't know what the fuck is going on here, one thing I sure is it will draw twice, blending
if (BlockCodex[thisTile].isFluid) { // over what had drawn in first pass (blendNormal)
val fluid = world.getFluid(x, y) // this code works, but may not work in the way I wanted
// also, it DOES have a code snippet written twice:
// if (BlockCodex[thisTile].isFluid) {
// ...
// }
// else {
// ...
// }
if (fluid.type == Fluid.NULL && fluid.amount != 0f) { if (drawModeTilesBlendMul) {
throw Error("Illegal fluid at ($x,$y): $fluid") // while iterating through, only the some tiles are actually eligible to be drawn as MUL,
} // so obviously when we caught not eligible tile, we need to skip that by marking as Tile No. zero
if (fluid.amount >= WorldSimulator.FLUID_MIN_MASS) { if (isBlendMul(thisTile)) {
val fluidLevel = fluid.amount.coerceIn(0f,1f).times(PairedMapLayer.RANGE - 1).roundToInt() if (BlockCodex[thisTile].isFluid) {
val baseTileID = (GameWorld.TILES_SUPPORTED) - fluid.type.abs() val fluid = world.getFluid(x, y)
val tileX = fluidLevel + (baseTileID % 16) * PairedMapLayer.RANGE
val tileY = baseTileID / 16
printdbg(this, "$fluid") if (AppLoader.IS_DEVELOPMENT_BUILD && fluid.type == Fluid.NULL && fluid.amount != 0f) {
printdbg(this, "$fluidLevel, $baseTileID, $tileX, $tileY") throw Error("Illegal fluid at ($x,$y): $fluid")
writeToBuffer(mode, bufferX, bufferY, tileX, tileY, 0)
}
}
else {
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, breakingStage)
}
} }
else {
writeToBuffer(mode, bufferX, bufferY, 0, 0, 0) 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 { else {
// do NOT add "if (!isBlendMul(thisTile))"!
// or else they will not look like they should be when backed with wall
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, breakingStage) writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, breakingStage)
} }
}
else {
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
if (BlockCodex[thisTile].isFluid) {
val fluid = world.getFluid(x, y)
//} // end if (is illuminated) if (AppLoader.IS_DEVELOPMENT_BUILD && fluid.type == Fluid.NULL && fluid.amount != 0f) {
//} // end if (not an air) 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)
}
}
} catch (e: NullPointerException) { } catch (e: NullPointerException) {
// do nothing. WARNING: This exception handling may hide erratic behaviour completely. // do nothing. WARNING: This exception handling may hide erratic behaviour completely.
} }