Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
input_system.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include "
action.hpp
"
12
#include "
keycodes.hpp
"
13
#include "
value.hpp
"
14
15
#include <glm/glm.hpp>
16
#include <toast/events/listener.hpp>
17
#include <unordered_map>
18
#include <unordered_set>
19
20
struct
SDL_Gamepad;
21
22
namespace
input {
23
24
class
TOAST_API InputSystem {
25
public
:
26
InputSystem();
27
~InputSystem();
28
29
InputSystem(
const
InputSystem&) =
delete
;
30
auto
operator=(
const
InputSystem&) -> InputSystem& =
delete
;
31
32
[[nodiscard]]
33
static
auto
get()
noexcept
-> InputSystem&;
34
35
void
tick();
36
void
reloadActions();
37
void
setViewport(glm::vec2 position, glm::vec2 size)
noexcept
;
38
39
[[nodiscard]]
40
auto
lastInputDevice
()
const
noexcept
->
Device
;
41
42
[[nodiscard]]
43
auto
lastInputName
()
const
noexcept
-> std::string_view;
44
45
[[nodiscard]]
46
auto
mousePosition
()
const
noexcept
-> glm::vec2;
47
48
[[nodiscard]]
49
auto
mouseDelta
()
const
noexcept
-> glm::vec2;
50
51
[[nodiscard]]
52
auto
activeGamepadId
()
const
noexcept
-> uint32_t;
53
54
private
:
55
void
subscribeEvents();
56
void
refreshGamepads();
57
void
noteLastInput(
Device
device, std::string name);
58
59
[[nodiscard]]
60
auto
activeGamepad()
const
noexcept
-> SDL_Gamepad*;
61
[[nodiscard]]
62
auto
sample(
const
KeyCode
& key) ->
InputSample
;
63
64
static
inline
InputSystem* instance =
nullptr
;
65
66
event::Listener
m_listener;
67
std::vector<std::unique_ptr<Action>> m_actions;
68
69
std::unordered_set<int> m_keys_down;
70
std::unordered_set<int> m_mouse_down;
71
ModifierKey
m_mods = ModifierKey::none;
72
73
glm::vec2 m_mouse_position {0.0f};
74
glm::vec2 m_prev_mouse_position {0.0f};
75
glm::vec2 m_mouse_delta {0.0f};
76
glm::vec2 m_scroll {0.0f};
77
78
glm::vec2 m_viewport_position {0.0f};
79
glm::vec2 m_viewport_size {0.0f};
80
81
std::unordered_map<uint32_t, SDL_Gamepad*> m_gamepads;
82
83
Device
m_last_device = Device::none;
84
std::string m_last_name;
85
86
std::chrono::steady_clock::time_point m_last_tick;
87
bool
m_has_last_tick =
false
;
88
};
89
90
}
action.hpp
Maps a group of binds to a function and a value.
event::Listener
manages the lifetime, subscription, and unsubscription of callbacks
Definition
listener.hpp:39
input::InputSystem::activeGamepadId
auto activeGamepadId() const noexcept -> uint32_t
Definition
input_system.cpp:227
input::InputSystem::mousePosition
auto mousePosition() const noexcept -> glm::vec2
Definition
input_system.cpp:356
input::InputSystem::lastInputDevice
auto lastInputDevice() const noexcept -> Device
Definition
input_system.cpp:348
input::InputSystem::mouseDelta
auto mouseDelta() const noexcept -> glm::vec2
Definition
input_system.cpp:360
input::InputSystem::lastInputName
auto lastInputName() const noexcept -> std::string_view
Definition
input_system.cpp:352
keycodes.hpp
input::ModifierKey
ModifierKey
Bit flags for the keyboard modifier keys held during an input.
Definition
keycodes.hpp:28
input::Device
Device
Physical device a keycode belongs to.
Definition
keycodes.hpp:18
input::InputSample
One frame of raw input for a single keycode.
Definition
value.hpp:130
input::KeyCode
A parsed keycode resolved to a device, kind and numeric code.
Definition
keycodes.hpp:63
value.hpp
Value type shared by triggers, modifiers and actionsg.
engine
src
toast
input
input_system.hpp
Generated by
1.17.0