From fb386681821d503b767c465d41d99126626c2789 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 15 Apr 2023 11:14:35 -0700 Subject: [PATCH] Fix regression with controller binds on first launch I noticed that in 2.3, the game would launch with default controller binds upon first launch (e.g. no pre-existing unlock.vvv or settings.vvv), but in 2.4, this wasn't the case, and the default binds would only be set the next time the game was launched. This would result in you being essentially unable to use the controller on first launch save for the analogue stick and D-pad to move between menu selections and move the player. Bisecting pointed to commit 3ef5248db93541f399e8220fe0280281881d8bd6 as the cause of the regression. It turns out returning early upon error or a file not existing didn't set the default controller binds, because they were done at the end of Game::deserializesettings(). But the binds would be set on the next launch because if the file didn't exist, a new file would be written, not with the default binds, but then the next launch would read the file, see there were no binds, and then set the default binds accordingly. To fix this, I made it so that the default controller binds are set when Game is initialized. That way, it covers all cases where the game can't read a settings file. --- desktop_version/src/Game.cpp | 47 +++++++++++++++++++++--------------- desktop_version/src/Game.h | 1 + 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index e5945f90..d75aaf8b 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -383,6 +383,32 @@ void Game::init(void) disableaudiopause = false; disabletemporaryaudiopause = true; inputdelay = false; + + setdefaultcontrollerbuttons(); +} + +void Game::setdefaultcontrollerbuttons(void) +{ + if (controllerButton_flip.size() < 1) + { + controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A); + } + if (controllerButton_map.size() < 1) + { + controllerButton_map.push_back(SDL_CONTROLLER_BUTTON_Y); + } + if (controllerButton_esc.size() < 1) + { + controllerButton_esc.push_back(SDL_CONTROLLER_BUTTON_B); + } + if (controllerButton_restart.size() < 1) + { + controllerButton_restart.push_back(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); + } + if (controllerButton_interact.size() < 1) + { + controllerButton_interact.push_back(SDL_CONTROLLER_BUTTON_X); + } } void Game::lifesequence(void) @@ -4593,26 +4619,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett } - if (controllerButton_flip.size() < 1) - { - controllerButton_flip.push_back(SDL_CONTROLLER_BUTTON_A); - } - if (controllerButton_map.size() < 1) - { - controllerButton_map.push_back(SDL_CONTROLLER_BUTTON_Y); - } - if (controllerButton_esc.size() < 1) - { - controllerButton_esc.push_back(SDL_CONTROLLER_BUTTON_B); - } - if (controllerButton_restart.size() < 1) - { - controllerButton_restart.push_back(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); - } - if (controllerButton_interact.size() < 1) - { - controllerButton_interact.push_back(SDL_CONTROLLER_BUTTON_X); - } + setdefaultcontrollerbuttons(); } bool Game::savestats(bool sync /*= true*/) diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 1192b395..12c3b895 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -136,6 +136,7 @@ class Game public: void init(void); + void setdefaultcontrollerbuttons(void); int crewrescued(void);