|
Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
|
Action-based input dispatcher for polled input values and callbacks. More...
#include <InputManager.h>
Classes | |
| struct | BoolAction |
| Runtime state for one bool action name. More... | |
| struct | BoolCallbackEntry |
| Stored callback registration for a bool action. More... | |
| struct | CallbackHandle |
| Opaque handle for a registered input callback. More... | |
| struct | FloatAction |
| Runtime state for one float action name. More... | |
| struct | FloatCallbackEntry |
| Stored callback registration for a float action. More... | |
| struct | ProviderHandle |
| Opaque handle for a registered input provider. More... | |
| struct | Vec2Action |
| Runtime state for one vec2 action name. More... | |
| struct | Vec2CallbackEntry |
| Stored callback registration for a vec2 action. More... | |
Public Types | |
| enum class | DispatchRule { EveryFrame , Changed , Pressed , Released } |
| Rule that controls when a registered callback runs during InputManager::dispatchCallbacks(). More... | |
| enum class | ActionValueType { Bool , Float , Vec2 } |
| Runtime value type for an action provider. More... | |
| using | BoolProvider = std::function<bool()> |
| Provider function for a bool action. | |
| using | FloatProvider = std::function<float()> |
| Provider function for a float action. | |
| using | Vec2Provider = std::function<glm::vec2()> |
| Provider function for a vec2 action. | |
| using | BoolCallback = std::function<void( bool value )> |
| Callback function for a bool action. Receives the current sampled value. | |
| using | FloatCallback = std::function<void( float value )> |
| Callback function for a float action. Receives the current sampled value. | |
| using | Vec2Callback = std::function<void( glm::vec2 value )> |
| Callback function for a vec2 action. Receives the current sampled value. | |
Public Member Functions | |
| InputManager () | |
| ~InputManager ()=default | |
| void | setupDefaultBindings () |
| Sets up the default controller mappings. | |
| ProviderHandle | bindBoolAction (std::string name, BoolProvider provider) |
| Binds a provider for a named bool action. | |
| ProviderHandle | bindFloatAction (std::string name, FloatProvider provider) |
| Binds a provider for a named float action. | |
| ProviderHandle | bindVec2Action (std::string name, Vec2Provider provider) |
| Binds a provider for a named vec2 action. | |
| CallbackHandle | onBoolAction (const std::string &name, DispatchRule rule, BoolCallback callback) |
| Registers a callback for a named bool action. | |
| CallbackHandle | onBoolPressed (const std::string &name, std::function< void()> callback) |
| Registers a callback for a bool action press transition. | |
| CallbackHandle | onBoolReleased (const std::string &name, std::function< void()> callback) |
| Registers a callback for a bool action release transition. | |
| CallbackHandle | onFloatAction (const std::string &name, DispatchRule rule, FloatCallback callback) |
| Registers a callback for a named float action. | |
| CallbackHandle | onVec2Action (const std::string &name, DispatchRule rule, Vec2Callback callback) |
| Registers a callback for a named vec2 action. | |
| void | removeCallback (CallbackHandle handle) |
| Removes a callback registered with one of the on-action functions. | |
| void | removeProvider (ProviderHandle handle) |
| Removes a provider registered with one of the bind-action functions. | |
| void | beginFrame () |
| Samples every bound provider and advances action state for a new frame. | |
| void | dispatchCallbacks () |
| Invokes callbacks that match their dispatch rule for the current frame. | |
| bool | getBoolAction (const std::string &name) const |
| Returns the latest sampled bool value for a named action. | |
| float | getFloatAction (const std::string &name) const |
| Returns the latest sampled float value for a named action. | |
| glm::vec2 | getVec2Action (const std::string &name) const |
| Returns the latest sampled vec2 value for a named action. | |
| const XrInputHandler & | getXrInputHandler () const |
| XrInputHandler & | getXrInputHandler () |
| const XrRig & | getXrRig () const |
| XrRig & | getXrRig () |
Private Member Functions | |
| CallbackHandle | makeHandle () |
| Allocates the next callback handle id. | |
Private Attributes | |
| std::unordered_map< std::string, BoolAction > | boolActions_ |
| Bool actions keyed by action name. | |
| std::unordered_map< std::string, FloatAction > | floatActions_ |
| Float actions keyed by action name. | |
| std::unordered_map< std::string, Vec2Action > | vec2Actions_ |
| Vec2 actions keyed by action name. | |
| uint64_t | nextCallbackId_ = 1 |
| Next non-zero callback id assigned by makeHandle(). | |
| uint64_t | nextProviderId_ = 1 |
| Next non-zero provider id assigned by a bind function. | |
| bool | callbacksDispatched_ = true |
| Guards against dispatching callbacks twice for one sampled frame. | |
| XrInputHandler | xrInputHandler_ |
| XrRig | xrRig_ |
Action-based input dispatcher for polled input values and callbacks.
InputManager stores named actions by value type: bool, float, and vec2. A provider function supplies the current value when InputManager::beginFrame() runs. Polling functions return the latest sampled value. Registered callbacks run when InputManager::dispatchCallbacks() is called.
Action names are type-local. The same string can be bound as a bool action and a float action without sharing state.
Definition at line 57 of file InputManager.h.
| using Input::InputManager::BoolCallback = std::function<void( bool value )> |
Callback function for a bool action. Receives the current sampled value.
Definition at line 145 of file InputManager.h.
| using Input::InputManager::BoolProvider = std::function<bool()> |
Provider function for a bool action.
Definition at line 138 of file InputManager.h.
| using Input::InputManager::FloatCallback = std::function<void( float value )> |
Callback function for a float action. Receives the current sampled value.
Definition at line 147 of file InputManager.h.
| using Input::InputManager::FloatProvider = std::function<float()> |
Provider function for a float action.
Definition at line 140 of file InputManager.h.
| using Input::InputManager::Vec2Callback = std::function<void( glm::vec2 value )> |
Callback function for a vec2 action. Receives the current sampled value.
Definition at line 149 of file InputManager.h.
| using Input::InputManager::Vec2Provider = std::function<glm::vec2()> |
Provider function for a vec2 action.
Definition at line 142 of file InputManager.h.
|
strong |
Runtime value type for an action provider.
| Enumerator | |
|---|---|
| Bool | Boolean action value. |
| Float | Floating-point action value. |
| Vec2 | 2D vector action value. |
Definition at line 81 of file InputManager.h.
|
strong |
Rule that controls when a registered callback runs during InputManager::dispatchCallbacks().
InputManager::DispatchRule::Pressed and InputManager::DispatchRule::Released apply to bool actions only. Float and vec2 callbacks dispatch for InputManager::DispatchRule::EveryFrame and InputManager::DispatchRule::Changed.
Definition at line 70 of file InputManager.h.
| Input::InputManager::InputManager | ( | ) |
|
default |
| void Input::InputManager::beginFrame | ( | ) |
Samples every bound provider and advances action state for a new frame.
The previous sampled value is updated before the provider is called. Call this once per frame before polling actions or dispatching callbacks.
| ProviderHandle Input::InputManager::bindBoolAction | ( | std::string | name, |
| BoolProvider | provider ) |
Binds a provider for a named bool action.
| name | Action name to bind. |
| provider | Function sampled by InputManager::beginFrame(). An empty provider samples as false. |
If a bool provider already exists for name, this call replaces it and resets the cached value to false. Existing bool callbacks for name remain registered.
| ProviderHandle Input::InputManager::bindFloatAction | ( | std::string | name, |
| FloatProvider | provider ) |
Binds a provider for a named float action.
| name | Action name to bind. |
| provider | Function sampled by InputManager::beginFrame(). An empty provider samples as 0.0f. |
If a float provider already exists for name, this call replaces it and resets the cached value to 0.0f. Existing float callbacks for name remain registered.
| ProviderHandle Input::InputManager::bindVec2Action | ( | std::string | name, |
| Vec2Provider | provider ) |
Binds a provider for a named vec2 action.
| name | Action name to bind. |
| provider | Function sampled by InputManager::beginFrame(). An empty provider samples as {0.0f, 0.0f}. |
If a vec2 provider already exists for name, this call replaces it and resets the cached value to zero. Existing vec2 callbacks for name remain registered.
| void Input::InputManager::dispatchCallbacks | ( | ) |
Invokes callbacks that match their dispatch rule for the current frame.
A dispatch pass runs at most once per InputManager::beginFrame() call. Additional calls before the next frame do nothing.
|
nodiscard |
Returns the latest sampled bool value for a named action.
| name | Action name to read. |
name.
|
nodiscard |
Returns the latest sampled float value for a named action.
| name | Action name to read. |
name.
|
nodiscard |
Returns the latest sampled vec2 value for a named action.
| name | Action name to read. |
name. | XrInputHandler & Input::InputManager::getXrInputHandler | ( | ) |
| const XrInputHandler & Input::InputManager::getXrInputHandler | ( | ) | const |
| XrRig & Input::InputManager::getXrRig | ( | ) |
| const XrRig & Input::InputManager::getXrRig | ( | ) | const |
|
nodiscardprivate |
Allocates the next callback handle id.
| CallbackHandle Input::InputManager::onBoolAction | ( | const std::string & | name, |
| DispatchRule | rule, | ||
| BoolCallback | callback ) |
Registers a callback for a named bool action.
| name | Action name to observe. |
| rule | Dispatch rule for the callback. |
| callback | Function invoked by InputManager::dispatchCallbacks(). Empty callbacks are ignored. |
Callbacks can be registered before a provider is bound. Missing providers sample as false.
| CallbackHandle Input::InputManager::onBoolPressed | ( | const std::string & | name, |
| std::function< void()> | callback ) |
Registers a callback for a bool action press transition.
| name | Action name to observe. |
| callback | Function invoked when the action changes from false to true. |
| CallbackHandle Input::InputManager::onBoolReleased | ( | const std::string & | name, |
| std::function< void()> | callback ) |
Registers a callback for a bool action release transition.
| name | Action name to observe. |
| callback | Function invoked when the action changes from true to false. |
| CallbackHandle Input::InputManager::onFloatAction | ( | const std::string & | name, |
| DispatchRule | rule, | ||
| FloatCallback | callback ) |
Registers a callback for a named float action.
| name | Action name to observe. |
| rule | Dispatch rule for the callback. Only InputManager::DispatchRule::EveryFrame and InputManager::DispatchRule::Changed dispatch. |
| callback | Function invoked by InputManager::dispatchCallbacks(). Empty callbacks are ignored. |
Changed callbacks dispatch when the absolute difference from the previous sampled value is greater than 0.0001f. Missing providers sample as 0.0f.
| CallbackHandle Input::InputManager::onVec2Action | ( | const std::string & | name, |
| DispatchRule | rule, | ||
| Vec2Callback | callback ) |
Registers a callback for a named vec2 action.
| name | Action name to observe. |
| rule | Dispatch rule for the callback. Only InputManager::DispatchRule::EveryFrame and InputManager::DispatchRule::Changed dispatch. |
| callback | Function invoked by InputManager::dispatchCallbacks(). Empty callbacks are ignored. |
Changed callbacks dispatch when the squared distance from the previous sampled value is greater than 0.000001f. Missing providers sample as {0.0f, 0.0f}.
| void Input::InputManager::removeCallback | ( | CallbackHandle | handle | ) |
Removes a callback registered with one of the on-action functions.
| handle | Callback handle returned at registration time. |
Invalid handles and already removed handles are ignored.
| void Input::InputManager::removeProvider | ( | ProviderHandle | handle | ) |
Removes a provider registered with one of the bind-action functions.
| handle | Provider handle returned at bind time. |
Removing a provider clears the provider function and resets the cached value to that type's default. Registered callbacks for the action remain registered. Invalid handles, stale handles, and already removed handles are ignored.
| void Input::InputManager::setupDefaultBindings | ( | ) |
Sets up the default controller mappings.
|
private |
Bool actions keyed by action name.
Definition at line 387 of file InputManager.h.
|
private |
Guards against dispatching callbacks twice for one sampled frame.
Definition at line 392 of file InputManager.h.
|
private |
Float actions keyed by action name.
Definition at line 388 of file InputManager.h.
|
private |
Next non-zero callback id assigned by makeHandle().
Definition at line 390 of file InputManager.h.
|
private |
Next non-zero provider id assigned by a bind function.
Definition at line 391 of file InputManager.h.
|
private |
Vec2 actions keyed by action name.
Definition at line 389 of file InputManager.h.
|
private |
Definition at line 394 of file InputManager.h.
|
private |
Definition at line 395 of file InputManager.h.