Scene Management

Started by
5 comments, last by lord_balron 15 years, 1 month ago
After my previous topic, I'd like to know of some ways of managing a dynamic scene, such that you can have derived objects that can all be dynamically added and removed in a contained space. This is because I'd like to be able to call Scene.Draw() or something along those lines to have all of the objects call their own draw functions. My Language is C++. Any help would be greatly appreciated.
Advertisement
Hm not totally sure what you're askin...

The scene is just a collection of renderable objects that persists across frames. Could be a simple vector, a graph, or a spatial data structure of some kind (eg octree). Each frame it does some broad culling, sometimes some sorting (eg back-to-front) and passes all probably-visible objects to the renderer for drawing.

Then the renderer may do its own sorting on the objects to be drawn that frame (eg on texture or state changes), then draws them and clears its draw lists to be ready for next frame.
Anthony Umfer
Have you looked at how other projects do it (Irrlicht, Ogre, OpenSceneGraph)?
Cool, i like your thinking! [smile]

Anyway, you could create a Scene class that contains a couple std::vectors for dynamic allocation of objects/sprites/models to draw

then create methods to add and remove certain objects either under circumstances or manually.

example:
void Scene::AddObject( const Object* obj ){    objVector.push_back(obj);    //....}


not sure if thats right, or what you wanted, but from what i could tell it is ok. :)
Yea, well thats the method I was using before, but I was having trouble removing objects except when destroying the entire scene.

I guess I could go look at the other projects...
I'm not convinced it is good way to learn by reading other source codes.

The context of this problem is lost in your previous thread. Having looked at that, I think this is a memory management problem. You're managing raw pointers everywhere, but I didn't see any calls to new or delete so I can only guess.

boost::shared_ptr could be your answer. Though it could give you alot of new problems, as I'm not sure how experienced you are to set up boost SDK just to solve this problem.

Anyways, you have two functions which take raw pointers and insert/erase in std::vector:
void Particle::AddChild(Object* Child)
void Particle::ReleaseChild(Object* ToRemove)

Now what we need to know, is where are these Object objects constructed and destructed.
Well originally I was doing this...

Particle* Part = new Particle(MouseX / 100, MouseY / 100, MouseX, MouseY);Part->SpriteLocation = "guy.png";Part->LoadSprite();Part->LayerNumber = 1;Part->IsDrawn = true;GameScene->AddChild(Part);


But I don't know if this is the right thing to do.

Where Particle is a derived class of the Base Object class.

This topic is closed to new replies.

Advertisement