From d853f9b355d4bdd411191966de738a5f5ec37cf9 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 21 Sep 2023 03:52:19 +0200 Subject: [PATCH] Use velocity to detect teleports in `am_path` drawing --- src/am_map.cpp | 11 +++++++---- src/am_map.h | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index d6916b27d5..9caac9b1b0 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -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; @@ -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); @@ -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); } //============================================================================= diff --git a/src/am_map.h b/src/am_map.h index 3665e44383..306e19611b 100644 --- a/src/am_map.h +++ b/src/am_map.h @@ -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;