mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 01:54:04 +09:00
fluid layer data and fluid sim specifications
See added note FLUID_SIMULATION
This commit is contained in:
@@ -8,7 +8,6 @@ import net.torvald.terrarum.serialise.ReadLayerDataLzma
|
|||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
typealias BlockAddress = Long
|
typealias BlockAddress = Long
|
||||||
typealias BlockDamage = Float
|
|
||||||
|
|
||||||
open class GameWorld {
|
open class GameWorld {
|
||||||
|
|
||||||
@@ -42,8 +41,10 @@ open class GameWorld {
|
|||||||
/** Tilewise spawn point */
|
/** Tilewise spawn point */
|
||||||
var spawnY: Int
|
var spawnY: Int
|
||||||
|
|
||||||
val wallDamages: HashMap<BlockAddress, BlockDamage>
|
val wallDamages: HashMap<BlockAddress, Float>
|
||||||
val terrainDamages: HashMap<BlockAddress, BlockDamage>
|
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) );
|
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
|
||||||
//physics
|
//physics
|
||||||
@@ -74,8 +75,10 @@ open class GameWorld {
|
|||||||
layerTerrainLowBits = PairedMapLayer(width, height)
|
layerTerrainLowBits = PairedMapLayer(width, height)
|
||||||
layerWallLowBits = PairedMapLayer(width, height)
|
layerWallLowBits = PairedMapLayer(width, height)
|
||||||
|
|
||||||
wallDamages = HashMap<BlockAddress, BlockDamage>()
|
wallDamages = HashMap<BlockAddress, Float>()
|
||||||
terrainDamages = HashMap<BlockAddress, BlockDamage>()
|
terrainDamages = HashMap<BlockAddress, Float>()
|
||||||
|
fluidTypes = HashMap<BlockAddress, Int>()
|
||||||
|
fluidFills = HashMap<BlockAddress, Float>()
|
||||||
|
|
||||||
// temperature layer: 2x2 is one cell
|
// temperature layer: 2x2 is one cell
|
||||||
//layerThermal = MapLayerHalfFloat(width, height, averageTemperature)
|
//layerThermal = MapLayerHalfFloat(width, height, averageTemperature)
|
||||||
@@ -100,6 +103,8 @@ open class GameWorld {
|
|||||||
|
|
||||||
wallDamages = layerData.wallDamages
|
wallDamages = layerData.wallDamages
|
||||||
terrainDamages = layerData.terrainDamages
|
terrainDamages = layerData.terrainDamages
|
||||||
|
fluidTypes = layerData.fluidTypes
|
||||||
|
fluidFills = layerData.fluidFills
|
||||||
|
|
||||||
spawnX = layerData.spawnX
|
spawnX = layerData.spawnX
|
||||||
spawnY = layerData.spawnY
|
spawnY = layerData.spawnY
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.torvald.terrarum.serialise
|
|||||||
import com.badlogic.gdx.utils.compression.Lzma
|
import com.badlogic.gdx.utils.compression.Lzma
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.gameworld.BlockAddress
|
import net.torvald.terrarum.gameworld.BlockAddress
|
||||||
import net.torvald.terrarum.gameworld.BlockDamage
|
|
||||||
import net.torvald.terrarum.gameworld.MapLayer
|
import net.torvald.terrarum.gameworld.MapLayer
|
||||||
import net.torvald.terrarum.gameworld.PairedMapLayer
|
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
@@ -155,8 +154,10 @@ internal object ReadLayerDataLzma {
|
|||||||
|
|
||||||
val spawnPoint = LandUtil.resolveBlockAddr(width, spawnAddress)
|
val spawnPoint = LandUtil.resolveBlockAddr(width, spawnAddress)
|
||||||
|
|
||||||
val terrainDamages = HashMap<BlockAddress, BlockDamage>()
|
val terrainDamages = HashMap<BlockAddress, Float>()
|
||||||
val wallDamages = HashMap<BlockAddress, BlockDamage>()
|
val wallDamages = HashMap<BlockAddress, Float>()
|
||||||
|
val fluidTypes = HashMap<BlockAddress, Int>()
|
||||||
|
val fluidFills = HashMap<BlockAddress, Float>()
|
||||||
|
|
||||||
// parse terrain damages
|
// parse terrain damages
|
||||||
for (c in 0 until payloadBytes["TdMG"]!!.size step 10) {
|
for (c in 0 until payloadBytes["TdMG"]!!.size step 10) {
|
||||||
@@ -179,6 +180,9 @@ internal object ReadLayerDataLzma {
|
|||||||
wallDamages[tileAddr.toLittleInt48()] = value.toLittleFloat()
|
wallDamages[tileAddr.toLittleInt48()] = value.toLittleFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO parse fluid(Types|Fills)
|
||||||
|
|
||||||
|
|
||||||
return LayerData(
|
return LayerData(
|
||||||
MapLayer(width, height, payloadBytes["WALL_MSB"]!!),
|
MapLayer(width, height, payloadBytes["WALL_MSB"]!!),
|
||||||
@@ -189,7 +193,7 @@ internal object ReadLayerDataLzma {
|
|||||||
|
|
||||||
spawnPoint.first, spawnPoint.second,
|
spawnPoint.first, spawnPoint.second,
|
||||||
|
|
||||||
wallDamages, terrainDamages
|
wallDamages, terrainDamages, fluidTypes, fluidFills
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +213,10 @@ internal object ReadLayerDataLzma {
|
|||||||
|
|
||||||
val spawnX: Int,
|
val spawnX: Int,
|
||||||
val spawnY: Int,
|
val spawnY: Int,
|
||||||
val wallDamages: HashMap<BlockAddress, BlockDamage>,
|
val wallDamages: HashMap<BlockAddress, Float>,
|
||||||
val terrainDamages: HashMap<BlockAddress, BlockDamage>
|
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()) {
|
private fun ByteArray.shiftLeftBy(size: Int, fill: Byte = 0.toByte()) {
|
||||||
|
|||||||
@@ -188,13 +188,13 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updating order:
|
* Updating order:
|
||||||
* +--------+ +--+-----+ +-----+--+ +--------+ -
|
* ,--------. ,--+-----. ,-----+--. ,--------. -
|
||||||
* |↘ | | | 3| |3 | | | ↙| ↕︎ overscan_open / overscan_opaque
|
* |↘ | | | 3| |3 | | | ↙| ↕︎ overscan_open / overscan_opaque
|
||||||
* | +-----+ | | 2 | | 2 | | +-----+ | - depending on the noop_mask
|
* | +-----+ | | 2 | | 2 | | +-----+ | - depending on the noop_mask
|
||||||
* | |1 | → | |1 | → | 1| | → | 1| |
|
* | |1 | → | |1 | → | 1| | → | 1| |
|
||||||
* | | 2 | | +-----+ +-----+ | | 2 | |
|
* | | 2 | | +-----+ +-----+ | | 2 | |
|
||||||
* | | 3| |↗ | | ↖| |3 | |
|
* | | 3| |↗ | | ↖| |3 | |
|
||||||
* +--+-----+ +--------+ +--------+ +-----+--+
|
* `--+-----' `--------' `--------' `-----+--'
|
||||||
* round: 1 2 3 4
|
* round: 1 2 3 4
|
||||||
* for all lightmap[y][x]
|
* for all lightmap[y][x]
|
||||||
*/
|
*/
|
||||||
|
|||||||
12
work_files/GameDesign/FLUID_SIMULATION.md
Normal file
12
work_files/GameDesign/FLUID_SIMULATION.md
Normal 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 don’t 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
|
||||||
Reference in New Issue
Block a user