This commit is contained in:
Hugo Locurcio 2025-04-04 04:29:28 +00:00 committed by GitHub
commit 739b7706a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 120 additions and 5 deletions

View file

@ -205,6 +205,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";
@ -304,6 +306,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);
@ -326,6 +329,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);
//=============================================================================
//
@ -389,6 +393,7 @@ static const char *ColorNames[] = {
"SecretSectorColor",
"UnexploredSecretColor",
"PortalColor",
"PathColor",
"AlmostBackgroundColor",
nullptr
};
@ -421,6 +426,7 @@ struct AMColorset
SecretSectorColor,
UnexploredSecretColor,
PortalColor,
PathColor,
AlmostBackgroundColor,
AM_NUM_COLORS
};
@ -546,7 +552,8 @@ static FColorCVarRef *cv_standard[] = {
&am_interlevelcolor,
&am_secretsectorcolor,
&am_unexploredsecretcolor,
&am_portalcolor
&am_portalcolor,
&am_pathcolor
};
static FColorCVarRef *cv_overlay[] = {
@ -573,7 +580,8 @@ static FColorCVarRef *cv_overlay[] = {
&am_ovinterlevelcolor,
&am_ovsecretsectorcolor,
&am_ovunexploredsecretcolor,
&am_ovportalcolor
&am_ovportalcolor,
&am_ovpathcolor
};
CCMD(am_restorecolors)
@ -616,8 +624,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[]= {
@ -644,8 +653,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[]= {
@ -672,8 +682,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
@ -979,6 +990,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)
{
@ -1023,6 +1036,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);
@ -1552,6 +1567,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;
@ -1816,6 +1835,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.
@ -3327,6 +3431,9 @@ void DAutomap::Drawer (int bottom)
if (am_showgrid)
drawGrid(AMColors.GridColor);
if (am_path)
drawPath(AMColors.PathColor);
drawWalls(allmap);
drawPlayers();

View file

@ -44,6 +44,9 @@ public:
// 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;

View file

@ -1350,6 +1350,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
@ -1409,6 +1411,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"
@ -1448,6 +1451,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
@ -1479,6 +1483,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