From 029f8807df476c23812b956fb8ee8c11800f0cf0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 1 Apr 2021 10:42:22 +1100 Subject: [PATCH] - Make `360. / 2048.` a constant expression and replace all uses throughout code. --- source/core/binaryangle.h | 1 + source/core/gameinput.cpp | 5 ++--- source/games/blood/src/qav.cpp | 2 +- source/games/blood/src/view.cpp | 2 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/sbar_r.cpp | 4 ++-- source/games/exhumed/src/movie.cpp | 2 +- source/games/sw/src/draw.cpp | 2 +- source/glbackend/glbackend.cpp | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index 373f5a02e..bec19e891 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -60,6 +60,7 @@ enum constexpr double BAngRadian = pi::pi() * (1. / 1024.); constexpr double BRadAngScale = 1. / BAngRadian; +constexpr double BAngToDegree = 360. / 2048.; //--------------------------------------------------------------------------- diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index a84df7574..a36edaa7a 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -154,8 +154,7 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn int const keymove = gi->playerKeyMove() << running; int const cntrlvelscale = g_gameType & GAMEFLAG_PSEXHUMED ? 8 : 1; float const mousevelscale = keymove / 160.f; - double const angtodegscale = 360. / 2048.; - double const hidspeed = ((running ? 1585. : 867.5) / GameTicRate) * angtodegscale; + double const hidspeed = ((running ? 1585. : 867.5) / GameTicRate) * BAngToDegree; // process mouse and initial controller input. if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe) @@ -199,7 +198,7 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn // allow Exhumed to use its legacy values given the drastic difference from the other games. if ((g_gameType & GAMEFLAG_PSEXHUMED) && cl_exhumedoldturn) { - preambleturn = turnamount = (running ? 12 : 8) * angtodegscale; + preambleturn = turnamount = (running ? 12 : 8) * BAngToDegree; } if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe)) diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index 9fd8d3566..607a73d40 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -46,7 +46,7 @@ void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int p { auto tex = tileGetTexture(pTile->picnum); double scale = pTile->z/65536.; - double angle = pTile->angle * (360./2048); + double angle = pTile->angle * BAngToDegree; int renderstyle = (stat & RS_NOMASK)? STYLE_Normal : STYLE_Translucent; double alpha = (stat & RS_TRANS1)? glblend[0].def[!!(stat & RS_TRANS2)].alpha : 1.; int pin = (stat & kQavOrientationLeft)? -1 : (stat & RS_ALIGN_R)? 1:0; diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 2048fc333..6575d1298 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -882,7 +882,7 @@ FString GameInterface::GetCoordString() FString out; out.Format("pos= %d, %d, %d - angle = %2.3f", - gMe->pSprite->x, gMe->pSprite->y, gMe->pSprite->z, gMe->pSprite->ang * (360./2048)); + gMe->pSprite->x, gMe->pSprite->y, gMe->pSprite->z, gMe->pSprite->ang * BAngToDegree); return out; } diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index c806bad00..f5ea986d9 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -577,7 +577,7 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang, else if (j > (65536 << 1)) j = (65536 << 1); DrawTexture(twod, tileGetTexture(i), xdim / 2. + spos.x / 4096., ydim / 2. + spos.y / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), pspr->pal), DTA_CenterOffset, true, - DTA_Rotate, daang * (-360./2048), DTA_Color, shadeToLight(pspr->shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); + DTA_Rotate, daang * -BAngToDegree, DTA_Color, shadeToLight(pspr->shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); } } return true; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 4bf022212..d8cbaa751 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -755,7 +755,7 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I } input.fvel = xs_CRoundToInt(p->MotoSpeed); - input.avel *= (45. / 256.); + input.avel *= BAngToDegree; loc.avel += input.avel; } diff --git a/source/games/duke/src/sbar_r.cpp b/source/games/duke/src/sbar_r.cpp index ee23a90a4..c6035b13a 100644 --- a/source/games/duke/src/sbar_r.cpp +++ b/source/games/duke/src/sbar_r.cpp @@ -413,8 +413,8 @@ public: p->drunkang = 400; } - DrawRotated(tileGetTexture(GUTMETER), 256, top + 15, DI_ITEM_RELCENTER, p->drunkang * (-360. / 2048), 1, scale, scale, 0xffffffff, 0); - DrawRotated(tileGetTexture(GUTMETER), 292, top + 15, DI_ITEM_RELCENTER, p->eatang * (-360. / 2048), 1, scale, scale, 0xffffffff, 0); + DrawRotated(tileGetTexture(GUTMETER), 256, top + 15, DI_ITEM_RELCENTER, p->drunkang * -BAngToDegree, 1, scale, scale, 0xffffffff, 0); + DrawRotated(tileGetTexture(GUTMETER), 292, top + 15, DI_ITEM_RELCENTER, p->eatang * -BAngToDegree, 1, scale, scale, 0xffffffff, 0); if (p->drink_amt >= 0 && p->drink_amt <= 30) { diff --git a/source/games/exhumed/src/movie.cpp b/source/games/exhumed/src/movie.cpp index bb18ea182..d26b9ce52 100644 --- a/source/games/exhumed/src/movie.cpp +++ b/source/games/exhumed/src/movie.cpp @@ -250,7 +250,7 @@ public: { twod->ClearScreen(); DrawTexture(twod, decoder.animTex().GetFrame(), 160, 100, DTA_FullscreenScale, FSMode_Fit320x200, - DTA_CenterOffset, true, DTA_FlipY, true, DTA_ScaleX, z / 65536., DTA_ScaleY, z / 65536., DTA_Rotate, (-angle - 512) * (360. / 2048.), TAG_DONE); + DTA_CenterOffset, true, DTA_FlipY, true, DTA_ScaleX, z / 65536., DTA_ScaleY, z / 65536., DTA_Rotate, (-angle - 512) * BAngToDegree, TAG_DONE); } lastclock = clock; diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 0110fb5e5..6763fd752 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1825,7 +1825,7 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang, double sc = MulScale(czoom * (spr->yrepeat), yxaspect, 16) / 32768.; if (spnum >= 0) { - DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), xd, yd, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang * (-360. / 2048), + DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), xd, yd, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang * -BAngToDegree, DTA_CenterOffsetRel, true, DTA_TranslationIndex, TRANSLATION(Translation_Remap, spr->pal), DTA_Color, shadeToLight(spr->shade), DTA_Alpha, (spr->cstat & 2) ? 0.33 : 1., TAG_DONE); } diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 8cc3d006d..b1abfbfce 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -557,7 +557,7 @@ void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dasha DTA_FlipX, !!(dastat & RS_XFLIPHUD), DTA_FlipY, !!(dastat & RS_YFLIPHUD), DTA_Pin, (dastat & RS_ALIGN_R) ? 1 : (dastat & RS_ALIGN_L) ? -1 : 0, - DTA_Rotate, a * (-360./2048), + DTA_Rotate, a * -BAngToDegree, DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)), DTA_Alpha, alpha, TAG_DONE);