I'm building a game with XNA at the moment, and I currently have my game object components set up like so:
class Character : GameComponent
{
public int health, state;
public float speed;
}
etc. Since making a menu system, I've played around with data container type objects, say I have a base class of DataContainer, and then subclasses like IntContainer, FloatContainer. Depending on their subclass, they return their contained data type. I'm wanting to hook up this menu system to the components, so that I can easily edit them, I'm wondering if I should change my components to also adopt this model of holding generic data containers instead of explicitly typed data, like so:
class Character : GameComponent
{
public DataContainer[] data;
public int health()
{
return (data[0].getValue());
}
}
I could keep appropriately named methods as above, so getting a value by name in code would still be simple. It will take a bit of work to swap my engine over to this method of data storage, so I'm wondering if anyone has input, does the more generic method affect performance in any measurable way? Is calling two methods to get a value worse than grabbing the value directly?