0

What is the best approach to switch to different scenes/areas in a 3D game from the render area?

Say you have a character and he moves into a new area, how would you go about unloading the area and loading the new area. Would you just load the render function up with different loading calls and only load them if they fell within certain parameters or would you create enumerators for each area and use something like a switch statement to switch to the new area after unloading your data for the current area?

I have always created REALLY bad transitions on small games I have made for a hobby and it usually kills my performance at some point or time.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • If you have a good resource manager, I would avoid unloading the current area. Just set the reference count to 0 and let the RM know it's not being used if it needs to free up memory in the future. That way if you ever go back to the original level you may not have to re-load it from disk. Having said that, there's http://gamedev.stackexchange.com/ that might offer you some better insight. – Andon M. Coleman Aug 21 '13 at 20:31

1 Answers1

1

Using enum or/and switch/case is not very flexible.

You can simply use a function, example load_area(i), to unload a previous level/area then load level i instead (it could use a smart resource manager as suggested by Andon M. Coleman).

You should separate the resource handling from the game logic and the engine. Example, the rendering system should display currently loaded drawable resources rather than looping through enums and select which scene to render.

You should minimize the unloading/loading phases; depending on the game, you can completely avoid discrete transitions by using an LOD-like (level of detail) manager that updates resources dynamically depending on the current state of the game.

a.lasram
  • 4,371
  • 1
  • 16
  • 24
  • Ya, I kinda understand what you are getting at there. But wouldn't that become cumbersome if you had a lot of areas in the game? Because you would have to still load all of the areas somewhere? All I'm getting from it is that you are moving the loading to an external function. Is there any way you could give me a little pseudo code or a small example so I could better understand it? – SonarSoundProgramming Aug 22 '13 at 01:38
  • For a very basic implementation, keep a list of everything in all areas in memory (eg list of model/file names and positions). When you get close to things, load them and when you go too far away, unload them. Loading might happen in another thread and the renderer only draws things that have finished loading (though make sure the rendering thread does all the needed GL calls for buffering data etc). As amount of stuff in your level increases you might want to separate the lists of models into groups for each area and place their position refs in a spatial data structure. – jozxyqk Aug 22 '13 at 11:38
  • @jozxyqk Thank you for that clarification. I see what he, and you means now. – SonarSoundProgramming Aug 22 '13 at 15:05