Skip to content

Commit

Permalink
Add an option to display the path travalled by the local player
Browse files Browse the repository at this point in the history
This is useful to avoid getting lost on larger maps.
  • Loading branch information
Calinou committed Apr 27, 2023
1 parent 86bc9ca commit 7d06a20
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 5 deletions.
112 changes: 107 additions & 5 deletions src/am_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ CUSTOM_CVAR(Int, am_emptyspacemargin, 0, CVAR_ARCHIVE)
CVAR(Bool, am_followplayer, true, CVAR_ARCHIVE)
CVAR(Bool, am_portaloverlay, true, CVAR_ARCHIVE)
CVAR(Bool, am_showgrid, false, CVAR_ARCHIVE)
CVAR(Bool, am_path, false, CVAR_ARCHIVE)
CVAR(Int, am_pathlength, 100, CVAR_ARCHIVE)
CVAR(Float, am_zoomdir, 0.f, CVAR_ARCHIVE)

static const char *const DEFAULT_FONT_NAME = "AMMNUMx";
Expand Down Expand Up @@ -296,6 +298,7 @@ CVAR (Color, am_thingcolor_ncmonster, 0xfcfcfc, CVAR_ARCHIVE);
CVAR (Color, am_thingcolor_item, 0xfcfcfc, CVAR_ARCHIVE);
CVAR (Color, am_thingcolor_citem, 0xfcfcfc, CVAR_ARCHIVE);
CVAR (Color, am_portalcolor, 0x404040, CVAR_ARCHIVE);
CVAR (Color, am_pathcolor, 0x4080c0, CVAR_ARCHIVE);

CVAR (Color, am_ovyourcolor, 0xfce8d8, CVAR_ARCHIVE);
CVAR (Color, am_ovwallcolor, 0x00ff00, CVAR_ARCHIVE);
Expand All @@ -318,6 +321,7 @@ CVAR (Color, am_ovthingcolor_ncmonster, 0xe88800, CVAR_ARCHIVE);
CVAR (Color, am_ovthingcolor_item, 0xe88800, CVAR_ARCHIVE);
CVAR (Color, am_ovthingcolor_citem, 0xe88800, CVAR_ARCHIVE);
CVAR (Color, am_ovportalcolor, 0x004022, CVAR_ARCHIVE);
CVAR (Color, am_ovpathcolor, 0x4080c0, CVAR_ARCHIVE);

//=============================================================================
//
Expand Down Expand Up @@ -381,6 +385,7 @@ static const char *ColorNames[] = {
"SecretSectorColor",
"UnexploredSecretColor",
"PortalColor",
"PathColor",
"AlmostBackgroundColor",
nullptr
};
Expand Down Expand Up @@ -413,6 +418,7 @@ struct AMColorset
SecretSectorColor,
UnexploredSecretColor,
PortalColor,
PathColor,
AlmostBackgroundColor,
AM_NUM_COLORS
};
Expand Down Expand Up @@ -538,7 +544,8 @@ static FColorCVarRef *cv_standard[] = {
&am_interlevelcolor,
&am_secretsectorcolor,
&am_unexploredsecretcolor,
&am_portalcolor
&am_portalcolor,
&am_pathcolor
};

