![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Named actions resolved from physical bindings, sampled once per frame. More...
#include <input_map.h>
Public Member Functions | |
| void | define (std::string_view action, std::vector< InputBinding > bindings) |
| Define (or replace) an action's bindings. | |
| void | addBinding (std::string_view action, InputBinding binding) |
| Add one binding to an action, defining it if new. | |
| void | clearBindings (std::string_view action) |
Drop every binding for action, keeping the action defined. | |
| const std::vector< InputBinding > & | bindings (std::string_view action) const |
Bindings currently feeding action. | |
| std::vector< std::string > | actions () const |
| Every defined action name, in name order. | |
| void | update (InputHandle &input, const HostChrome &chrome) |
Sample every action from input, rolling the previous values. | |
| void | setPointerOverUI (bool over) |
| Say whether the pointer is over a blocking element of the game's UI. | |
| void | discardPendingEdges () |
| Drop the edges latched since the last command. | |
| void | reset () |
| Forget every action and every latched edge, then define the engine's own. | |
| void | beginTick (uint32_t tick) |
Build the command for tick from everything since the last one. | |
| void | setView (const glm::quat &view) |
| Say where the player is looking, for the commands that follow. | |
| int | indexOf (std::string_view action) const |
The command's slot for action, or -1 when it has none. | |
| uint64_t | actionFingerprint () const |
| A fingerprint of which action holds which command slot. | |
| bool | held (std::string_view action) const |
| Is the action active this frame? | |
| bool | pressed (std::string_view action) const |
| Did it become active this frame? | |
| bool | released (std::string_view action) const |
| Did it stop being active this frame? | |
| float | axis (std::string_view action) const |
| Summed, clamped value of the action's bindings, -1..1. | |
| bool | held (const InputCommand &command, std::string_view action) const |
Is the action active in command? (the tick's answer) | |
| bool | pressed (const InputCommand &command, std::string_view action) const |
| Did it become active since the previous command? | |
| bool | released (const InputCommand &command, std::string_view action) const |
| Did it stop being active since the previous command? | |
| float | axis (const InputCommand &command, std::string_view action) const |
The action's value in command, -1..1. | |
| bool | pointerOverUI () const |
| Whether the pointer was over a blocking element of the game's UI. | |
| const glm::vec2 & | pointer () const |
| Where the pointer is this frame, in window pixels. | |
| const glm::vec2 & | pointerDelta () const |
| How far the pointer moved since the previous frame, in window pixels. | |
| float | wheel () const |
| Wheel notches turned this frame for gameplay, positive away from the viewer. | |
| float | uiWheel () const |
| Wheel notches turned this frame, whatever is under the pointer. | |
| std::u32string_view | text () const |
| The characters typed this frame, in order, as UTF-32. | |
| bool | typed (int key) const |
Whether key went down or auto-repeated this frame. | |
| const InputCommand & | command () const |
| The command the current fixed step is running under. | |
| uint32_t | actionCount () const |
| How many action slots are in use. | |
Named actions resolved from physical bindings, sampled once per frame.
Sampled before any system runs, so every reader in the frame agrees. The frame queries serve frame-rate work only: a fixed update reads the per-tick InputCommand that beginTick() builds from the edges latched between ticks.
| void Vkm::Engine::InputMap::define | ( | std::string_view | action, |
| std::vector< InputBinding > | bindings ) |
Define (or replace) an action's bindings.
| action | Action name, e.g. "Move/Forward"; the stable identity a saved binding file refers to. |
| bindings | Physical controls feeding it. |
| void Vkm::Engine::InputMap::addBinding | ( | std::string_view | action, |
| InputBinding | binding ) |
Add one binding to an action, defining it if new.
| action | Action name. |
| binding | Control added alongside the existing ones. |
| void Vkm::Engine::InputMap::clearBindings | ( | std::string_view | action | ) |
Drop every binding for action, keeping the action defined.
| action | Action name; an undefined one is a no-op. |
| const std::vector< InputBinding > & Vkm::Engine::InputMap::bindings | ( | std::string_view | action | ) | const |
Bindings currently feeding action.
| action | Action name. |
| std::vector< std::string > Vkm::Engine::InputMap::actions | ( | ) | const |
Every defined action name, in name order.
| void Vkm::Engine::InputMap::update | ( | InputHandle & | input, |
| const HostChrome & | chrome ) |
Sample every action from input, rolling the previous values.
Called once per frame before the systems run; also latches edges for the next command. A binding struck since the last sample reads as down, so a sub-frame tap is held for one frame. A device the host's UI holds reads as untouched (the pointer position still travels). A press belongs to whoever held the device when it began, until let go; a press beginning over a blocking game UI element reads as down for UI_CLICK alone.
| input | Device state to sample; its strikes are cleared. |
| chrome | What the host's UI holds this frame. |
|
inline |
Say whether the pointer is over a blocking element of the game's UI.
Read by the next update(): one frame of lag, as the host's chrome has.
| over | Whether a blocking element is under the pointer. |
| void Vkm::Engine::InputMap::discardPendingEdges | ( | ) |
Drop the edges latched since the last command.
For a frame no tick follows (Clock::isSimulationStill); otherwise the next tick, such as the first of a Play session, would get every press made meanwhile.
| void Vkm::Engine::InputMap::reset | ( | ) |
Forget every action and every latched edge, then define the engine's own.
Frees the command slots, which kept would fill MAX_INPUT_ACTIONS across sessions. The command sequence keeps counting, since an ack names it; a press held across a reset stays with its holder until let go.
| void Vkm::Engine::InputMap::beginTick | ( | uint32_t | tick | ) |
Build the command for tick from everything since the last one.
Called once per fixed step before the systems run. Clears the latch, so one keypress does not read as pressed on every tick of a slow frame.
| tick | Simulation tick the command drives. |
|
inline |
Say where the player is looking, for the commands that follow.
Read back off InputCommand::view in a fixed update. A game steering relative to its camera calls this once per frame after moving it.
| view | Orientation the input from now on is aimed with. |
| int Vkm::Engine::InputMap::indexOf | ( | std::string_view | action | ) | const |
The command's slot for action, or -1 when it has none.
Assigned in definition order, stable for the session. An action past MAX_INPUT_ACTIONS has no slot: absent from every command, still answered by the frame queries.
| action | Action name. |
| uint64_t Vkm::Engine::InputMap::actionFingerprint | ( | ) | const |
A fingerprint of which action holds which command slot.
Two ends defining the same actions in a different order agree on actionCount() but misread each other's commands; this tells them apart.
| bool Vkm::Engine::InputMap::held | ( | std::string_view | action | ) | const |
Is the action active this frame?
The summed value decides: W and S held together cancel.
| action | Action name. |
| bool Vkm::Engine::InputMap::pressed | ( | std::string_view | action | ) | const |
Did it become active this frame?
| action | Action name. |
| bool Vkm::Engine::InputMap::released | ( | std::string_view | action | ) | const |
Did it stop being active this frame?
| action | Action name. |
| float Vkm::Engine::InputMap::axis | ( | std::string_view | action | ) | const |
Summed, clamped value of the action's bindings, -1..1.
| action | Action name. |
| bool Vkm::Engine::InputMap::held | ( | const InputCommand & | command, |
| std::string_view | action ) const |
Is the action active in command? (the tick's answer)
A fixed update must read these command queries: the frame queries drop a tap between ticks and repeat a press on every tick of a slow frame. Only the name-to-slot resolution comes from this map; an action with no slot reads as inactive.
| command | Command to read; the tick's, a peer's, or a replayed one. |
| action | Action name. |
| bool Vkm::Engine::InputMap::pressed | ( | const InputCommand & | command, |
| std::string_view | action ) const |
Did it become active since the previous command?
| command | Command to read. |
| action | Action name. |
| bool Vkm::Engine::InputMap::released | ( | const InputCommand & | command, |
| std::string_view | action ) const |
Did it stop being active since the previous command?
| command | Command to read. |
| action | Action name. |
| float Vkm::Engine::InputMap::axis | ( | const InputCommand & | command, |
| std::string_view | action ) const |
The action's value in command, -1..1.
| command | Command to read. |
| action | Action name. |
|
inline |
Whether the pointer was over a blocking element of the game's UI.
As of the last UI layout; e.g. for hiding a crosshair over a panel.
|
inline |
Where the pointer is this frame, in window pixels.
Not framebuffer pixels: scale by WindowManager::framebufferScale for those.
|
inline |
How far the pointer moved since the previous frame, in window pixels.
Zero on the first frame and while no window exists.
|
inline |
Wheel notches turned this frame for gameplay, positive away from the viewer.
Zero while the pointer is over a blocking game UI element or the host's UI holds it.
|
inline |
Wheel notches turned this frame, whatever is under the pointer.
Zero only while the host's UI holds the pointer.
|
inline |
The characters typed this frame, in order, as UTF-32.
Layout, Shift and dead keys applied, which no binding can say. Empty while the host's UI holds the keyboard.
|
inline |
Whether key went down or auto-repeated this frame.
For editing keys (Backspace, arrows, Enter), which act again at the repeat rate as pressed() does not. False while the host's UI holds the keyboard.
| key | GLFW key code. |
|
inline |
The command the current fixed step is running under.
Zeroed before the first beginTick(), so an early reader sees no input, not stale input.
|
inline |
How many action slots are in use.
The width of the part of a command that carries anything; both ends of a session must agree on it.