Managing objects in a game
I have a 2d World that has many objects in it.
This is roughly the way i implemented the managing system.
Object has a valid state.
Setting valid state to false is equivalent to removing Object from the World.
When the World traverses all the objects to be rendered or check if they are still in view it will skip any invalid once.
The World has a list of pointers to all objects it contains and it also has a list of pointers to objects that are visible and can be rendered.
When there is time between frames the invalid objects are going to be found and removed from the heap.
Of course objects that are never removed are put in a vector instead of a list.
I realize that using smart pointers with reference counting could be an option but i thought my approach would be more efficient.
I am new to game programing so give me some hints.
Consider using some sort of tree to store static objects. That way if you have tons of, say trees in the world and in a huge area, you won''t have to check every single one every frame to determine what to render. A quad tree works well in 2D worlds, and that''s what I''ve been using.
As for dynamic objects, I''m not entirely sure about performance of different techniques.
As for dynamic objects, I''m not entirely sure about performance of different techniques.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement