perf: use squared distance for nearby

This commit is contained in:
Anna 2024-07-22 13:39:09 -04:00
parent 5f9787884b
commit cf16b931bb
Signed by: anna
GPG Key ID: D0943384CD9F87D1
2 changed files with 2 additions and 4 deletions

View File

@ -251,7 +251,7 @@ internal class Messages : IDisposable {
internal IEnumerable<Message> Nearby() { internal IEnumerable<Message> Nearby() {
if (this.Plugin.ClientState.LocalPlayer is not { } player) { if (this.Plugin.ClientState.LocalPlayer is not { } player) {
return Array.Empty<Message>(); return [];
} }
var position = player.Position; var position = player.Position;
@ -262,13 +262,12 @@ internal class Messages : IDisposable {
nearby = this.Current nearby = this.Current
.Values .Values
.Where(msg => Math.Abs(msg.Position.Y - position.Y) <= 1f) .Where(msg => Math.Abs(msg.Position.Y - position.Y) <= 1f)
.Where(msg => Vector3.Distance(msg.Position, position) <= 2f) .Where(msg => Vector3.DistanceSquared(msg.Position, position) <= 4f)
.ToList(); .ToList();
} finally { } finally {
this.CurrentMutex.Release(); this.CurrentMutex.Release();
} }
return nearby; return nearby;
} }

View File

@ -49,7 +49,6 @@ internal class ActorManager : IDisposable {
success = true; success = true;
} }
if (success) { if (success) {
this._tasks.Dequeue(); this._tasks.Dequeue();
} }