Fluid Modeling

Demo video showing water flow, pressure, and other aspects of the fluid system.

Summary

  • Outer Colony features a fluid modeling system designed to facilitate the flow of liquids throughout OC worlds.
  • Real world fluid dynamics are extremely complex, but OC’s system is built to behave realistically on a macro level without requiring a supercomputer to run.
  • By treating liquids as compressible fluids, we can overcome deficiencies of some of the most simplistic water models and achieve behavior that looks pretty good.
  • Flowing liquids respond to all world changes and terrain deformation.
    • Nothing is pre-calculated. The flow algorithm is dynamic and local, so whatever you do to change the world will affect spatially adjacent liquids.
    • All sorts of gameplay can be derived from this. You can carve a canal from a distant river to your colony for a large supply of fresh water. You can destroy a dam that overlooks an enemy position to drown your enemies. This is the sort of simulation derived gameplay that just isn’t possible in traditional RTS games.
    • Like everything else in OC, liquids are another part of the world model that can be manipulated and exploited however you deem fit. Have fun with it!

Liquid Behavior, Pressure, Upward Flow & the U-Bend Problem

Outer Colony’s model for liquids is actually very simple, but produces pretty good results. The system is based on simple cellular automata where liquids exert downward, outward, and upward pressures based on mutable “mass factor” values. Some of the values involved in the figuring are exposed in the tile inspection tool, as they can help to understand what’s going on. The end result is that liquids will generally flow intuitively, as you’d expect them to in the real world.

One example where the simplest cellular automata fail for liquid flow is when moving material through “U bend” shapes. Consider a large water of volume entering a pipe that’s shaped like a U, like the U trap under your sink. The most basic falling sand models don’t really model pressure, so they won’t move water upward through the second part of the U shape, and the fluid will back up. Since OC’s model accounts for pressure, water and low-viscosity liquids will flow upward and through U shaped bends, given sufficient pressure.

Keen observers will notice a variety of issues with Outer Colony’s flow system, but I think it’s a reasonable facsimile of real behavior that’ll run on consumer hardware. There’s a lot of room for improvement, and I hope to work more on the system in the future to make it as effective a model as practically possible.

Physics Processing in Outer Colony

Outer Colony’s physics processing framework is designed to impact performance as little possible. After all, really cool physics doesn’t do any good if it causes the game to lag, and because of the dynamic nature of Outer Colony worlds, situations can arise that would normally grind frame rate to a halt. Consider a giant dam that’s 50 Z levels tall and holds 1,000,000 cubic meters of water. Think about what happens if the dam is suddenly destroyed, and that huge volume of water has to spill out into the world. Even the most efficient system possible still has to perform an astronomical number of calculations in real time in order to make that work.

Outer Colony’s answer to this problem draws on the multithreaded design of its game engine. Physics processing is throttled so that it can’t swamp all of your cores at once. What this means is that blowing up the dam won’t result in OC dropping to 0 FPS. Rather, the apparent flow of the water will slow down until the physics processing system can catch up with the normal passage of time. It’s a bit strange to think about, but I think it’s the best possible answer for this use case. As a player, it’s extremely frustrating when a game slows down, and this system represents a design choice to decrease the likelihood of this happening.

So, if you notice artifacts from the potentially variable speed of applying the laws of physics, know that your computer is trying its best to keep up with a computationally complex situation.

There’s always room for improvement in the code, too, and I hope that I can further optimize performance-critical aspects of the system, like physics processing, in the future.

Be Careful!

My final word of advice with fluids in OC is to be careful! Pay attention to the Z levels you’re manipulating and remain cognizant of water’s desire to flow downward. If your miners rip a hole in the bottom of a giant river, whatever cavern system they’ve dug underneath it is going to quickly flood, and it’ll probably drown everyone unfortunate enough to be trapped there. Always be aware of where water is located, especially when you’re mining near it!

Posted in Simulation