|
| static void | ClearEventHandlers () |
| | Drops every handler for every event type; equivalent to UnregisterAllEvents().
|
| template<typename EventT> |
| static void | DispatchEvent (const EventT &event) |
| | Invokes every handler registered for event's type, in registration order.
|
| template<typename EventT> |
| static std::string | RegisterEventCallback (std::function< void(const EventT &)> callback) |
| | Registers a free-function/lambda callback for EventT, returning an ID for later unregistration.
|
| template<typename T, typename EventT> |
| static std::string | RegisterEventHandler (T *instance, void(T::*memberFunction)(const EventT &)) |
| | Registers a member-function handler bound to instance, returning an ID for later unregistration.
|
| static void | UnregisterAllEvents () |
| | Drops every handler for every event type.
|
| static void | UnregisterEvent (EventType type, std::string id) |
| | Removes the single handler with matching id from type's handler list.
|
| static void | UnregisterEvents (EventType type) |
| | Drops every handler registered for type.
|
Static registry mapping EventType to subscribed handlers; dispatches events synchronously to every handler registered for its type.
Everything here is static, so there is no dispatcher instance to pass around: subscribe from anywhere, and the window layer's keyboard, mouse, and window events reach you. RegisterEventHandler() binds a member function and is the form you will use most; RegisterEventCallback() takes a std::function for lambdas and free functions.
Both return a string id. Keep it and pass it to UnregisterEvent() when the subscriber goes away, typically in a scene's OnDeactivate() or destructor. Handlers outlive the objects they were bound to otherwise, and the next dispatch calls into freed memory.
Dispatch is synchronous and runs in registration order on the calling thread. The handler list is copied before iteration, so a handler may register or unregister during dispatch safely.
public:
this, &WorldScene::OnKeyPressed);
}
if (!m_keyId.empty()) {
m_keyId.clear();
}
}
void OnKeyPressed(
const Sleak::Events::Input::KeyPressedEvent& e) {
}
private:
std::string m_keyId;
};
#define if_key_press(key)
static void UnregisterEvent(EventType type, std::string id)
Removes the single handler with matching id from type's handler list.
static std::string RegisterEventHandler(T *instance, void(T::*memberFunction)(const EventT &))
Registers a member-function handler bound to instance, returning an ID for later unregistration.
void Begin() override
Activates every owned object; runs once after Initialize().
void OnDeactivate() override
Override for logic that should run when the scene stops being active.
- See also
- Event, EventType, Events::Input::KeyPressedEvent, Events::Input::MouseMovedEvent
Definition at line 132 of file Event.hpp.