acdream had never implemented retail's SECOND cell-membership algorithm.
CPhysicsObj::calc_cross_cells @0x00515230 tests HAS_PHYSICS_BSP_PS at
0x00515285 and jumps (0x0051528f jne 0x515305) to find_bbox_cell_list
@0x00510fc0 for a BSP-bearing object; everything below that jump is the
OTHER algorithm, CObjCell::find_cell_list, and that is all we had. Every
object, BSP-bearing or not, was routed through it.
That path's outdoor expansion is a HARD CAP of one cell in each direction.
CellTransit.AddAllOutsideCells computes minRad = radius, maxRad = 24 - radius
and adds at most the eight neighbours of the sphere's own cell, so for any
radius >= 12 m both boundary tests are unconditionally true and the result is
exactly 3x3. Widening the radius or adding a second sphere is mechanically
incapable of adding a tenth cell. The user's live probe measured the
consequence directly: standing inside a Neftet formation, inCell=2 exempt=2
reached=0 -- the geometry was not a candidate at all.
The port. AddAllOutsideCellsFromParts is CLandCell::add_all_outside_cells
@0x00533360 plus add_cell_block @0x005331d0: base landcell from the FIRST
part's own adjust_to_outside, baseX/baseY within-block, each part's authored
CGfxObj::gfx_bound_box re-fit through all eight corners
(BBox::LocalToGlobal @0x005b2120), floor(v / square_length) where
square_length = 0x7c920c = 24.0f, four accumulators seeded to zero, ONE
rectangle unioned across all parts, FILLED, in GLOBAL lcoords so it crosses
landblocks freely, clamped only to [0, 0x7f8).
BuildShadowCellSetFromParts is find_bbox_cell_list's worklist.
RegisterMultiPart dispatches on the same flag retail does, and
BuildFloodSpheres' BSP arm is deleted rather than left unreachable.
Disassembled from the PDB-paired 2013-09-06 binary, not read from Binary
Ninja: BN mis-renders four separate constructs inside add_all_outside_cells
alone -- a dropped `and eax,0xffff` on baseX, a neg/sbb/and select shown as
identically zero, a wrong get_landcell argument, and both x87 flag tests as
`unimplemented {test ah}`.
ShadowPartGeometry pairs the BSP root sphere with the authored box so no
resolver can answer one and leave the other call site to synthesize a
substitute -- the AP-156 invariant applied a second time, since that split is
what produced AP-156 and then this. The box comes from
FlatGfxObjVisualBounds, already computed by exactly CGfxObj::init_end's
algorithm and already in the prepared package: no bake change, no DAT re-read.
Cost, measured over the installed DATs before any code was written: 1,258
physics-BSP GfxObjs, cells/object p50 4, p90 4, p99 12, max 49. The port is
CHEAPER than the old 3x3 = 9 for 98.97% of them. Row totals (shapes x cells)
over all 1,031 landblocks with BSP owners fall 97,173 -> 15,607 (0.161x);
dense Arwic 0xC6A9 falls 342 -> 43. One landblock more than doubles.
Precondition confirmed before pinning any expected cell set: 0x010046D8's box
is 96 m x 96 m about cell (2,2) = 0x87640013, which independently corroborates
the 3x3-centred-there diagnosis, and its rectangle does contain 0x87640011 and
0x87640019 -- the two cells the probe measured empty.
Register: AP-156's outdoor half CLOSED and its risk column CORRECTED (it read
"extra broadphase candidates, never a missed one", which generalised the indoor
direction to the whole row and is why #334 sat inside it unnoticed). AP-159 +
issue #335 file the unported indoor arm; AD-49 records the seed-time rectangle.
Issue #336 files a fourth load-sensitive test flake seen once during the gate.
Ten tests, every one sabotage-verified in both directions across eight
mutations (dispatch, 8-corner refit, floor-vs-truncation, union-vs-per-part,
map clamp, adjust guard, landblock clamp, box-path-for-everything). The
strongest is an installed-DAT replay of the user's own probe evidence.
Suite 11,208 -> 11,218 passed / 4 skipped / 0 failed; the +10 is exactly the
new tests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
474 lines
20 KiB
C#
474 lines
20 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using AcDream.Core.Physics;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.Physics;
|
|
|
|
public class ShadowObjectRegistryMultiPartTests
|
|
{
|
|
private const uint LbId = 0xA9B40000u;
|
|
private const float OffX = 0f;
|
|
private const float OffY = 0f;
|
|
|
|
private static IReadOnlyList<ShadowShape> DoorShapes() => new[]
|
|
{
|
|
ShadowShape.Cylinder(
|
|
gfxObjId: 0u,
|
|
localPosition: new Vector3(0f, 0f, 0.018f),
|
|
localRotation: Quaternion.Identity,
|
|
scale: 1.0f,
|
|
radius: 0.100f,
|
|
cylHeight: 0.200f),
|
|
ShadowShape.Bsp(
|
|
gfxObjId: 0x010044B5u,
|
|
localPosition: Vector3.Zero,
|
|
localRotation: Quaternion.Identity,
|
|
scale: 1.0f,
|
|
localGeometry: ShadowPartGeometry.Create(new FlatCollisionSphere(Vector3.Zero, 2.0f), null)),
|
|
ShadowShape.Bsp(
|
|
gfxObjId: 0x010044B6u,
|
|
localPosition: Vector3.Zero,
|
|
localRotation: Quaternion.Identity,
|
|
scale: 1.0f,
|
|
localGeometry: ShadowPartGeometry.Create(new FlatCollisionSphere(Vector3.Zero, 2.0f), null)),
|
|
ShadowShape.Bsp(
|
|
gfxObjId: 0x010044B6u,
|
|
localPosition: Vector3.Zero,
|
|
localRotation: Quaternion.Identity,
|
|
scale: 1.0f,
|
|
localGeometry: ShadowPartGeometry.Create(new FlatCollisionSphere(Vector3.Zero, 2.0f), null))
|
|
};
|
|
|
|
[Fact]
|
|
public void RegisterMultiPart_FourShapes_AllShareEntityId()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint doorEntityId = 0x000F4244u;
|
|
|
|
reg.RegisterMultiPart(
|
|
entityId: doorEntityId,
|
|
entityWorldPos: new Vector3(132.6f, 17.1f, 94.08f),
|
|
entityWorldRot: Quaternion.Identity,
|
|
shapes: DoorShapes(),
|
|
state: 0x10008u,
|
|
flags: EntityCollisionFlags.None,
|
|
worldOffsetX: OffX,
|
|
worldOffsetY: OffY,
|
|
landblockId: LbId);
|
|
|
|
int found = 0;
|
|
foreach (var entry in reg.AllEntriesForDebug())
|
|
{
|
|
if (entry.EntityId == doorEntityId) found++;
|
|
}
|
|
Assert.True(found >= 4,
|
|
$"Expected at least 4 entries for door entity (one per shape); found {found}");
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterMultiPart_EmptyShapeList_NoOp()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
reg.RegisterMultiPart(
|
|
entityId: 0x1u,
|
|
entityWorldPos: Vector3.Zero,
|
|
entityWorldRot: Quaternion.Identity,
|
|
shapes: System.Array.Empty<ShadowShape>(),
|
|
state: 0u,
|
|
flags: EntityCollisionFlags.None,
|
|
worldOffsetX: OffX, worldOffsetY: OffY, landblockId: LbId);
|
|
|
|
Assert.Equal(0, reg.TotalRegistered);
|
|
}
|
|
|
|
[Fact]
|
|
public void Deregister_RemovesAllParts()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint doorEntityId = 0x000F4244u;
|
|
reg.RegisterMultiPart(doorEntityId, new Vector3(132.6f, 17.1f, 94.08f),
|
|
Quaternion.Identity, DoorShapes(), 0x10008u,
|
|
EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
reg.Deregister(doorEntityId);
|
|
|
|
Assert.Equal(0, reg.TotalRegistered);
|
|
foreach (var entry in reg.AllEntriesForDebug())
|
|
Assert.NotEqual(doorEntityId, entry.EntityId);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdatePhysicsState_PropagatesEtherealToAllParts()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint doorEntityId = 0x000F4244u;
|
|
reg.RegisterMultiPart(doorEntityId, new Vector3(132.6f, 17.1f, 94.08f),
|
|
Quaternion.Identity, DoorShapes(), 0x10008u,
|
|
EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
reg.UpdatePhysicsState(doorEntityId, 0x1000Cu); // 0x10008 | 0x4
|
|
|
|
int updated = 0;
|
|
foreach (var entry in reg.AllEntriesForDebug())
|
|
{
|
|
if (entry.EntityId != doorEntityId) continue;
|
|
Assert.Equal(0x1000Cu, entry.State);
|
|
updated++;
|
|
}
|
|
Assert.True(updated >= 4, $"Expected all parts updated, only {updated} were");
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterMultiPart_PartsAcrossMultipleCells_AllCellsListed()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
// Two shapes 30m apart in X — must span two outdoor 24m cells.
|
|
var shapes = new[]
|
|
{
|
|
ShadowShape.Cylinder(0u, new Vector3( 0f, 0f, 0f), Quaternion.Identity, 1f, 1f, 2f),
|
|
ShadowShape.Cylinder(0u, new Vector3(30f, 0f, 0f), Quaternion.Identity, 1f, 1f, 2f),
|
|
};
|
|
reg.RegisterMultiPart(0x1u, new Vector3(12f, 12f, 50f), Quaternion.Identity,
|
|
shapes, 0u, EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
// Part 1 at world (12, 12) → cell (0,0) = LbId | 1
|
|
// Part 2 at world (42, 12) → cell (1,0) = LbId | 9
|
|
var entriesIn1 = reg.GetObjectsInCell(LbId | 1u);
|
|
var entriesIn9 = reg.GetObjectsInCell(LbId | 9u);
|
|
Assert.Contains(entriesIn1, e => e.EntityId == 0x1u);
|
|
Assert.Contains(entriesIn9, e => e.EntityId == 0x1u);
|
|
}
|
|
|
|
[Fact]
|
|
public void Register_SingleShapeCompat_Unchanged()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
reg.Register(42u, 0x01000001u, new Vector3(12f, 12f, 50f),
|
|
Quaternion.Identity, 1f, OffX, OffY, LbId);
|
|
|
|
Assert.Equal(1, reg.TotalRegistered);
|
|
Assert.Single(reg.GetObjectsInCell(LbId | 1u),
|
|
e => e.EntityId == 42u);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdatePosition_MovesAllPartsWithEntity()
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint movingEntityId = 0xA1u;
|
|
|
|
var shapes = new[]
|
|
{
|
|
ShadowShape.Cylinder(0u, new Vector3(0f, 0f, 0f), Quaternion.Identity, 1f, 0.5f, 1f),
|
|
ShadowShape.Cylinder(0u, new Vector3(1f, 0f, 0f), Quaternion.Identity, 1f, 0.5f, 1f),
|
|
};
|
|
reg.RegisterMultiPart(movingEntityId, new Vector3(10f, 10f, 50f),
|
|
Quaternion.Identity, shapes, 0u,
|
|
EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
// Move entity to (50, 10, 50). Parts should be at (50, 10, 50) and (51, 10, 50).
|
|
reg.UpdatePosition(movingEntityId,
|
|
new Vector3(50f, 10f, 50f), Quaternion.Identity,
|
|
OffX, OffY, LbId);
|
|
|
|
Vector3 expectedPart0 = new(50f, 10f, 50f);
|
|
Vector3 expectedPart1 = new(51f, 10f, 50f);
|
|
var atNew = reg.AllEntriesForDebug().Where(e => e.EntityId == movingEntityId).ToList();
|
|
Assert.Equal(2, atNew.Count);
|
|
bool found0 = atNew.Any(e => Vector3.Distance(e.Position, expectedPart0) < 0.01f);
|
|
bool found1 = atNew.Any(e => Vector3.Distance(e.Position, expectedPart1) < 0.01f);
|
|
Assert.True(found0 && found1,
|
|
"Expected both parts at new world positions (50, 10, 50) and (51, 10, 50)");
|
|
}
|
|
|
|
[Fact]
|
|
public void Deregister_ClearsEntityShapesCache_NoStaleUpdatePositionRebuild()
|
|
{
|
|
// A6.P4 door fix (2026-05-24) regression: after Deregister, a stray
|
|
// UpdatePosition with the same entityId must NOT resurrect the entity
|
|
// via the _entityShapes path. The Deregister cleanup added in Task 4
|
|
// (which folded Task 6 into the multi-part registration commit) clears
|
|
// _entityShapes[entityId] alongside the cell-list cleanup.
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint doorEntityId = 0x000F4244u;
|
|
reg.RegisterMultiPart(doorEntityId, new Vector3(132.6f, 17.1f, 94.08f),
|
|
Quaternion.Identity, DoorShapes(), 0x10008u,
|
|
EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
reg.Deregister(doorEntityId);
|
|
|
|
// Stray UpdatePosition should be a no-op now (no entry to find AND
|
|
// no _entityShapes entry to rebuild from).
|
|
reg.UpdatePosition(doorEntityId, new Vector3(200f, 200f, 50f),
|
|
Quaternion.Identity, OffX, OffY, LbId);
|
|
|
|
Assert.Equal(0, reg.TotalRegistered);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
// AP-152 — cross-cell dispatch. CPhysicsObj::calc_cross_cells @0x00515230
|
|
// tests HAS_PHYSICS_BSP_PS at 0x00515285 and routes a BSP-bearing object
|
|
// to CPhysicsObj::find_bbox_cell_list @0x00510fc0 through
|
|
// 0x0051528f jne 0x515305. The cylsphere branch (0x005152d1
|
|
// CObjCell::find_cell_list @0x0052b9f0) and the sorting-sphere branch
|
|
// (0x005152fb ... @0x0052b990) are BOTH below that jump and unreachable
|
|
// from it. BuildFloodSpheres used to prefer Cylinders over everything
|
|
// whenever any Cylinder was present, which is retail's SECOND priority
|
|
// applied ahead of its first.
|
|
// ---------------------------------------------------------------------
|
|
|
|
/// <summary>Cells of the landblock that hold at least one row for owner.</summary>
|
|
private static List<uint> OutdoorCellsHolding(ShadowObjectRegistry reg, uint ownerId)
|
|
{
|
|
var cells = new List<uint>();
|
|
for (uint index = 1u; index <= 64u; index++)
|
|
{
|
|
uint cellId = LbId | index;
|
|
if (reg.GetObjectsInCell(cellId).Any(e => e.EntityId == ownerId))
|
|
cells.Add(cellId);
|
|
}
|
|
return cells;
|
|
}
|
|
|
|
private static ShadowShape Cyl(float radius, Vector3 localPosition = default)
|
|
=> ShadowShape.Cylinder(
|
|
gfxObjId: 0u,
|
|
localPosition: localPosition,
|
|
localRotation: Quaternion.Identity,
|
|
scale: 1f,
|
|
radius: radius,
|
|
cylHeight: radius * 2f);
|
|
|
|
/// <summary>
|
|
/// A physics-BSP part shape. <paramref name="boundsCenter"/> defaults
|
|
/// OFF-CENTRE because that is the DAT-real configuration: a GfxObj's
|
|
/// physics BSP is authored in the GfxObj's own coordinates and 376 of the
|
|
/// 973 installed physics-BSP parts have a root bounding sphere further
|
|
/// from the part origin than half their own radius. A fixture pinned at
|
|
/// <c>Vector3.Zero</c> is the one configuration in which discarding the
|
|
/// centre is invisible.
|
|
/// </summary>
|
|
private static ShadowShape Bsp(
|
|
float radius,
|
|
Vector3 boundsCenter = default,
|
|
Vector3 localPosition = default,
|
|
Quaternion localRotation = default)
|
|
=> ShadowShape.Bsp(
|
|
gfxObjId: 0x010044B5u,
|
|
localPosition: localPosition,
|
|
localRotation: localRotation == default ? Quaternion.Identity : localRotation,
|
|
scale: 1f,
|
|
localGeometry: ShadowPartGeometry.Create(
|
|
new FlatCollisionSphere(
|
|
boundsCenter == default ? new Vector3(0f, 6f, 0f) : boundsCenter,
|
|
radius),
|
|
null));
|
|
|
|
private static List<uint> FloodCellsFor(params ShadowShape[] shapes)
|
|
{
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint ownerId = 0xBEEF01u;
|
|
// Centre of the landblock's cell (1,1) so a 14 m footprint stays
|
|
// inside the block's own 8x8 outdoor grid on every side.
|
|
reg.RegisterMultiPart(
|
|
ownerId, new Vector3(36f, 36f, 50f), Quaternion.Identity,
|
|
shapes, 0x10008u, EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
return OutdoorCellsHolding(reg, ownerId);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildFloodSpheres_BspBearingOwner_FloodsFromBspNotFromCylinder()
|
|
{
|
|
List<uint> cylinderOnly = FloodCellsFor(Cyl(0.5f));
|
|
List<uint> bspOnly = FloodCellsFor(Bsp(14f));
|
|
List<uint> mixed = FloodCellsFor(Cyl(0.5f), Bsp(14f));
|
|
|
|
|
|
// Controls: the two footprints must actually differ, or the fact below
|
|
// is satisfiable by any dispatch rule at all.
|
|
Assert.Equal([LbId | 10u], cylinderOnly);
|
|
Assert.True(bspOnly.Count > 1,
|
|
$"BSP footprint control failed: expected >1 cell, got {bspOnly.Count}");
|
|
|
|
// The fact: a mixed list floods from the BSP shapes, exactly as if the
|
|
// cylinder were not there. Retail 0x0051528f.
|
|
Assert.Equal(bspOnly, mixed);
|
|
Assert.NotEqual(cylinderOnly, mixed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// AP-156. Retail's per-part cross-cell walk transforms the BSP root
|
|
/// bounding sphere's CENTRE through the part's own frame before it uses
|
|
/// the radius: <c>CGfxObj::physics_sphere</c> is
|
|
/// <c>BSPTREE::GetSphere(physics_bsp)</c> @0x005397e0 (root
|
|
/// <c>BSPNODE</c> + 4, past its vftable), and
|
|
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 — the part-array
|
|
/// overload reached from <c>find_bbox_cell_list</c> @0x00510fc0 through
|
|
/// <c>CPartArray::calc_cross_cells_static</c> @0x00518160's
|
|
/// <c>[vtbl+0x7c]</c> — loads it at <c>0x0052cb36 mov esi,[ecx+0x74]</c>,
|
|
/// runs <c>Position::localtolocal</c> on it against
|
|
/// <c>[part+0x30]</c> (<c>0x0052cb4c add eax,0x30</c>), and only then
|
|
/// reads <c>[esi+0xc]</c> for the radius.
|
|
///
|
|
/// <para>
|
|
/// acdream used to flood from the part ORIGIN with the sphere's radius.
|
|
/// Over the installed DAT that failed to contain the parts' own physics
|
|
/// polygons for 428 of the 530 BSP-bearing Setups, shortfall up to
|
|
/// 35.869 m at entity scale 1.75 (0x0200129A) — under-inclusive
|
|
/// membership, the #98 / #168 class. (172 is AP-152's DISPATCH
|
|
/// population; the AP-156 row's original "170 of 172" understated this
|
|
/// 2.5x and was corrected at the fix review.)
|
|
/// </para>
|
|
/// </summary>
|
|
[Fact]
|
|
public void BuildFloodSpheres_BspShape_CentresOnTheBoundsCentreNotThePartOrigin()
|
|
{
|
|
// Same sphere, three placements of the SAME 6 m radius:
|
|
// a) part origin at (0,0,0), bounds centre at the origin too;
|
|
// b) part origin at (0,0,0), bounds centre 30 m along +Y;
|
|
// c) part origin 30 m along +Y, bounds centre at the origin.
|
|
// (b) and (c) describe the identical world sphere, so they must flood
|
|
// the identical cells — and neither may equal (a).
|
|
List<uint> concentric = FloodCellsFor(
|
|
Bsp(6f, boundsCenter: new Vector3(0.001f, 0f, 0f)));
|
|
List<uint> viaBoundsCentre = FloodCellsFor(
|
|
Bsp(6f, boundsCenter: new Vector3(0f, 30f, 0f)));
|
|
List<uint> viaPartOrigin = FloodCellsFor(
|
|
Bsp(6f,
|
|
boundsCenter: new Vector3(0.001f, 0f, 0f),
|
|
localPosition: new Vector3(0f, 30f, 0f)));
|
|
|
|
// Control: the offset must actually move the footprint, or the
|
|
// equality below is satisfiable by ignoring BoundsCenter entirely.
|
|
Assert.NotEqual(concentric, viaBoundsCentre);
|
|
|
|
Assert.Equal(viaPartOrigin, viaBoundsCentre);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retail's 10-sphere clamp is on the CYLSPHERE branch and nowhere else.
|
|
/// <c>CObjCell::find_cell_list</c> @0x0052b9f0 clamps the cylsphere count
|
|
/// (<c>0x0052ba21 cmp eax,0xa</c> / <c>0x0052ba28 mov ebp,0xa</c>); the
|
|
/// BSP branch — <c>find_bbox_cell_list</c> @0x00510fc0 →
|
|
/// <c>CPartArray::calc_cross_cells_static</c> @0x00518160 →
|
|
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 — walks every part with
|
|
/// no cap, and the sorting-sphere overload @0x0052b990 takes one sphere.
|
|
/// 7 installed Setups carry more than 10 physics-BSP parts (max 49,
|
|
/// Setup 0x02001A91) and landblock-baked stair runs and fences routinely
|
|
/// do, so clamping the BSP branch dropped their tail parts out of the
|
|
/// flood entirely.
|
|
/// </summary>
|
|
[Fact]
|
|
public void BuildFloodSpheres_CapsCylSpheresAtTenButNeverTheBspParts()
|
|
{
|
|
// Ten shapes on the owner's own cell, then an eleventh 72 m north.
|
|
var near = new Vector3(0f, 0f, 0f);
|
|
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 bsp = new ShadowShape[11];
|
|
for (int i = 0; i < 10; i++)
|
|
bsp[i] = Bsp(1f, boundsCenter: new Vector3(0.001f, 0f, 0f));
|
|
bsp[10] = Bsp(1f, boundsCenter: far);
|
|
List<uint> bspCells = FloodCellsFor(bsp);
|
|
|
|
var cyls = new ShadowShape[11];
|
|
for (int i = 0; i < 10; i++)
|
|
cyls[i] = Cyl(1f, near);
|
|
cyls[10] = Cyl(1f, far);
|
|
List<uint> cylCells = FloodCellsFor(cyls);
|
|
|
|
Assert.Contains(ownCell, bspCells);
|
|
Assert.Contains(ownCell, cylCells);
|
|
|
|
// The eleventh BSP part still floods; the eleventh cylsphere does not.
|
|
Assert.Contains(farCell, bspCells);
|
|
Assert.DoesNotContain(farCell, cylCells);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The BoundsCentre is expressed in the SHAPE's own frame, so the part's
|
|
/// LocalRotation must carry it — exactly as retail transforms the sphere
|
|
/// centre through <c>[part+0x30]</c>, the part's full Position, not just
|
|
/// its origin. A +Y offset on a part yawed 180 degrees must land at -Y.
|
|
/// </summary>
|
|
[Fact]
|
|
public void BuildFloodSpheres_BspShape_RotatesTheBoundsCentreByThePartRotation()
|
|
{
|
|
Quaternion yaw180 = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathF.PI);
|
|
|
|
List<uint> yawed = FloodCellsFor(
|
|
Bsp(6f, boundsCenter: new Vector3(0f, 20f, 0f), localRotation: yaw180));
|
|
List<uint> negatedUnrotated = FloodCellsFor(
|
|
Bsp(6f, boundsCenter: new Vector3(0f, -20f, 0f)));
|
|
List<uint> unrotated = FloodCellsFor(
|
|
Bsp(6f, boundsCenter: new Vector3(0f, 20f, 0f)));
|
|
|
|
Assert.NotEqual(unrotated, negatedUnrotated); // control
|
|
Assert.Equal(negatedUnrotated, yawed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The AP-152 delta end-to-end: a CylSphere+BSP Setup (73 of the 172
|
|
/// affected installed Setups are this shape) registered through the
|
|
/// production builder. Before the fix the emitted list carried both, and
|
|
/// BuildFloodSpheres' cylinder preference confined the owner to the
|
|
/// cylinder's cell while its slab BSP reached further — an object absent
|
|
/// from shadow cells it physically occupies, the #98 / #168 symptom class.
|
|
///
|
|
/// <para>
|
|
/// The BSP bounds are supplied through the production seam
|
|
/// (<c>physicsBspBounds</c>, the same resolver
|
|
/// <c>LiveEntityCollisionBuilder</c> passes) and are OFF-CENTRE, so the
|
|
/// flood is asserted where the geometry is rather than where the part
|
|
/// origin is.
|
|
/// </para>
|
|
/// </summary>
|
|
[Fact]
|
|
public void FromSetup_CylSphereAndBspSetup_FloodsTheBspFootprint()
|
|
{
|
|
const uint part = 0x010044B5u;
|
|
var setup = new DatReaderWriter.DBObjs.Setup
|
|
{
|
|
Parts = { part },
|
|
CylSpheres = { new DatReaderWriter.Types.CylSphere
|
|
{ Radius = 0.5f, Height = 1f, Origin = Vector3.Zero } },
|
|
};
|
|
|
|
// 14 m stands in for a slab wide enough to leave its own landcell;
|
|
// the +18 m Y offset stands in for the 376-of-973 installed parts
|
|
// whose root sphere is nowhere near the part origin.
|
|
var bounds = new FlatCollisionSphere(new Vector3(0f, 18f, 0f), 14f);
|
|
IReadOnlyList<ShadowShape> shapes = ShadowShapeBuilder.FromSetup(
|
|
setup,
|
|
entScale: 1f,
|
|
hasPhysicsBsp: id => id == part,
|
|
physicsBspBounds: id => id == part
|
|
? ShadowPartGeometry.Create(bounds, null)
|
|
: (ShadowPartGeometry?)null);
|
|
|
|
ShadowShape only = Assert.Single(shapes);
|
|
Assert.Equal(ShadowCollisionType.BSP, only.CollisionType);
|
|
Assert.Equal(14f, only.Radius);
|
|
Assert.Equal(new Vector3(0f, 18f, 0f), only.BoundsCenter);
|
|
|
|
var reg = new ShadowObjectRegistry();
|
|
const uint ownerId = 0xBEEF02u;
|
|
reg.RegisterMultiPart(
|
|
ownerId, new Vector3(36f, 36f, 50f), Quaternion.Identity,
|
|
shapes, 0x10008u, EntityCollisionFlags.None, OffX, OffY, LbId);
|
|
|
|
List<uint> cells = OutdoorCellsHolding(reg, ownerId);
|
|
Assert.True(cells.Count > 1,
|
|
$"Expected the slab footprint to span more than its own landcell; got {cells.Count}");
|
|
// Landcells are 24 m. The slab's sphere is centred at y = 54 m with
|
|
// r = 14 m, so it spans y in [40, 68] — rows 1 and 2, and it comes no
|
|
// closer than 16 m to row 0 (y < 24). Flooding it around the PART
|
|
// ORIGIN instead (y = 36 m, span [22, 50]) would drag row 0 in.
|
|
Assert.Contains(LbId | (uint)(1 * 8 + 2 + 1), cells); // (x=1, y=2)
|
|
Assert.DoesNotContain(LbId | (uint)(1 * 8 + 0 + 1), cells); // (x=1, y=0)
|
|
}
|
|
}
|