From d4985c39fd128c46c1aa14fad4cf26dd340e54f9 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Fri, 24 Nov 2023 01:40:52 +0100 Subject: [PATCH] EnumTags: Replace iterator usage with etag function. Simplifies the code and is compatible with the upcoming EnumTag API change. --- src/game_config.cpp | 13 ++++++------- src/input_source.cpp | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/game_config.cpp b/src/game_config.cpp index 677809d347b..c38c3c12163 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -19,6 +19,7 @@ #include "cmdline_parser.h" #include "filefinder.h" #include "input_buttons.h" +#include "keys.h" #include "output.h" #include "input.h" #include @@ -390,9 +391,8 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { if (Input::IsProtectedButton(button)) { // Check for protected (important) buttons if they have more than zero mappings for (const auto& key: keys) { - const auto& kNames = Input::Keys::kNames; - auto it = std::find(kNames.begin(), kNames.end(), key); - if (it != Input::Keys::kNames.end()) { + Input::Keys::InputKey k; + if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) { has_mapping = true; break; } @@ -406,10 +406,9 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { // Load mappings from ini for (const auto& key: keys) { - const auto& kNames = Input::Keys::kNames; - auto it = std::find(kNames.begin(), kNames.end(), key); - if (it != Input::Keys::kNames.end()) { - mappings.Add({button, static_cast(std::distance(kNames.begin(), it))}); + Input::Keys::InputKey k; + if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) { + mappings.Add({button, k}); } } } diff --git a/src/input_source.cpp b/src/input_source.cpp index c530be949fa..25d6f194683 100644 --- a/src/input_source.cpp +++ b/src/input_source.cpp @@ -127,9 +127,9 @@ void Input::LogSource::Update() { } if (Main_Data::game_system->GetFrameCounter() == last_read_frame) { for (const auto& key : keys) { - auto it = std::find(Input::kButtonNames.begin(), Input::kButtonNames.end(), key); - if (it != Input::kButtonNames.end()) { - pressed_buttons[std::distance(Input::kButtonNames.begin(), it)] = true; + Input::InputButton btn; + if (Input::kInputButtonNames.etag(key.c_str(), btn)) { + pressed_buttons[(int)btn] = true; } } last_read_frame = -1;