mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Finish FastVector2 Optimization
This commit is contained in:
1 parent
a51be2d60b
commit
b9198b9639
81 files changed
+91
-179
No files matched your search
@@ -44,7 +44,7 @@ public static class FastVector2
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool TryGetClosestInRange(
|
||||
in Vector2 origin,
|
||||
IReadOnlyList<Vector2> positions,
|
||||
IEnumerable<Vector2> positions,
|
||||
float range,
|
||||
out Vector2 closest)
|
||||
{
|
||||
@@ -72,6 +72,37 @@ public static class FastVector2
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the closest position to origin.
|
||||
/// Returns true if one was found.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool TryGetClosest(
|
||||
in Vector2 origin,
|
||||
IEnumerable<Vector2> positions,
|
||||
out Vector2 closest)
|
||||
{
|
||||
float minSq = float.MaxValue;
|
||||
bool found = false;
|
||||
closest = default(Vector2);
|
||||
|
||||
foreach (Vector2 p in positions)
|
||||
{
|
||||
float dx = p.x - origin.x;
|
||||
float dy = p.y - origin.y;
|
||||
float sq = dx * dx + dy * dy;
|
||||
|
||||
if (sq < minSq)
|
||||
{
|
||||
minSq = sq;
|
||||
closest = p;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the closest living player to origin.
|
||||
/// Returns true if one was found.
|
||||
@@ -80,7 +111,7 @@ public static class FastVector2
|
||||
public static bool TryGetClosestPlayer(
|
||||
in Vector2 origin,
|
||||
out PlayerControl closest,
|
||||
Predicate<PlayerControl> predicate = null)
|
||||
[Annotations.InstantHandle] Predicate<PlayerControl> predicate = null)
|
||||
{
|
||||
predicate ??= _ => true;
|
||||
float minSq = float.MaxValue;
|
||||
|
||||
Reference in new issue
Block a user