4#include <unordered_map>
10 std::vector<asw::input::ActionBinding>
bindings;
12 bool pressed {
false };
13 bool released {
false };
15 float strength { 0.0F };
18 bool prev_down {
false };
31 [&out_strength](
const auto& b) ->
bool {
32 using T = std::decay_t<
decltype(b)>;
34 if constexpr (std::is_same_v<T, asw::input::KeyBinding>) {
36 out_strength = std::max(out_strength, 1.0F);
41 }
else if constexpr (std::is_same_v<T, asw::input::MouseButtonBinding>) {
43 out_strength = std::max(out_strength, 1.0F);
48 }
else if constexpr (std::is_same_v<T, asw::input::ControllerButtonBinding>) {
50 out_strength = std::max(out_strength, 1.0F);
55 }
else if constexpr (std::is_same_v<T, asw::input::ControllerAxisBinding>) {
57 const float effective = b.positive_direction ? val : -val;
58 if (effective >= b.threshold) {
59 out_strength = std::max(out_strength, effective);
76 [](
const auto& b) ->
bool {
77 using T = std::decay_t<
decltype(b)>;
79 if constexpr (std::is_same_v<T, asw::input::KeyBinding>) {
82 }
else if constexpr (std::is_same_v<T, asw::input::MouseButtonBinding>) {
85 }
else if constexpr (std::is_same_v<T, asw::input::ControllerButtonBinding>) {
100 [](
const auto& b) ->
bool {
101 using T = std::decay_t<
decltype(b)>;
103 if constexpr (std::is_same_v<T, asw::input::KeyBinding>) {
106 }
else if constexpr (std::is_same_v<T, asw::input::MouseButtonBinding>) {
109 }
else if constexpr (std::is_same_v<T, asw::input::ControllerButtonBinding>) {
128 action_map[std::string(name)].bindings.push_back(binding);
144 return it !=
action_map.end() && it->second.pressed;
150 return it !=
action_map.end() && it->second.released;
156 return it !=
action_map.end() && it->second.down;
162 return it !=
action_map.end() ? it->second.strength : 0.0F;
168 bool any_down =
false;
169 bool any_pressed =
false;
170 bool any_released =
false;
171 float max_strength = 0.0F;
173 for (
const auto& binding : action.bindings) {
181 if (any_down && !action.prev_down) {
184 if (!any_down && action.prev_down) {
188 action.pressed = any_pressed;
189 action.released = any_released;
190 action.down = any_down;
191 action.strength = max_strength;
192 action.prev_down = any_down;
Action binding system for the ASW library.
bool binding_is_pressed(const asw::input::ActionBinding &binding)
std::unordered_map< std::string, ActionData > action_map
bool binding_is_down(const asw::input::ActionBinding &binding, float &out_strength)
Returns true if the binding is currently active, and updates out_strength.
bool binding_is_released(const asw::input::ActionBinding &binding)
Returns true if the binding was released this frame (digital sources only).
std::vector< asw::input::ActionBinding > bindings