acdream/src/AcDream.App/Rendering/LiveStaticAnimationResidency.cs

34 lines
1.4 KiB
C#

using AcDream.App.World;
using AcDream.Core.World;
namespace AcDream.App.Rendering;
/// <summary>
/// Resolves static-workset residency against the canonical live incarnation.
/// DAT-only statics have no server identity and remain resident for their
/// enclosing landblock resource lifetime.
/// </summary>
internal sealed class LiveStaticAnimationResidency
{
private readonly ILiveEntityRuntimeSource _runtime;
public LiveStaticAnimationResidency(ILiveEntityRuntimeSource runtime) =>
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
public bool IsResident(WorldEntity entity) =>
entity.ServerGuid == 0
|| (_runtime.Current?.TryGetRecord(entity.ServerGuid, out LiveEntityRecord resident) == true
&& resident.ProjectionKind is LiveEntityProjectionKind.World
&& ReferenceEquals(resident.WorldEntity, entity)
&& resident.IsSpatiallyProjected
&& resident.IsSpatiallyVisible
&& resident.FullCellId != 0);
public ulong ProjectionVersion(WorldEntity entity) =>
entity.ServerGuid == 0
? 0UL
: _runtime.Current?.TryGetRecord(entity.ServerGuid, out LiveEntityRecord resident) == true
&& ReferenceEquals(resident.WorldEntity, entity)
? resident.ProjectionMutationVersion
: ulong.MaxValue;
}