I'm toying with a 2d tile based game where you need to deal with maintaining air pressure in the planetary base you are constructing, and want to see if I can make a simple system for the dispersal of gas in a closed vacuum. For each tick of the game loop, the gas creeps outwards and fills up empty cells in all directions. If there is a hole in your construction, gas should leak out (ideally at a high velocity).
I have made a crude attempt, which follows this logic:
- Consider a cell (C)
- Look at the cell north of it (N)
- If N has more gas than C, calculate the difference (dN).
- Remove 1/4 dN from N, add 1/4 dN to C
- Repeat for the cells south, west and east of C.
Now this sort of works, but not very smoothly. The system stagnates quickly as a lot of gas is trapped in cells with similar gas content, while at the edges of the cloud very little progression is made for each tick. If there is a hole in a contained construction, gas escape is ridiculously slow, having to wait for individual cell difference to start sucking at the content.
Now I expect my solution needs to be quite a lot more complex, maybe considering clusters of cells and comparing them to other clusters, but I have no idea how to go about this. Can anyone point me in the direction of better solutions?
Here is an illustration I made of how I want it to work. As I finished it I realised it may be a bit flawed. https://i.stack.imgur.com/6f4CO.jpg