static FColorCVarRef *cv_overlay[] = {
Expand All @@ -565,7 +572,8 @@ static FColorCVarRef *cv_overlay[] = {
&am_ovinterlevelcolor,
&am_ovsecretsectorcolor,
&am_ovunexploredsecretcolor,
&am_ovportalcolor
&am_ovportalcolor,
&am_ovpathcolor
};

CCMD(am_restorecolors)
Expand Down Expand Up @@ -608,8 +616,9 @@ static unsigned char DoomColors[]= {
NOT_USED, // interteleport
NOT_USED, // secretsector
NOT_USED, // unexploredsecretsector
0x40,0x40,0x40, // portal
0x40,0x80,0xb0, // path
0x10,0x10,0x10, // almostbackground
0x40,0x40,0x40 // portal
};

static unsigned char StrifeColors[]= {
Expand All @@ -636,8 +645,9 @@ static unsigned char StrifeColors[]= {
NOT_USED, // interteleport
NOT_USED, // secretsector
NOT_USED, // unexploredsecretsector
0x40,0x40,0x40, // portal
0x40,0x80,0xb0, // path
0x10,0x10,0x10, // almostbackground
0x40,0x40,0x40 // portal
};

static unsigned char RavenColors[]= {
Expand All @@ -664,8 +674,9 @@ static unsigned char RavenColors[]= {
NOT_USED, // interteleport
NOT_USED, // secretsector
NOT_USED, // unexploredsecretsector
0x50,0x50,0x50, // portal
0x40,0x80,0xb0, // path
0x10,0x10,0x10, // almostbackground
0x50,0x50,0x50 // portal
};

#undef NOT_USED
Expand Down Expand Up @@ -971,6 +982,8 @@ class DAutomap :public DAutomapBase

TArray<FVector2> points;

TArray<mline_t> path_history; // history of points the local player has travelled to

// translates between frame-buffer and map distances
double FTOM(double x)
{
Expand Down Expand Up @@ -1015,6 +1028,8 @@ class DAutomap :public DAutomapBase
bool clipMline(mline_t *ml, fline_t *fl);
void drawMline(mline_t *ml, const AMColor &color);
void drawMline(mline_t *ml, int colorindex);
void collectPath();
void drawPath(int color);
void drawGrid(int color);
void drawSubsectors();
void drawSeg(seg_t *seg, const AMColor &color);
Expand Down Expand Up @@ -1544,6 +1559,10 @@ void DAutomap::doFollowPlayer ()

void DAutomap::Ticker ()
{
// Player path is collected even while the automap isn't visible or if am_path is disabled.
// This way, you can toggle am_path during gameplay and still see your previously travelled path.
collectPath();

if (!automapactive)
return;

Expand Down Expand Up @@ -1808,6 +1827,86 @@ void DAutomap::drawMline (mline_t *ml, int colorindex)
drawMline(ml, AMColors[colorindex]);
}

//=============================================================================
//
// Computes the list of lines to be drawn in drawPath() based on local player
// position.
//
//=============================================================================

void DAutomap::collectPath ()
{
DVector2 pos = players[consoleplayer].camera->InterpolatedPosition(r_viewpoint.TicFrac);
mline_t ml;
if (path_history.Size() >= 1)
{
// Create a path between the last point and current point if there's enough distance
// travelled by the player since the last point.
mline_t last_line = path_history.Last();
if (abs(last_line.b.x - pos.X) >= 32 || abs(last_line.b.y - pos.Y) >= 32)
{
// If the distance between two points is very high, the player has likely teleported so no path should be drawn between the points.
if (abs(last_line.b.x - pos.X) >= 300 || abs(last_line.b.y - pos.Y) >= 300)
{
ml.a.x = pos.X;
ml.a.y = pos.Y;
}
else
{
ml.a.x = last_line.b.x;
ml.a.y = last_line.b.y;
}

ml.b.x = pos.X;
ml.b.y = pos.Y;

if (path_history.Size() > am_pathlength)
{
// Path is too long; remove the oldest lines.
path_history.Delete(0);
}
path_history.Push(ml);
}
}
else
{
// Create the first line in the path history.
ml.a.x = pos.X;
ml.a.y = pos.Y;
ml.b.x = pos.X;
ml.b.y = pos.Y;
path_history.Push(ml);
}
}

//=============================================================================
//
// Draws the path taken by the local player.
// This can be useful to avoid getting lost in larger maps.
//
//=============================================================================

void DAutomap::drawPath (int color)
{
if (am_rotate == 1 || (am_rotate == 2 && viewactive))
{
TArray<mline_t> path_history_rotated = path_history;
for (mline_t line : path_history_rotated)
{
rotatePoint(&line.a.x, &line.a.y);
rotatePoint(&line.b.x, &line.b.y);
drawMline(&line, color);
}
}
else
{
for (mline_t line : path_history)
{
drawMline(&line, color);
}
}
}

//=============================================================================
//
// Draws flat (floor/ceiling tile) aligned grid lines.
Expand Down Expand Up @@ -3308,6 +3407,9 @@ void DAutomap::Drawer (int bottom)

if (am_showgrid)
drawGrid(AMColors.GridColor);

if (am_path)
drawPath(AMColors.PathColor);

drawWalls(allmap);
drawPlayers();
Expand Down
5 changes: 5 additions & 0 deletions wadsrc/static/menudef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,8 @@ OptionMenu AutomapOptions protected
StaticText ""
Option "$AUTOMAPMNU_ROTATE", "am_rotate", "RotateTypes"
Option "$AUTOMAPMNU_FOLLOW", "am_followplayer", "OnOff"
Option "$AUTOMAPMNU_PATH", "am_path", "OnOff"
Slider "$AUTOMAPMNU_PATHLENGTH", "am_pathlength", 100, 10000, 100, 0
Option "$AUTOMAPMNU_OVERLAY", "am_overlay", "OverlayTypes"
Option "$AUTOMAPMNU_TEXTURED", "am_textured", "OnOff"
Slider "$AUTOMAPMNU_LINEALPHA", "am_linealpha", 0.1, 1.0, 0.1, 1
Expand Down Expand Up @@ -1402,6 +1404,7 @@ OptionMenu MapControlsMenu protected
MapControl "$MAPCNTRLMNU_TOGGLEZOOM", "am_gobig"
MapControl "$MAPCNTRLMNU_TOGGLEFOLLOW", "am_togglefollow"
MapControl "$MAPCNTRLMNU_ROTATE", "toggle am_rotate"
MapControl "$MAPCNTRLMNU_PATH", "toggle am_path"
MapControl "$MAPCNTRLMNU_TOGGLEGRID", "am_togglegrid"
MapControl "$MAPCNTRLMNU_TOGGLETEXTURE", "am_toggletexture"

Expand Down Expand Up @@ -1441,6 +1444,7 @@ OptionMenu MapColorMenu protected
ColorPicker "$MAPCOLORMNU_UNEXPLOREDSECRETCOLOR", "am_unexploredsecretcolor"
ColorPicker "$MAPCOLORMNU_SPECIALWALLCOLOR", "am_specialwallcolor"
ColorPicker "$MAPCOLORMNU_PORTAL", "am_portalcolor"
ColorPicker "$MAPCOLORMNU_PATH", "am_pathcolor"
}

OptionMenu MapColorMenuCheats protected
Expand Down Expand Up @@ -1471,6 +1475,7 @@ OptionMenu MapColorMenuOverlay protected
ColorPicker "$MAPCOLORMNU_SECRETSECTORCOLOR", "am_ovsecretsectorcolor"
ColorPicker "$MAPCOLORMNU_SPECIALWALLCOLOR", "am_ovspecialwallcolor"
ColorPicker "$MAPCOLORMNU_PORTAL", "am_ovportalcolor"
ColorPicker "$MAPCOLORMNU_PATH", "am_ovpathcolor"
}

OptionMenu MapColorMenuCheatsOverlay protected
Expand Down

0 comments on commit 7d06a20

Please sign in to comment.