I have made an input system based kind of on this:
http://www.gamedev.net/blog/355/entry-2250186-designing-a-robust-input-handling-system-for-games/
I have my raw input -> context map -> actions.
I have a dispatcher / subject / observerable (whatever) that will do the notifying when actions are triggered.
Implemented very roughly as:
vector<*listeners>
I have a listener which registers to the dispatcher to handle certain actions.
It is implemented roughly as
vector<*dispatchers> /// to automatically unregister on destruction
map<actions, std::functions> /// function to call given an action, bound to *this with std::bind
I would like to place this listener as a member of any game object which should do something with input.
class Camera
{
Camera();
InputListener m_listener;
}
Camera::Camera()
{
dispatcher.register(m_listener, event::CAM_MOVE_LEFT); /// probably occurs someplace else, really.
m_listener.addCallback(event::CAM_MOVE_LEFT, std::function<void()>(std::bind(Camera::moveLeft, this)));
}
Problem #1
I had to use std::bind to bring along the *this so that the callback can call the member function. This isn't a problem unto itself until...
...The parent object is copied.
The callbacks which are stored in the listener are now pointing to the pre-copied-object.
This means that any object which decides to have an inputListener as a member must implement a non-trivial copy constructor to rebind all the callbacks with the proper *this.
Kinda stinks of poor design.
I could make the member static, but then wouldn't *all* cameras move left when this callback occurs?
I'm overcomplicating this somehow.