I know this question has been asked several times, but I'm still not sure how to implement input handling in a component based engine.
There are three main ideas I have in implementing input handling:
- The input component will hold events it's interested. The input system will translate key and mouse events to game events and loop through the entities with the input component and if they are interested in the event an appropriate action will be taken by the input system. This action would be hard coded to the input system.
- No input component. You would register entities with specific events to the input system. The input system would then send messages (with the entity id and event type) to other systems so that these can take the appropriate action. Or as in the first case, the actions would be hard-coded to the input system.
- Similar to the first method, but instead of hard coding the action to the input system, the component would contain a map of events to functions (i.e.
std::map<std::function>) which would be called by the input system. This has the added effect of being able to couple the same event to different actions.
Would you recommend any of the above methods or do you have any suggestions that would help me implement a flexible input handling system? Also, I'm not yet familiar with multi-threading but any suggestions that would make the implementation thread-friendly are also welcome.
Note: One added requirement I'd like the implementation to fulfill is that I'd be able to pass the same input to many entities, like for example moving a camera entity and the player at the same time.