Skip to content

Commit

Permalink
Use velocity to detect teleports in am_path drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed Sep 21, 2023
1 parent 7444c22 commit d853f9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/am_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,9 +1846,10 @@ void DAutomap::collectPath ()
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 distance between two points is very high, the player has likely teleported so no path should be drawn between the points.
constexpr int MAX_DISTANCE_BETWEEN_TICKS = 100;
if (abs(last_line.b.x - pos.X) >= MAX_DISTANCE_BETWEEN_TICKS || abs(last_line.b.y - pos.Y) >= MAX_DISTANCE_BETWEEN_TICKS)
// 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;
Expand All @@ -1862,7 +1863,7 @@ void DAutomap::collectPath ()
ml.b.x = pos.X;
ml.b.y = pos.Y;

if (path_history.Size() > am_pathlength)
if (path_history.Size() > uint32_t(am_pathlength))
{
// Path is too long; remove the oldest lines.
path_history.Delete(0);
Expand All @@ -1879,6 +1880,8 @@ void DAutomap::collectPath ()
ml.b.y = pos.Y;
path_history.Push(ml);
}

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

//=============================================================================
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

0 comments on commit d853f9b

Please sign in to comment.