Client LuaCsForBarotrauma
CachedDistance.cs
1 using Microsoft.Xna.Framework;
2 
3 namespace Barotrauma
4 {
5  public class CachedDistance
6  {
7  public readonly Vector2 StartWorldPos;
8  public readonly Vector2 EndWorldPos;
9  public readonly float Distance;
10  public double RecalculationTime;
11 
12  public CachedDistance(Vector2 startWorldPos, Vector2 endWorldPos, float dist, double recalculationTime)
13  {
14  StartWorldPos = startWorldPos;
15  EndWorldPos = endWorldPos;
16  Distance = dist;
17  RecalculationTime = recalculationTime;
18  }
19 
20  public bool ShouldUpdateDistance(Vector2 currentStartWorldPos, Vector2 currentEndWorldPos, float minDistanceToUpdate = 500.0f)
21  {
22  if (Timing.TotalTime < RecalculationTime) { return false; }
23  float minDistSquared = minDistanceToUpdate * minDistanceToUpdate;
24  return Vector2.DistanceSquared(StartWorldPos, currentStartWorldPos) > minDistSquared ||
25  Vector2.DistanceSquared(EndWorldPos, currentEndWorldPos) > minDistSquared;
26  }
27  }
28 
29  public readonly record struct CachedLocation(Vector2 Location, double RecalculationTime);
30 }
readonly Vector2 StartWorldPos
CachedDistance(Vector2 startWorldPos, Vector2 endWorldPos, float dist, double recalculationTime)
readonly Vector2 EndWorldPos
bool ShouldUpdateDistance(Vector2 currentStartWorldPos, Vector2 currentEndWorldPos, float minDistanceToUpdate=500.0f)
readonly record struct CachedLocation(Vector2 Location, double RecalculationTime)