From a9f07ccc8f36d78d901032fd9948f141cfc86a5c Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 14 Jun 2020 11:57:33 -0700 Subject: [PATCH] Move fixed loop to its own function To improve code readability because otherwise the code would be one giant blob. --- desktop_version/src/main.cpp | 84 +++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index b9c98ffa..9952bd6a 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -65,6 +65,7 @@ volatile Uint32 f_accumulator = 0; void gameloop(); void deltaloop(); +void fixedloop(); int main(int argc, char *argv[]) { @@ -387,6 +388,50 @@ void deltaloop() { accumulator = fmodf(accumulator, timesteplimit); + fixedloop(); + } + const float alpha = game.over30mode ? static_cast(accumulator) / timesteplimit : 1.0f; + graphics.alpha = alpha; + + if (game.infocus) + { + switch (game.gamestate) + { + case PRELOADER: + preloaderrender(); + break; + case EDITORMODE: + graphics.flipmode = false; + editorrender(); + break; + case TITLEMODE: + titlerender(); + break; + case GAMEMODE: + gamerender(); + break; + case MAPMODE: + maprender(); + break; + case TELEPORTERMODE: + teleporterrender(); + break; + case GAMECOMPLETE: + gamecompleterender(); + break; + case GAMECOMPLETE2: + gamecompleterender2(); + break; + case CLICKTOSTART: + help.updateglow(); + break; + } + gameScreen.FlipScreen(); + } +} + +void fixedloop() +{ key.Poll(); if(key.toggleFullscreen) { @@ -607,43 +652,4 @@ void deltaloop() music.processmusic(); graphics.processfade(); game.gameclock(); - } - const float alpha = game.over30mode ? static_cast(accumulator) / timesteplimit : 1.0f; - graphics.alpha = alpha; - - if (game.infocus) - { - switch (game.gamestate) - { - case PRELOADER: - preloaderrender(); - break; - case EDITORMODE: - graphics.flipmode = false; - editorrender(); - break; - case TITLEMODE: - titlerender(); - break; - case GAMEMODE: - gamerender(); - break; - case MAPMODE: - maprender(); - break; - case TELEPORTERMODE: - teleporterrender(); - break; - case GAMECOMPLETE: - gamecompleterender(); - break; - case GAMECOMPLETE2: - gamecompleterender2(); - break; - case CLICKTOSTART: - help.updateglow(); - break; - } - gameScreen.FlipScreen(); - } }