class Entity{
public:
Entity(unsigned int id):
id_(id)
{};
void handleMessage(BaseMessage &message&message){
for(auto element: components_){
element.second->handleMessage>handleMessage(message);
}
}
template<classtemplate<class T>T>
void attachComponent(T *component){
//Consider making safer in case someone tries to attach same component type twice
components_[typeid(T).hash_code()] = component;
}
template<classtemplate<class T>T>
void detachComponent(void){
components_.erase(typeid(T).hash_code());
}
template<classtemplate<class T>T>
T* getComponent(void)const{
return *components_.find(typeid(T).hash_code());
}
unsigned int getInstanceID(void)const{
return id_;
}
private:
unsigned int id_;
std::map<size_tmap<size_t, BaseComponent*>BaseComponent*> components_;
};
class BaseComponent{
public:
virtual void handleMessage(BaseMessage &message&message){};
};
class BaseMessage{
public:
virtual int getType(void) = 0;
};
template<classtemplate<class T>T>
handleMessage(T&T& message){};
My thought was to create an InputHandlerComponent which registers with the keyboard class to listen to specific key presses defined possibly in some file. For example,
keyboard.register( player.getComponent<InputHandler>() , 'W') .
keyboard.register( player.getComponent<InputHandler>() , 'W')