• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to implement an object manager?

This topic is 5828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I´m starting my first game and I would like to know how you ppl implent an object manager. What I mean is, say you have a 3d shooter, you have a lot of objects on the screen, enemies, bullets flying, etc... How do you manage all this?. I have thought about create an Objet manager where you create objects of different types (I think I will need IDs or Handlers in orther to referenciate them later to change their properties, like decrease its energy if it is hit, move, etc...). THnx in advance.

Share this post


Link to post
Share on other sites
Advertisement
One way would be to have all your game objects derived from the same base object. Then using virtual functions and the vector class, you can store all the game objects in a vector and iterated through the vector to update each object.(don''t really us vector, this is just an example. In 3D games BSPs are one way that is quicker.)


class GameObject; //this is the base object
class Player; //this is derived from GameObject
class Enemy; //this is derived from GameObject
class Weapon; //this is derived from GameObject

GameObject would have a couple of pure virtual functions like update and render, and these functions would be implemented in the derived classes.

Then you have:

vector objectList;
Player *p;
Enemy *e;
Weapon *w;
//create these things
objectList.push_back(p);
objectList.push_back(e);
objectList.push_back(w);
//to use them later on
for(int i=0;i objectList.update();
objectList[i].render();
}
//present your scene


ps. Again I am only using vector to illustrate the point. Vector is to slow to use in a 3D game


---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
I personally like vector for it''s ease of use. I just thought vector was slow, because that''s what I hear all the time. I always hear use a hash map or binary search tree, etc... their faster.


---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
Try a linked list.

A linked list is like a series of objects in a row, and every object in the row knows where the object behind him and infront of him is located (using pointers).

nexe.gamedev.net has a tutorial on a linked list, and you don''t need to know DX in order to understand the linked list tutorial there.

Share this post


Link to post
Share on other sites
Why cant the STL vector class be declared with multiple demensions. what i mean is i tried to do this code to make a 2D map once:

using namespace std;

vector> m_Map2D;

Why doesn''t this work and how do you make a 2D array using container classes rather that standard

CTile * m_Map2D;

// later
m_Map2D = new CTile[10][10];

He who said money was the root of all evil knew little of the nature of money and less about the nature of man.

Share this post


Link to post
Share on other sites

  • Advertisement