From 25ca6fa1423f16400712dd6887add5ca8b6a8a2b Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Sat, 12 Oct 2024 20:13:06 +1100 Subject: [PATCH] Fix path in automap after player teleports, rotate mode off Plus a bit of refactoring. --- src/am_map.c | 148 +++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 65 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index 8f7e7823f..f74bbc960 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -1154,8 +1154,7 @@ static void AM_RotatePoint(mpoint_t *point) static void AM_CorrectAspectRatio(mpoint_t *point) { - if (am_correctaspectratio) - point->y = am_frame.center.y + FixedMul(point->y - am_frame.center.y, AM_CORRECTASPECTRATIO); + point->y = am_frame.center.y + FixedMul(point->y - am_frame.center.y, AM_CORRECTASPECTRATIO); } // @@ -1424,21 +1423,6 @@ static void AM_DrawFline(int x0, int y0, int x1, int y1, const byte *color, } } -static mline_t (*rotatelinefunc)(mline_t); - -static mline_t AM_RotateLine(mline_t mline) -{ - AM_RotatePoint(&mline.a); - AM_RotatePoint(&mline.b); - - return mline; -} - -static mline_t AM_DoNotRotateLine(mline_t mline) -{ - return mline; -} - // // Draws flat (floor/ceiling tile) aligned grid lines. // @@ -1463,9 +1447,18 @@ static void AM_DrawGrid(void) { mline_t mline = { { x, starty }, { x, endy } }; - mline = rotatelinefunc(mline); - AM_CorrectAspectRatio(&mline.a); - AM_CorrectAspectRatio(&mline.b); + if (am_rotatemode) + { + AM_RotatePoint(&mline.a); + AM_RotatePoint(&mline.b); + } + + if (am_correctaspectratio) + { + AM_CorrectAspectRatio(&mline.a); + AM_CorrectAspectRatio(&mline.b); + } + AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, &gridcolor, putbigdot2); } @@ -1474,9 +1467,18 @@ static void AM_DrawGrid(void) { mline_t mline = { { startx, y }, { endx, y } }; - mline = rotatelinefunc(mline); - AM_CorrectAspectRatio(&mline.a); - AM_CorrectAspectRatio(&mline.b); + if (am_rotatemode) + { + AM_RotatePoint(&mline.a); + AM_RotatePoint(&mline.b); + } + + if (am_correctaspectratio) + { + AM_CorrectAspectRatio(&mline.a); + AM_CorrectAspectRatio(&mline.b); + } + AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, &gridcolor, putbigdot2); } } @@ -1542,9 +1544,17 @@ static void AM_DrawWalls(void) const unsigned short special = line.special; byte *doorcolor; - mline = rotatelinefunc(mline); - AM_CorrectAspectRatio(&mline.a); - AM_CorrectAspectRatio(&mline.b); + if (am_rotatemode) + { + AM_RotatePoint(&mline.a); + AM_RotatePoint(&mline.b); + } + + if (am_correctaspectratio) + { + AM_CorrectAspectRatio(&mline.a); + AM_CorrectAspectRatio(&mline.b); + } if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor) AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, doorcolor, putbigdot); @@ -1594,9 +1604,17 @@ static void AM_DrawWalls_AllMap(void) const unsigned short special = line.special; byte *doorcolor; - mline = rotatelinefunc(mline); - AM_CorrectAspectRatio(&mline.a); - AM_CorrectAspectRatio(&mline.b); + if (am_rotatemode) + { + AM_RotatePoint(&mline.a); + AM_RotatePoint(&mline.b); + } + + if (am_correctaspectratio) + { + AM_CorrectAspectRatio(&mline.a); + AM_CorrectAspectRatio(&mline.b); + } if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor) AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, doorcolor, putbigdot); @@ -1645,9 +1663,17 @@ static void AM_DrawWalls_Cheating(void) const unsigned short special = line.special; byte *doorcolor; - mline = rotatelinefunc(mline); - AM_CorrectAspectRatio(&mline.a); - AM_CorrectAspectRatio(&mline.b); + if (am_rotatemode) + { + AM_RotatePoint(&mline.a); + AM_RotatePoint(&mline.b); + } + + if (am_correctaspectratio) + { + AM_CorrectAspectRatio(&mline.a); + AM_CorrectAspectRatio(&mline.b); + } if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor) AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, doorcolor, putbigdot); @@ -1779,7 +1805,8 @@ static void AM_DrawPlayer(void) else angle = viewangle >> ANGLETOFINESHIFT; - AM_CorrectAspectRatio(&point); + if (am_correctaspectratio) + AM_CorrectAspectRatio(&point); if (viewplayer->cheats & (CF_ALLMAP | CF_ALLMAP_THINGS)) { @@ -1833,7 +1860,8 @@ static void AM_DrawThings(void) if (am_rotatemode) AM_RotatePoint(&point); - AM_CorrectAspectRatio(&point); + if (am_correctaspectratio) + AM_CorrectAspectRatio(&point); if (!(flags & MF_SHOOTABLE) && !(flags & MF_CORPSE)) width = (12 << FRACBITS) >> FRACTOMAPBITS; @@ -1866,7 +1894,8 @@ static void AM_DrawBloodSplats(void) if (am_rotatemode) AM_RotatePoint(&point); - AM_CorrectAspectRatio(&point); + if (am_correctaspectratio) + AM_CorrectAspectRatio(&point); if ((fx = CXMTOF(point.x)) >= -BLOODSPLATWIDTH && fx <= MAPWIDTH + BLOODSPLATWIDTH && (fy = CYMTOF(point.y)) >= -BLOODSPLATWIDTH && fy <= MAPHEIGHT + BLOODSPLATWIDTH) @@ -1939,7 +1968,8 @@ static void AM_DrawMarks(const char *nums[]) if (am_rotatemode) AM_RotatePoint(&point); - AM_CorrectAspectRatio(&point); + if (am_correctaspectratio) + AM_CorrectAspectRatio(&point); x = CXMTOF(point.x) - MARKWIDTH / 2 + 1; y = CYMTOF(point.y) - MARKHEIGHT / 2 - 1; @@ -2000,44 +2030,36 @@ static void AM_DrawPath(void) mpoint_t end = { 0, 0 }; mpoint_t player = { viewx >> FRACTOMAPBITS, viewy >> FRACTOMAPBITS }; - if (am_rotatemode) + for (int i = 1; i < numbreadcrumbs; i++) { - for (int i = 1; i < numbreadcrumbs; i++) - { - mpoint_t start = { breadcrumb[i - 1].x >> FRACTOMAPBITS, breadcrumb[i - 1].y >> FRACTOMAPBITS }; + mpoint_t start = { breadcrumb[i - 1].x >> FRACTOMAPBITS, breadcrumb[i - 1].y >> FRACTOMAPBITS }; - end.x = breadcrumb[i].x >> FRACTOMAPBITS; - end.y = breadcrumb[i].y >> FRACTOMAPBITS; + end.x = breadcrumb[i].x >> FRACTOMAPBITS; + end.y = breadcrumb[i].y >> FRACTOMAPBITS; - if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT) - continue; + if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT) + continue; + if (am_rotatemode) + { AM_RotatePoint(&start); AM_RotatePoint(&end); + } + + if (am_correctaspectratio) + { AM_CorrectAspectRatio(&start); AM_CorrectAspectRatio(&end); - AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2); } - AM_RotatePoint(&player); - AM_CorrectAspectRatio(&player); + AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2); } - else - { - mpoint_t start = { breadcrumb[0].x >> FRACTOMAPBITS, breadcrumb[0].y >> FRACTOMAPBITS }; - for (int i = 1; i < numbreadcrumbs; i++) - { - end.x = breadcrumb[i].x >> FRACTOMAPBITS; - end.y = breadcrumb[i].y >> FRACTOMAPBITS; - - if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT) - continue; + if (am_rotatemode) + AM_RotatePoint(&player); - AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2); - start = end; - } - } + if (am_correctaspectratio) + AM_CorrectAspectRatio(&player); if (ABS(end.x - player.x) <= 4 * FRACUNIT && ABS(end.y - player.y) <= 4 * FRACUNIT) AM_DrawFline(end.x, end.y, player.x, player.y, &pathcolor, putbigdot2); @@ -2190,11 +2212,7 @@ static void AM_SetFrameVariables(void) am_frame.sin = finesine[angle]; am_frame.cos = finecosine[angle]; - - rotatelinefunc = &AM_RotateLine; } - else - rotatelinefunc = &AM_DoNotRotateLine; } static void AM_ApplyAntialiasing(void)