From 942c1d8471e3856cfd05898daa391b97f4e282ec Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:41:19 +0200 Subject: [PATCH] relocated input parser to the new namespace --- src/sdl_window.cpp | 68 +++++++++++++++++++++++----------------------- src/sdl_window.h | 3 +- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 63f292137..19128a468 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -308,40 +308,7 @@ SDL_Keymod KeyBinding::getCustomModState() { return state; } -} // namespace KBMConfig - -namespace Frontend { -using Libraries::Pad::OrbisPadButtonDataOffset; - -using namespace KBMConfig; -using KBMConfig::AxisMapping; -using KBMConfig::KeyBinding; - -// modifiers are bitwise or-d together, so we need to check if ours is in that -template -typename std::map::const_iterator FindKeyAllowingPartialModifiers( - const std::map& map, KeyBinding binding) { - for (typename std::map::const_iterator it = map.cbegin(); it != map.cend(); - it++) { - if ((it->first.key == binding.key) && (it->first.modifier & binding.modifier) != 0) { - return it; - } - } - return map.end(); // Return end if no match is found -} -template -typename std::map::const_iterator FindKeyAllowingOnlyNoModifiers( - const std::map& map, KeyBinding binding) { - for (typename std::map::const_iterator it = map.cbegin(); it != map.cend(); - it++) { - if (it->first.key == binding.key && it->first.modifier == SDL_KMOD_NONE) { - return it; - } - } - return map.end(); // Return end if no match is found -} - -void WindowSDL::parseInputConfig() { +void parseInputConfig() { // Read configuration file of the game, and if it doesn't exist, generate it from default // If that doesn't exist either, generate that from getDefaultConfig() and try again // If even the folder is missing, we start with that. @@ -500,6 +467,39 @@ void WindowSDL::parseInputConfig() { file.close(); } +} // namespace KBMConfig + +namespace Frontend { +using Libraries::Pad::OrbisPadButtonDataOffset; + +using namespace KBMConfig; +using KBMConfig::AxisMapping; +using KBMConfig::KeyBinding; + +// modifiers are bitwise or-d together, so we need to check if ours is in that +template +typename std::map::const_iterator FindKeyAllowingPartialModifiers( + const std::map& map, KeyBinding binding) { + for (typename std::map::const_iterator it = map.cbegin(); it != map.cend(); + it++) { + if ((it->first.key == binding.key) && (it->first.modifier & binding.modifier) != 0) { + return it; + } + } + return map.end(); // Return end if no match is found +} +template +typename std::map::const_iterator FindKeyAllowingOnlyNoModifiers( + const std::map& map, KeyBinding binding) { + for (typename std::map::const_iterator it = map.cbegin(); it != map.cend(); + it++) { + if (it->first.key == binding.key && it->first.modifier == SDL_KMOD_NONE) { + return it; + } + } + return map.end(); // Return end if no match is found +} + Uint32 WindowSDL::keyRepeatCallback(void* param, Uint32 id, Uint32 interval) { auto* data = (std::pair*)param; KeyBinding binding(data->second); diff --git a/src/sdl_window.h b/src/sdl_window.h index 757f3891f..6062569ed 100644 --- a/src/sdl_window.h +++ b/src/sdl_window.h @@ -19,6 +19,7 @@ class GameController; namespace KBMConfig { std::string getDefaultKeyboardConfig(); +void parseInputConfig(); class KeyBinding { public: @@ -103,8 +104,6 @@ private: static Uint32 keyRepeatCallback(void* param, Uint32 id, Uint32 interval); static Uint32 mousePolling(void* param, Uint32 id, Uint32 interval); - void parseInputConfig(); - private: s32 width; s32 height;