Both #280 review lenses returned FAIL on the same defect, and both were
right. IsRenderNeighborhoodResident's widened outer arm requires
IsRenderReady out to FarRadius, justified by "a Far-tier landblock
registers with an empty mesh set and is therefore render-ready." That held
only for a landblock that ARRIVED as Far. The second, equally first-class
way to be Far tier is a Near->Far DEMOTE:
DemoteLandblock -> EnqueueNearLayerRetirement
-> LandblockRetirementStage.MeshReferences
-> GpuWorldState.ReleaseLandblockMeshReferences
-> LandblockSpawnAdapter.OnLandblockUnloaded => WantsLoaded = false
while DetachNearLayer deliberately keeps the landblock loaded, terrain-mesh
resident, terrain-collision resident and DRAWN. Nothing re-publishes an
already-loaded landblock, so the demoted member satisfied NEITHER arm of
the gate, permanently: wormhole tunnel plus centered "In Portal Space -
Please Wait..." forever, no recovery short of relog.
Reachable by ordinary play. Two consecutive recalls to the same landblock
with walking in between makes ChangesStreamingCenter false, so there is no
origin recenter and the region recentres through the ordinary demote diff.
Also reachable via a mid-hold quality-preset drop -- ironically the exact
scenario ReconcileDestinationReservationRadius was added to support. The
pre-#280 radius-1 gate never touched that band, because nothing inside the
Near ring can demote.
FIX SHAPE. Make the two routes genuinely equivalent rather than teaching
the predicate to tolerate the difference. ReleaseLandblockMeshReferences
becomes "reconcile the registration to the post-retirement tier": after the
release converges, if the landblock is still loaded AND still Far tier,
re-assert the empty registration -- the identical OnLandblockLoaded(lb,
empty) a PublicationKind.Far activation makes. It is empty by construction:
DetachNearLayer retains only live server projections, which the adapter's
atlas-tier filter skips. A full retirement is unaffected (DetachLandblock
clears both _loaded and _tierByLandblock), and a throwing release still
retries because the re-assert is only reached after the adapter converged.
The alternative -- "|| (IsFarTier && IsLoaded)" at the gate -- was
rejected: it fixes one caller while leaving IsRenderReady meaning two
different things, which is precisely how this defect arose. After this
change the predicate reads "drawable at its current tier" for every caller,
with no knowledge of how the landblock got there.
WHY THE TESTS MISSED IT, fixed here too:
- Proof obligation P2 was discharged against RESIDENCY (the FarRadius+2
eviction threshold) rather than against IsRenderReady, the gate's actual
atom. The contract now carries the correction and the restated
obligation: no transition may REVOKE IsRenderReady from a landblock that
stays inside FarRadius.
- WorldRevealDerivedWindowIntegrationTests advertised itself as end-to-end
against the real GpuWorldState but constructed it with no spawn adapter,
so its IsRenderReady degenerated to IsLoaded via the "?? true". The
single most load-bearing predicate in the change was stubbed out by a
null in the test named after it -- the same shape as C5b's D3 and #276's
three settler tests. Every fixture in that file now owns a real
LandblockSpawnAdapter.
- The P1 test's comment described its subject as "a Near-shaped completion
the streaming window has since DEMOTED to Far". It is not; it is a fresh
PublishAsFar, the case that does hold. Corrected, since a future reader
would have taken it as demote coverage.
Four new regression tests, all driving the real GpuWorldState +
LandblockSpawnAdapter + LandblockPresentationPipeline through an actual
demote, and all sabotage-verified in both directions (fail with the
production change reverted, pass with it):
NearToFarDemote_LeavesTheLandblockRenderReadyThroughTheRealPipeline
NearToFarDemote_LeavesTheLandblockRenderReadyUnderBudgetedRetirement
TieredWindow_StaysResidentAfterAnOuterRingDemote
OutdoorReveal_SurvivesAnOuterRingDemoteDuringTheHold
The budgeted variant exists because production composes
LandblockRetirementCoordinator.CreateBudgeted, whose MeshReferences stage
is a separate call site from the legacy pipeline's.
SECONDARY, same commit:
- R-1: ACDREAM_PROBE_REVEAL_RADIUS=0 was parser-accepted and
Runtime-rejected -- it yields far = 0 for an outdoor destination, which
fails invalid-readiness-shape on every acknowledgement, hanging the very
A/B route the probe exists to measure. Parser floor raised to 1, with a
7-case table test.
- R-2: the composite-warmup TRIGGER had silently moved onto the far
window's critical path. Pre-#280 the gate and the composite domain were
the same radius-1 square; #280 widened the gate without widening the
domain, so every composite upload serialised behind the last outer-ring
landblock for no readiness benefit. Warmup now starts once the NEAR
sub-window is published -- trigger scope == domain scope, as before. The
reveal gate is untouched: Evaluate still requires the full window AND
composite readiness.
- AP-150 filed: acdream's RetailWaitCueDelay = 5 s arming is NOT retail's
trigger, and #280's commit message got this wrong on both clauses. Retail
emits the notice unconditionally per tunnel rotation segment, in the else
arm of the segment-expiry test at 0x004D6FCD; segment duration is
RandDouble(0.6, 1.8) s, byte-decoded at 0x004D6FE6. The 5.0 constant at
VA 0x007991B0 is CellManager::CheckPrefetchStatus's prefetch RETRY
cadence and has nothing to do with the cue. acdream's own 0.6/1.8 segment
constants already match retail exactly; only the arming is wrong.
Adopting retail's unconditional emit is filed as #329 rather than folded
in here -- it is a user-visible presentation change and wants the user's
eyes.
- AP-151 filed: the gate is materially STRICTER than retail on the
mesh-build/GPU-upload axis. Retail's LScape::PreFetchCells blocks on DAT
RESIDENCY only -- no geometry construction, no upload; that work is lazy
at draw. acdream requires a DAT read, terrain mesh build, render-thread
upload, spatial commit, collision admission and spawn-adapter activation
per member of a 625-member window, metered at MaxCompletionsPerFrame.
Nothing bounds the hold. This is the OPPOSITE asymmetry from AP-149; both
are live at once, on different axes.
- AD-2's amendment stated the false Far-tier readiness assumption verbatim;
corrected, along with the same error in
claude-memory/reference_two_tier_streaming.md, which now carries an
explicit DO-NOT-RETRY on the special-case-the-predicate shape.
- AP-115 scope-noted (it covers the cue's presentation, not its arming).
- #326's SmartBox::set_mid_radius citation corrected: the entry is
0x00453180; 0x004531D0 is the mid-function re-arm branch.
Blast radius: GpuWorldState, LandblockSpawnAdapter,
WorldRevealReadinessBarrier and StreamingDiagnostics are all App-internal;
AcDream.Headless and AcDream.Runtime reference none of them outside
comments. Headless tests run green as part of the gate below, per C5b's
lesson about surveys that skip the no-window host.
Gates: Release build 0 errors, 18 pre-existing xUnit analyzer warnings.
Complete suite "dotnet test AcDream.slnx -c Release -m:1" with
ACDREAM_PAK_PATH set: 11,192 passed / 4 skipped / 0 failed, from a clean
rebuild (a prior session's deleted probe file had been compiled into a
stale test DLL). Baseline at fafc0b65 was 11,179 / 4 / 0; the +13 delta
reconciles exactly to this commit's additions -- 3 readiness tests, 1
integration test, 7 parser table cases, 2 warmup-trigger tests. None of the
known flakes #302/#308/#321 surfaced, and none is conflated with the
finding above.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
343 lines
13 KiB
C#
343 lines
13 KiB
C#
using AcDream.App.Rendering.Wb;
|
|
using AcDream.App.Streaming;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World;
|
|
using AcDream.Runtime.World;
|
|
using DatReaderWriter.DBObjs;
|
|
|
|
namespace AcDream.App.Tests.Streaming;
|
|
|
|
/// <summary>
|
|
/// #280 end-to-end: the derived reveal window, the tiered render predicate,
|
|
/// the terrain-residency gate, the destination reservation, and the loosened
|
|
/// Runtime shape invariant, wired together with the REAL
|
|
/// <see cref="StreamingController"/>, <see cref="GpuWorldState"/>, and
|
|
/// <see cref="PhysicsEngine"/> rather than fakes.
|
|
///
|
|
/// <para>
|
|
/// This is the test that fails if any single piece is missing: raising the
|
|
/// radius without the tier-aware predicate hangs forever (T2), and loosening
|
|
/// neither the Runtime invariant nor the predicate makes
|
|
/// <c>AcknowledgeDestinationReadiness</c> fail
|
|
/// <c>invalid-readiness-shape</c> (T1).
|
|
/// </para>
|
|
/// </summary>
|
|
public sealed class WorldRevealDerivedWindowIntegrationTests
|
|
{
|
|
private const int CenterX = 0x40;
|
|
private const int CenterY = 0x40;
|
|
private const uint DestinationCell = (uint)CenterX << 24
|
|
| (uint)CenterY << 16
|
|
| 0x0021u;
|
|
|
|
[Theory]
|
|
[InlineData(1, 2)]
|
|
[InlineData(2, 4)]
|
|
public void OutdoorReveal_HoldsUntilTheWholeDerivedWindowIsPublished(
|
|
int nearRadius,
|
|
int farRadius)
|
|
{
|
|
GpuWorldState world = CreateWorld();
|
|
var physics = new PhysicsEngine();
|
|
var transit = new RuntimeWorldTransitState();
|
|
var streaming = new RecordingReservations();
|
|
StreamingController controller = CreateController(
|
|
world,
|
|
nearRadius,
|
|
farRadius);
|
|
WorldRevealCoordinator coordinator = CreateCoordinator(
|
|
transit,
|
|
controller,
|
|
physics,
|
|
streaming);
|
|
|
|
long generation = coordinator.BeginLogin(DestinationCell);
|
|
|
|
// The reservation opens on the same square the gate measures.
|
|
Assert.Equal(
|
|
(generation, DestinationCell, farRadius),
|
|
Assert.Single(streaming.Begins));
|
|
|
|
// Publish the Near window only. Pre-#280 this was the entire gate; it
|
|
// must no longer be enough.
|
|
for (int radius = 0; radius <= nearRadius; radius++)
|
|
PublishRing(world, physics, radius, LandblockStreamTier.Near);
|
|
Assert.False(coordinator.Evaluate(DestinationCell).IsReady);
|
|
|
|
// Fill the outer rings with Far-tier terrain publication, one ring at
|
|
// a time, so the hold is proven to track the outer boundary and not
|
|
// just the first missing member.
|
|
for (int radius = nearRadius + 1; radius < farRadius; radius++)
|
|
{
|
|
PublishRing(world, physics, radius, LandblockStreamTier.Far);
|
|
Assert.False(coordinator.Evaluate(DestinationCell).IsReady);
|
|
}
|
|
|
|
PublishRing(world, physics, farRadius, LandblockStreamTier.Far);
|
|
WorldRevealReadinessSnapshot ready =
|
|
coordinator.Evaluate(DestinationCell);
|
|
|
|
Assert.True(ready.IsReady);
|
|
Assert.Equal(farRadius, ready.RequiredRenderRadius);
|
|
Assert.Equal(nearRadius, ready.RequiredNearRadius);
|
|
// The loosened Runtime shape invariant accepted the derived radius.
|
|
Assert.Equal(0, transit.Snapshot.InvariantFailureCount);
|
|
Assert.True(transit.Snapshot.IsReady);
|
|
}
|
|
|
|
/// <summary>
|
|
/// P7/§9-8: login and portal share the barrier, so first login gets the
|
|
/// same widened gate. Asserted through the production readiness predicate
|
|
/// the login auto-entry context calls.
|
|
/// </summary>
|
|
[Fact]
|
|
public void LoginReveal_UsesTheSameWidenedGateAsPortalArrival()
|
|
{
|
|
const int nearRadius = 1;
|
|
const int farRadius = 3;
|
|
GpuWorldState world = CreateWorld();
|
|
var physics = new PhysicsEngine();
|
|
var transit = new RuntimeWorldTransitState();
|
|
StreamingController controller = CreateController(
|
|
world,
|
|
nearRadius,
|
|
farRadius);
|
|
WorldRevealCoordinator coordinator = CreateCoordinator(
|
|
transit,
|
|
controller,
|
|
physics,
|
|
streaming: null);
|
|
|
|
coordinator.BeginLogin(DestinationCell);
|
|
for (int radius = 0; radius < farRadius; radius++)
|
|
{
|
|
PublishRing(
|
|
world,
|
|
physics,
|
|
radius,
|
|
radius <= nearRadius
|
|
? LandblockStreamTier.Near
|
|
: LandblockStreamTier.Far);
|
|
}
|
|
|
|
Assert.False(coordinator.Evaluate(DestinationCell).IsReady);
|
|
|
|
PublishRing(world, physics, farRadius, LandblockStreamTier.Far);
|
|
|
|
Assert.True(coordinator.Evaluate(DestinationCell).IsReady);
|
|
Assert.Equal(0, transit.Snapshot.InvariantFailureCount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indoor destinations keep retail's EnvCell arm: no landscape ring at
|
|
/// all, regardless of how wide the streaming window is.
|
|
/// </summary>
|
|
[Fact]
|
|
public void IndoorReveal_IgnoresTheStreamingWindowEntirely()
|
|
{
|
|
const uint indoorCell = (uint)CenterX << 24
|
|
| (uint)CenterY << 16
|
|
| 0x0100u;
|
|
GpuWorldState world = CreateWorld();
|
|
var physics = new PhysicsEngine();
|
|
var transit = new RuntimeWorldTransitState();
|
|
StreamingController controller = CreateController(world, 2, 6);
|
|
WorldRevealCoordinator coordinator = CreateCoordinator(
|
|
transit,
|
|
controller,
|
|
physics,
|
|
streaming: null);
|
|
|
|
coordinator.BeginLogin(indoorCell);
|
|
Assert.False(coordinator.Evaluate(indoorCell).IsReady);
|
|
|
|
// Only the destination's own landblock, at Near tier.
|
|
PublishRing(world, physics, 0, LandblockStreamTier.Near);
|
|
WorldRevealReadinessSnapshot snapshot = coordinator.Evaluate(indoorCell);
|
|
|
|
Assert.True(snapshot.IsRenderNeighborhoodReady);
|
|
Assert.Equal(0, snapshot.RequiredRenderRadius);
|
|
Assert.Equal(0, transit.Snapshot.InvariantFailureCount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// #280 D-1, end to end. The reveal gate opens on a fully published
|
|
/// window, then a Near→Far demote lands on an outer-ring member —
|
|
/// the ordinary outcome of a region recenter that does not move the world
|
|
/// origin, and of a mid-hold quality-preset drop. Before the fix, the
|
|
/// demoted member could never become <c>IsRenderReady</c> again, so the
|
|
/// coordinator never returned <c>IsReady</c> and the client stayed in
|
|
/// portal space until relog.
|
|
/// </summary>
|
|
[Fact]
|
|
public void OutdoorReveal_SurvivesAnOuterRingDemoteDuringTheHold()
|
|
{
|
|
const int nearRadius = 1;
|
|
const int farRadius = 3;
|
|
var meshes = new RecordingMeshAdapter();
|
|
var world = new GpuWorldState(new LandblockSpawnAdapter(meshes));
|
|
var physics = new PhysicsEngine();
|
|
var transit = new RuntimeWorldTransitState();
|
|
var pipeline = new LandblockPresentationPipeline(
|
|
publishBeforeSpatialCommit: (_, _) => { },
|
|
world);
|
|
StreamingController controller = CreateController(
|
|
world,
|
|
nearRadius,
|
|
farRadius);
|
|
WorldRevealCoordinator coordinator = CreateCoordinator(
|
|
transit,
|
|
controller,
|
|
physics,
|
|
streaming: null);
|
|
|
|
coordinator.BeginLogin(DestinationCell);
|
|
// Publish the WHOLE window at Near tier, entities included. That is
|
|
// what a region centred on the destination actually produces before it
|
|
// starts trimming its trailing edge.
|
|
for (int radius = 0; radius <= farRadius; radius++)
|
|
PublishRing(world, physics, radius, LandblockStreamTier.Near, withEntity: true);
|
|
|
|
Assert.True(coordinator.Evaluate(DestinationCell).IsReady);
|
|
|
|
// A single outer-ring member demotes. Chebyshev 3: inside the far
|
|
// window, outside the near ring.
|
|
uint demoted = ((uint)(CenterX + farRadius) << 24)
|
|
| ((uint)(CenterY - farRadius) << 16)
|
|
| 0xFFFFu;
|
|
pipeline.BeginNearLayerRetirement(demoted);
|
|
|
|
Assert.True(world.IsLoaded(demoted));
|
|
Assert.False(world.IsNearTier(demoted));
|
|
Assert.True(coordinator.Evaluate(DestinationCell).IsReady);
|
|
Assert.Equal(0, transit.Snapshot.InvariantFailureCount);
|
|
}
|
|
|
|
private sealed class RecordingMeshAdapter : IWbMeshAdapter
|
|
{
|
|
public Dictionary<ulong, int> ReferenceCounts { get; } = new();
|
|
|
|
public void IncrementRefCount(ulong id) =>
|
|
ReferenceCounts[id] = ReferenceCounts.GetValueOrDefault(id) + 1;
|
|
|
|
public void DecrementRefCount(ulong id)
|
|
{
|
|
int next = ReferenceCounts.GetValueOrDefault(id) - 1;
|
|
if (next <= 0)
|
|
ReferenceCounts.Remove(id);
|
|
else
|
|
ReferenceCounts[id] = next;
|
|
}
|
|
|
|
public bool IsRenderDataReady(ulong id) => true;
|
|
}
|
|
|
|
private sealed class RecordingReservations : IWorldRevealStreamingScheduler
|
|
{
|
|
public List<(long Generation, uint Cell, int Radius)> Begins { get; } = [];
|
|
public List<long> Ends { get; } = [];
|
|
|
|
public void BeginDestinationReservation(
|
|
long revealGeneration,
|
|
uint destinationCell,
|
|
int requiredRenderRadius) =>
|
|
Begins.Add((revealGeneration, destinationCell, requiredRenderRadius));
|
|
|
|
public void EndDestinationReservation(long revealGeneration) =>
|
|
Ends.Add(revealGeneration);
|
|
}
|
|
|
|
private static WorldRevealCoordinator CreateCoordinator(
|
|
RuntimeWorldTransitState transit,
|
|
StreamingController controller,
|
|
PhysicsEngine physics,
|
|
IWorldRevealStreamingScheduler? streaming) =>
|
|
new(
|
|
transit,
|
|
() => new StreamingRevealWindow(
|
|
controller.NearRadius,
|
|
controller.FarRadius),
|
|
controller.IsRenderNeighborhoodResident,
|
|
physics.IsSpawnCellReady,
|
|
physics.IsNeighborhoodTerrainResident,
|
|
() => true,
|
|
(_, _) => { },
|
|
() => { },
|
|
_ => false,
|
|
streaming: streaming);
|
|
|
|
private static StreamingController CreateController(
|
|
GpuWorldState state,
|
|
int nearRadius,
|
|
int farRadius) =>
|
|
new(
|
|
(_, _, _) => { },
|
|
(_, _) => { },
|
|
_ => Array.Empty<LandblockStreamResult>(),
|
|
(_, _) => { },
|
|
state,
|
|
nearRadius: nearRadius,
|
|
farRadius: farRadius);
|
|
|
|
/// <summary>
|
|
/// The gate's most load-bearing predicate is
|
|
/// <c>GpuWorldState.IsRenderReady</c>, which degenerates to
|
|
/// <c>IsLoaded</c> when no spawn adapter is wired. Every fixture here owns
|
|
/// a real <see cref="LandblockSpawnAdapter"/> so the predicate is actually
|
|
/// under test.
|
|
/// </summary>
|
|
private static GpuWorldState CreateWorld() =>
|
|
new(new LandblockSpawnAdapter(new RecordingMeshAdapter()));
|
|
|
|
private static void PublishRing(
|
|
GpuWorldState world,
|
|
PhysicsEngine physics,
|
|
int radius,
|
|
LandblockStreamTier tier,
|
|
bool withEntity = false)
|
|
{
|
|
for (int dx = -radius; dx <= radius; dx++)
|
|
for (int dy = -radius; dy <= radius; dy++)
|
|
{
|
|
if (Math.Abs(dx) != radius && Math.Abs(dy) != radius)
|
|
continue;
|
|
|
|
uint id = ((uint)(CenterX + dx) << 24)
|
|
| ((uint)(CenterY + dy) << 16)
|
|
| 0xFFFFu;
|
|
WorldEntity[] entities = withEntity
|
|
?
|
|
[
|
|
new WorldEntity
|
|
{
|
|
Id = 1,
|
|
ServerGuid = 0,
|
|
SourceGfxObjOrSetupId = 0x01000010u,
|
|
Position = System.Numerics.Vector3.Zero,
|
|
Rotation = System.Numerics.Quaternion.Identity,
|
|
MeshRefs =
|
|
[
|
|
new MeshRef(
|
|
0x01000010u,
|
|
System.Numerics.Matrix4x4.Identity),
|
|
],
|
|
},
|
|
]
|
|
: Array.Empty<WorldEntity>();
|
|
world.AddLandblock(
|
|
new LoadedLandblock(id, new LandBlock(), entities),
|
|
tier: tier);
|
|
// The Far tier publishes terrain COLLISION as well as terrain
|
|
// render (LandblockPhysicsPublisher, reached for
|
|
// PublicationKind.Far), which is what makes the outer arm of the
|
|
// reveal gate satisfiable on the collision side too.
|
|
physics.AddLandblock(
|
|
id,
|
|
new TerrainSurface(new byte[81], new float[256]),
|
|
Array.Empty<CellSurface>(),
|
|
Array.Empty<PortalPlane>(),
|
|
worldOffsetX: 0f,
|
|
worldOffsetY: 0f);
|
|
}
|
|
}
|
|
}
|