The core of my entities are parameters. There is nothing that really specialises my entities. It's a bunch of paramters. I had to write some classes to manage those parameters.
I have a class called CParameter which contains one parameter. It's identified by its name and a value, which can either be a string or a float value. There's a function in this class which can load/save the name/value from/to an xml file. The xml structure of a parameter looks like this :
The first one is a string value parameter while the second one is a float value.
Since it doesn't make to only have one parameter, I've created the CParameterList class. This class also has I/O functions to load/save parameter lists from/to an xml file. There are also functions to find a parameter given its name. So you could do something like this :
CParameter *pParam = oParamList.Find( "type" );
This code snipped would return the first parameter of the above shown xml file structure.
The third class I've created is the CParameterized class, where classes who can have parameters are derived from. It has a function to access the parameter list and I/O functions that pass to the CParameterList I/O functions. It's possible to have named parameter lists (more than one parameter list) but this option is not yet fully implemented.
My CEntity class is derived from the CParameterized class. This enabled my CEntityManager class to find entities by looking an the parameters. A possible access would look like this :
// Access entities by a param/value pair.
apAllBuildings = oManager.GetEntityWhere( "type", "building" );
apAllUnits = oManager.GetEntityWhere( "type", "units" );
apAllVehicles = oManager.GetEntityWhere( "subtype", "vehicles" );
// or access all entities having a given parameter.
apAllEntitiesWithBonusValue = oManager.GetEntityWith( "bonus" );
I did some tests and it works all as expected : Fast and simple.
One thing I have to think of is the templates. I would like to have templates which are the base of an entity that has to be created. It's solvable through either having a parameter that will automatically filter out entities with a given parameter name or though a seperate template management within the CEntityManager class. I think I prefer the second option since it's more easy to implement and more intuitive.