3#include <unordered_map>
12 std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> pressed {
false };
13 std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> released {
false };
14 std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> down {
false };
16 bool any_pressed {
false };
17 int last_pressed { -1 };
18 float dead_zone { 0.25F };
20 std::array<float, asw::input::NUM_CONTROLLER_AXES> axis { 0 };
22 SDL_Gamepad* gamepad {
nullptr };
28std::array<SDL_Cursor*, asw::input::NUM_CURSORS>
cursors {
nullptr };
67 auto& m_state =
mouse;
70 k_state.any_pressed =
false;
71 k_state.last_pressed = -1;
73 for (
auto& pressed : k_state.pressed) {
77 for (
auto& released : k_state.released) {
82 m_state.any_pressed =
false;
83 m_state.change = { 0.0F, 0.0F };
86 for (
auto& pressed : m_state.pressed) {
90 for (
auto& released : m_state.released) {
99 cont.any_pressed =
false;
100 cont.last_pressed = -1;
102 for (
auto& button : cont.pressed) {
106 for (
auto& button : cont.released) {
117 return mouse.down[
static_cast<int>(button)];
122 return mouse.pressed[
static_cast<int>(button)];
127 return mouse.released[
static_cast<int>(button)];
132 auto cursor_int =
static_cast<uint32_t
>(cursor);
134 if (cursor_int >=
cursors.size()) {
138 if (
cursors[cursor_int] ==
nullptr) {
139 cursors[cursor_int] = SDL_CreateSystemCursor(
static_cast<SDL_SystemCursor
>(cursor_int));
142 SDL_SetCursor(
cursors[cursor_int]);
150 return keyboard.down[
static_cast<int>(key)];
155 return keyboard.pressed[
static_cast<int>(key)];
160 return keyboard.released[
static_cast<int>(key)];
172 return controller[index].down[
static_cast<int>(button)];
181 return controller[index].pressed[
static_cast<int>(button)];
190 return controller[index].released[
static_cast<int>(button)];
199 return controller[index].axis[
static_cast<int>(axis)];
243 const auto button_int =
static_cast<int>(button);
244 mouse.pressed[button_int] =
true;
245 mouse.down[button_int] =
true;
246 mouse.any_pressed =
true;
247 mouse.last_pressed = button_int;
252 const auto button_int =
static_cast<int>(button);
253 mouse.released[button_int] =
true;
254 mouse.down[button_int] =
false;
259 mouse.position.x = x;
260 mouse.position.y = y;
261 mouse.change.x = delta_x;
262 mouse.change.y = delta_y;
272 if (!SDL_IsGamepad(
id)) {
277 auto* opened = SDL_OpenGamepad(
id);
278 if (opened ==
nullptr) {
283 auto& new_controller =
controller.emplace_back();
284 new_controller.gamepad = opened;
285 new_controller.name = SDL_GetGamepadName(opened);
288 asw::log::info(
"Gamepad added: {} (ID: {})", new_controller.name,
id);
299 const auto index = it->second;
304 if (
auto* existing = SDL_GetGamepadFromID(
id); existing !=
nullptr) {
305 SDL_CloseGamepad(existing);
316 const auto index = it->second;
321 controller[index].axis[axis] = value / 32768.0F;
331 const auto index = it->second;
349 const auto index = it->second;
Action binding system for the ASW library.
Structured logging system.
void info(const std::string &message)
Log an info message.
void warn(const std::string &message)
Log a warning message.