fix(physics): S2 — static publication emits authored Spheres as Spheres (AP-155 narrowed)
Some checks are pending
Headless portability / portable-headless (ubuntu-latest) (push) Waiting to run
Headless portability / portable-headless (windows-latest) (push) Waiting to run
Headless portability / linux-graphical (push) Waiting to run
Headless portability / linux-vulkan (push) Waiting to run
Some checks are pending
Headless portability / portable-headless (ubuntu-latest) (push) Waiting to run
Headless portability / portable-headless (windows-latest) (push) Waiting to run
Headless portability / linux-graphical (push) Waiting to run
Headless portability / linux-vulkan (push) Waiting to run
Both static sites (LandblockPhysicsPublisher, the headless-only LandblockPhysicsContentBuilder) emitted an authored Setup Sphere as a base-anchored Cylinder of radius r and height 2r. The live path emits a Sphere for the same data, so the same object collided differently by arrival route, and the narrow phase met a flat cap where retail meets a curved surface. Both sites now mirror ShadowShapeBuilder.FromSetup's Sphere block exactly. Combined Opus review: PASS. Its numeric verification of the dispatch test's geometry (head-sphere clearance 0.201 m for the true sphere; the cylinder counterfactual inside by 0.10 m XY with the Z band overlapping) is what makes the discrimination claim more than a sabotage anecdote, and its F8 finding is applied: the test now carries a POSITIVE control — aiming straight through the boulder's centre must block — so a membership/seed regression can no longer masquerade as a curve-hit pass. F4 applied: CylHeight is asserted, not inferred (the C4 lesson). F3 applied: the deleted Quaternion.Inverse base composition is recorded as internally coherent for the old cylinder's world-Z axis — the defect was the shape TYPE, not that rotation math. The review also verified the deleted-cylinder blast radius: the F2 overlay's drawn span is IDENTICAL for both shapes (old [c-r, c+r], new [c-r, c+r]); the flood sphere's centre rises by exactly r, which cannot change outdoor membership (XY rectangle) and lands the indoor half on Session B's dungeon gate alongside S1B; and the sphere-branch flood is now pinned uncapped by a genuine eleventh-shape A/B test. PublishStaticCollision — the headless static path — gains its first test ever. AP-155 is NARROWED, not deleted (review F13): the has-BSP source split (entity.MeshRefs vs setup.Parts + AnimPartChanged) survives and keeps the row active. The shared-primitive-emitter refactor that would make route independence a compile-time property is the filed follow-up (review F20). Population: 3,506 of 5,935 installed Setups, structurally equal to AP-157's third-branch count (byte-identical classifier — three independent routes agree: 3,605 - 99 = 3,506). Clean-room suite at implementation: 11,253 passed / 6 skipped / 0 failed on landed S1B. Post-review-hardening: Publisher tests 25/25, Content tests 2/2, both green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
b3e43d22c9
commit
9671af0273
7 changed files with 470 additions and 18 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1011,6 +1011,16 @@ public sealed class LandblockPhysicsPublisher
|
||||||
|
|
||||||
if (setup.Cylinders.Length == 0)
|
if (setup.Cylinders.Length == 0)
|
||||||
{
|
{
|
||||||
|
// AP-155: mirror ShadowShapeBuilder.FromSetup's step-2 Sphere
|
||||||
|
// emission EXACTLY (same origin/scale composition, same
|
||||||
|
// Radius<=0 guard) — a true Sphere, not a height-capped
|
||||||
|
// Cylinder. Retail's CPhysicsObj::FindObjCollisions dispatches
|
||||||
|
// an authored Setup Sphere to CSphere::intersects_sphere;
|
||||||
|
// there is no cylinder substitution for this branch. Emitting
|
||||||
|
// Cylinder here (base = origin - r*ẑ, height = 2r) made a
|
||||||
|
// static object's narrow phase disagree with the SAME object
|
||||||
|
// arriving as a live spawn via FromSetup — the route-
|
||||||
|
// dependence this fix closes.
|
||||||
for (int sphereIndex = 0;
|
for (int sphereIndex = 0;
|
||||||
sphereIndex < setup.Spheres.Length;
|
sphereIndex < setup.Spheres.Length;
|
||||||
sphereIndex++)
|
sphereIndex++)
|
||||||
|
|
@ -1022,17 +1032,15 @@ public sealed class LandblockPhysicsPublisher
|
||||||
|
|
||||||
float radius = sphere.Radius * scale;
|
float radius = sphere.Radius * scale;
|
||||||
Vector3 localOffset = sphere.Origin * scale;
|
Vector3 localOffset = sphere.Origin * scale;
|
||||||
Vector3 localBaseOffset = localOffset
|
setupShapes.Add(// (Review F3: the deleted Quaternion.Inverse base composition was
|
||||||
+ Vector3.Transform(
|
// internally coherent for the old CYLINDER's world-Z axis — the
|
||||||
-Vector3.UnitZ * radius,
|
// defect was the shape TYPE, not that rotation math.)
|
||||||
Quaternion.Inverse(entity.Rotation));
|
ShadowShape.Sphere(
|
||||||
setupShapes.Add(ShadowShape.Cylinder(
|
|
||||||
gfxObjId: entity.SourceGfxObjOrSetupId,
|
gfxObjId: entity.SourceGfxObjOrSetupId,
|
||||||
localPosition: localBaseOffset,
|
localPosition: localOffset,
|
||||||
localRotation: Quaternion.Identity,
|
localRotation: Quaternion.Identity,
|
||||||
scale: scale,
|
scale: scale,
|
||||||
radius: radius,
|
radius: radius));
|
||||||
cylHeight: radius * 2f));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1080,8 +1088,11 @@ public sealed class LandblockPhysicsPublisher
|
||||||
|
|
||||||
for (int index = 0; index < shapes.Count; index++)
|
for (int index = 0; index < shapes.Count; index++)
|
||||||
{
|
{
|
||||||
|
// AP-155: the Setup-derived shape can now be Cylinder OR Sphere
|
||||||
|
// (never both — see ShadowShapeBuilder.FromSetup step 1/2). Read
|
||||||
|
// the actual emitted type rather than assuming Cylinder.
|
||||||
Console.WriteLine(FormattableString.Invariant(
|
Console.WriteLine(FormattableString.Invariant(
|
||||||
$"[entity-source] id=0x{entity.Id:X8} entityId=0x{entity.Id:X8} src=0x{entity.SourceGfxObjOrSetupId:X8} gfxObj=0x{shapes[index].GfxObjId:X8} lb=0x{landblock.LandblockId:X8} type=Cylinder note=setup-part{index} state=0x{0u:X8} flags={EntityCollisionFlags.None}"));
|
$"[entity-source] id=0x{entity.Id:X8} entityId=0x{entity.Id:X8} src=0x{entity.SourceGfxObjOrSetupId:X8} gfxObj=0x{shapes[index].GfxObjId:X8} lb=0x{landblock.LandblockId:X8} type={shapes[index].CollisionType} note=setup-part{index} state=0x{0u:X8} flags={EntityCollisionFlags.None}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -666,6 +666,11 @@ public static class LandblockPhysicsContentBuilder
|
||||||
|
|
||||||
if (setup.Cylinders.Length == 0)
|
if (setup.Cylinders.Length == 0)
|
||||||
{
|
{
|
||||||
|
// AP-155: mirror ShadowShapeBuilder.FromSetup's step-2 Sphere
|
||||||
|
// emission EXACTLY (same origin/scale composition, same
|
||||||
|
// Radius<=0 guard) — a true Sphere, not a height-capped
|
||||||
|
// Cylinder. See LandblockPhysicsPublisher's identical fix for
|
||||||
|
// the full retail-anchor note.
|
||||||
for (int index = 0;
|
for (int index = 0;
|
||||||
index < setup.Spheres.Length;
|
index < setup.Spheres.Length;
|
||||||
index++)
|
index++)
|
||||||
|
|
@ -675,17 +680,15 @@ public static class LandblockPhysicsContentBuilder
|
||||||
continue;
|
continue;
|
||||||
float radius = sphere.Radius * scale;
|
float radius = sphere.Radius * scale;
|
||||||
Vector3 localOffset = sphere.Origin * scale;
|
Vector3 localOffset = sphere.Origin * scale;
|
||||||
Vector3 localBaseOffset = localOffset
|
setupShapes.Add(// (Review F3: the deleted Quaternion.Inverse base composition was
|
||||||
+ Vector3.Transform(
|
// internally coherent for the old CYLINDER's world-Z axis — the
|
||||||
-Vector3.UnitZ * radius,
|
// defect was the shape TYPE, not that rotation math.)
|
||||||
Quaternion.Inverse(entity.Rotation));
|
ShadowShape.Sphere(
|
||||||
setupShapes.Add(ShadowShape.Cylinder(
|
|
||||||
entity.SourceGfxObjOrSetupId,
|
entity.SourceGfxObjOrSetupId,
|
||||||
localBaseOffset,
|
localOffset,
|
||||||
Quaternion.Identity,
|
Quaternion.Identity,
|
||||||
scale,
|
scale,
|
||||||
radius,
|
radius));
|
||||||
radius * 2f));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -462,6 +462,186 @@ public sealed class LandblockPhysicsPublisherTests
|
||||||
Assert.Equal(0, fixture.Publisher.Diagnostics.StaticCylinderOwnerCount);
|
Assert.Equal(0, fixture.Publisher.Diagnostics.StaticCylinderOwnerCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AP-155 parity (route independence). A Setup carrying only authored
|
||||||
|
/// Spheres (no CylSpheres) must register the SAME shapes — type, local
|
||||||
|
/// position, radius, scale — through the static publication path as
|
||||||
|
/// through <see cref="ShadowShapeBuilder.FromSetup"/>, the LIVE path.
|
||||||
|
/// Before the fix this site emitted a height-capped Cylinder instead
|
||||||
|
/// (base = origin - r*ẑ, height = 2r): same object, different narrow
|
||||||
|
/// phase depending on how it arrived.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void CompletePublication_SphereOnlySetup_MatchesFromSetupShapeForShape()
|
||||||
|
{
|
||||||
|
var fixture = Fixture();
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
fixture.Cache.CacheSetup(SetupId, setup);
|
||||||
|
|
||||||
|
const float entScale = 1.3f;
|
||||||
|
WorldEntity entity = new()
|
||||||
|
{
|
||||||
|
Id = 0x80A9B401u,
|
||||||
|
SourceGfxObjOrSetupId = SetupId,
|
||||||
|
Position = Vector3.Zero,
|
||||||
|
Rotation = Quaternion.Identity,
|
||||||
|
Scale = entScale,
|
||||||
|
MeshRefs = Array.Empty<MeshRef>(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Publish(fixture.Publisher, Build(FirstLandblock, [entity]));
|
||||||
|
|
||||||
|
// The LIVE-path oracle for the SAME Setup/scale.
|
||||||
|
IReadOnlyList<ShadowShape> 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 = fixture.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>
|
||||||
|
/// AP-155 dispatch. A statically-published Sphere must actually run the
|
||||||
|
/// Sphere narrow phase (<c>CSphere::intersects_sphere</c> — true 3-D
|
||||||
|
/// distance) at query time, not the Cylinder narrow phase (XY distance +
|
||||||
|
/// flat Z-band). Geometry: a 1 m-radius "boulder" Setup Sphere centred at
|
||||||
|
/// world Z=2.0 (spans Z=[1,3]). A tall, narrow capsule mover's HEAD sphere
|
||||||
|
/// grazes the boulder's shoulder at Z~2.85 (0.85 m above the boulder's own
|
||||||
|
/// centre, out of its 1 m radius) with a 1.05 m lateral offset; its FOOT
|
||||||
|
/// sphere (Z~0.15) never comes close. At that height/offset the true
|
||||||
|
/// sphere's surface has tapered well inside the mover's path (curve-hit —
|
||||||
|
/// clean miss, ~0.2 m 3-D clearance), while the retired flat-capped
|
||||||
|
/// Cylinder never tapers and still fills the same footprint the whole
|
||||||
|
/// height of its cap (cap-hit — the 1.05 m offset sits ~0.10 m inside its
|
||||||
|
/// XY radius). The two verdicts differ; this asserts the Sphere one —
|
||||||
|
/// unobstructed straight-line arrival at the far side.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void CompletePublication_SphereOnlySetup_MoverGrazesShoulderAndPassesThroughUnobstructed()
|
||||||
|
{
|
||||||
|
var fixture = Fixture();
|
||||||
|
var setup = new Setup();
|
||||||
|
setup.Spheres.Add(new Sphere
|
||||||
|
{
|
||||||
|
Origin = new Vector3(0f, 0f, 2.0f),
|
||||||
|
Radius = 1.0f,
|
||||||
|
});
|
||||||
|
fixture.Cache.CacheSetup(SetupId, setup);
|
||||||
|
|
||||||
|
WorldEntity entity = new()
|
||||||
|
{
|
||||||
|
Id = 0x80A9B401u,
|
||||||
|
SourceGfxObjOrSetupId = SetupId,
|
||||||
|
Position = new Vector3(12f, 12f, 0f),
|
||||||
|
Rotation = Quaternion.Identity,
|
||||||
|
MeshRefs = Array.Empty<MeshRef>(),
|
||||||
|
};
|
||||||
|
Publish(fixture.Publisher, Build(FirstLandblock, [entity]));
|
||||||
|
|
||||||
|
// Sanity: the fix registered a Sphere, not a Cylinder — the dispatch
|
||||||
|
// this test exercises depends on it.
|
||||||
|
ShadowEntry registered = Assert.Single(
|
||||||
|
fixture.Engine.ShadowObjects.AllEntriesForDebug());
|
||||||
|
Assert.Equal(ShadowCollisionType.Sphere, registered.CollisionType);
|
||||||
|
|
||||||
|
var body = MakeGroundedBody(new Vector3(10.7f, 13.05f, 0f));
|
||||||
|
Vector3 target = new(13.3f, 13.05f, 0f);
|
||||||
|
|
||||||
|
ResolveResult result = fixture.Engine.ResolveWithTransition(
|
||||||
|
body.Position, target, 0xA9B40001u,
|
||||||
|
sphereRadius: 0.15f, sphereHeight: 3.0f,
|
||||||
|
stepUpHeight: 0.60f, stepDownHeight: 0.04f,
|
||||||
|
isOnGround: true, body: body,
|
||||||
|
moverFlags: ObjectInfoState.IsPlayer | ObjectInfoState.EdgeSlide,
|
||||||
|
movingEntityId: 0u);
|
||||||
|
|
||||||
|
Assert.True(
|
||||||
|
MathF.Abs(result.Position.X - target.X) < 0.05f
|
||||||
|
&& MathF.Abs(result.Position.Y - target.Y) < 0.05f,
|
||||||
|
"Mover must clear the boulder unobstructed (true-sphere curve-hit "
|
||||||
|
+ $"clears at this height/offset); got {result.Position}, wanted {target}.");
|
||||||
|
|
||||||
|
// Review F8 (2026-08-07): the POSITIVE control. Without it, the graze
|
||||||
|
// assertion above also passes when the shadow object is absent from
|
||||||
|
// the queried cell entirely (a membership/seed/flood regression) —
|
||||||
|
// the discriminating power lived only in an unreproducible sabotage
|
||||||
|
// run. Same publication, same cell, but aimed straight THROUGH the
|
||||||
|
// boulder's centre: the head sphere's closest approach to the centre
|
||||||
|
// is (0, 0, 0.85), |d| = 0.85 < radsum 1.15 — the true sphere MUST
|
||||||
|
// block this one. The pair proves reachable AND correctly shaped.
|
||||||
|
var throughBody = MakeGroundedBody(new Vector3(10.7f, 12f, 0f));
|
||||||
|
ResolveResult blockedResult = fixture.Engine.ResolveWithTransition(
|
||||||
|
throughBody.Position, new Vector3(13.3f, 12f, 0f), 0xA9B40001u,
|
||||||
|
sphereRadius: 0.15f, sphereHeight: 3.0f,
|
||||||
|
stepUpHeight: 0.60f, stepDownHeight: 0.04f,
|
||||||
|
isOnGround: true, body: throughBody,
|
||||||
|
moverFlags: ObjectInfoState.IsPlayer | ObjectInfoState.EdgeSlide,
|
||||||
|
movingEntityId: 0u);
|
||||||
|
Assert.True(
|
||||||
|
MathF.Abs(blockedResult.Position.X - 13.3f) >= 0.05f,
|
||||||
|
"Aiming straight through the boulder's centre must NOT arrive at "
|
||||||
|
+ $"the far side; got {blockedResult.Position} — the sphere is "
|
||||||
|
+ "either unregistered in cell 0xA9B40001 or not colliding.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PhysicsBody MakeGroundedBody(Vector3 position)
|
||||||
|
{
|
||||||
|
var floorPlane = new Plane(Vector3.UnitZ, 0f);
|
||||||
|
var floorVerts = new[]
|
||||||
|
{
|
||||||
|
new Vector3(-100f, -100f, 0f),
|
||||||
|
new Vector3( 100f, -100f, 0f),
|
||||||
|
new Vector3( 100f, 100f, 0f),
|
||||||
|
new Vector3(-100f, 100f, 0f),
|
||||||
|
};
|
||||||
|
return new PhysicsBody
|
||||||
|
{
|
||||||
|
Position = position,
|
||||||
|
Orientation = Quaternion.Identity,
|
||||||
|
ContactPlaneValid = true,
|
||||||
|
ContactPlane = floorPlane,
|
||||||
|
ContactPlaneCellId = 0xA9B40001u,
|
||||||
|
WalkablePolygonValid = true,
|
||||||
|
WalkablePlane = floorPlane,
|
||||||
|
WalkableVertices = floorVerts,
|
||||||
|
WalkableUp = Vector3.UnitZ,
|
||||||
|
TransientState = TransientStateFlags.Contact | TransientStateFlags.OnWalkable,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CompletePublication_BuildingShellNeverRegistersSetupCollision()
|
public void CompletePublication_BuildingShellNeverRegistersSetupCollision()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using AcDream.Core.Physics;
|
||||||
|
using DatReaderWriter;
|
||||||
|
using DatReaderWriter.DBObjs;
|
||||||
|
using DatReaderWriter.Enums;
|
||||||
|
using DatReaderWriter.Options;
|
||||||
|
|
||||||
|
namespace AcDream.Content.Tests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AP-155 population MEASUREMENT ONLY (contract
|
||||||
|
/// <c>docs/research/2026-08-07-s2-static-sphere-contract.md</c>, "Measurement"
|
||||||
|
/// section) — not a gate. Counts, over the installed <c>client_portal.dat</c>
|
||||||
|
/// Setups (the same <c>dats.GetAllIdsOfType<Setup>()</c> enumeration
|
||||||
|
/// <see cref="InstalledSetupCollisionReachabilityTests"/> and
|
||||||
|
/// <see cref="InstalledSetupBspPrimitiveDispatchTests"/> already sweep), how
|
||||||
|
/// many actually REACH the fixed static-publication Sphere emission — i.e.
|
||||||
|
/// <see cref="ShadowShapeBuilder.FromSetup"/>'s production dispatch, at
|
||||||
|
/// scale 1, emits ONLY <see cref="ShadowCollisionType.Sphere"/> shapes for
|
||||||
|
/// them. That dispatch (not a raw "has Spheres, no CylSpheres" field read) is
|
||||||
|
/// the correct population: a Setup can carry authored Spheres and STILL never
|
||||||
|
/// reach the sphere branch if a physics-BSP part suppresses it (AP-152) — 99
|
||||||
|
/// of the 3,605 "sphere-only, no cylinder" Setups the reachability sweep
|
||||||
|
/// already counted fall into exactly that trap.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class Ap155StaticSpherePopulationMeasurementTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void InstalledSetups_SphereOnlyStaticPopulation_Measured()
|
||||||
|
{
|
||||||
|
string? datDir = ContentConformanceDats.ResolveDatDir();
|
||||||
|
if (datDir is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("SKIP: installed retail DAT directory is unavailable.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
||||||
|
|
||||||
|
// Production physics-BSP predicate — same as
|
||||||
|
// InstalledSetupBspPrimitiveDispatchTests / FlatCollisionAssetBuilder.cs:377-380.
|
||||||
|
var physicsBspCache = new Dictionary<uint, bool>();
|
||||||
|
bool HasPhysicsBsp(uint gfxObjId)
|
||||||
|
{
|
||||||
|
if (physicsBspCache.TryGetValue(gfxObjId, out bool cached))
|
||||||
|
return cached;
|
||||||
|
bool result =
|
||||||
|
dats.Portal.TryGet<GfxObj>(gfxObjId, out GfxObj? gfx)
|
||||||
|
&& gfx is not null
|
||||||
|
&& gfx.Flags.HasFlag(GfxObjFlags.HasPhysics)
|
||||||
|
&& gfx.PhysicsBSP?.Root is not null
|
||||||
|
&& gfx.VertexArray is not null;
|
||||||
|
physicsBspCache[gfxObjId] = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalSetups = 0;
|
||||||
|
int sphereOnlyReachable = 0;
|
||||||
|
var samples = new List<uint>();
|
||||||
|
|
||||||
|
foreach (uint id in dats.GetAllIdsOfType<Setup>())
|
||||||
|
{
|
||||||
|
if (!dats.Portal.TryGet<Setup>(id, out Setup? setup) || setup is null)
|
||||||
|
continue;
|
||||||
|
totalSetups++;
|
||||||
|
|
||||||
|
// The classifier: production FromSetup output, not raw Setup
|
||||||
|
// fields — this is what a landblock static entity built from
|
||||||
|
// this Setup actually registers.
|
||||||
|
var shapes = ShadowShapeBuilder.FromSetup(setup, 1f, HasPhysicsBsp);
|
||||||
|
if (shapes.Count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool sphereOnly = true;
|
||||||
|
foreach (var shape in shapes)
|
||||||
|
{
|
||||||
|
if (shape.CollisionType != ShadowCollisionType.Sphere)
|
||||||
|
{
|
||||||
|
sphereOnly = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!sphereOnly)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sphereOnlyReachable++;
|
||||||
|
if (samples.Count < 3)
|
||||||
|
samples.Add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("===== AP-155 static-sphere population measurement =====");
|
||||||
|
Console.WriteLine($"Total installed Setups: {totalSetups}");
|
||||||
|
Console.WriteLine($"Reach the static Sphere emission (post-fix, production dispatch): {sphereOnlyReachable}");
|
||||||
|
Console.WriteLine("Three example object ids:");
|
||||||
|
foreach (uint sample in samples)
|
||||||
|
Console.WriteLine($" 0x{sample:X8}");
|
||||||
|
Console.WriteLine("=========================================================");
|
||||||
|
|
||||||
|
// Structural sanity only — this is a measurement, not a gate.
|
||||||
|
Assert.True(totalSetups > 0, "Expected the installed DAT to enumerate at least one Setup.");
|
||||||
|
Assert.True(
|
||||||
|
sphereOnlyReachable > 0,
|
||||||
|
"Expected at least one Setup to reach the static Sphere emission in the installed DAT.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -241,6 +241,14 @@ public class ShadowObjectRegistryMultiPartTests
|
||||||
radius: radius,
|
radius: radius,
|
||||||
cylHeight: radius * 2f);
|
cylHeight: radius * 2f);
|
||||||
|
|
||||||
|
private static ShadowShape Sph(float radius, Vector3 localPosition = default)
|
||||||
|
=> ShadowShape.Sphere(
|
||||||
|
gfxObjId: 0u,
|
||||||
|
localPosition: localPosition,
|
||||||
|
localRotation: Quaternion.Identity,
|
||||||
|
scale: 1f,
|
||||||
|
radius: radius);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A physics-BSP part shape. <paramref name="boundsCenter"/> defaults
|
/// A physics-BSP part shape. <paramref name="boundsCenter"/> defaults
|
||||||
/// OFF-CENTRE because that is the DAT-real configuration: a GfxObj's
|
/// OFF-CENTRE because that is the DAT-real configuration: a GfxObj's
|
||||||
|
|
@ -389,6 +397,40 @@ public class ShadowObjectRegistryMultiPartTests
|
||||||
Assert.DoesNotContain(farCell, cylCells);
|
Assert.DoesNotContain(farCell, cylCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AP-155 (S2 contract, 2026-08-07). Retail's 10-sphere clamp
|
||||||
|
/// (<c>CObjCell::find_cell_list</c> @0x0052b9f0, <c>0x0052ba21 cmp
|
||||||
|
/// eax,0xa</c>) is a fixed-size destination-buffer limit on the CYLSPHERE
|
||||||
|
/// overload alone — it is not read by the Sphere-shape branch
|
||||||
|
/// <c>BuildFloodSpheres</c> takes as acdream's substitute for retail's
|
||||||
|
/// sorting-sphere overload (@0x0052b990, AP-157, still open): that branch
|
||||||
|
/// caps at <c>int.MaxValue</c>, i.e. not at all. Before this fix a static
|
||||||
|
/// Setup-Sphere entity registered as Cylinder shapes and so WAS subject to
|
||||||
|
/// this cap; after it, the same entity registers as Sphere shapes and
|
||||||
|
/// reaches this uncapped branch instead — verified here directly rather
|
||||||
|
/// than inferred from the source comment, matching
|
||||||
|
/// <see cref="BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts"/>'s
|
||||||
|
/// eleventh-shape technique one branch over.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void BuildFloodSpheres_SphereBranchIsNeverCappedAtTen()
|
||||||
|
{
|
||||||
|
var far = new Vector3(0f, 72f, 0f);
|
||||||
|
uint ownCell = LbId | (uint)(1 * 8 + 1 + 1); // (x=1, y=1)
|
||||||
|
uint farCell = LbId | (uint)(1 * 8 + 4 + 1); // (x=1, y=4)
|
||||||
|
|
||||||
|
var spheres = new ShadowShape[11];
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
spheres[i] = Sph(1f);
|
||||||
|
spheres[10] = Sph(1f, far);
|
||||||
|
List<uint> sphereCells = FloodCellsFor(spheres);
|
||||||
|
|
||||||
|
Assert.Contains(ownCell, sphereCells);
|
||||||
|
// The eleventh Sphere still floods — unlike the eleventh CylSphere in
|
||||||
|
// BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts above.
|
||||||
|
Assert.Contains(farCell, sphereCells);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The BoundsCentre is expressed in the SHAPE's own frame, so the part's
|
/// The BoundsCentre is expressed in the SHAPE's own frame, so the part's
|
||||||
/// LocalRotation must carry it — exactly as retail transforms the sphere
|
/// LocalRotation must carry it — exactly as retail transforms the sphere
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue