Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Water algoritm improvement  (Read 988 times)

Silverionmox

  • Bay Watcher
    • View Profile
Water algoritm improvement
« on: October 12, 2010, 05:12:46 pm »

Water still flows like jelly. That might be fine for magma, but water should flow more smoothly. If you fill a broad channel, you'll see that the water does not quickly fill the lowest water level, but instead it slowly flows down from the top of the water source. As a result, you get a diagonal slope, as if it were a candle where drops of molten wax flow from the top, accumulating into a mass near the candle.

Instead it would be better if water spread out quickly, only to rise in level when there's no lower place to go. So water that needs to find another place has to teleport (as it works now: http://www.gamasutra.com/view/feature/3549/interview_the_making_of_dwarf_.php?page=9) to the lowest place available.

However, sometimes we want to have a "wall of water" effect, especially when great volumes or high pressure are present. To preserve this, we pose a limit (e.g.. 100 squares) for the distance searched to place water. So even if square 101 from the originating point of the water is dry, it will still only search within 100 squares, placing the extra water on top of layer 1, making it 2.

With these modifications, water would flow more quickly and smoothly, while still seeing to it that long distances or huge spaces aren't filled in a flash.
Logged
Dwarf Fortress cured my savescumming.

Draco18s

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #1 on: October 13, 2010, 08:34:25 am »

You realize that only stacks of 7 teleport, right?
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #2 on: October 13, 2010, 09:22:53 am »

Currently, if you want to observe exactly what happens, when water moves,

Put a 1/7 layer on top of a 7/7 layer, in a chaotic area like a volcano.


On the topic of flat water mixing in the game, all water is simultaneously moving either up, down, left, or right at any given moment.
This is what causes most mixing.
I have watched the excess water move north for 5 frames, all 1/7 tiles on 7/7 in a volcano.
Then it switches direction, as far as I can tell, randomly, and moves say east for 10 frames.
Then moves west for 2 frames. Ect.

Water which hits a wall during this process moves in a different direction.

It will leak diagonally but I'm just not sure when this is triggered.
Logged

Silverionmox

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #3 on: October 13, 2010, 12:58:07 pm »

You realize that only stacks of 7 teleport, right?
Smaller pieces should too; That probably causes the slow flow. (Beats me whether it would nuke the fps though, I only can do thought experiments.) Currently the dwarves don't even need two legs to stay ahead of a broken dam flood. Luckily they're smart enough to go back there to get more socks.

Logged
Dwarf Fortress cured my savescumming.

Draco18s

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #4 on: October 13, 2010, 02:12:19 pm »

Except that you can't reliably teleport 1 stacks and have reasonable flow.

Rather what needs to happen is that the "high volume" stacks need to know which direction the "low volume" stacks are and flow that way, rather than at random.
Logged

Silverionmox

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #5 on: October 14, 2010, 03:49:39 pm »

The way I said it that's covered by using a large search space. Presumably the water would teleport to the lowest space in the search space (defined by flood filling to the limit eg. 100 squares), if there are more options than 1 the nearest would be filled. It might be too intensive pathfinding to work fast enough.
Logged
Dwarf Fortress cured my savescumming.

ZCM

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #6 on: October 14, 2010, 05:49:06 pm »

For many common scenarios I suspect you could get much better performance by using a flood fill algorithm to find the "basin" the water is in, calculating the total amount of water in the basin, and then spreading it around roughly evenly. You'd lose flow though, and having water instantly travel large distances regardless of pressure might be weird.
Logged
Badger badgers badger badger badgers badgers badger.

Daetrin

  • Bay Watcher
    • View Profile
Re: Water algoritm improvement
« Reply #7 on: October 14, 2010, 07:43:22 pm »

For many common scenarios I suspect you could get much better performance by using a flood fill algorithm to find the "basin" the water is in, calculating the total amount of water in the basin, and then spreading it around roughly evenly. You'd lose flow though, and having water instantly travel large distances regardless of pressure might be weird.

It wouldn't have to be instant, if you wanted to calculate the transient solutions as well.  That'd require a lot more processing power of course, but you'd only have to do it once.
Logged
All you need to know about Ardentdikes
It is really, really easy to flood this place with magma fwiw.

Doors stop fire, right?