fluid layer data and fluid sim specifications

See added note FLUID_SIMULATION
This commit is contained in:
Minjae Song
2018-12-12 18:39:14 +09:00
parent 9c3c35067d
commit e441cdf5f0
4 changed files with 36 additions and 13 deletions

View File

@@ -8,7 +8,6 @@ import net.torvald.terrarum.serialise.ReadLayerDataLzma
import org.dyn4j.geometry.Vector2
typealias BlockAddress = Long
typealias BlockDamage = Float
open class GameWorld {
@@ -42,8 +41,10 @@ open class GameWorld {
/** Tilewise spawn point */
var spawnY: Int
val wallDamages: HashMap<BlockAddress, BlockDamage>
val terrainDamages: HashMap<BlockAddress, BlockDamage>
val wallDamages: HashMap<BlockAddress, Float>
val terrainDamages: HashMap<BlockAddress, Float>
val fluidTypes: HashMap<BlockAddress, Int>
val fluidFills: HashMap<BlockAddress, Float>
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
//physics
@@ -74,8 +75,10 @@ open class GameWorld {
layerTerrainLowBits = PairedMapLayer(width, height)
layerWallLowBits = PairedMapLayer(width, height)
wallDamages = HashMap<BlockAddress, BlockDamage>()
terrainDamages = HashMap<BlockAddress, BlockDamage>()
wallDamages = HashMap<BlockAddress, Float>()
terrainDamages = HashMap<BlockAddress, Float>()
fluidTypes = HashMap<BlockAddress, Int>()
fluidFills = HashMap<BlockAddress, Float>()
// temperature layer: 2x2 is one cell
//layerThermal = MapLayerHalfFloat(width, height, averageTemperature)
@@ -100,6 +103,8 @@ open class GameWorld {
wallDamages = layerData.wallDamages
terrainDamages = layerData.terrainDamages
fluidTypes = layerData.fluidTypes
fluidFills = layerData.fluidFills
spawnX = layerData.spawnX
spawnY = layerData.spawnY

View File

@@ -3,7 +3,6 @@ package net.torvald.terrarum.serialise
import com.badlogic.gdx.utils.compression.Lzma
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.BlockDamage
import net.torvald.terrarum.gameworld.MapLayer
import net.torvald.terrarum.gameworld.PairedMapLayer
import net.torvald.terrarum.realestate.LandUtil
@@ -155,8 +154,10 @@ internal object ReadLayerDataLzma {
val spawnPoint = LandUtil.resolveBlockAddr(width, spawnAddress)
val terrainDamages = HashMap<BlockAddress, BlockDamage>()
val wallDamages = HashMap<BlockAddress, BlockDamage>()
val terrainDamages = HashMap<BlockAddress, Float>()
val wallDamages = HashMap<BlockAddress, Float>()
val fluidTypes = HashMap<BlockAddress, Int>()
val fluidFills = HashMap<BlockAddress, Float>()
// parse terrain damages
for (c in 0 until payloadBytes["TdMG"]!!.size step 10) {
@@ -179,6 +180,9 @@ internal object ReadLayerDataLzma {
wallDamages[tileAddr.toLittleInt48()] = value.toLittleFloat()
}
// TODO parse fluid(Types|Fills)
return LayerData(
MapLayer(width, height, payloadBytes["WALL_MSB"]!!),
@@ -189,7 +193,7 @@ internal object ReadLayerDataLzma {
spawnPoint.first, spawnPoint.second,
wallDamages, terrainDamages
wallDamages, terrainDamages, fluidTypes, fluidFills
)
}
@@ -209,8 +213,10 @@ internal object ReadLayerDataLzma {
val spawnX: Int,
val spawnY: Int,
val wallDamages: HashMap<BlockAddress, BlockDamage>,
val terrainDamages: HashMap<BlockAddress, BlockDamage>
val wallDamages: HashMap<BlockAddress, Float>,
val terrainDamages: HashMap<BlockAddress, Float>,
val fluidTypes: HashMap<BlockAddress, Int>,
val fluidFills: HashMap<BlockAddress, Float>
)
private fun ByteArray.shiftLeftBy(size: Int, fill: Byte = 0.toByte()) {

View File

@@ -188,13 +188,13 @@ object LightmapRenderer {
/**
* Updating order:
* +--------+ +--+-----+ +-----+--+ +--------+ -
* ,--------. ,--+-----. ,-----+--. ,--------. -
* |↘ | | | 3| |3 | | | ↙| ↕︎ overscan_open / overscan_opaque
* | +-----+ | | 2 | | 2 | | +-----+ | - depending on the noop_mask
* | |1 | → | |1 | → | 1| | → | 1| |
* | | 2 | | +-----+ +-----+ | | 2 | |
* | | 3| |↗ | | ↖| |3 | |
* +--+-----+ +--------+ +--------+ +-----+--+
* `--+-----' `--------' `--------' `-----+--'
* round: 1 2 3 4
* for all lightmap[y][x]
*/

View File

@@ -0,0 +1,12 @@
#### Before we begin, please read following articles:
- Celluar Automata https://w-shadow.com/blog/2009/09/01/simple-fluid-simulation/
- Pressure sim in DF http://www.gamasutra.com/view/feature/131954/interview_the_making_of_dwarf_.php
### Serialisation
- FluidType: Hashed list of BlockAddress, Int
- FluidFill: Hashed list of BlockAddress, Float32
### Notes
- By doing this, you dont need 16 blocks to represent a water; you only need 1 block for all kinds of fluids
- Storing the overfill (treat water as compressible) is important, will work as a temporary storage until the overfill is resolved, and rim of the update area will always be overfilled before they get updated