aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSvenson Han Göthel <[email protected]>2024-06-12 17:54:38 +0200
committerSvenson Han Göthel <[email protected]>2024-06-12 17:54:38 +0200
commit3466ddc4af4529d84e95615b150a45444499ab7d (patch)
tree202c0f7b789b3ab8fe229bffc7a16d0d11bcc5e8
parent61c5a28709e4a1ddd1ac60b9d8c06239d7b6df68 (diff)
input_event_type_t add player three (P3), sdl2 only
-rw-r--r--include/pixel/pixel.hpp20
-rw-r--r--src/sdl_subsys.cpp15
2 files changed, 35 insertions, 0 deletions
diff --git a/include/pixel/pixel.hpp b/include/pixel/pixel.hpp
index 1f6cfb5..b71c8ac 100644
--- a/include/pixel/pixel.hpp
+++ b/include/pixel/pixel.hpp
@@ -515,6 +515,13 @@ namespace pixel {
P2_ACTION1,
P2_ACTION2,
P2_ACTION3,
+ P3_UP,
+ P3_DOWN,
+ P3_RIGHT,
+ P3_LEFT,
+ P3_ACTION1,
+ P3_ACTION2,
+ P3_ACTION3,
RESET, // 18
/** Request to close window, which then should be closed by caller */
WINDOW_CLOSE_REQ,
@@ -553,6 +560,15 @@ namespace pixel {
bitmask(input_event_type_t::P2_ACTION1) |
bitmask(input_event_type_t::P2_ACTION2) |
bitmask(input_event_type_t::P2_ACTION3);
+
+ constexpr static const uint32_t p3_mask =
+ bitmask(input_event_type_t::P3_UP) |
+ bitmask(input_event_type_t::P3_DOWN) |
+ bitmask(input_event_type_t::P3_RIGHT) |
+ bitmask(input_event_type_t::P3_LEFT) |
+ bitmask(input_event_type_t::P3_ACTION1) |
+ bitmask(input_event_type_t::P3_ACTION2) |
+ bitmask(input_event_type_t::P3_ACTION3);
uint32_t m_pressed; // [P1_UP..RESET]
uint32_t m_lifted; // [P1_UP..RESET]
bool m_paused;
@@ -616,6 +632,7 @@ namespace pixel {
m_paused = !m_paused;
}
}
+ void set_paused(bool v) noexcept { m_paused = v; }
bool paused() const noexcept { return m_paused; }
bool pressed(input_event_type_t e) const noexcept {
const int bit = bitno(e);
@@ -650,6 +667,9 @@ namespace pixel {
bool has_any_p2() const noexcept {
return 0 != ( ( m_pressed | m_lifted ) & p2_mask );
}
+ bool has_any_p3() const noexcept {
+ return 0 != ( ( m_pressed | m_lifted ) & p3_mask );
+ }
std::string to_string() const noexcept;
};
inline std::string to_string(const input_event_t& e) noexcept { return e.to_string(); }
diff --git a/src/sdl_subsys.cpp b/src/sdl_subsys.cpp
index 0ff1791..5e49ac4 100644
--- a/src/sdl_subsys.cpp
+++ b/src/sdl_subsys.cpp
@@ -26,6 +26,7 @@
#include <thread>
#include <SDL2/SDL.h>
+#include <SDL2/SDL_scancode.h>
#include <SDL2/SDL_ttf.h>
#if !defined(__EMSCRIPTEN__)
#include <SDL2/SDL_image.h>
@@ -356,6 +357,20 @@ static input_event_type_t to_event_type(SDL_Scancode scancode) {
/**
case SDL_SCANCODE_LGUI:
return input_event_type_t::P2_ACTION4; */
+ case SDL_SCANCODE_I:
+ return input_event_type_t::P3_UP;
+ case SDL_SCANCODE_J:
+ return input_event_type_t::P3_LEFT;
+ case SDL_SCANCODE_K:
+ return input_event_type_t::P3_DOWN;
+ case SDL_SCANCODE_L:
+ return input_event_type_t::P3_RIGHT;
+ case SDL_SCANCODE_V:
+ return input_event_type_t::P3_ACTION1;
+ case SDL_SCANCODE_B:
+ return input_event_type_t::P3_ACTION2;
+ case SDL_SCANCODE_N:
+ return input_event_type_t::P3_ACTION3;
case SDL_SCANCODE_R:
return input_event_type_t::RESET;
default: