Files
opengenesislinkserver/OpenSim/Framework/FlightNeighbourPrefetchPolicy.cs
T
OpenGenesis (MPL 2.0) 0ed672264c feat(crossing): prewarm child agents for fast region-edge flight (#223)
* feat(crossing): add bounded high-speed edge prediction for child-agent prefetch

* build(crossing): include fast flyer neighbour prefetch policy

* feat(crossing): prewarm neighbour agents at fast flying region approaches

* test(crossing): validate directional speed-bounded neighbour prefetch

* test(crossing): validate directional speed-bounded neighbour prefetch

* ci(crossing): execute directional fast flight prefetch regression

* docs(crossing): document bounded flight prefetch and measurement requirements

* test(crossing): reference OpenMetaverse types for velocity regression

* test(crossing): reference split OpenMetaverseTypes assembly for Vector3

* fix(crossing): use OpenSim uint region dimensions for prefetch policy

* fix(crossing): use OpenSim uint region dimensions for prefetch policy
2026-10-15 00:44:48 +02:00

46 lines
1.8 KiB
C#

// SPDX-License-Identifier: MPL-2.0
using System;
using OpenMetaverse;
namespace OpenSim.Framework
{
/// <summary>
/// Bounded early neighbour refresh when a fast-flying avatar is
/// approaching a real X/Y region edge. Does NOT initiate the crossing.
/// </summary>
public static class FlightNeighbourPrefetchPolicy
{
public const float MinimumHorizontalSpeed = 20f; // metres / second
public const float MaximumLookAheadMetres = 128f;
public static bool NeedsPrefetch(bool isFlying, Vector3 position,
Vector3 velocity, uint regionSizeX, uint regionSizeY)
{
if (!isFlying || regionSizeX <= 0 || regionSizeY <= 0)
return false;
if (!float.IsFinite(position.X) || !float.IsFinite(position.Y) ||
!float.IsFinite(velocity.X) || !float.IsFinite(velocity.Y) ||
position.X < 0 || position.Y < 0 ||
position.X >= regionSizeX || position.Y >= regionSizeY)
return false;
float speedSquared =
velocity.X * velocity.X + velocity.Y * velocity.Y;
if (!float.IsFinite(speedSquared) ||
speedSquared < MinimumHorizontalSpeed * MinimumHorizontalSpeed)
return false;
float horizon = MathF.Min(MaximumLookAheadMetres,
MathF.Max(32f, MathF.Sqrt(speedSquared) * 1.5f));
// Directional checks prevent needless traffic while an avatar
// flies parallel to, rather than towards, a region boundary.
return (velocity.X > 0 && regionSizeX - position.X <= horizon) ||
(velocity.X < 0 && position.X <= horizon) ||
(velocity.Y > 0 && regionSizeY - position.Y <= horizon) ||
(velocity.Y < 0 && position.Y <= horizon);
}
}
}