Your areas should mainly reside in python.
Each area knows of the objects they belong to it. For example, you organize your forest in squares (can be any shape). So every tree, rock, bush (game objects) are known by the area.
The area should knows enough to create these game objects when they are not there (position, scale, orientation, template object for addObject) [alternative the area might know how to LibLoad the game objects … but this is an advanced topic].
Now you can now focus on managing areas (rather than on game objects).
When the player is that far away from an area (an area has a location within the 3D world), that none of it’s objects can be seen in the near future, you can remove all game objects without the player will notice (assuming there is no logic/physics that is needed).
With the squares this should not be that difficult. Please do not make the mistake to calculate the distance to all squares all the time. This will eat too much time when your world increases. Better find an efficient way to identify areas that just left the range. It might sound the same but is not. You do not need to touch all areas when moving around. There is a very limited number of areas that can have this condition. With a clever method you just touch the possible areas, rather than all areas.
I would try to draw the “before” and “after” situation with pen and paper. E.g. move the camera forward until I need to switch areas. Then check what areas that are and if there is a formula. Try it with other operations too (circling, moving diagonal) and check if the formula still fits.
While you do that you might discover a formula that gives you the areas that are just entering the range around the camera. Here belongs the same … efficient as possible.
With that you should get two sets of data:
A) areas that left range
B) areas that entered range
[Both should not be visible to the camera at that stage]
Now you process culling:
A1) remove all objects from areas of A)
and unculling:
B1) addObject all objects from areas of B)
That is the basic concept.
Thoughts:
- areas can have counterparts in the 3D scene, but many areas (even when invisible) eat still processing power
- you can organize areas in larger areas the same way as with single objects. You will get super areas. This can help on managing planet-size worlds.
- large areas are easier to manage, but cause more objects to exist at the same time
- unculling (adding) many objects of an area, can cause short time lags.
- many small areas increase management overhead.
- Yes you will need Python to do this.