Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Games like Skyrim, Morrowind, and more are using quads or square to divide the terrain if im correct. The player is always at #5

1 | 2 | 3
4 | 5 | 6
7 | 8 | 9

So whenever you cross the border you unload and load the new "areas" But if the user goes just over the edge and then the second after goes back previous area a lot of unnecessary loading and unloading is done. Is there a general approach to this because I dont think games like skyrim have this issue?

Cheers!

share|improve this question
    
You might be right about the algorithm, but it's still a gross approximation. You can have certain objects (houses, dungeons) only load if you're close enough to them (regardless of what cell you're in) or you can delay the loading of the new cells until you're certain the player needs it. Basically, there are lots of ways to optimize it, and I'm pretty sure the programmers came up with fancy ways of doing it. –  rootlocus Nov 19 '12 at 17:03
add comment

1 Answer

up vote 7 down vote accepted

The general approach is called hysteresis: instead of immediately changing when you cross a border, you change only after you are some distance past the border.

For the simplest example, suppose you want to draw a warning on the screen if you are too close to something. The straightforward code is:

if distance < 20:
    draw warning

But if you're wobbling between 20.001 and 19.999, the warning might flash on and off. Instead, you can

  1. remember whether the warning is on or off
  2. use a different threshold for turning it on and turning it off

The code is a bit longer (which is probably why people don't do it all the time):

var warning_displayed

if warning_displayed and distance > 22:
    warning_displayed = false
else if not warning_displayed and distance < 18:
    warning_displayed = true

if warning_displayed:
    draw warning

Now what happens? If you're wobbling between 20.001 and 19.999 the warning will either stay on (if you last went below 18) or it will stay off (if you last went above 22), but it won't flash on and off.

The same general idea can be used for loading map areas in Skyrim. The wikipedia article gives lots of examples of where this technique comes in handy (not just maps or games or software).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.