Cervator edit: Back when last this worked it was in a standalone module, so I moved it to the Modules forum. However it needs a refresh at which point what repo(s) it might occupy should be reevaluated
Name: Cellular Automata and Liquid Simulation
Summary: A system to run block based cellular automata (CA) and the implementation of a CA to simulate water and other liquids.
Scope: Engine
Current Goal: Allow CA's to move between update regions and clean up water implementation.
Phase: Implementation
Curator: DizzyDragon
Related: World generation
CA System
Fluid Dynamics covers the simulation of liquids and gas. The generation of rivers, lakes,oceans, volcano's etc. on the map are outside of the scope of the project. To keep the scope of the project manageable I think it is good to just assume that we already know where the fluids are located on the map.
Reasons for choosing the CA approach
First an volume based approach was chosen for simulating liquids. This was favored over a particle based approach because the world was already divided up into cells. Letting the state of a cell only depend on it's direct neighbors makes it a lot easier to deal with a world where not all chunks are loaded at all times. This considered, it seems a lot more logical to go for a more general CA system, that can easily be reused to do more simulations, than to go for a system that is specifically made to simulate water and nothing else.
Done
Data per block of fluid
To simulate a liquids the following data is stored in the extra data of a liquid block:
There are 10 CABWater blocks, each with a number indicating how much water is in them.
CABWater1 has 0-9 water units, CABWater2 has 10-19 units, CABWater3 has 20-29 units and so forth. These block follow the following rules:
For those of you who want to test the liquid implementation, beware that it still far from finished. Water cannot disappears when it crosses the boundary of a UpdateRegion. The purple CAWater block is usefull to find the boundaries of UpdateRegions. At the moment, the only way to force a region to restart updating is by placing a CABWater10 block. When water can no longer flow, the region will stop updating.
Done
Name: Cellular Automata and Liquid Simulation
Summary: A system to run block based cellular automata (CA) and the implementation of a CA to simulate water and other liquids.
Scope: Engine
Current Goal: Allow CA's to move between update regions and clean up water implementation.
Phase: Implementation
Curator: DizzyDragon
Related: World generation
CA System
Fluid Dynamics covers the simulation of liquids and gas. The generation of rivers, lakes,oceans, volcano's etc. on the map are outside of the scope of the project. To keep the scope of the project manageable I think it is good to just assume that we already know where the fluids are located on the map.
Reasons for choosing the CA approach
First an volume based approach was chosen for simulating liquids. This was favored over a particle based approach because the world was already divided up into cells. Letting the state of a cell only depend on it's direct neighbors makes it a lot easier to deal with a world where not all chunks are loaded at all times. This considered, it seems a lot more logical to go for a more general CA system, that can easily be reused to do more simulations, than to go for a system that is specifically made to simulate water and nothing else.
Done
- Basic architecture:
- abstract CellularAutomaton class: Responsible for calling the actual block updates of a system and doing this efficiently,
- children of CellularAutomaton class: provide update/state transition rules. Should be easy to implement, without worrying about the actual update procedure.
- CellularAutomatonManager/CellularAutomatonSystem class: Handles calling updates on the CellularAutomaton implementations.
- Synchronous block updates: The system is able to synchronously update a region of blocks. This is by using a buffer to write new block states to instead of directly writing them to the world.
- Allow CAs to cause updates in neighboring regions
- Fix light updating situation, so only one update call is needed after changing all blocks
- Move CA to it's own thread
- Allow CAs to catch block update events
Data per block of fluid
To simulate a liquids the following data is stored in the extra data of a liquid block:
- amount of fluid (A)
(Unsigned) byte to store how much water is currently in a block - flow direction (F),
6 bits to be able to set a flag to each direction to which water is flowing out of a block
Makes it possible to let blocks flow to multiple directions at the same time - flow magnitude (M)
How much water is flowing out of the block
extra data int: 0000 0000 00MM MMMM MMDD DDDD AAAA AAAA
There are 10 CABWater blocks, each with a number indicating how much water is in them.
CABWater1 has 0-9 water units, CABWater2 has 10-19 units, CABWater3 has 20-29 units and so forth. These block follow the following rules:
- Water blocks can have any ammount of water in them between 1 and 100 (inclusive).
- Water can only flow into air blocks or water blocks.
- If water can flow down it will flow down.
- If water can not flow down it will try to flow sideways
- Water can only flow sideways to blocks that contain less water than the current block
- Water will flow to the side(s) with the maximal possible inflow.
For those of you who want to test the liquid implementation, beware that it still far from finished. Water cannot disappears when it crosses the boundary of a UpdateRegion. The purple CAWater block is usefull to find the boundaries of UpdateRegions. At the moment, the only way to force a region to restart updating is by placing a CABWater10 block. When water can no longer flow, the region will stop updating.
Done
- Down flow and side flow
- Reading/Writing flow direction, flow magnitude and liquid ammount to/from extradata.
- Fix water disappearing in some certain situations
- Add evaporation for small puddles of non-moving water
- Add more stuff: source/sink blocks, buckets, pressure and upflow
- Make the flow direction of a block affect it's neighboring water block flows
Last edited by a moderator: