From f5116dd7874ad7d169c12d4258fd36310f8be897 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 29 Aug 2022 20:51:30 +1000 Subject: [PATCH] - Pass a DAngle through to all the automap code. --- source/core/automap.cpp | 43 +++++++++++++++-------------- source/core/automap.h | 2 +- source/core/gamestruct.h | 2 +- source/games/blood/src/blood.h | 2 +- source/games/blood/src/view.cpp | 8 +++--- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/game_misc.cpp | 14 +++++----- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/map.cpp | 8 +++--- source/games/sw/src/draw.cpp | 14 +++++----- source/games/sw/src/game.h | 2 +- 11 files changed, 50 insertions(+), 49 deletions(-) diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 2eb158623..6a83ee83a 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -57,7 +57,8 @@ CVAR(Bool, am_nameontop, false, CVAR_ARCHIVE) int automapMode; static float am_zoomdir; -int follow_x = INT_MAX, follow_y = INT_MAX, follow_a = INT_MAX; +int follow_x = INT_MAX, follow_y = INT_MAX; +DAngle follow_a = DAngle::fromDeg(INT_MAX); static int gZoom = 768; bool automapping; bool gFullMap; @@ -239,11 +240,11 @@ void AutomapControl() if (buttonMap.ButtonDown(gamefunc_AM_PanDown)) panvert -= keymove; - int momx = MulScale(panvert, bcos(follow_a), 9); - int momy = MulScale(panvert, bsin(follow_a), 9); + int momx = MulScale(panvert, follow_a.Cos() * 16384., 9); + int momy = MulScale(panvert, follow_a.Sin() * 16384., 9); - momx += MulScale(panhorz, bsin(follow_a), 9); - momy += MulScale(panhorz, -bcos(follow_a), 9); + momx += MulScale(panhorz, follow_a.Sin() * 16384., 9); + momy += MulScale(panhorz, -follow_a.Cos() * 16384., 9); follow_x += int(momx * j); follow_y += int(momy * j); @@ -409,10 +410,10 @@ bool ShowRedLine(int j, int i) // //--------------------------------------------------------------------------- -void drawredlines(int cposx, int cposy, int czoom, int cang) +static void drawredlines(int cposx, int cposy, int czoom, const DAngle cang) { - int xvect = -bsin(cang) * czoom; - int yvect = -bcos(cang) * czoom; + int xvect = -cang.Sin() * 16384. * czoom; + int yvect = -cang.Cos() * 16384. * czoom; int width = screen->GetWidth(); int height = screen->GetHeight(); @@ -457,10 +458,10 @@ void drawredlines(int cposx, int cposy, int czoom, int cang) // //--------------------------------------------------------------------------- -static void drawwhitelines(int cposx, int cposy, int czoom, int cang) +static void drawwhitelines(int cposx, int cposy, int czoom, const DAngle cang) { - int xvect = -bsin(cang) * czoom; - int yvect = -bcos(cang) * czoom; + int xvect = -cang.Sin() * 16384. * czoom; + int yvect = -cang.Cos() * 16384. * czoom; int width = screen->GetWidth(); int height = screen->GetHeight(); @@ -499,7 +500,7 @@ static void drawwhitelines(int cposx, int cposy, int czoom, int cang) // //--------------------------------------------------------------------------- -void DrawPlayerArrow(int cposx, int cposy, int cang, int pl_x, int pl_y, int zoom, int pl_angle) +static void DrawPlayerArrow(int cposx, int cposy, const DAngle cang, int pl_x, int pl_y, int zoom, const DAngle pl_angle) { int arrow[] = { @@ -508,11 +509,11 @@ void DrawPlayerArrow(int cposx, int cposy, int cang, int pl_x, int pl_y, int zoo 0, 65536, 32768, 32878, }; - int xvect = -bsin(cang) * zoom; - int yvect = -bcos(cang) * zoom; + int xvect = -cang.Sin() * 16384. * zoom; + int yvect = -cang.Cos() * 16384. * zoom; - int pxvect = -bsin(pl_angle); - int pyvect = -bcos(pl_angle); + int pxvect = -pl_angle.Sin() * 16384.; + int pyvect = -pl_angle.Cos() * 16384.; int width = screen->GetWidth(); int height = screen->GetHeight(); @@ -546,10 +547,10 @@ void DrawPlayerArrow(int cposx, int cposy, int cang, int pl_x, int pl_y, int zoo // //--------------------------------------------------------------------------- -void renderDrawMapView(int cposx, int cposy, int czoom, int cang) +static void renderDrawMapView(int cposx, int cposy, int czoom, const DAngle cang) { - int xvect = -bsin(cang) * czoom; - int yvect = -bcos(cang) * czoom; + int xvect = -cang.Sin() * 16384. * czoom; + int yvect = -cang.Cos() * 16384. * czoom; int width = screen->GetWidth(); int height = screen->GetHeight(); TArray vertices; @@ -655,7 +656,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang) // //--------------------------------------------------------------------------- -void DrawOverheadMap(int pl_x, int pl_y, int pl_angle, double const smoothratio) +void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smoothratio) { if (am_followplayer || follow_x == INT_MAX) { @@ -664,7 +665,7 @@ void DrawOverheadMap(int pl_x, int pl_y, int pl_angle, double const smoothratio) } int x = follow_x; int y = follow_y; - follow_a = am_rotate ? pl_angle : 1536; + follow_a = am_rotate ? pl_angle : DAngle::fromBuild(1536); AutomapControl(); if (automapMode == am_full) diff --git a/source/core/automap.h b/source/core/automap.h index 5be3194bd..9cdbfe3b2 100644 --- a/source/core/automap.h +++ b/source/core/automap.h @@ -16,7 +16,7 @@ extern BitArray show2dwall; void SerializeAutomap(FSerializer& arc); void ClearAutomap(); void MarkSectorSeen(sectortype* sect); -void DrawOverheadMap(int x, int y, int ang, double const smoothratio); +void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smoothratio); bool AM_Responder(event_t* ev, bool last); void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, PalEntry p); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 6fac7be74..c7c3e02e3 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -107,7 +107,7 @@ struct GameInterface virtual void NextLevel(MapRecord* map, int skill) {} virtual void NewGame(MapRecord* map, int skill, bool special = false) {} virtual void LevelCompleted(MapRecord* map, int skill) {} - virtual bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) { return false; } + virtual bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) { return false; } virtual void SetTileProps(int tile, int surf, int vox, int shade) {} virtual fixed_t playerHorizMin() { return IntToFixed(-200); } virtual fixed_t playerHorizMax() { return IntToFixed(200); } diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 5044e9d25..f3ba77b3e 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -133,7 +133,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord* sng, int skill, bool) override; void NextLevel(MapRecord* map, int skill) override; void LevelCompleted(MapRecord* map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) override; + bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) override; void SetTileProps(int til, int surf, int vox, int shade) override; fixed_t playerHorizMin() override { return IntToFixed(-180); } fixed_t playerHorizMax() override { return IntToFixed(120); } diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index e52c3fd7e..09196b38a 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -474,7 +474,7 @@ static void DrawMap(DBloodActor* view) VIEW* pView = &gPrevView[gViewIndex]; int x = interpolatedvalue(pView->x, view->int_pos().X, gInterpolate); int y = interpolatedvalue(pView->y, view->int_pos().Y, gInterpolate); - int ang = (!SyncInput() ? gView->angle.sum() : gView->angle.interpolatedsum(gInterpolate)).Buildang(); + auto ang = !SyncInput() ? gView->angle.sum() : gView->angle.interpolatedsum(gInterpolate); DrawOverheadMap(x, y, ang, gInterpolate); if (tm) setViewport(hud_size); @@ -860,15 +860,15 @@ std::pair GameInterface::GetCoordinates() // //--------------------------------------------------------------------------- -bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) { for (int i = connecthead; i >= 0; i = connectpoint2[i]) { PLAYER* pPlayer = &gPlayer[i]; auto actor = pPlayer->actor; - int xvect = -bsin(a) * z; - int yvect = -bcos(a) * z; + int xvect = -a.Sin() * 16384. * z; + int yvect = -a.Cos() * 16384. * z; int ox = mx - x; int oy = my - y; int x1 = DMulScale(ox, xvect, -oy, yvect, 16); diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 598491b05..bc9088bed 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -50,7 +50,7 @@ struct GameInterface : public ::GameInterface void NextLevel(MapRecord* map, int skill) override; void NewGame(MapRecord* map, int skill, bool) override; void LevelCompleted(MapRecord* map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) override; + bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) override; int playerKeyMove() override { return 40; } void WarpToCoords(int x, int y, int z, int a, int h) override; void ToggleThirdPerson() override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 2edefd37b..f5424f665 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -283,7 +283,7 @@ void drawoverlays(double smoothratio) cposy = pp->player_int_opos().Y; cang = pp->angle.oang; } - DrawOverheadMap(cposx, cposy, cang.Buildang(), smoothratio); + DrawOverheadMap(cposx, cposy, cang, smoothratio); RestoreInterpolations(); } } @@ -385,17 +385,17 @@ ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize) // //--------------------------------------------------------------------------- -bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int czoom, int cang, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int czoom, const DAngle cang, double const smoothratio) { int i, j, k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff; int dax, day, cosang, sinang, xspan, yspan, sprx, spry; - int xrepeat, yrepeat, tilenum, daang; + int xrepeat, yrepeat, tilenum; int xvect, yvect; int p; PalEntry col; - xvect = -bsin(cang) * czoom; - yvect = -bcos(cang) * czoom; + xvect = -cang.Sin() * 16384. * czoom; + yvect = -cang.Cos() * 16384. * czoom; int xdim = twod->GetWidth() << 11; int ydim = twod->GetHeight() << 11; @@ -559,7 +559,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int int xx = twod->GetWidth() / 2. + x1 / 4096.; int yy = twod->GetHeight() / 2. + y1 / 4096.; - daang = ((!SyncInput() ? act->spr.angle : act->interpolatedangle(smoothratio / 65536.)).Buildang() - cang) & 2047; + auto const daang = -((!SyncInput() ? act->spr.angle : act->interpolatedangle(smoothratio / 65536.)) - cang).Normalized360().Degrees(); if (p == screenpeek || ud.coop == 1) { @@ -576,7 +576,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int else if (j > (65536 << 1)) j = (65536 << 1); DrawTexture(twod, tileGetTexture(i), xx, yy, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true, - DTA_Rotate, daang * -BAngToDegree, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); + DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); } } return true; diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 56c814931..c2800ac03 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -230,7 +230,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord *map, int skill, bool) override; void LevelCompleted(MapRecord *map, int skill) override; void NextLevel(MapRecord *map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) override; + bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) override; fixed_t playerHorizMin() override { return IntToFixed(-150); } fixed_t playerHorizMax() override { return IntToFixed(150); } int playerKeyMove() override { return 6; } diff --git a/source/games/exhumed/src/map.cpp b/source/games/exhumed/src/map.cpp index e1aaf8578..bfccac284 100644 --- a/source/games/exhumed/src/map.cpp +++ b/source/games/exhumed/src/map.cpp @@ -52,7 +52,7 @@ void DrawMap(double const smoothratio) int x = pPlayerActor->__interpolatedx(smoothratio); int y = pPlayerActor->__interpolatedy(smoothratio); - int ang = (!SyncInput() ? PlayerList[nLocalPlayer].angle.sum() : PlayerList[nLocalPlayer].angle.interpolatedsum(smoothratio)).Buildang(); + auto ang = !SyncInput() ? PlayerList[nLocalPlayer].angle.sum() : PlayerList[nLocalPlayer].angle.interpolatedsum(smoothratio); DrawOverheadMap(x, y, ang, smoothratio); } } @@ -69,14 +69,14 @@ void GetActorExtents(DExhumedActor* actor, int* top, int* bottom) } } -bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) { for (int i = connecthead; i >= 0; i = connectpoint2[i]) { auto pPlayerActor = PlayerList[i].pActor; - int xvect = -bsin(a) * z; - int yvect = -bcos(a) * z; + int xvect = -a.Sin() * 16384. * z; + int yvect = -a.Cos() * 16384. * z; int ox = mx - x; int oy = my - y; int x1 = DMulScale(ox, xvect, -oy, yvect, 16); diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 1f562f93a..7835a5f76 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1505,7 +1505,7 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly) } } } - DrawOverheadMap(tx, ty, tang.Buildang(), smoothratio); + DrawOverheadMap(tx, ty, tang, smoothratio); } SWSpriteIterator it; @@ -1567,11 +1567,11 @@ bool GameInterface::GenerateSavePic() -bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int czoom, int cang, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int czoom, const DAngle cang, double const smoothratio) { int k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff; int dax, day, cosang, sinang, xspan, yspan, sprx, spry; - int xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; + int xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum; int xvect, yvect; walltype* wal, * wal2; short p; @@ -1579,8 +1579,8 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int bool sprisplayer = false; short txt_x, txt_y; - xvect = -bsin(cang) * czoom; - yvect = -bcos(cang) * czoom; + xvect = -cang.Sin() * 16384. * czoom; + yvect = -cang.Cos() * 16384. * czoom; int xdim = twod->GetWidth() << 11; int ydim = twod->GetHeight() << 11; @@ -1637,7 +1637,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int if (czoom > 192) { - daang = ((!SyncInput() ? actor->spr.angle : actor->interpolatedangle(smoothratio / 65536.)).Buildang() - cang) & 2047; + const auto daang = -((!SyncInput() ? actor->spr.angle : actor->interpolatedangle(smoothratio / 65536.)) - cang).Normalized360().Degrees(); // Special case tiles if (actor->spr.picnum == 3123) break; @@ -1653,7 +1653,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int double sc = czoom * (actor->spr.yrepeat) / 32768.; if (spnum >= 0) { - DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), xx, yy, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang * -BAngToDegree, + DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), xx, yy, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang, DTA_CenterOffsetRel, 2, DTA_TranslationIndex, TRANSLATION(Translation_Remap, actor->spr.pal), DTA_Color, shadeToLight(actor->spr.shade), DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT) ? 0.33 : 1., TAG_DONE); } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 7840ad472..96901c45b 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2038,7 +2038,7 @@ struct GameInterface : public ::GameInterface void LevelCompleted(MapRecord *map, int skill) override; void NextLevel(MapRecord *map, int skill) override; void NewGame(MapRecord *map, int skill, bool) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, int a, double const smoothratio) override; + bool DrawAutomapPlayer(int mx, int my, int x, int y, int z, const DAngle a, double const smoothratio) override; int playerKeyMove() override { return 35; } void WarpToCoords(int x, int y, int z, int a, int h) override; void ToggleThirdPerson() override;