le2d v0.4.7
2D game engine framework
 
Loading...
Searching...
No Matches
action_mapping.hpp
Go to the documentation of this file.
1#pragma once
4#include <functional>
5#include <gsl/pointers>
6#include <vector>
7
8namespace le::input {
10using OnAction = std::move_only_function<void(action::Value const&)>;
11
13class ActionMapping : public IMapping {
14 public:
15 ActionMapping() = default;
16
20 void bind_action(gsl::not_null<IAction*> action, OnAction on_action);
21
24 void unbind_action(gsl::not_null<IAction const*> action);
25
27 void clear_bindings() { m_bindings.clear(); }
28
32 void dispatch(std::span<le::Event const> events, Gamepad::Manager const& gamepads) override;
33
35 void disengage() override;
36
37 private:
38 template <typename F>
39 void iterate(F f) const;
40
41 struct Binding {
42 gsl::not_null<IAction*> action;
43 std::vector<OnAction> callbacks{};
44
45 void update_gamepad(Gamepad::Manager const& gamepads) const;
46 void dispatch();
47 };
48
49 std::vector<Binding> m_bindings{};
50};
51} // namespace le::input
Stores bindings of actions to callbacks.
Definition action_mapping.hpp:13
void disengage() override
Disengage all bindings.
void unbind_action(gsl::not_null< IAction const * > action)
Remove existing bindings for an action, if any.
void dispatch(std::span< le::Event const > events, Gamepad::Manager const &gamepads) override
Process events and dispatch callbacks.
void clear_bindings()
Remove all existing bindings.
Definition action_mapping.hpp:27
void bind_action(gsl::not_null< IAction * > action, OnAction on_action)
Bind an action to a callback.
Stores and maintains Gamepad states.
Definition gamepad.hpp:58
Interface for a set of input bindings.
Definition mapping.hpp:9
Value associated with an action callback.
Definition action_types.hpp:35
Definition action.hpp:4
std::move_only_function< void(action::Value const &)> OnAction
Action callback type.
Definition action_mapping.hpp:10