Toast Engine
Loading...
Searching...
No Matches
action.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
12#include "bind.hpp"
13#include "modifier.hpp"
14#include "value.hpp"
15
17#include <toast/uid.hpp>
18
19namespace input {
20
21class TOAST_API Action {
22public:
23 Action() = default;
24
26 using Sampler = std::function<InputSample(const KeyCode&)>;
27
33 static auto fromAsset(assets::Handle<assets::Action> handle) -> std::unique_ptr<Action>;
34
41 auto evaluate(const Sampler& sampler, const EvalContext& ctx) -> SignalList;
42
43 [[nodiscard]]
44 auto uid() const noexcept -> toast::UID;
45
46 [[nodiscard]]
47 auto name() const noexcept -> std::string_view;
48
49 [[nodiscard]]
50 auto functionName() const noexcept -> std::string_view;
51
52 [[nodiscard]]
53 auto valueType() const noexcept -> ValueType;
54
55 [[nodiscard]]
56 auto value() const noexcept -> const Value&;
57
58 [[nodiscard]]
59 auto modifiers() const noexcept -> ModifierKey;
60
61 [[nodiscard]]
62 auto device() const noexcept -> Device;
63
64 [[nodiscard]]
65 auto timeSinceStart() const noexcept -> float;
66
67 [[nodiscard]]
68 auto timeSinceTry() const noexcept -> float;
69
70 [[nodiscard]]
71 auto remainingCountdown() const noexcept -> float;
72
73 [[nodiscard]]
74 auto binds() const noexcept -> const std::vector<Bind>& {
75 return m_binds;
76 }
77
78private:
79 void updateTiming(const SignalList& fired, bool active, float delta);
80
82 toast::UID m_uid;
83 std::string m_name;
84 std::string m_function_name;
85 ValueType m_value_type = ValueType::axis_0d;
86 assets::AccumulationType m_accumulation = assets::AccumulationType::highest;
87
88 std::vector<Bind> m_binds;
89 std::vector<std::shared_ptr<IModifier>> m_modifiers;
90
91 Value m_value;
92 float m_time_since_start = 0.0f;
93 float m_time_since_try = 0.0f;
94 float m_remaining_countdown = 0.0f;
95 ModifierKey m_modifier_keys = ModifierKey::none;
96 Device m_device = Device::none;
97 bool m_was_active = false;
98 bool m_was_trying = false;
99};
100
101}
A bind maps one keycode to a set of triggers and per-bind modifiers.
Type-safe smart pointer for assets.
Definition core_types.hpp:149
auto evaluate(const Sampler &sampler, const EvalContext &ctx) -> SignalList
Evaluates every bind, accumulates the value and updates timing state.
Definition action.cpp:78
std::function< InputSample(const KeyCode &)> Sampler
Supplies the current raw input for a keycode; provided by the input system.
Definition action.hpp:26
auto timeSinceTry() const noexcept -> float
Definition action.cpp:201
auto valueType() const noexcept -> ValueType
Definition action.cpp:181
auto name() const noexcept -> std::string_view
Definition action.cpp:173
auto modifiers() const noexcept -> ModifierKey
Definition action.cpp:189
auto remainingCountdown() const noexcept -> float
Definition action.cpp:205
auto binds() const noexcept -> const std::vector< Bind > &
Definition action.hpp:74
auto device() const noexcept -> Device
Definition action.cpp:193
auto uid() const noexcept -> toast::UID
Definition action.cpp:169
static auto fromAsset(assets::Handle< assets::Action > handle) -> std::unique_ptr< Action >
Builds a runtime action from its asset.
Definition action.cpp:31
auto value() const noexcept -> const Value &
Definition action.cpp:185
auto timeSinceStart() const noexcept -> float
Definition action.cpp:197
auto functionName() const noexcept -> std::string_view
Definition action.cpp:177
Binds a single keycode to its triggers and per-bind modifiers.
Definition bind.hpp:23
Asset describing a single input action and its binds.
AccumulationType
How an action combines values coming from several binds.
Definition input_action.hpp:27
ModifierKey
Bit flags for the keyboard modifier keys held during an input.
Definition keycodes.hpp:28
Device
Physical device a keycode belongs to.
Definition keycodes.hpp:18
Modifiers post-process a value in place before it reaches the action.
Per-frame context passed down to triggers and modifiers during evaluation.
Definition value.hpp:140
One frame of raw input for a single keycode.
Definition value.hpp:130
A parsed keycode resolved to a device, kind and numeric code.
Definition keycodes.hpp:63
Fixed-capacity buffer of discrete events fired in a single frame.
Definition value.hpp:90
A tagged value that may represent a bool, a float or a glm::vec2.
Definition value.hpp:31
Definition uid.hpp:20
Concrete asset types for the Toast engine.
Unique identifier for everything that exists in our engine.
Value type shared by triggers, modifiers and actionsg.
ValueType
Value domain of an action or an input sample.
Definition value.hpp:22
@ axis_0d
boolean
Definition value.hpp:23