feat(teleport B): PhysicsEngine.IsLandblockTerrainResident worldReady query

Adds a high-16-bit-prefix landblock residency check used as the teleport
worldReady gate — true once the destination landblock's terrain+cells
have been registered via AddLandblock, regardless of whether the caller
passes a canonical (0xFFFF), cell-resolved, or bare landblock id.

Two TDD tests confirm: false before registration, true after, and
that a cell-resolved id on the same landblock returns true.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-22 13:05:38 +02:00
parent f918b3ea2c
commit aba882cec6
2 changed files with 48 additions and 0 deletions

View file

@ -31,6 +31,20 @@ public sealed class PhysicsEngine
/// <summary>Number of registered landblocks (diagnostic).</summary> /// <summary>Number of registered landblocks (diagnostic).</summary>
public int LandblockCount => _landblocks.Count; public int LandblockCount => _landblocks.Count;
/// <summary>
/// True once the landblock covering <paramref name="cellOrLandblockId"/> has had its
/// terrain + cells registered via <see cref="AddLandblock"/>. Accepts a canonical
/// (0xFFFF) id, a cell-resolved id, or a bare landblock id — compares on the high 16
/// bits. This is the teleport "worldReady" gate (the destination is grounded).
/// </summary>
public bool IsLandblockTerrainResident(uint cellOrLandblockId)
{
uint prefix = cellOrLandblockId & 0xFFFF0000u;
foreach (var key in _landblocks.Keys)
if ((key & 0xFFFF0000u) == prefix) return true;
return false;
}
/// <summary> /// <summary>
/// Cell-based spatial index for static object collision. /// Cell-based spatial index for static object collision.
/// Populated during landblock streaming; queried by the Transition system. /// Populated during landblock streaming; queried by the Transition system.

View file

@ -0,0 +1,34 @@
using System;
using System.Numerics;
using AcDream.Core.Physics;
using Xunit;
namespace AcDream.Core.Tests.Physics;
public class PhysicsEngineResidencyTests
{
[Fact]
public void IsLandblockTerrainResident_trueOnlyAfterAddLandblock()
{
var eng = new PhysicsEngine();
uint canonical = 0xA9B4FFFFu; // canonical (streaming) form
uint lbId = canonical & 0xFFFF0000u; // AddLandblock id
Assert.False(eng.IsLandblockTerrainResident(canonical));
eng.AddLandblock(lbId, terrain: null!, cells: Array.Empty<CellSurface>(),
portals: Array.Empty<PortalPlane>(), worldOffsetX: 0f, worldOffsetY: 0f);
Assert.True(eng.IsLandblockTerrainResident(canonical));
}
[Fact]
public void IsLandblockTerrainResident_matchesOnHigh16_acceptsCellResolvedId()
{
var eng = new PhysicsEngine();
eng.AddLandblock(0xA9B40000u, null!, Array.Empty<CellSurface>(),
Array.Empty<PortalPlane>(), 0f, 0f);
Assert.True(eng.IsLandblockTerrainResident(0xA9B40019u)); // cell-resolved id, same LB
Assert.False(eng.IsLandblockTerrainResident(0xC6A90019u)); // different LB
}
}