Skip to content

Commit

Permalink
EnumTags: Replace iterator usage with etag function.
Browse files Browse the repository at this point in the history
Simplifies the code and is compatible with the upcoming EnumTag API change.
  • Loading branch information
Ghabry committed Nov 24, 2023
1 parent 1ffb8de commit d4985c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <lcf/inireader.h>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<Input::Keys::InputKey>(std::distance(kNames.begin(), it))});
Input::Keys::InputKey k;
if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) {
mappings.Add({button, k});
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/input_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d4985c3

Please sign in to comment.