From 1cf857e7880e95715864c3e12e45d8d8082cbcd0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 31 Jul 2020 10:35:24 +1000 Subject: [PATCH] - create an enum for MaxSmoothRatio and replace multiple hard-coded uses of '65536' constant. --- source/core/gamecontrol.cpp | 3 +-- source/core/gamecontrol.h | 4 ++++ source/games/duke/src/animatesprites_d.cpp | 10 +++++----- source/games/duke/src/animatesprites_r.cpp | 10 +++++----- source/games/duke/src/game_misc.cpp | 2 -- source/games/duke/src/inlines.h | 2 +- source/games/duke/src/render.cpp | 7 +++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index b483654e9..1cf9e5bdb 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1040,7 +1040,6 @@ void S_SetSoundPaused(int state) int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int realgameticspersec) { - const int baseValue = 65536; uint64_t currentTime = I_nsTime(); if ((lastototalclk == ototalclk) && (lastTime != 0)) @@ -1054,7 +1053,7 @@ int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int } lastTime = currentTime; - return clamp(baseValue * (elapsedTime / (1'000'000'000. / realgameticspersec)), 0, baseValue); + return clamp(MaxSmoothRatio * (elapsedTime / (1'000'000'000. / realgameticspersec)), 0, MaxSmoothRatio); } FString G_GetDemoPath() diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index a16be4da8..61b2de7d0 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -193,6 +193,10 @@ void S_SetSoundPaused(int state); void G_FatalEngineError(void); int CalcSmoothRatio(const ClockTicks& totalclk, const ClockTicks& ototalclk, int realgameticspersec); +enum +{ + MaxSmoothRatio = FRACUNIT +}; FString G_GetDemoPath(); diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index e2bc2abfe..166e12de8 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -168,16 +168,16 @@ void animatesprites_d(int x,int y,int a,int smoothratio) if( t->statnum == 99 ) continue; if( s->statnum != 1 && s->picnum == APLAYER && ps[s->yvel].newowner == -1 && s->owner >= 0 ) { - t->x -= mulscale16(65536-smoothratio,ps[s->yvel].posx-ps[s->yvel].oposx); - t->y -= mulscale16(65536-smoothratio,ps[s->yvel].posy-ps[s->yvel].oposy); + t->x -= mulscale16(MaxSmoothRatio-smoothratio,ps[s->yvel].posx-ps[s->yvel].oposx); + t->y -= mulscale16(MaxSmoothRatio-smoothratio,ps[s->yvel].posy-ps[s->yvel].oposy); t->z = ps[s->yvel].oposz + mulscale16(smoothratio,ps[s->yvel].posz-ps[s->yvel].oposz); t->z += (40<<8); } else if( ( s->statnum == 0 && s->picnum != CRANEPOLE) || s->statnum == 10 || s->statnum == 6 || s->statnum == 4 || s->statnum == 5 || s->statnum == 1 ) { - t->x -= mulscale16(65536-smoothratio,s->x-hittype[i].bposx); - t->y -= mulscale16(65536-smoothratio,s->y-hittype[i].bposy); - t->z -= mulscale16(65536-smoothratio,s->z-hittype[i].bposz); + t->x -= mulscale16(MaxSmoothRatio-smoothratio,s->x-hittype[i].bposx); + t->y -= mulscale16(MaxSmoothRatio-smoothratio,s->y-hittype[i].bposy); + t->z -= mulscale16(MaxSmoothRatio-smoothratio,s->z-hittype[i].bposz); } sect = s->sectnum; diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index abcda3679..5cece5bbc 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -155,8 +155,8 @@ void animatesprites_r(int x,int y,int a,int smoothratio) if( t->statnum == 99 ) continue; if( s->statnum != 1 && s->picnum == APLAYER && ps[s->yvel].newowner == -1 && s->owner >= 0 ) { - t->x -= mulscale16(65536-smoothratio,ps[s->yvel].posx-ps[s->yvel].oposx); - t->y -= mulscale16(65536-smoothratio,ps[s->yvel].posy-ps[s->yvel].oposy); + t->x -= mulscale16(MaxSmoothRatio-smoothratio,ps[s->yvel].posx-ps[s->yvel].oposx); + t->y -= mulscale16(MaxSmoothRatio-smoothratio,ps[s->yvel].posy-ps[s->yvel].oposy); t->z = ps[s->yvel].oposz + mulscale16(smoothratio,ps[s->yvel].posz-ps[s->yvel].oposz); t->z += (40<<8); s->xrepeat = 24; @@ -164,9 +164,9 @@ void animatesprites_r(int x,int y,int a,int smoothratio) } else if( ( s->statnum == 0 && s->picnum != CRANEPOLE) || s->statnum == 10 || s->statnum == 6 || s->statnum == 4 || s->statnum == 5 || s->statnum == 1 ) { - t->x -= mulscale16(65536-smoothratio,s->x-hittype[i].bposx); - t->y -= mulscale16(65536-smoothratio,s->y-hittype[i].bposy); - t->z -= mulscale16(65536-smoothratio,s->z-hittype[i].bposz); + t->x -= mulscale16(MaxSmoothRatio-smoothratio,s->x-hittype[i].bposx); + t->y -= mulscale16(MaxSmoothRatio-smoothratio,s->y-hittype[i].bposy); + t->z -= mulscale16(MaxSmoothRatio-smoothratio,s->z-hittype[i].bposz); } sect = s->sectnum; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 74ccfc125..6466147d8 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -296,8 +296,6 @@ void displayrest(int smoothratio) if (ud.overhead_on > 0) { - // smoothratio = min(max(smoothratio,0),65536); - smoothratio = calc_smoothratio(totalclock, ototalclock); dointerpolations(smoothratio); if (ud.scrollmode == 0) diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 732260c3a..0f50e1dee 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -173,7 +173,7 @@ inline int calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk) { if (!playrunning()) { - return 65536; + return MaxSmoothRatio; } return CalcSmoothRatio(totalclk, ototalclk, REALGAMETICSPERSEC); } diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index e51890d72..56c9d7e1a 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -489,8 +489,7 @@ void displayrooms(int snum, int smoothratio) newaspect_enable = 1; videoSetCorrectedAspect(); - smoothratio = min(max(smoothratio, 0), 65536); - if (!playrunning() || ps[snum].on_crane > -1) smoothratio = 65536; + if (!playrunning() || ps[snum].on_crane > -1) smoothratio = MaxSmoothRatio; sect = p->cursectnum; if (sect < 0 || sect >= MAXSECTORS) return; @@ -594,7 +593,7 @@ void displayrooms(int snum, int smoothratio) cposy = p->posy; cposz = p->posz; sect = sprite[p->newowner].sectnum; - smoothratio = 65536L; + smoothratio = MaxSmoothRatio; } else if (p->over_shoulder_on == 0) { @@ -660,7 +659,7 @@ void displayrooms(int snum, int smoothratio) bool GameInterface::GenerateSavePic() { - displayrooms(myconnectindex, 65536); + displayrooms(myconnectindex, MaxSmoothRatio); return true; }