Use velocity to detect teleports in am_path drawing

This commit is contained in:
Hugo Locurcio 2023-09-21 03:52:19 +02:00
parent 7444c22950
commit d853f9b355
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
2 changed files with 10 additions and 4 deletions

View file

@ -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);
}
//=============================================================================

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;