From adbedd30c4a4495ec34d84f52e41246ca143cafa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 5 Sep 2020 00:58:25 +0200 Subject: [PATCH] - consolidated the 4 functions for handling the automap zoom. --- source/blood/src/blood.cpp | 34 ++------------------------ source/core/gamecontrol.cpp | 39 ++++++++++++++++++++++++++++++ source/core/gamecontrol.h | 1 + source/exhumed/src/gameloop.cpp | 1 - source/exhumed/src/input.cpp | 28 +-------------------- source/games/duke/src/funct.h | 1 - source/games/duke/src/gameloop.cpp | 2 +- source/games/duke/src/input.cpp | 37 ---------------------------- source/sw/src/draw.cpp | 36 +-------------------------- 9 files changed, 45 insertions(+), 134 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 688e63615..1cef2ad57 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -491,41 +491,11 @@ void GameInterface::Startup() } -static void nonsharedkeys(void) -{ - static int nonsharedtimer; - int ms = screen->FrameTime; - int interval; - if (nonsharedtimer > 0 || ms < nonsharedtimer) - { - interval = ms - nonsharedtimer; - } - else - { - interval = 0; - } - nonsharedtimer = screen->FrameTime; - - if (System_WantGuiCapture()) - return; - - if (automapMode != am_off) - { - double j = interval * (120. / 1000); - - if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) - gZoom += (int)fmulscale6(j, max(gZoom, 256)); - if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) - gZoom -= (int)fmulscale6(j, max(gZoom, 256)); - - gZoom = clamp(gZoom, 48, 2048); - gViewMap.nZoom = gZoom; - } -} void GameInterface::Render() { - nonsharedkeys(); + gZoom = GetAutomapZoom(gZoom); + gViewMap.nZoom = gZoom; drawtime.Reset(); drawtime.Clock(); viewDrawScreen(); diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 892c95ebd..e164310b1 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1195,3 +1195,42 @@ void GameInterface::FreeLevelData() numsectors = numwalls = 0; currentLevel = nullptr; } + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +int GetAutomapZoom(int gZoom) +{ + static int nonsharedtimer; + int ms = screen->FrameTime; + int interval; + if (nonsharedtimer > 0 || ms < nonsharedtimer) + { + interval = ms - nonsharedtimer; + } + else + { + interval = 0; + } + nonsharedtimer = screen->FrameTime; + + if (System_WantGuiCapture()) + return gZoom; + + if (automapMode != am_off) + { + double j = interval * (120. / 1000); + + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) + gZoom += (int)fmulscale6(j, max(gZoom, 256)); + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) + gZoom -= (int)fmulscale6(j, max(gZoom, 256)); + + gZoom = clamp(gZoom, 48, 2048); + + } + return gZoom; +} diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index ca53cc2db..c2f333508 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -55,6 +55,7 @@ void CONFIG_ReadCombatMacros(); int GameMain(); void startmainmenu(); +int GetAutomapZoom(int gZoom); void updatePauseStatus(); void DeferedStartGame(MapRecord* map, int skill); void ChangeLevel(MapRecord* map, int skill); diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index feaaf496f..2597bf1a7 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -51,7 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS short nBestLevel; -static int32_t nonsharedtimer; extern uint8_t nCinemaSeen; diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index 9faac17cb..cf7c8f1e3 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -88,37 +88,11 @@ void SendInput() } -static int32_t nonsharedtimer; void CheckKeys2() { - static int nonsharedtimer; - int ms = screen->FrameTime; - int interval; - if (nonsharedtimer > 0 || ms < nonsharedtimer) - { - interval = ms - nonsharedtimer; - } - else - { - interval = 0; - } - nonsharedtimer = screen->FrameTime; + lMapZoom = GetAutomapZoom(lMapZoom); - if (System_WantGuiCapture()) - return; - - if (automapMode != am_off) - { - double j = interval * (120. / 1000); - - if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) - lMapZoom += (int)fmulscale6(j, max(lMapZoom, 256)); - if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) - lMapZoom -= (int)fmulscale6(j, max(lMapZoom, 256)); - - lMapZoom = clamp(lMapZoom, 48, 2048); - } if (PlayerList[nLocalPlayer].nHealth <= 0) { SetAirFrame(); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index da7691791..1d9755557 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -228,7 +228,6 @@ void startnewgame(MapRecord* map, int skill); void setlocalplayerinput(player_struct *pp); int playercolor2lookup(int color); void PlayerColorChanged(void); -void nonsharedkeys(void); void apply_seasick(player_struct* p, double scalefactor); void calcviewpitch(player_struct* p, double factor); void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index fd392eb17..282d296ac 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -146,7 +146,7 @@ void GameInterface::Startup() void GameInterface::Render() { - nonsharedkeys(); // automap zoom + ps[myconnectindex].zoom = GetAutomapZoom(ps[myconnectindex].zoom); drawtime.Reset(); drawtime.Clock(); videoSetBrightness(thunder_brightness); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index cd5653eee..9622bc311 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -41,7 +41,6 @@ source as it is released. BEGIN_DUKE_NS // State timer counters. -static int nonsharedtimer; static int turnheldtime; static int lastcontroltime; static double lastCheck; @@ -58,42 +57,6 @@ void GameInterface::ResetFollowPos(bool message) if (message) FTA(automapFollow? QUOTE_MAP_FOLLOW_ON : QUOTE_MAP_FOLLOW_OFF, &ps[myconnectindex]); } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void nonsharedkeys(void) -{ - int ms = screen->FrameTime; - int interval; - if (nonsharedtimer > 0 || ms < nonsharedtimer) - { - interval = ms - nonsharedtimer; - } - else - { - interval = 0; - } - nonsharedtimer = screen->FrameTime; - - if (System_WantGuiCapture()) - return; - - if (automapMode != am_off) - { - double j = interval * (120./1000); - - if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) - ps[myconnectindex].zoom += (int)fmulscale6(j, max(ps[myconnectindex].zoom, 256)); - if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) - ps[myconnectindex].zoom -= (int)fmulscale6(j, max(ps[myconnectindex].zoom, 256)); - - ps[myconnectindex].zoom = clamp(ps[myconnectindex].zoom, 48, 2048); - } -} - //--------------------------------------------------------------------------- // // handles all HUD related input, i.e. inventory item selection and activation plus weapon selection. diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 52ccfacf8..d347b1b0e 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -939,39 +939,6 @@ post_analyzesprites(void) } #endif -static int nonsharedtimer; - -void -ResizeView(PLAYERp pp) -{ - int ms = screen->FrameTime; - int interval; - if (nonsharedtimer > 0 || ms < nonsharedtimer) - { - interval = ms - nonsharedtimer; - } - else - { - interval = 0; - } - nonsharedtimer = screen->FrameTime; - - if (System_WantGuiCapture()) - return; - - if (automapMode != am_off) - { - double j = interval * (120. / 1000); - - if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) - zoom += (int)fmulscale6(j, max(zoom, 256)); - if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) - zoom -= (int)fmulscale6(j, max(zoom, 256)); - - zoom = clamp(zoom, 48, 2048); - } -} - void BackView(int *nx, int *ny, int *nz, short *vsect, fixed_t *nq16ang, short horiz) @@ -1911,8 +1878,7 @@ drawscreen(PLAYERp pp, double smoothratio) SyncStatMessage(); #endif - // certain input is done here - probably shouldn't be - ResizeView(pp); + zoom = GetAutomapZoom(zoom); restoreinterpolations(); // Stick at end of drawscreen short_restoreinterpolations(); // Stick at end of drawscreen