Skip to content

Commit 25ca6fa

Browse files
committed
Fix path in automap after player teleports, rotate mode off
Plus a bit of refactoring.
1 parent 2940684 commit 25ca6fa

File tree

1 file changed

+83
-65
lines changed

1 file changed

+83
-65
lines changed

src/am_map.c

+83-65
Original file line numberDiff line numberDiff line change
@@ -1154,8 +1154,7 @@ static void AM_RotatePoint(mpoint_t *point)
11541154

11551155
static void AM_CorrectAspectRatio(mpoint_t *point)
11561156
{
1157-
if (am_correctaspectratio)
1158-
point->y = am_frame.center.y + FixedMul(point->y - am_frame.center.y, AM_CORRECTASPECTRATIO);
1157+
point->y = am_frame.center.y + FixedMul(point->y - am_frame.center.y, AM_CORRECTASPECTRATIO);
11591158
}
11601159

11611160
//
@@ -1424,21 +1423,6 @@ static void AM_DrawFline(int x0, int y0, int x1, int y1, const byte *color,
14241423
}
14251424
}
14261425

1427-
static mline_t (*rotatelinefunc)(mline_t);
1428-
1429-
static mline_t AM_RotateLine(mline_t mline)
1430-
{
1431-
AM_RotatePoint(&mline.a);
1432-
AM_RotatePoint(&mline.b);
1433-
1434-
return mline;
1435-
}
1436-
1437-
static mline_t AM_DoNotRotateLine(mline_t mline)
1438-
{
1439-
return mline;
1440-
}
1441-
14421426
//
14431427
// Draws flat (floor/ceiling tile) aligned grid lines.
14441428
//
@@ -1463,9 +1447,18 @@ static void AM_DrawGrid(void)
14631447
{
14641448
mline_t mline = { { x, starty }, { x, endy } };
14651449

1466-
mline = rotatelinefunc(mline);
1467-
AM_CorrectAspectRatio(&mline.a);
1468-
AM_CorrectAspectRatio(&mline.b);
1450+
if (am_rotatemode)
1451+
{
1452+
AM_RotatePoint(&mline.a);
1453+
AM_RotatePoint(&mline.b);
1454+
}
1455+
1456+
if (am_correctaspectratio)
1457+
{
1458+
AM_CorrectAspectRatio(&mline.a);
1459+
AM_CorrectAspectRatio(&mline.b);
1460+
}
1461+
14691462
AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, &gridcolor, putbigdot2);
14701463
}
14711464

@@ -1474,9 +1467,18 @@ static void AM_DrawGrid(void)
14741467
{
14751468
mline_t mline = { { startx, y }, { endx, y } };
14761469

1477-
mline = rotatelinefunc(mline);
1478-
AM_CorrectAspectRatio(&mline.a);
1479-
AM_CorrectAspectRatio(&mline.b);
1470+
if (am_rotatemode)
1471+
{
1472+
AM_RotatePoint(&mline.a);
1473+
AM_RotatePoint(&mline.b);
1474+
}
1475+
1476+
if (am_correctaspectratio)
1477+
{
1478+
AM_CorrectAspectRatio(&mline.a);
1479+
AM_CorrectAspectRatio(&mline.b);
1480+
}
1481+
14801482
AM_DrawFline(mline.a.x, mline.a.y, mline.b.x, mline.b.y, &gridcolor, putbigdot2);
14811483
}
14821484
}
@@ -1542,9 +1544,17 @@ static void AM_DrawWalls(void)
15421544
const unsigned short special = line.special;
15431545
byte *doorcolor;
15441546

1545-
mline = rotatelinefunc(mline);
1546-
AM_CorrectAspectRatio(&mline.a);
1547-
AM_CorrectAspectRatio(&mline.b);
1547+
if (am_rotatemode)
1548+
{
1549+
AM_RotatePoint(&mline.a);
1550+
AM_RotatePoint(&mline.b);
1551+
}
1552+
1553+
if (am_correctaspectratio)
1554+
{
1555+
AM_CorrectAspectRatio(&mline.a);
1556+
AM_CorrectAspectRatio(&mline.b);
1557+
}
15481558

15491559
if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor)
15501560
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)
15941604
const unsigned short special = line.special;
15951605
byte *doorcolor;
15961606

1597-
mline = rotatelinefunc(mline);
1598-
AM_CorrectAspectRatio(&mline.a);
1599-
AM_CorrectAspectRatio(&mline.b);
1607+
if (am_rotatemode)
1608+
{
1609+
AM_RotatePoint(&mline.a);
1610+
AM_RotatePoint(&mline.b);
1611+
}
1612+
1613+
if (am_correctaspectratio)
1614+
{
1615+
AM_CorrectAspectRatio(&mline.a);
1616+
AM_CorrectAspectRatio(&mline.b);
1617+
}
16001618

16011619
if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor)
16021620
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)
16451663
const unsigned short special = line.special;
16461664
byte *doorcolor;
16471665

1648-
mline = rotatelinefunc(mline);
1649-
AM_CorrectAspectRatio(&mline.a);
1650-
AM_CorrectAspectRatio(&mline.b);
1666+
if (am_rotatemode)
1667+
{
1668+
AM_RotatePoint(&mline.a);
1669+
AM_RotatePoint(&mline.b);
1670+
}
1671+
1672+
if (am_correctaspectratio)
1673+
{
1674+
AM_CorrectAspectRatio(&mline.a);
1675+
AM_CorrectAspectRatio(&mline.b);
1676+
}
16511677

16521678
if (special && (doorcolor = AM_DoorColor(special)) != cdwallcolor)
16531679
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)
17791805
else
17801806
angle = viewangle >> ANGLETOFINESHIFT;
17811807

