acdream/src/AcDream.Core/Physics/PositionFrameValidation.cs
Erik 8a5d77f7f4 feat(net): port retail physics spawn and event timestamps
Parse the complete PhysicsDesc plus F754/F755 packets, correct every PhysicsState bit, and gate all nine retail update channels with generation-safe immutable snapshots. Preserve ForcePosition, teleport, placement, velocity, parent, pickup, delete, and same-generation CreateObject ordering from the named client.

Separate accepted logical lifecycle notifications from retained UI qualities, make GUID replacement and session reset clear every projection exactly once, and add packet, wraparound, malformed-input, parent FIFO, canonical-position, reconnect, and GUID-reuse conformance coverage.

Co-Authored-By: Codex <noreply@openai.com>
2026-07-14 00:22:17 +02:00

30 lines
945 B
C#

using System.Numerics;
namespace AcDream.Core.Physics;
/// <summary>
/// Retail <c>Position::IsValid</c> 0x005A9480 composed with
/// <c>Frame::IsValid</c> 0x00534ED0. The quaternion test is performed on its
/// squared norm with retail's exact <c>0.0002 * 5</c> tolerance.
/// </summary>
public static class PositionFrameValidation
{
public static bool IsValid(uint cellId, Vector3 origin, Quaternion rotation)
{
if (!LandDefs.InboundValidCellId(cellId)
|| float.IsNaN(origin.X)
|| float.IsNaN(origin.Y)
|| float.IsNaN(origin.Z)
|| float.IsNaN(rotation.W)
|| float.IsNaN(rotation.X)
|| float.IsNaN(rotation.Y)
|| float.IsNaN(rotation.Z))
{
return false;
}
float normSquared = rotation.LengthSquared();
return !float.IsNaN(normSquared)
&& MathF.Abs(normSquared - 1f) <= 0.001f;
}
}