1

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

revesvans
  • 11
  • 2
  • have you tried a higher diffusion coefficient, e.g. 3/4 instead of 1/4? –  Aug 05 '16 at 13:47
  • Thing is that every cell could possibly transfer gas in four directions, so if each of these cells demand 3/4 of the difference, the middle cell will be left with less than zero gas content. – revesvans Aug 08 '16 at 07:26
  • 1
    [psst](https://tomforsyth1000.github.io/papers/cellular_automata_for_physical_modelling.html) – genpfault Jul 13 '18 at 14:36

0 Answers0