Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to display the path travalled by the local player #2062

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 112 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, 1000, 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,91 @@ 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();
constexpr int MIN_DISTANCE_BETWEEN_POINTS = 32;
if (abs(last_line.b.x - pos.X) >= MIN_DISTANCE_BETWEEN_POINTS || abs(last_line.b.y - pos.Y) >= MIN_DISTANCE_BETWEEN_POINTS)
{
// If the player's velocity is lower than the distance between the last two ticks (with some tolerance),
// the player has likely teleported so no path should be drawn between the points.
constexpr float EPSILON = 10.0;
if ((pos - last_tick_pos).Length() > (players[consoleplayer].camera->VelXYToSpeed() + EPSILON))
{
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() > uint32_t(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);
}

last_tick_pos = players[consoleplayer].camera->InterpolatedPosition(r_viewpoint.TicFrac);
}

//=============================================================================
//
// 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 @@ -3310,6 +3414,9 @@ void DAutomap::Drawer (int bottom)

if (am_showgrid)
drawGrid(AMColors.GridColor);

if (am_path)
drawPath(AMColors.PathColor);

drawWalls(allmap);
drawPlayers();
Expand Down
3 changes: 3 additions & 0 deletions src/am_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class DAutomapBase : public DObject
// called instead of view drawer if automap active.
virtual void Drawer(int bottom) = 0;

// Used for am_path drawing to calculate distance between ticks.
DVector2 last_tick_pos;

virtual void NewResolution() = 0;
virtual void LevelInit() = 0;
virtual void UpdateShowAllLines() = 0;
Expand Down
5 changes: 5 additions & 0 deletions wadsrc/static/menudef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,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 @@ -1395,6 +1397,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 @@ -1434,6 +1437,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 @@ -1465,6 +1469,7 @@ OptionMenu MapColorMenuOverlay protected
ColorPicker "$MAPCOLORMNU_UNEXPLOREDSECRETCOLOR", "am_ovunexploredsecretcolor"
ColorPicker "$MAPCOLORMNU_SPECIALWALLCOLOR", "am_ovspecialwallcolor"
ColorPicker "$MAPCOLORMNU_PORTAL", "am_ovportalcolor"
ColorPicker "$MAPCOLORMNU_PATH", "am_ovpathcolor"
}

OptionMenu MapColorMenuCheatsOverlay protected
Expand Down
Loading