Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualpinebanana

Posted 01 December 2012 - 07:41 AM

Alright, that helps me.

I have run into another problem though.
Since the hierarchy manager will have functions that returns objects of a ceirtain requested type, would it be a good idea to keep a different list for each object type? Iterating through all objects and checking their type seems pretty slow to me.


Although it may be complicated, this can be achieved through mapping each type of GameObject to an index in an array.
I realise that sentence doesn't make all that much sense, but I'll try to explain it further.
Basically this may be a way of storing your GameObjects:
std::vector<std::vector<GameObject*> > gameObjects;

Where the first index is the GameObject's class type ID, and the second index is the GameObject's ID, or vise versia (1st = GAMEOBJECT_ID and 2nd = TYPE_ID)
i.e.
gameObjects[TYPE_ID][GAMEOBJECT_ID]
// or
gameObjects[GAMEOBJECT_ID][TYPE_ID] // this way may be more efficient, since there is more GameObject objects than there is GameObject classes

This means you will need to store an ID in the GameObject, and register the ID when you add the GameObject.

Now to store/get the TYPE_ID of a GameObject calss is possible without the use of RTTI you just need to think hard (you can do it with virtual functions and macros; using virtual functions since you need to know what type a GameObject is). Currently, I am doing something similiar (storing objects by type) by using macros that are defined WITHIN each class.

For example, here's what a class that derives a GameObject may look like:
class Player : public GameObject
{
	 // registers the class, adds an ID to the game object CLASS
	 // also defines virtual/staitc functions to retrieve class information (ID, name, etc.)
	 REGISTER_CLASS(Player)
public:
};
Then.. to access a game object it may be something like this:
template <typename Type>
Type* getGameObject(int id)
{
	 return gameObjects[typename Type::GetClass().getId()][id];
}
// or...
GameObject* getGameObject(const GameObject::Class& gameObjectClassType, int id)
{
	 return gameObject[gameObjectClassType.getId()][id];
}
Of course, I don't really want to give it away all that much, and there is probably another method of doing this (through the use of templates)

#3pinebanana

Posted 01 December 2012 - 07:41 AM

Alright, that helps me.

I have run into another problem though.
Since the hierarchy manager will have functions that returns objects of a ceirtain requested type, would it be a good idea to keep a different list for each object type? Iterating through all objects and checking their type seems pretty slow to me.


Although it may be complicated, this can be achieved through mapping each type of GameObject to an index in an array.
I realise that sentence doesn't make all that much sense, but I'll try to explain it further.
Basically this may be a way of storing your GameObjects:
std::vector<std::vector<GameObject*> > gameObjects;

Where the first index is the GameObject's class type ID, and the second index is the GameObject's ID, or vise versia (1st = GAMEOBJECT_ID and 2nd = TYPE_ID)
i.e.
gameObjects[TYPE_ID][GAMEOBJECT_ID]
// or
gameObjects[GAMEOBJECT_ID][TYPE_ID] // this way may be more efficient, since there is more GameObject objects than there is GameObject classes

This means you will need to store an ID in the GameObject, and register the ID when you add the GameObject.

Now to store/get the TYPE_ID of a GameObject calss is possible without the use of RTTI you just need to think hard (you can do it with virtual functions and macros; using virtual functions since you need to know what type a GameObject is). Currently, I am doing something similiar (storing objects by type) by using macros that are defined WITHIN each class.

For example, here's what a class that derives a GameObject may look like:
class Player : public GameObject
{
	 // registers the class, adds an ID to the game object CLASS
     // also defines virtual/staitc functions to retrieve class information (ID, name, etc.)
	 REGISTER_CLASS(Player)
public:
};
Then.. to access a game object it may be something like this:
template <typename Type>
Type* getGameObject(int id)
{
	 return gameObjects[typename Type::GetClass().getId()][id];
}
// or...
GameObject* getGameObject(const GameObject::Class& gameObjectClassType, int id)
{
     return gameObject[gameObjectClassType.getId()][id];
}
Of course, I don't really want to give it away all that much, and there is probably another method of doing this (through the use of templates)

#2pinebanana

Posted 01 December 2012 - 07:35 AM

Alright, that helps me.

I have run into another problem though.
Since the hierarchy manager will have functions that returns objects of a ceirtain requested type, would it be a good idea to keep a different list for each object type? Iterating through all objects and checking their type seems pretty slow to me.


Although it may be complicated, this can be achieved through mapping each type of GameObject to an index in an array.
I realise that sentence doesn't make all that sense, but I'll try to explain it further.
Basically an ideal way of storing your components is...
std::vector<std::vector<GameObject*> > gameObjects;
The way to access a GameObject would be...
gameObjects[TYPE_ID][GAMEOBJECT_ID]
This means you will need to store an ID in the GameObject, and register the ID when you add the GameObject.

Now to store/get the TYPE_ID of a game object is possible without the use of RTTI, you just need to think hard. Currently, I am doing something similiar (storing objects by type) by using macros that are defined WITHIN each class.

For example, here's what a class that derives a GameObject may look like:
class Player : public GameObject
{
	 // registers the class, adds an ID to the game object
	 REGISTER_CLASS(Player)
public:
};
Then.. to access a game object it may be something like this:
template <typename Type>
GameObject* getGameObject(int id)
{
	 return gameObjects[typename Type::GetClass().getId()][id];
}
Of course, I don't really want to give it away all that much, and there is probably another method of doing this.

#1pinebanana

Posted 01 December 2012 - 07:34 AM

Alright, that helps me.

I have run into another problem though.
Since the hierarchy manager will have functions that returns objects of a ceirtain requested type, would it be a good idea to keep a different list for each object type? Iterating through all objects and checking their type seems pretty slow to me.


Although it may be complicated, this can be achieved through mapping each type to an index of each type of GameObject.
I realise that sentence doesn't make all that sense, but I'll try to explain it further.
Basically an ideal way of storing your components is...
std::vector<std::vector<GameObject*> > gameObjects;
The way to access a GameObject would be...
gameObjects[TYPE_ID][GAMEOBJECT_ID]
This means you will need to store an ID in the GameObject, and register the ID when you add the GameObject.

Now to store/get the TYPE_ID of a game object is possible without the use of RTTI, you just need to think hard. Currently, I am doing something similiar (storing objects by type) by using macros that are defined WITHIN each class.

For example, here's what a class that derives a GameObject may look like:
class Player : public GameObject
{
     // registers the class, adds an ID to the game object
	 REGISTER_CLASS(Player)
public:
};
Then.. to access a game object it may be something like this:
template <typename Type>
GameObject* getGameObject(int id)
{
     return gameObjects[typename Type::GetClass().getId()][id];
}
Of course, I don't really want to give it away all that much, and there is probably another method of doing this.

PARTNERS