Hey guys,
Im working on creating an entity component system but I am stuck on one particular problem that I need some help with.
Currently i have a base class entity that have a vector of component pointers like the following
class entity { int id; std::vector<component*> mycomponents; int entity_type; bool deleteme; }
I have public functions that will allow me to both add and delete components from the entity. after this i will have a bunch of systems that will do the updating for me (the components will just have information other then maybe the ai component which would contain a behaviour tree/FSM)
The problem that I am trying to figure out is how would i get the correct component i need for a system (say i need the position and velocity components for the movement system). After having a google a round I can see that i could do a dynamic cast (as my base component class will have variable to say what type of component it is) but i have heard that this is not really a very efficient method and not really good practice (feel free to correct me). I could also do some kind of messaging system for changing the data in a component but getting data out of it would be harder (would need a virtual return function of each data type).
Any advice on a way I could get around this problem. is their a method that i have over looked?
No comments:
Post a Comment