From 3da0e3121531ba22e76ce34050fbec0e3e41dae2 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 10 Jan 2021 14:48:25 -0800 Subject: [PATCH] Remove game.shouldreturntoeditor in favor of using defer callback game.shouldreturntoeditor was added to fix a frame ordering issue that was causing a bug where if you started playtesting in a room with a horizontal/vertical warp background, and exited playtesting in a different room that also had a horizontal/vertical warp background and which was different, then the background of the room you exited in would slowly scroll offscreen, when you re-entered the editor, instead of the background consisting entirely of the actual background of the room. Namely, the issue was that the game would render one more frame of GAMEMODE after graphics.backgrounddrawn got set to false, and re-set it to true, thus negating the background redraw, so the editor background would be incorrect. With defer callbacks, we can now just use a couple lines of code, instead of having to add an extra kludge variable and putting handling for it all over the code. --- desktop_version/src/Game.cpp | 14 ++++++++------ desktop_version/src/Game.h | 1 - desktop_version/src/Input.cpp | 2 +- desktop_version/src/Logic.cpp | 7 ------- desktop_version/src/editor.cpp | 10 ---------- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index bf2c6458..c81357ae 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -7,6 +7,7 @@ #include #include +#include "DeferCallbacks.h" #include "editor.h" #include "Entity.h" #include "Enums.h" @@ -365,10 +366,6 @@ void Game::init(void) fadetolab = false; fadetolabdelay = 0; -#if !defined(NO_CUSTOM_LEVELS) - shouldreturntoeditor = false; -#endif - over30mode = false; glitchrunnermode = false; @@ -1902,7 +1899,7 @@ void Game::updatestate(void) } else { - shouldreturntoeditor = true; + returntoeditor(); if(!muted && ed.levmusic>0) music.fadeMusicVolumeIn(3000); if(ed.levmusic>0) music.fadeout(); } @@ -6584,6 +6581,11 @@ void Game::returntolab(void) } #if !defined(NO_CUSTOM_LEVELS) +static void resetbg(void) +{ + graphics.backgrounddrawn = false; +} + void Game::returntoeditor(void) { gamestate = EDITORMODE; @@ -6602,7 +6604,7 @@ void Game::returntoeditor(void) ed.notedelay = 0; ed.roomnamehide = 0; - graphics.backgrounddrawn=false; + DEFER_CALLBACK(resetbg); music.fadeout(); //If warpdir() is used during playtesting, we need to set it back after! for (int j = 0; j < ed.maxheight; j++) diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index a8eceb98..7596325a 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -434,7 +434,6 @@ public: #if !defined(NO_CUSTOM_LEVELS) void returntoeditor(void); - bool shouldreturntoeditor; #endif int gametimer; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index dff5b350..f8f58d7e 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -1779,7 +1779,7 @@ void gameinput(void) }else if(game.activetele && game.readytotele > 20 && game.press_map){ //pass, let code block below handle it }else{ - game.shouldreturntoeditor = true; + game.returntoeditor(); game.mapheld = true; } } diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index 5f708556..a8021034 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -1576,11 +1576,4 @@ void gamelogic(void) if (game.teleport_to_new_area) script.teleport(); - -#if !defined(NO_CUSTOM_LEVELS) - if (game.shouldreturntoeditor) - { - game.returntoeditor(); - } -#endif } diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 70ce0f6b..c5b73bdf 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -2419,11 +2419,6 @@ static void editormenurender(int tr, int tg, int tb) void editorrender(void) { extern editorclass ed; - if (game.shouldreturntoeditor) - { - graphics.backgrounddrawn = false; - } - //Draw grid ClearSurface(graphics.backBuffer); @@ -3647,11 +3642,6 @@ void editorlogic(void) //Misc help.updateglow(); - if (game.shouldreturntoeditor) - { - game.shouldreturntoeditor = false; - } - graphics.titlebg.bypos -= 2; graphics.titlebg.bscroll = -2;