Skip to main content
gamedev.net
🔒 Locked

Managing many objects

Started by Marusu 0 replies 500+ views
Original Post
Marusu
Marusu
I've been developing for a while and have written many objects.
Somehow I became very uncomfortable with the way I use them.
I create pointer of everyone of it in my main CDirect3D class,
instantiate them in OnCreate() method and use their Render()
methods in main CDirect3D::Render method.
Since I used only one of each object it wasn't hard,
but now I'm starting to use more objects, and editing becomes a pain...

Since I written them in a way, that they all have almost the same methods
I decided to derive them from one base class and put instantiated objects
to pointer-to-pointer-to-base class. This way all I'll need will be to run through cycle and use same method on everyone of them. Would this be the
right way? How do you manage many objects?

I also wanted to ask about Release() method of COM objects.
Is it hard to implement? Do I only need to delete every single variable in object which is pointed to by a pointer? Or should I also use something like delete this and stuff?
programmermattc
programmermattc
Typically you would have some kind of base class with a list of objects instantiated from that base class, then just load that list full of all the subtyped implementation objects. Given that they all have the same methods like you mentioned you could do something like (psudo-code):

// Updating
foreach renderObj in myGameObjects {
renderObj.Update();
}

// Rendering
foreach renderObj in myGameObjects {
renderObj.Render();
}

This is classic polymorphism.
=============================RhinoXNA - Easily start building 2D games in XNA!Projects

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.