Skip to content

Commit

Permalink
Fix path in automap after player teleports, rotate mode off
Browse files Browse the repository at this point in the history
Plus a bit of refactoring.
  • Loading branch information
bradharding committed Oct 12, 2024
1 parent 2940684 commit 25ca6fa
Showing 1 changed file with 83 additions and 65 deletions.
148 changes: 83 additions & 65 deletions src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//
Expand Down Expand Up @@ -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.
//
Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 25ca6fa

Please sign in to comment.