From 287061c768b1b44bdd20c4016ebbfe7c41a7f1c7 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 17 Mar 2021 17:53:17 -0700 Subject: [PATCH] Fix filter/screenshake/flash update order In 2.2, at render time, the game rendered screenshakes and flashes if their timers were above 0, and then decremented them afterwards. The game would also update the analogue filter right before rendering it, too. In 2.3, this was changed so the flash and screenshake timers were unified, and also done at the end of the frame - right before rendering happened. This resulted in 1-frame flashes and screenshakes not rendering at all. The other changes in this patchset don't fix this either. The analogue filter was also in the wrong order, but that is less of an issue than flashes and screenshakes. So, what I've done is made the flash and screenshake timers update right before the loop switches over to rendering, and only decrements them when we switch back to fixed functions (after rendering). The analogue filter is also updated right before rendering as well. This restores 1-frame flashes and screenshakes, as well as restores the correct order of analogue filter updates. --- desktop_version/src/Graphics.cpp | 27 +++++++++++++++++++++++++++ desktop_version/src/Graphics.h | 2 ++ desktop_version/src/main.cpp | 22 +++++++--------------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index dda2eb34..8a1bb266 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -8,6 +8,7 @@ #include "Entity.h" #include "Exit.h" #include "FileSystemUtils.h" +#include "GraphicsUtil.h" #include "Map.h" #include "Music.h" #include "Screen.h" @@ -3069,6 +3070,32 @@ void Graphics::renderwithscreeneffects(void) } } +void Graphics::renderfixedpre(void) +{ + if (game.screenshake > 0) + { + updatescreenshake(); + } + + if (screenbuffer != NULL && screenbuffer->badSignalEffect) + { + UpdateFilter(); + } +} + +void Graphics::renderfixedpost(void) +{ + /* Screen effects timers */ + if (game.flashlight > 0) + { + --game.flashlight; + } + if (game.screenshake > 0) + { + --game.screenshake; + } +} + void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen, float sc) { std::vector& font = flipmode ? flipbfont : bfont; diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index ee901c3f..366857b8 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -156,6 +156,8 @@ public: void render(void); void renderwithscreeneffects(void); + void renderfixedpre(void); + void renderfixedpost(void); bool Hitest(SDL_Surface* surface1, point p1, SDL_Surface* surface2, point p2); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index eec68c0e..faef0503 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -318,6 +318,9 @@ static enum LoopCode loop_run_active_funcs(void) } } + /* About to switch over to rendering... but call this first. */ + graphics.renderfixedpre(); + return Loop_stop; } @@ -682,6 +685,9 @@ static void inline deltaloop(void) accumulator = SDL_fmodf(accumulator, timesteplimit); + /* We are done rendering. */ + graphics.renderfixedpost(); + fixedloop(); } const float alpha = game.over30mode ? static_cast(accumulator) / timesteplimit : 1.0f; @@ -744,25 +750,11 @@ static void focused_begin(void) static void focused_end(void) { - //Screen effects timers - if (game.flashlight > 0) - { - game.flashlight--; - } - if (game.screenshake > 0) - { - game.screenshake--; - graphics.updatescreenshake(); - } + /* no-op. */ } static enum LoopCode loop_end(void) { - if (graphics.screenbuffer->badSignalEffect) - { - UpdateFilter(); - } - //We did editorinput, now it's safe to turn this off key.linealreadyemptykludge = false;