So anyway this code works properly for calling callbacks on events, and even adding in unchanging parameters but if I wanted to place something where the mouse cursor is when the action happens I wouldn't be able to do that since the callbacks don't know about the input or the event.
Couldn't you pass a reference to sf::Input to the callback?
void OnJump(const sf::Input& realtimeInput);
sf::RenderWindow window = ...;
thor::EventSystem<std::string> system;
system.Connect( "on-jump", std::tr1::bind(&OnJump, std::tr1::cref(window.GetInput())) );
I've been working on wrapping my head around the proper way to go about handling events with Thor's Action and EventSystem. So far I have a system that works but it seems clunky
Yes, I am not very happy about the current way of event handling either. In Thor 1.0, there was mainly the callback system thor::SfmlEventSystem to handle events. Later, I introduced thor::ActionMap and thor::Action (which I think are very useful) but these classes are not very well integrated to the rest. Currently, the Events module contains the following components:
- ActionMap and Action: Bind combinations of key/mouse/joystick events to action IDs
- SfmlEventSystem: Map sf::Event objects to callbacks with the signature void Listener(sf::Event)
- EventSystem: Map any event type to callbacks taking the event object
Generally, I tend to make ActionSystem more powerful and to get rid of SfmlEventSystem; I don't know if the latter is even used by anybody. We have recently had a similar discussion in the
french thread about this.
However, for thor::ActionMap to completely replace thor::SfmlEventSystem, it needs to be able to pass the events to the callbacks. And here is my problem: Because ActionMap abstracts the events away (you can use sf::Event as a trigger for actions, as well as sf::Input), there needn't necessarily be a event to forward. So we cannot connect a listener like
void OnTextEntered(sf::Event event), but we need the sf::Event object to extract
event.Text.Unicode. I have to think more about this...
So, I am open to any suggestions as well as reports about the usefulness of the current Events module (especially the SfmlEventSystem class)