Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Why doesn't every water tile update every frame?  (Read 995 times)

Danjen

  • Bay Watcher
    • View Profile
Why doesn't every water tile update every frame?
« on: March 02, 2014, 11:49:23 pm »

Hi guys,

I was trying to model simple water flow for a little game project of mine (more of a programming exercise than anything), but I wasn't having much luck with it. So, I figured I'd try my luck here, since DF has a pretty solid fluid system in place, and you guys probably know the quirks of it better than I do.

Now, I have done some research on DF fluids, so don't worry. The wiki wasn't incredibly useful for specifics, but a few posts by Kanddak were very helpful. In order to emulate it though, I need to understand it...

Spoiler: 2x2 grid (click to show/hide)

I went into the object arena, paused the game, and put down a 2x2 grid of water. I stepped frame-by-frame until one of the water tiles updated, noting how many frames it took it to update. I stopped once all the initial water had moved. Now as you can see, 1 frame does not necessarily indicate 1 update. It takes an "unpredictable" number of turns before a fluid will move. Does each tile have an "update timer" similar to a creature's speed? Is this related to fluid density (or whatever the property is called) in the raws?

It's the only explanation I can think of for the "staggered" updates, both in regards to tile position and time, especially since I placed all the water on the same frame on a dry area. Take a look here for a more exaggerated example:

Spoiler: 4x4 grid (click to show/hide)

However it seems that whenever a tile DOES update, it will go down to 1/7, dispersing everything else to its neighbours, or at least in the case of a flat area with only minimal water present.
Logged
Quote from: mrbobbyg
Hey, I'm cool with you tying a dog up and shooting it with a ballista if you're short on elves, but there's not need to lie about it to us.

hermes

  • Bay Watcher
    • View Profile
Re: Why doesn't every water tile update every frame?
« Reply #1 on: March 03, 2014, 02:01:52 am »

In a YouTube interview Toady gave recently, IIRC, he talked about spreading processes out over a 100 tick cycle, or something like that, to avoid bottlenecks that cause stuttering.  This sounds connected, possibly.  Can't find the link right now.  I guess that would explain the different decay times on the piles of water?
Logged
We can only guess at the longing of the creator. Someone who would need to create one such as you. - A Computer
I've been working on this type of thing...

Danjen

  • Bay Watcher
    • View Profile
Re: Why doesn't every water tile update every frame?
« Reply #2 on: March 03, 2014, 02:05:17 am »

Yes, that could be it. I suppose there might be a simple chunking going on under the hood. That gives me some insight into it.
Logged
Quote from: mrbobbyg
Hey, I'm cool with you tying a dog up and shooting it with a ballista if you're short on elves, but there's not need to lie about it to us.

Boltgun

  • Bay Watcher
  • [UTTERANCES]
    • View Profile
Re: Why doesn't every water tile update every frame?
« Reply #3 on: March 03, 2014, 03:42:34 am »

Fluidity has an effect, magma take slower to flow despite using the same mechanics. Perhaps there is a cap of the number of tiles that are checked too, to reduce the FPS loss.
« Last Edit: March 03, 2014, 08:54:27 am by Boltgun »
Logged

Sizik

  • Bay Watcher
    • View Profile
Re: Why doesn't every water tile update every frame?
« Reply #4 on: March 03, 2014, 08:46:36 am »

Also, if you have a bunch of 7/7 water with a few 6/7 tiles in it, you can see a definite pattern in the way they move around.
Logged
Skyscrapes, the Tower-Fortress, finally complete!
Skyscrapes 2, repelling the zombie horde!

hermes

  • Bay Watcher
    • View Profile
Re: Why doesn't every water tile update every frame?
« Reply #5 on: March 03, 2014, 08:59:49 am »

Here is the interview I was thinking of, from about 21:00 onwards he talks about optimisation.  22:00 has the part about "staggered timers" and fluids.
Logged
We can only guess at the longing of the creator. Someone who would need to create one such as you. - A Computer
I've been working on this type of thing...