1782-
AM_CorrectAspectRatio(&point);
1808+
if (am_correctaspectratio)
1809+
AM_CorrectAspectRatio(&point);
17831810

17841811
if (viewplayer->cheats & (CF_ALLMAP | CF_ALLMAP_THINGS))
17851812
{
@@ -1833,7 +1860,8 @@ static void AM_DrawThings(void)
18331860
if (am_rotatemode)
18341861
AM_RotatePoint(&point);
18351862

1836-
AM_CorrectAspectRatio(&point);
1863+
if (am_correctaspectratio)
1864+
AM_CorrectAspectRatio(&point);
18371865

18381866
if (!(flags & MF_SHOOTABLE) && !(flags & MF_CORPSE))
18391867
width = (12 << FRACBITS) >> FRACTOMAPBITS;
@@ -1866,7 +1894,8 @@ static void AM_DrawBloodSplats(void)
18661894
if (am_rotatemode)
18671895
AM_RotatePoint(&point);
18681896

1869-
AM_CorrectAspectRatio(&point);
1897+
if (am_correctaspectratio)
1898+
AM_CorrectAspectRatio(&point);
18701899

18711900
if ((fx = CXMTOF(point.x)) >= -BLOODSPLATWIDTH && fx <= MAPWIDTH + BLOODSPLATWIDTH
18721901
&& (fy = CYMTOF(point.y)) >= -BLOODSPLATWIDTH && fy <= MAPHEIGHT + BLOODSPLATWIDTH)
@@ -1939,7 +1968,8 @@ static void AM_DrawMarks(const char *nums[])
19391968
if (am_rotatemode)
19401969
AM_RotatePoint(&point);
19411970

1942-
AM_CorrectAspectRatio(&point);
1971+
if (am_correctaspectratio)
1972+
AM_CorrectAspectRatio(&point);
19431973

19441974
x = CXMTOF(point.x) - MARKWIDTH / 2 + 1;
19451975
y = CYMTOF(point.y) - MARKHEIGHT / 2 - 1;
@@ -2000,44 +2030,36 @@ static void AM_DrawPath(void)
20002030
mpoint_t end = { 0, 0 };
20012031
mpoint_t player = { viewx >> FRACTOMAPBITS, viewy >> FRACTOMAPBITS };
20022032

2003-
if (am_rotatemode)
2033+
for (int i = 1; i < numbreadcrumbs; i++)
20042034
{
2005-
for (int i = 1; i < numbreadcrumbs; i++)
2006-
{
2007-
mpoint_t start = { breadcrumb[i - 1].x >> FRACTOMAPBITS, breadcrumb[i - 1].y >> FRACTOMAPBITS };
2035+
mpoint_t start = { breadcrumb[i - 1].x >> FRACTOMAPBITS, breadcrumb[i - 1].y >> FRACTOMAPBITS };
20082036

2009-
end.x = breadcrumb[i].x >> FRACTOMAPBITS;
2010-
end.y = breadcrumb[i].y >> FRACTOMAPBITS;
2037+
end.x = breadcrumb[i].x >> FRACTOMAPBITS;
2038+
end.y = breadcrumb[i].y >> FRACTOMAPBITS;
20112039

2012-
if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT)
2013-
continue;
2040+
if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT)
2041+
continue;
20142042

2043+
if (am_rotatemode)
2044+
{
20152045
AM_RotatePoint(&start);
20162046
AM_RotatePoint(&end);
2047+
}
2048+
2049+
if (am_correctaspectratio)
2050+
{
20172051
AM_CorrectAspectRatio(&start);
20182052
AM_CorrectAspectRatio(&end);
2019-
AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2);
20202053
}
20212054

2022-
AM_RotatePoint(&player);
2023-
AM_CorrectAspectRatio(&player);
2055+
AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2);
20242056
}
2025-
else
2026-
{
2027-
mpoint_t start = { breadcrumb[0].x >> FRACTOMAPBITS, breadcrumb[0].y >> FRACTOMAPBITS };
20282057

2029-
for (int i = 1; i < numbreadcrumbs; i++)
2030-
{
2031-
end.x = breadcrumb[i].x >> FRACTOMAPBITS;
2032-
end.y = breadcrumb[i].y >> FRACTOMAPBITS;
2033-
2034-
if (ABS(start.x - end.x) > 4 * FRACUNIT || ABS(start.y - end.y) > 4 * FRACUNIT)
2035-
continue;
2058+
if (am_rotatemode)
2059+
AM_RotatePoint(&player);
20362060

2037-
AM_DrawFline(start.x, start.y, end.x, end.y, &pathcolor, putbigdot2);
2038-
start = end;
2039-
}
2040-
}
2061+
if (am_correctaspectratio)
2062+
AM_CorrectAspectRatio(&player);
20412063

20422064
if (ABS(end.x - player.x) <= 4 * FRACUNIT && ABS(end.y - player.y) <= 4 * FRACUNIT)
20432065
AM_DrawFline(end.x, end.y, player.x, player.y, &pathcolor, putbigdot2);
@@ -2190,11 +2212,7 @@ static void AM_SetFrameVariables(void)
21902212

21912213
am_frame.sin = finesine[angle];
21922214
am_frame.cos = finecosine[angle];
2193-
2194-
rotatelinefunc = &AM_RotateLine;
21952215
}
2196-
else
2197-
rotatelinefunc = &AM_DoNotRotateLine;
21982216
}
21992217

22002218
static void AM_ApplyAntialiasing(void)

0 commit comments

Comments
 (0)