This might belong in the suggestions forum, but I'm not sure:
So I was fooling around with a cellular automata model for fluid motion, and came across a quote from Toady in the Gamasutra interview where he said it would be nice to have a local model for handling things like water pressure. Then the last DF talk brought up time dilation and fluids again.
So while I'm optimizing my implementation, I thought it would be nice to do it in such a way that the algorithm would be easily portable into the Dwarf Fortress code. I was wondering if anyone here had any insights on what specific considerations I should be making or whether that's a question only Toady can answer.
Looking at the dfhack github gave me a rough idea of how the map tiles are stored in memory, but what's really useful here is how the game loop processes and refers to each tile. For instance: ignoring the rest of the game, if we only need 3 bits each for water and magma volume and maybe a "static" flag for each, the most efficient approach would be a big 8bit 3D array which gets directly referenced. However, I suspect the current game is already performing the overhead of scraping through a large array to pull "map tile" objects which have a bunch of pointers to relevant info like items, material types, etc. ...or it may be linked lists or something. But I'd like to know which method of storage/referencing would be most useful to DF.
Other specific concerns are probably TL;DR so open spoiler at own risk:
My current setup mainly works off of material density and gravity. (from which pressure and velocity are derived.) It has 3 material types:
•Gas (Compressible Fluid)
•Liquid (Incompressible Fluid)
•Solid (Viscosity of 0)
Fluids do not mix; they form layers according to density.
Suggestions are more than welcome, but I'm guessing some useful optimizations for DF would be:
•use integers for stored values rather than floating point
•assume terminal velocity for any substance in free-fall
•Ignore motion of gasses, and assume that tile with fluid less than max contains generic air in the remaining space
•Solid materials always occupy entire tile volume.
(there may be items which allow flow, such as fortifications but those still allow 7/7 luid to occupy tile)
...and then I have questions about what the ultimate "desired" behavior model should be.
Will there be multiple arbitrary fluids, or just magma/water (and air)? I know Toady has mentioned oil...
Is it okay to use a max fluid volume of 6 or 10 rather than 7 if it significantly improves the math and physical realism?
An integer volume leaves "fractions" of water sloshing across the surface of containers: Is it okay for those to bounce around frictionless forever? can the whole world have a slight rotational drift to counteract this? How much wiggle room is there with using evaporation/absorption rates to solve this, etc.
A local model also has implications for velocity/flow rate.
With this approach, velocity is tied to frame rate rather than game time. That is, each calculated frame can only move substances as far as the local area being calculated. SO: is 7 Urists per tile per frame acceptible as a max velocity? (Currently, we can make much faster water cannons via the "teleport" logic for pressurized water).