Accessible Object Storage In a Game Engine
Posted: Fri Jul 20, 2012 3:43 pm
Good day,
I was thinking about the most efficient way to store objects (game objects (entities), components, levels) in my game engine.
So far what I have is the basic concept of storing them as a static member of the main base class.
This would make it easy for all the objects to access resources easily without the mess of pointers
(like my last game engine), as for the implementation of this my thoughts so far have led up to a std::map of
strings and vectors to store everything. For example:
However I am not convinced it is the most efficient and or stable (stable being the keyword here I need more
stability in my engine) method of going about this. Does anyone have a better idea? How do you do it in your
game and or game engine?
Thanks for reading!
P.s Please tell me if it is too much code. Thanks
I was thinking about the most efficient way to store objects (game objects (entities), components, levels) in my game engine.
So far what I have is the basic concept of storing them as a static member of the main base class.
This would make it easy for all the objects to access resources easily without the mess of pointers
(like my last game engine), as for the implementation of this my thoughts so far have led up to a std::map of
strings and vectors to store everything. For example:
Code: Select all
//Everything in the engine will inherit from Dummy.//
struct Dummy
{
//Stuff.//
//Is this a core?//
virtual bool IsCore() {
return false;
}
};
struct Core : public Dummy
{
//Mostly virtual methods, and some data.//
//IMPORTANT DATA: //
/*A "type ID" will be assosaited with the
heirarchy branch that the particular class instance
is a part of, for example: "component", "entity", "level".*/
std::string typeId;
/*A compID, is used to specify a particular subclass, while and id
is used to specify a specific class-instance (object).*/
unsigned int compId, id;
//////////////////////////
//The code in question.//
/////////////////////////
static std::map< std::string, std::vector<Dummy*> > cache;
//This is a instance of core.//
bool IsCore() {
return true;
}
//Cast a Dummy pointer to Core pointer and return it so it can be processed.//
Core* CastToCore( Dummy* core ) {
//Stuff.//
}
};
class Entity : public Core
{
Entity() {
typeId = "Entity";
compID = 0;
id = 0;
}
};
//Example of how this would be used.//
int main()
{
/*Imagine this for components, more
entities, sub-classes of entities and components, levels ect.*/
Core::cache[ "Entity" ].push_back( new Entity );
return 0;
}
stability in my engine) method of going about this. Does anyone have a better idea? How do you do it in your
game and or game engine?
Thanks for reading!
P.s Please tell me if it is too much code. Thanks