From 45c72920960de45fe075f6d7149b7239b1963ce4 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 28 Apr 2020 20:31:29 -0700 Subject: [PATCH] Simplify menu-off rendering/logic code Since "if (graphics.resumegamemode)" and "if (menuoffset > 0)" both do the same thing, they've been combined with an "or" conjunction. As well, the map.extrarow check in maplogic() has been refactored to use a variable instead of duplicating the entire code block. Not that it matters anyway, because the difference between 240 and 230 is only 10 pixels, far short of the 25 pixel increment that bringing the menu up and down uses, and both 240 and 230 integer-divided by 25 have the same non-remainder value of 9. --- desktop_version/src/Logic.cpp | 24 ++++++------------------ desktop_version/src/Render.cpp | 12 ++---------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/desktop_version/src/Logic.cpp b/desktop_version/src/Logic.cpp index 5f2683f6..f9bb5cc0 100644 --- a/desktop_version/src/Logic.cpp +++ b/desktop_version/src/Logic.cpp @@ -43,25 +43,13 @@ void maplogic() if (graphics.resumegamemode) { graphics.menuoffset += 25; - if (map.extrarow) + int threshold = map.extrarow ? 230 : 240; + if (graphics.menuoffset >= threshold) { - if (graphics.menuoffset >= 230) - { - graphics.menuoffset = 230; - //go back to gamemode! - game.mapheld = true; - game.gamestate = GAMEMODE; - } - } - else - { - if (graphics.menuoffset >= 240) - { - graphics.menuoffset = 240; - //go back to gamemode! - game.mapheld = true; - game.gamestate = GAMEMODE; - } + graphics.menuoffset = threshold; + //go back to gamemode! + game.mapheld = true; + game.gamestate = GAMEMODE; } } else if (graphics.menuoffset > 0) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 44c6c588..3f3da98f 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2455,11 +2455,7 @@ void maprender() graphics.drawfade(); } - if (graphics.resumegamemode) - { - graphics.menuoffrender(); - } - else if (graphics.menuoffset > 0) + if (graphics.resumegamemode || graphics.menuoffset > 0) { graphics.menuoffrender(); } @@ -2595,11 +2591,7 @@ void teleporterrender() } - if (graphics.resumegamemode) - { - graphics.menuoffrender(); - } - else if (graphics.menuoffset > 0) + if (graphics.resumegamemode || graphics.menuoffset > 0) { graphics.menuoffrender(); }