Here's something I've been playing with for a while->
http://tinypic.com/r/hwg4r8/5 (video)
It's supposed to be a terraria
[1] clone. I'm using the jmonkey engine
[2] for this, mainly for portability. I'm doing it just for fun, but I'll try to create something of commercial level. So far, I've implemented basic map editing, player movement (and collision detection / resolution), and fluid simulation. That last one is what I'll be talking about in this post.
I wanted to make it realistic but keep it simple at the same time, so I stayed away from methods involving strange physics formulas that make you have nightmares. The first thing that got my attention was some guy's blog entry
[3]. However, it wasn't enough. As he states...
CA-based algorithms have both advantages and disadvantages. On the one hand, they’re relatively fast and the simulation quality is often good enough for games and software toys. On the other, they can produce behaviour that is very unrealistic - for example, water falling into a basin will form a little "hill" and spread out slowly, instead of near-instantly as real water would. Whether this is an acceptable downside depends on your application. |
However, right below that, he also says...
For a different take on simulating fluid dynamics with cellular automata, check out this interview with the author of Dwarf Fortress. |
That
[4] was the second thing that got my attention. I liked the teleport solution that guy used for the U shaped tube problem and I decided to do something similar.
So, every water tile, when spawned, lies inside its own so called water pool. When water tiles come together, they are put in the same water pool. When they move away from each other, they are put in distinct water pools again. Now, apart from the typical moves a water tile makes (e.g. move down if there's empty space), each water pool is iterated over and water tiles in high positions teleport to empty space near water tiles (of the same water pool) in low positions.
It works pretty well, but I find it a bit expensive. I don't know if it's able to handle a world with thousands or tens of thousands of water tiles :/ The complexity is O(n log n) (n -> number of water tiles), but I process every water tile several times. Any thoughts?
[1]
http://www.terraria.org/
[2]
http://jmonkeyengine.com/
[3]
http://w-shadow.com/blog/2009/09/01/simple-fluid-simulation/
[4]
http://www.gamasutra.com/view/feature/3549/interview_the_making_of_dwarf_.php?page=9