Board index FlightGear Development Weather

Weather dynamics

Everything related to weather simulation, visuals should be discussed in the shader subforum.

Re: Weather dynamics

Postby erik » Thu May 13, 2010 9:31 am

If you want that to get the same random numbers every time over, it's a simple matter of setting the seed constant between these runs.
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Weather dynamics

Postby Thorsten » Thu May 13, 2010 12:01 pm

Here's the problem in a nutshell:

Two systems want to generate the same cloud scenery. To ease workload, generating of weather tiles is split across several frames. In principle even the amount of work done per frame could be different on each system, dependent on performance. In practice, it actually is different between different releases of the system because I'm getting better at performance tuning.

What we want to avoid is even a single call to rand() from any other Nasal process except the weather, because that destroys the sequence. I don't know if it is guaranteed that if I set a seed at the beginning of a function call that no other Nasal is processed before that function terminates - but suppose it is.

So, one could possibly feed a new seed to each system each frame to be used when the work on the weather starts. The multiplayer server would also need to know how much work per frame is done, so that you get a different seed when your system calculates 30 clouds than another system that does 50 per frame. I don't actually know if that is even easily doable, but suppose it is.

Then the multiplayer system takes care of all seeds ever sent to players, because if you sent one set of seeds to one player to build weather, and another player arrives a minute later, he must of course get the same sequence of seeds. So you need good bookkeeping of many seeds sent at different times...

If you think it through, it is anything but a simple matter. Using a dedicated random number generator for weather only which isn't accessed by any other Nasal is far easier.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Weather dynamics

Postby erik » Thu May 13, 2010 12:41 pm

I can see the problem, even the solution used for the random scenery doesn't work since you don't want the same cloud layout everytime you start at a given location.

If the total number of random numbers is rather small then fetching them upfront in the first frame of the sequence and storing them in an array might be the solution. subsequent frames than read from the array rather than calling rand().
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: Weather dynamics

Postby Thorsten » Tue May 18, 2010 8:14 pm

If the total number of random numbers is rather small then fetching them upfront in the first frame of the sequence and storing them in an array might be the solution.


Usually it's at least one random number per coordinate, sometimes more (placement calls usually have some random component) - so transmitting coordinates is generally cheaper than random sequences. :?
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Weather dynamics

Postby jimduchek » Tue May 18, 2010 10:55 pm

Take a look at rand_r() -- it allows you to store the state of the RNG such that you can generate a reproducible string of numbers without having to worry about other things screwing you up.

Jim
jimduchek
 
Posts: 12
Joined: Thu Apr 29, 2010 4:02 am

Previous

Return to Weather

Who is online

Users browsing this forum: No registered users and 1 guest