Chunk 5 (consumer cutover): WalkProductionWorldData's per-cell views are borrowed from ShadowObjectRegistry.GetRetailPartEntriesInCell and resolved through RenderSceneQuery.TryGetByLocalEntityId; every render-side sweep, bucket, parent-cell and root-position fallback is deleted (AD-116 for the one-frame registry→scene window, counted in UnregisteredRenderMembershipCount). A live entity with visual parts but no collision geometry registers render-only (LiveEntityCollisionBuilder computes the part array before the empty-shapes gate). Closeout fixes found while landing it: - RefloodOwnerForLandblock forwards the retained part array — a reflood is retail's recalc_cross_cells over the SAME CPartArray; without it every owner touched by a landblock replacement commit lost its render membership. - Non-colliding DAT statics register render-only from BOTH publishers (LandblockPhysicsPublisher.PublishStaticEntity, LandblockPhysicsContentBuilder.RegisterRenderOnlyStatic). The G2 self-gate pixel diff caught them vanishing (Facility Hub wall panels): retail floods every object regardless of collision (CEnvCell::init_static_objects 0x0052c350, add_shadows_to_cells 0x00514ae0). - S2 dual review fix batch (arch + retail lens, lead-verified): Suspend clears the retail product (remove_shadows_from_cells 0x00511230 is one transaction); AttachChild/DetachChild advance the mutation revision so a prepared SetPosition cannot clobber a child's rows; an attached child never floods on its own re-registration; RemoveLandblock and the non-rooted RetireOwnerFromLandblock prune retail rows (render-only statics end with their landblock); a render-only owner's no-cell-array commit republishes at its destination cell (AD-117); an empty non-null part array is treated as null; per-move closures/LINQ replaced by index loops; EnvCell shells stay out of the scene's LocalEntityId index (payload-less records); the index predicate compares the id; the dead per-cell scene indices are deleted. Register: AD-116 (chunk 5), AD-117 (four residual Contract A/B readings). Evidence: s2-membership-ownership-map.md §8 (chunk 5) and §9 (closeout). Gates (Release): Core 4,984/4,984; Content 214/214; Runtime 1,884/1,884; App hermetic lane 6,760/6,760; App InstalledDat lane 217 pass / 1 skip / 2 pre-existing #383 layout-fixture failures; App Windows lane 1/1. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
184 lines
8.2 KiB
C#
184 lines
8.2 KiB
C#
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using AcDream.Content;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World;
|
|
using DatReaderWriter.DBObjs;
|
|
using DatReaderWriter.Types;
|
|
|
|
namespace AcDream.Content.Tests;
|
|
|
|
/// <summary>
|
|
/// AP-155 parity (route independence) for the second static publication site,
|
|
/// <see cref="LandblockPhysicsContentBuilder.PublishStaticCollision"/>. A
|
|
/// Setup carrying only authored Spheres (no CylSpheres) must register the
|
|
/// SAME shapes — type, local position, radius, scale — as
|
|
/// <see cref="ShadowShapeBuilder.FromSetup"/>, the LIVE path. Before the fix
|
|
/// this site emitted a height-capped Cylinder instead (base = origin - r*ẑ,
|
|
/// height = 2r), identically to <c>LandblockPhysicsPublisher</c>'s copy of
|
|
/// the same bug — see that class's tests
|
|
/// (<c>LandblockPhysicsPublisherTests.CompletePublication_SphereOnlySetup_*</c>)
|
|
/// for the dispatch-level (Cylinder-vs-Sphere narrow phase) proof; the two
|
|
/// sites share the SAME <c>ShadowObjectRegistry</c>/<c>TransitionTypes</c>
|
|
/// query code; this class only needs to prove ITS emission is correct.
|
|
/// </summary>
|
|
public sealed class LandblockPhysicsContentBuilderStaticSphereTests
|
|
{
|
|
private const uint LandblockId = 0xA9B40000u;
|
|
private const uint SetupId = 0x02000042u;
|
|
|
|
[Fact]
|
|
public void PublishStaticCollision_SphereOnlySetup_MatchesFromSetupShapeForShape()
|
|
{
|
|
var setup = new Setup();
|
|
setup.Spheres.Add(new Sphere
|
|
{
|
|
Origin = new Vector3(0.3f, -0.2f, 0.9f),
|
|
Radius = 0.55f,
|
|
});
|
|
setup.Spheres.Add(new Sphere
|
|
{
|
|
Origin = new Vector3(-0.1f, 0.4f, 1.4f),
|
|
Radius = 0.25f,
|
|
});
|
|
FlatSetupCollision flatSetup = FlatCollisionAssetBuilder.FlattenSetup(setup);
|
|
|
|
const float entScale = 1.3f;
|
|
var entity = new WorldEntity
|
|
{
|
|
Id = 0x80A9B401u,
|
|
SourceGfxObjOrSetupId = SetupId,
|
|
Position = Vector3.Zero,
|
|
Rotation = Quaternion.Identity,
|
|
Scale = entScale,
|
|
MeshRefs = Array.Empty<MeshRef>(),
|
|
};
|
|
var landblock = new LoadedLandblock(
|
|
LandblockId,
|
|
new LandBlock { Terrain = new TerrainInfo[81], Height = new byte[81] },
|
|
new[] { entity });
|
|
var collisions = new LandblockCollisionBuild(
|
|
ImmutableDictionary<uint, FlatGfxObjCollisionAsset>.Empty,
|
|
ImmutableDictionary<uint, FlatSetupCollision>.Empty.Add(SetupId, flatSetup),
|
|
ImmutableDictionary<uint, FlatCellStructureCollisionAsset>.Empty,
|
|
ImmutableDictionary<uint, FlatEnvCellTopology>.Empty,
|
|
ImmutableArray<uint>.Empty,
|
|
ImmutableArray.Create(SetupId),
|
|
ImmutableArray<uint>.Empty);
|
|
|
|
var engine = new PhysicsEngine();
|
|
var cache = new PhysicsDataCache();
|
|
LandblockPhysicsContentBuilder.CachePreparedObjects(cache, collisions);
|
|
|
|
LandblockPhysicsContentBuilder.StaticCollisionPublication publication =
|
|
LandblockPhysicsContentBuilder.PublishStaticCollision(
|
|
engine, cache, landblock, collisions, origin: Vector3.Zero);
|
|
|
|
Assert.Equal(1, publication.SetupOwnerCount);
|
|
Assert.Equal(0, publication.BspOwnerCount);
|
|
Assert.Equal(0, publication.NoCollisionCount);
|
|
|
|
// The LIVE-path oracle for the SAME Setup/scale.
|
|
var expected = ShadowShapeBuilder.FromSetup(setup, entScale, _ => false);
|
|
Assert.Equal(2, expected.Count);
|
|
Assert.All(
|
|
expected,
|
|
shape => Assert.Equal(ShadowCollisionType.Sphere, shape.CollisionType));
|
|
|
|
ShadowShape[] expectedOrdered = expected.OrderBy(shape => shape.Radius).ToArray();
|
|
// Entity registered at world origin with identity rotation, so
|
|
// RegisterMultiPart's world composition (entityWorldPos +
|
|
// Transform(shape.LocalPosition, entityWorldRot)) reduces to exactly
|
|
// shape.LocalPosition — the static entry's world Position is directly
|
|
// comparable to FromSetup's LocalPosition.
|
|
ShadowEntry[] entries = engine.ShadowObjects.AllEntriesForDebug()
|
|
.Where(entry => entry.EntityId == entity.Id)
|
|
.OrderBy(entry => entry.Radius)
|
|
.ToArray();
|
|
|
|
Assert.Equal(expectedOrdered.Length, entries.Length);
|
|
for (int i = 0; i < entries.Length; i++)
|
|
{
|
|
Assert.Equal(ShadowCollisionType.Sphere, entries[i].CollisionType);
|
|
Assert.Equal(expectedOrdered[i].LocalPosition, entries[i].Position);
|
|
Assert.Equal(expectedOrdered[i].Radius, entries[i].Radius);
|
|
Assert.Equal(expectedOrdered[i].Scale, entries[i].Scale);
|
|
// Review F4 (2026-08-07): assert, don't infer — the C4 lesson.
|
|
Assert.Equal(expectedOrdered[i].CylHeight, entries[i].CylHeight);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Campaign OVERHAUL S2 chunk 5 closeout (G2 self-gate finding): a DAT
|
|
/// static whose GfxObj has visual geometry but no physics BSP is still a
|
|
/// CPhysicsObj retail floods into its cells (calc_cross_cells_static
|
|
/// 0x00515160 bbox route over the part array + add_shadows_to_cells
|
|
/// 0x00514ae0 AddPartsShadow rows), so the Content publisher registers it
|
|
/// render-only: retail cell array + part entry, zero collision rows, and
|
|
/// it still counts as a no-collision owner.
|
|
/// </summary>
|
|
[Fact]
|
|
public void PublishStaticCollision_NonCollidingGfxObjStatic_RegistersRenderOnly()
|
|
{
|
|
const uint gfxObjId = 0x01000043u;
|
|
var gfx = new GfxObj
|
|
{
|
|
VertexArray = new VertexArray
|
|
{
|
|
Vertices = new Dictionary<ushort, SWVertex>
|
|
{
|
|
[0] = new SWVertex { Origin = new Vector3(-0.5f, -0.5f, 0f) },
|
|
[1] = new SWVertex { Origin = new Vector3(0.5f, -0.5f, 0f) },
|
|
[2] = new SWVertex { Origin = new Vector3(0f, 0.5f, 1.2f) },
|
|
},
|
|
},
|
|
};
|
|
FlatGfxObjCollisionAsset asset = FlatCollisionAssetBuilder.FlattenGfxObj(gfx);
|
|
Assert.True(asset.PhysicsBsp.RootIndex < 0); // the fixture really has no physics
|
|
Assert.NotNull(asset.VisualBounds);
|
|
|
|
var entity = new WorldEntity
|
|
{
|
|
Id = 0x80A9B402u,
|
|
SourceGfxObjOrSetupId = gfxObjId,
|
|
Position = new Vector3(12f, 12f, 0f),
|
|
Rotation = Quaternion.Identity,
|
|
MeshRefs = new[] { new MeshRef(gfxObjId, Matrix4x4.Identity) },
|
|
};
|
|
var landblock = new LoadedLandblock(
|
|
LandblockId,
|
|
new LandBlock { Terrain = new TerrainInfo[81], Height = new byte[81] },
|
|
new[] { entity });
|
|
var collisions = new LandblockCollisionBuild(
|
|
ImmutableDictionary<uint, FlatGfxObjCollisionAsset>.Empty.Add(gfxObjId, asset),
|
|
ImmutableDictionary<uint, FlatSetupCollision>.Empty,
|
|
ImmutableDictionary<uint, FlatCellStructureCollisionAsset>.Empty,
|
|
ImmutableDictionary<uint, FlatEnvCellTopology>.Empty,
|
|
ImmutableArray.Create(gfxObjId),
|
|
ImmutableArray<uint>.Empty,
|
|
ImmutableArray<uint>.Empty);
|
|
var engine = new PhysicsEngine();
|
|
var cache = new PhysicsDataCache();
|
|
LandblockPhysicsContentBuilder.CachePreparedObjects(cache, collisions);
|
|
|
|
LandblockPhysicsContentBuilder.StaticCollisionPublication publication =
|
|
LandblockPhysicsContentBuilder.PublishStaticCollision(
|
|
engine, cache, landblock, collisions, origin: Vector3.Zero);
|
|
|
|
Assert.Equal(0, publication.SetupOwnerCount);
|
|
Assert.Equal(0, publication.BspOwnerCount);
|
|
Assert.Equal(1, publication.NoCollisionCount);
|
|
Assert.Empty(engine.ShadowObjects.AllEntriesForDebug());
|
|
Assert.True(engine.ShadowObjects.TryGetRetailCellArray(entity.Id, out var cells));
|
|
Assert.NotEmpty(cells);
|
|
Assert.Equal(
|
|
RetailCellArrayRoute.BoundingBox,
|
|
engine.ShadowObjects.GetRetailCellArrayRoute(entity.Id));
|
|
var parts = engine.ShadowObjects.GetRetailPartEntriesInCell(cells[0])
|
|
.Where(part => part.EntityId == entity.Id)
|
|
.ToArray();
|
|
Assert.Single(parts);
|
|
Assert.Equal(gfxObjId, parts[0].GfxObjId);
|
|
}
|
|
}
|