Skip to content

Commit

Permalink
feat: track current game mode config index
Browse files Browse the repository at this point in the history
Track index of current game mode config to prevent switching from one
GameModeConfig to the same GameModeConfig, which in turn prevents
spamming of keypresses when entering a keyboard mode on RP2040.

Closes #21
  • Loading branch information
JonnyHaystack committed Oct 21, 2023
1 parent 775a5c0 commit 66ed1bf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/mode_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

uint64_t mode_activation_masks[sizeof(Config::game_mode_configs) / sizeof(GameModeConfig)];

size_t current_mode_index = 0;

void set_mode(CommunicationBackend *backend, ControllerMode *mode) {
// Delete keyboard mode in case one is set, so we don't end up getting both controller and
// keyboard inputs.
Expand Down Expand Up @@ -107,7 +109,8 @@ void select_mode(

for (size_t i = 0; i < mode_configs_count; i++) {
const GameModeConfig &mode_config = mode_configs[i];
if (all_buttons_held(inputs.buttons, mode_activation_masks[i])) {
if (all_buttons_held(inputs.buttons, mode_activation_masks[i]) && i != current_mode_index) {
current_mode_index = i;
set_mode(backend, mode_config, keyboard_modes, keyboard_modes_count);
return;
}
Expand Down

0 comments on commit 66ed1bf

Please sign in to comment.