Jump to content
  • Advertisement
Sign in to follow this  
Narf the Mouse

Looking for information on Anytime algorithms

This topic is 2774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Specifically, best practices and general implementation. I've got scrolling perlin noise terrain (that is, terrain generated by a series of perlin noise functions) and I want to be able to load data for new sections in the background. Having the game pause while it runs the perlin algorithm for every point on the terrain is non-optimal. Much better if it does that in the background and just needs to slot in already-generated data.

Share this post


Link to post
Share on other sites
Advertisement
I haven't done this before, but I have some ideas - even if my ideas are wrong they tend to get people talking :)

Ok so clearly you need to do the loading in a separate thread.
It should also be non-aggressive so it doesn't use all your processing and create bad frame rates. Perhaps putting a sleep(1) somewhere in your perlin generation loop would keep your game running smoothly while your game is loading.
However there may become a point where the terrain absolutely has to be loaded (such as the player is within 20 meters of it) in which case the sleep should be disabled.

Along with this you need to know exactly when to start and stop loading a chunk. The naive method for this would be something like:
if within minDistance of player startLoading
if without maxDistance of player stopLoading

stopLoading actually interrupts the perlin generation algorithm and frees up the data.

minDistance and maxDistance would be specific to how far ahead you need to load and unload your titles. We use two different values here (min, max) so that if a player dances over the threshold it is not going to start the process repeatedly loading and unloading.

Share this post


Link to post
Share on other sites
I think if you only have a single core CPU you may as well do the work on the main thread - you just need to do small enough quantities of work each frame to maintain a decent frame rate.

You can estimate how much work to do each frame based on the minimum time to get to where you'll need the data (e.g. I'll need a million pixels of data in 100 frames time, so that's 10,000 pixels per frame I need to generate).

However almost everyone has a multi core CPU these days, and if you have one using a thread will be much quicker and you don't need to worry about slowing down your frame rate.

Share this post


Link to post
Share on other sites
Quote:
Original post by Adam_42
I think if you only have a single core CPU you may as well do the work on the main thread - you just need to do small enough quantities of work each frame to maintain a decent frame rate.

You can estimate how much work to do each frame based on the minimum time to get to where you'll need the data (e.g. I'll need a million pixels of data in 100 frames time, so that's 10,000 pixels per frame I need to generate).

However almost everyone has a multi core CPU these days, and if you have one using a thread will be much quicker and you don't need to worry about slowing down your frame rate.

Almost everyone would include me. I'm not near as familar with threading as I should be, so I didn't think of using a thread.

Share this post


Link to post
Share on other sites
Well, I've got it loading all possible new map data (all eight of them, plus an additional center point just in case the player goes back across the line) for each map, in a background thread. This data overload slows loading down to about twenty-five seconds.

On the other hand, loading in new terrain is very fast.

Next up: Only loading tiles when the player gets close enough to the edge and only those edge-tiles. Anyone have any other suggestions?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!