From f8f6f3b96e77c4a761b0ab92c490034ab7151a5d Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 1 Apr 2021 15:39:56 -0700 Subject: [PATCH] Add option to re-enable 1-frame input delay This is an option for speedrunners whose muscle memory is precisely trained and used to the 1-frame input delay that existed in 2.2 and below. It is located in Game Options -> Advanced Options, and is off by default. To re-add the 1-frame input delay, we simply move the key.Poll() to the start of the frame, instead of before an input function gets ran - undoing what #535 did. There is a frame ordering-sensitive issue here, where toggling game.inputdelay at the wrong time could cause double-polling. However, we only toggle it in an input function, which regardless is always guaranteed to be ran after key.Poll() (it either happened at the start of the frame or just before the input function got ran), so this is not an issue. But, in case we ever need to toggle this variable in the future, we can just use the defer callbacks system to defer the toggle to the end of the frame - also added by #535. Added at the request of Habeechee on the VVVVVV speedrunning Discord server. --- desktop_version/src/Game.cpp | 9 +++++++++ desktop_version/src/Game.h | 1 + desktop_version/src/Input.cpp | 6 ++++++ desktop_version/src/Render.cpp | 13 +++++++++++++ desktop_version/src/main.cpp | 7 ++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 61b1118d..1a5fac33 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -385,6 +385,7 @@ void Game::init(void) kludge_ingametemp = Menu::mainmenu; disablepause = false; + inputdelay = false; } void Game::lifesequence(void) @@ -4173,6 +4174,11 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s over30mode = help.Int(pText); } + if (SDL_strcmp(pKey, "inputdelay") == 0) + { + inputdelay = help.Int(pText); + } + if (SDL_strcmp(pKey, "glitchrunnermode") == 0) { glitchrunnermode = help.Int(pText); @@ -4423,6 +4429,8 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSetting xml::update_tag(dataNode, "over30mode", (int) over30mode); + xml::update_tag(dataNode, "inputdelay", (int) inputdelay); + xml::update_tag(dataNode, "glitchrunnermode", (int) glitchrunnermode); xml::update_tag(dataNode, "vsync", (int) screen_settings->useVsync); @@ -6017,6 +6025,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) option("fake load screen"); option("room name background"); option("glitchrunner mode"); + option("input delay"); option("return"); menuyoff = 0; break; diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index d7a3cfbf..f0cec0fd 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -452,6 +452,7 @@ public: void unlockAchievement(const char *name); bool disablepause; + bool inputdelay; }; #ifndef GAME_DEFINITION diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index e3c9cf73..fbad1e54 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -578,6 +578,12 @@ static void menuactionpress(void) game.savestatsandsettings_menu(); break; case 5: + /* Input delay */ + music.playef(11); + game.inputdelay = !game.inputdelay; + game.savestatsandsettings_menu(); + break; + default: //back music.playef(11); game.returnmenu(); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 70cb8184..c8d76756 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -518,6 +518,19 @@ static void menurender(void) graphics.Print( -1, 95, "Glitchrunner mode is OFF", tr/2, tg/2, tb/2, true); } break; + case 5: + graphics.bigprint(-1, 30, "Input Delay", tr, tg, tb, true); + graphics.Print(-1, 65, "Re-enable the 1-frame input delay", tr, tg, tb, true); + graphics.Print(-1, 75, "from previous versions of the game.", tr, tg, tb, true); + if (game.inputdelay) + { + graphics.Print(-1, 95, "Input delay is ON", tr, tg, tb, true); + } + else + { + graphics.Print(-1, 95, "Input delay is OFF", tr/2, tg/2, tb/2, true); + } + break; } break; case Menu::accessibility: diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index eb3f63d4..1d98eb9d 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -302,7 +302,7 @@ static enum LoopCode loop_run_active_funcs(void) const struct ImplFunc* implfunc = &(*active_funcs)[*active_func_index]; enum IndexCode index_code; - if (implfunc->type == Func_input) + if (implfunc->type == Func_input && !game.inputdelay) { key.Poll(); } @@ -721,6 +721,11 @@ static void inline deltaloop(void) static enum LoopCode loop_begin(void) { + if (game.inputdelay) + { + key.Poll(); + } + // Update network per frame. NETWORK_update();