The AP-152 retail review (docs/research/2026-08-06-ap152-review-retail.md) FAILED `4abd1b5e` and is right. `ShadowObjectRegistry.BuildFloodSpheres` took each physics-BSP part's ROOT BOUNDING SPHERE RADIUS (FlatCollisionAssetBuilder.cs:393 -> LiveEntityCollisionBuilder.cs:137) and centred it on the PART ORIGIN (ShadowShapeBuilder.cs:194), discarding the root sphere's own Origin. Re-measured independently against the installed client_portal.dat, reproducing the reviewer's numbers exactly: 376 of 973 physics-BSP parts have |origin| > radius/2, worst 20.762 m on a 27.708 m sphere (gfx 0x010036DD, Setup 0x0200129A). Over the 172 Setups AP-152 moved onto that path the emitted flood FAILED TO CONTAIN the object's own BSP sphere for 170 of them (73 CylSphere-bearing, 97 Sphere-bearing), worst shortfall 9.911 m on Setup 0x02000255 — whose one part's sphere sits 9.911 m above the part origin — and for 43 the post-AP-152 flood was strictly SMALLER than the pre-AP-152 one. Indoor flooding is 3-D (CellTransit.cs:601 routes every id & 0xFFFF >= 0x0100 candidate through FindTransitCellsSphere), so a tall prop or door slab was absent from EnvCells it physically occupies and therefore never a broadphase candidate there (TransitionTypes.cs:3763 iterates only entries already in the cell). That is the #98 / #168 class AP-152 exists to remove. Retail, re-disassembled from the PDB-paired binary (check_exe_pdb.py MATCH, CodeView GUID 9e847e2f-777c-4bd9-886c-22256bb87f32), every address resolved back through named-retail/symbols.json: CGfxObj::physics_sphere is [gfxobj+0x74] (physics_bsp is [+0x78], as CPartArray::CacheHasPhysicsBSP @0x00518110 reads at 0x00518127), and acclient pseudo-C 0x00534b5b assigns it BSPTREE::GetSphere(physics_bsp). BSPTREE::GetSphere @0x005397e0 8b01 mov eax,[ecx] ; BSPTREE::root_node 83c004 add eax,4 ; past BSPNODE::vfptr -> CSphere sphere So retail's per-part flood sphere IS the BSP root bounding sphere, ORIGIN INCLUDED (acclient.h: BSPNODE { vfptr; CSphere sphere; ... }, CSphere { Vector3 center; float radius; } -> radius at +0xc). CPhysicsObj::find_bbox_cell_list @0x00510fc0 adds the object's own cell and then walks the PART ARRAY: 0x00511012 call 0x518160 (CPartArray::calc_cross_cells_static), which dispatches [edx+0x7c] with (num_parts, parts, cellarray). Its EnvCell body, CEnvCell::find_transit_cells @0x0052cae0: 0x0052cb31 mov edx,[eax+0x20] ; CPhysicsPart::gfxobj (CGfxObj**) 0x0052cb36 mov esi,[ecx+0x74] ; physics_sphere (else +0x90 drawing) 0x0052cb4c add eax,0x30 ; CPhysicsPart::pos 0x0052cb5a call Position::localtolocal ; transform the sphere CENTRE 0x0052cb65 fadd [esi+0xc] ; only NOW the radius Retail transforms the centre through the part's own Position before it ever touches the radius. Carrying the radius alone is not an approximation of that; it is a different sphere. Changes: * `ShadowShape` gains `BoundsCenter` — the bounding sphere's centre in the shape's own local frame, scaled like LocalPosition and Radius. Zero for Cylinder/Sphere shapes, whose LocalPosition already IS their centre. * `ShadowShapeBuilder.FromSetup` gains a `physicsBspBounds` resolver that supplies radius AND centre from ONE call, replacing the placeholder radius plus a downstream substitution. `LiveEntityCollisionBuilder` now holds a single `Func<uint, FlatCollisionSphere?>` and derives its dispatch predicate from it, so the gate and the geometry cannot disagree and the radius cannot be taken while the origin is dropped. That split is what produced this bug; it no longer exists. * `FromLandblockBspParts` carries the centre too. A landblock-baked part array is the same CPartArray walk, so stair runs, fences and rock clusters had the identical defect. Both storage forms (flat BSP and the graph fallback) are covered. * `BuildFloodSpheres` places each sphere at partWorldPos + rotate(BoundsCenter, partWorldRot), composed exactly as the ShadowEntry rows are. * The 10-sphere clamp now applies to the CYLSPHERE branch only. Retail's clamp is inside CObjCell::find_cell_list @0x0052b9f0 (0x0052ba21 cmp eax,0xa / 0x0052ba28 mov ebp,0xa); the BSP walk has none and the sorting-sphere overload @0x0052b990 takes one sphere. 7 installed Setups carry more than 10 physics-BSP parts (max 49, Setup 0x02001A91) and their tail parts were dropped from the flood entirely. Without this the new containment assertion would have covered shapes production never floods from. Register. AP-155 was two divergences with different code paths, populations and gates under one id; it is NARROWED to its static-publication half and its flood half is split out as AP-156 WITH ITS DIRECTION CORRECTED. AP-155(b) recorded the approximation as over-inclusive — "floods MORE cells rather than fewer, the safe direction for membership" — and that false direction was the stated reason the residual was safe to defer. It was under-inclusive for 170 of 172. AP-156 records the correction, this fix, and the one genuine residual: acdream's sphere-vs-portal traversal where retail walks each part's sphere against the cell's own portal planes. AP-155(b)'s "acdream approximates retail's bounding BOX" was wrong too — find_bbox_cell_list forms no box. AP-157 filed for the review's F4: retail's third branch floods from ONE CPartArray::GetSortingSphere @0x00518b00 ([partArray+0x54]+0x70 = CSetup::sorting_sphere; 4,154 of 5,935 installed Setups carry a non-zero one) where acdream floods from every Sphere shape, and acdream's cylinder flood ignores CylHeight. Deliberately NOT bundled here: different branch, disjoint population, different live gate. Active AP rows 107 -> 109, literal count. Tests. Both flood tests the review named substituted a CONCENTRIC Radius = 14f at LocalPosition = Zero — the one configuration in which the defect cannot appear. Every fixture is now off-centre by default, and `FromSetup_CylSphereAndBspSetup_FloodsTheBspFootprint` drives the production `physicsBspBounds` seam instead of hand-substituting. Five new facts: the flood centres on BoundsCenter not the part origin; it rotates BoundsCenter by the part rotation; it caps cylspheres at ten but never the BSP parts; the landblock path carries the scaled centre in both storage forms; and an installed-DAT containment sweep asserting every emitted BSP flood sphere contains that part's real bounding sphere at entity scale 1.75, behind four external controls — 973 parts, 376 off-centre, 172 affected, and 170 would-fail-if-the-origin-were-discarded, the last of which fails if the population ever stops exercising the field. Nine sabotages, each reverted and re-verified: A drop BoundsCenter from the flood -> 3 Core B rotate by entity rot, not part rot -> 1 Core (the rotation fact only) C FromSetup discards the origin -> 1 Core + 2 App + 1 Content (the shipped defect, now caught in three projects) D drop entScale on BoundsCenter -> 2 App + 1 Content E landblock flat branch drops the centre -> 1 Core F landblock graph branch drops it -> 1 Core G drop partScale on the landblock centre -> 1 Core H re-apply the 10-cap to every branch -> 1 Core I remove the cylsphere cap -> 1 Core AP-152's own two sabotages re-run against this tree: the step-0 gate disabled still reddens exactly its five facts with Headless 89/89 green, and cylinder-first flooding still reddens exactly one. Clean Release build after deleting all 44 bin/obj: 0 errors, 21 pre-existing warnings. Complete suite 11,208 passed / 4 skipped / 0 failed, +5 on the 11,203 baseline at4abd1b5e— Core 4264 -> 4268, Content 126 -> 127, App unchanged (one rename, not an addition). No new skips. NOT yet gated live. This moves shadow-cell membership for real objects, in both directions, and the connected session must look for both: props and doors that START blocking from a neighbouring cell (the 73 CylSphere+BSP Setups), AND ones that STOP blocking (the 99 Sphere+BSP Setups can shrink; 43 shrink below their pre-4abd1b5e size, which is the regression this fixes). Tall indoor props and door slabs — the ones whose sphere sits metres above the part origin — are where the change is largest. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
457 lines
18 KiB
C#
457 lines
18 KiB
C#
using System.Numerics;
|
|
using AcDream.App.Physics;
|
|
using AcDream.App.World;
|
|
using AcDream.Core.Items;
|
|
using AcDream.Core.Net;
|
|
using AcDream.Core.Net.Messages;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World;
|
|
using DatReaderWriter.DBObjs;
|
|
using DatReaderWriter.Types;
|
|
|
|
namespace AcDream.App.Tests.Physics;
|
|
|
|
public sealed class LiveEntityCollisionBuilderTests
|
|
{
|
|
private const uint Guid = 0x70000100u;
|
|
private const uint Cell = 0x01010001u;
|
|
|
|
[Fact]
|
|
public void EffectivePartResolution_IsSetupAndVisualOptionIndependent()
|
|
{
|
|
uint[] resolved = LiveEntityCollisionBuilder.ResolveEffectivePartIdentities(
|
|
[0x01001000u, 0x01002000u],
|
|
id => id == 0x01001000u ? 0x01001001u : id);
|
|
|
|
Assert.Equal([0x01001001u, 0x01002000u], resolved);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Re-hosts the state/flag/seed-cell coverage that used to ride on the
|
|
/// deleted Setup-radius fallback (AP-22). The old fixture was a Setup with
|
|
/// a radius and zero primitives, which cannot exist in client_portal.dat —
|
|
/// all 1,294 shapeless Setups have Radius exactly 0. This uses a
|
|
/// DAT-possible single-CylSphere Setup instead.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Build_PropagatesExactStateFlagsScaleAndFullSeedCell()
|
|
{
|
|
var setup = new Setup();
|
|
setup.CylSpheres.Add(new CylSphere
|
|
{
|
|
Origin = Vector3.Zero,
|
|
Radius = 0.4f,
|
|
Height = 1.2f,
|
|
});
|
|
WorldSession.EntitySpawn spawn = Spawn(
|
|
scale: 2f,
|
|
itemType: (uint)ItemType.Creature,
|
|
descriptionFlags: 0x28u);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
record.FinalPhysicsState =
|
|
PhysicsStateFlags.Hidden | PhysicsStateFlags.Static;
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = Builder();
|
|
|
|
LiveEntityCollisionRegistration registration = Assert.IsType<LiveEntityCollisionRegistration>(
|
|
builder.Build(entity, setup, Array.Empty<uint>(), spawn, record, new Vector3(192f, -192f, 0f)));
|
|
|
|
ShadowShape shape = Assert.Single(registration.Shapes);
|
|
Assert.Equal(ShadowCollisionType.Cylinder, shape.CollisionType);
|
|
Assert.Equal(0.8f, shape.Radius);
|
|
Assert.Equal(2.4f, shape.CylHeight);
|
|
Assert.Equal((uint)record.FinalPhysicsState, registration.State);
|
|
Assert.True(registration.Flags.HasFlag(EntityCollisionFlags.HasWeenie));
|
|
Assert.True(registration.Flags.HasFlag(EntityCollisionFlags.IsCreature));
|
|
Assert.True(registration.Flags.HasFlag(EntityCollisionFlags.IsPlayer));
|
|
Assert.True(registration.Flags.HasFlag(EntityCollisionFlags.IsPK));
|
|
Assert.Equal(Cell, registration.LandblockId);
|
|
Assert.Equal(Cell, registration.SeedCellId);
|
|
Assert.Equal((192f, -192f), (registration.WorldOffsetX, registration.WorldOffsetY));
|
|
}
|
|
|
|
/// <summary>
|
|
/// AP-22: retail synthesizes no shape for a Setup with no primitives and
|
|
/// no physics-BSP part, whatever its summary Radius/Height say.
|
|
/// <c>CPhysicsObj::FindObjCollisions</c> (0x0050f050) branches to the
|
|
/// epilogue at <c>0x0050f22f je 0x50f31b</c> and returns the seeded
|
|
/// OK_TS; <c>CPartArray::GetRadius</c>/<c>GetHeight</c> are absent from
|
|
/// its call set. This is the direct inverse of the deleted
|
|
/// RadiusFallback fact.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ShapelessSetupWithRadius_ProducesNoRegistration()
|
|
{
|
|
var setup = new Setup { Radius = 0.75f, Height = 2.5f };
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 2f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
|
|
Assert.Null(Builder().Build(
|
|
entity,
|
|
setup,
|
|
Array.Empty<uint>(),
|
|
spawn,
|
|
record,
|
|
new Vector3(192f, -192f, 0f)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The BSP root bounding sphere reaches the shape WHOLE — radius and
|
|
/// centre, both scaled. Retail's <c>CGfxObj::physics_sphere</c> is
|
|
/// <c>BSPTREE::GetSphere(physics_bsp)</c> @0x005397e0, and
|
|
/// <c>CEnvCell::find_transit_cells</c> @0x0052cae0 transforms its centre
|
|
/// through the part's Position (<c>0x0052cb4c add eax,0x30</c>) before
|
|
/// reading the radius at <c>0x0052cb65</c>. Carrying only the radius is
|
|
/// AP-156: 170 of the 172 affected installed Setups then flood from a
|
|
/// sphere that does not contain their own collision geometry.
|
|
/// </summary>
|
|
[Fact]
|
|
public void BspOnlyPart_UsesRealScaledPhysicsBoundingSphere()
|
|
{
|
|
const uint part = 0x0100ABCDu;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(part);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1.5f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == part ? Bsp(3f, centerZ: 2f) : null,
|
|
PoseResolver());
|
|
|
|
LiveEntityCollisionRegistration registration = Assert.IsType<LiveEntityCollisionRegistration>(
|
|
builder.Build(entity, setup, [part], spawn, record, Vector3.Zero));
|
|
|
|
ShadowShape shape = Assert.Single(registration.Shapes);
|
|
Assert.Equal(ShadowCollisionType.BSP, shape.CollisionType);
|
|
Assert.Equal(4.5f, shape.Radius); // 3 m * 1.5
|
|
Assert.Equal(new Vector3(0f, 0f, 3f), shape.BoundsCenter); // 2 m * 1.5
|
|
Assert.Equal(part, shape.GfxObjId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// AP-152. Every other fixture in this file is primitive-only or BSP-only,
|
|
/// so nothing at the App layer used to exercise the CylSphere+BSP
|
|
/// combination — 73 of the 172 affected installed Setups.
|
|
/// Retail's <c>CPhysicsObj::FindObjCollisions</c> @0x0050f050 tests
|
|
/// <c>HAS_PHYSICS_BSP_PS</c> at 0x0050f165 and leaves the BSP branch
|
|
/// through the unconditional <c>0x0050f19d jmp 0x50f2b0</c>, past both the
|
|
/// CylSphere loop (0x50f1a2) and the Sphere loop (0x50f21d);
|
|
/// <c>calc_cross_cells</c> @0x00515230 dispatches identically at
|
|
/// 0x00515285. The CylSphere must not survive, and the surviving BSP shape
|
|
/// must still receive the real scaled bounding radius.
|
|
/// </summary>
|
|
[Fact]
|
|
public void CylSphereAndPhysicsBspPart_EmitsOnlyTheScaledBspShape()
|
|
{
|
|
const uint part = 0x0100AC01u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(part);
|
|
setup.CylSpheres.Add(new CylSphere
|
|
{
|
|
Origin = Vector3.Zero,
|
|
Radius = 0.4f,
|
|
Height = 1.2f,
|
|
});
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1.5f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == part ? Bsp(3f, centerZ: 2f) : null,
|
|
PoseResolver());
|
|
|
|
LiveEntityCollisionRegistration registration =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [part], spawn, record, Vector3.Zero));
|
|
|
|
ShadowShape shape = Assert.Single(registration.Shapes);
|
|
Assert.Equal(ShadowCollisionType.BSP, shape.CollisionType);
|
|
Assert.Equal(4.5f, shape.Radius); // 3 m physics-BSP radius * 1.5 scale
|
|
Assert.Equal(new Vector3(0f, 0f, 3f), shape.BoundsCenter);
|
|
Assert.Equal(part, shape.GfxObjId);
|
|
}
|
|
|
|
[Fact]
|
|
public void EffectiveReplacementWithoutPhysicsBsp_RemovesBasePartCollision()
|
|
{
|
|
const uint basePart = 0x0100AB01u;
|
|
const uint replacement = 0x0100AB02u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(basePart);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == basePart ? Bsp(1f) : null,
|
|
PoseResolver());
|
|
|
|
Assert.Null(builder.Build(
|
|
entity,
|
|
setup,
|
|
[replacement],
|
|
spawn,
|
|
record,
|
|
Vector3.Zero));
|
|
}
|
|
|
|
[Fact]
|
|
public void EffectiveReplacementWithPhysicsBsp_AddsReplacementCollision()
|
|
{
|
|
const uint basePart = 0x0100AB11u;
|
|
const uint replacement = 0x0100AB12u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(basePart);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == replacement ? Bsp(2.25f) : null,
|
|
PoseResolver());
|
|
|
|
LiveEntityCollisionRegistration registration =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity,
|
|
setup,
|
|
[replacement],
|
|
spawn,
|
|
record,
|
|
Vector3.Zero));
|
|
|
|
ShadowShape shape = Assert.Single(registration.Shapes);
|
|
Assert.Equal(replacement, shape.GfxObjId);
|
|
Assert.Equal(2.25f, shape.Radius);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReconcileAppearance_VisibleReplacementWithoutBspRemovesOldPayload()
|
|
{
|
|
const uint basePart = 0x0100AC01u;
|
|
const uint replacement = 0x0100AC02u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(basePart);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == basePart ? Bsp(1f) : null,
|
|
PoseResolver());
|
|
LiveEntityCollisionRegistration initial =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [basePart], spawn, record, Vector3.Zero));
|
|
var registry = new ShadowObjectRegistry();
|
|
LiveEntityCollisionBuilder.Register(registry, initial);
|
|
|
|
LiveEntityCollisionRegistration? changed = builder.Build(
|
|
entity, setup, [replacement], spawn, record, Vector3.Zero,
|
|
retainEmptyPayload: true);
|
|
LiveEntityCollisionBuilder.ReconcileAppearance(
|
|
registry, entity.Id, changed, suspendIfNew: false);
|
|
|
|
Assert.Equal(1, registry.RetainedRegistrationCount);
|
|
Assert.DoesNotContain(
|
|
registry.GetObjectsInCell(Cell),
|
|
entry => entry.EntityId == entity.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReconcileAppearance_SuspendedReplacementRetainsNewPayloadUntilRestore()
|
|
{
|
|
const uint basePart = 0x0100AC11u;
|
|
const uint replacement = 0x0100AC12u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(basePart);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == basePart || id == replacement ? Bsp(1f) : null,
|
|
PoseResolver());
|
|
LiveEntityCollisionRegistration initial =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [basePart], spawn, record, Vector3.Zero));
|
|
var registry = new ShadowObjectRegistry();
|
|
LiveEntityCollisionBuilder.Register(registry, initial);
|
|
Assert.True(registry.Suspend(entity.Id));
|
|
LiveEntityCollisionRegistration changed =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [replacement], spawn, record, Vector3.Zero));
|
|
|
|
LiveEntityCollisionBuilder.ReconcileAppearance(
|
|
registry, entity.Id, changed, suspendIfNew: true);
|
|
|
|
Assert.Equal(1, registry.RetainedRegistrationCount);
|
|
Assert.Equal(1, registry.SuspendedRegistrationCount);
|
|
Assert.DoesNotContain(
|
|
registry.GetObjectsInCell(Cell),
|
|
entry => entry.EntityId == entity.Id);
|
|
|
|
LiveEntityCollisionRegistration empty =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity,
|
|
setup,
|
|
[0x0100AC13u],
|
|
spawn,
|
|
record,
|
|
Vector3.Zero,
|
|
retainEmptyPayload: true));
|
|
LiveEntityCollisionBuilder.ReconcileAppearance(
|
|
registry, entity.Id, empty, suspendIfNew: true);
|
|
LiveEntityCollisionBuilder.ReconcileAppearance(
|
|
registry, entity.Id, changed, suspendIfNew: true);
|
|
Assert.Equal(1, registry.RetainedRegistrationCount);
|
|
Assert.Equal(1, registry.SuspendedRegistrationCount);
|
|
|
|
registry.UpdatePosition(
|
|
entity.Id,
|
|
entity.Position,
|
|
entity.Rotation,
|
|
worldOffsetX: 0f,
|
|
worldOffsetY: 0f,
|
|
landblockId: Cell,
|
|
seedCellId: Cell);
|
|
ShadowEntry restored = Assert.Single(
|
|
registry.GetObjectsInCell(Cell),
|
|
entry => entry.EntityId == entity.Id);
|
|
Assert.Equal(replacement, restored.GfxObjId);
|
|
Assert.Equal(0, registry.SuspendedRegistrationCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReconcileAppearance_ExistingMembershipDoesNotDependOnNewFlood()
|
|
{
|
|
const uint basePart = 0x0100AC21u;
|
|
const uint replacement = 0x0100AC22u;
|
|
var setup = new Setup();
|
|
setup.Parts.Add(basePart);
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
var builder = new LiveEntityCollisionBuilder(
|
|
id => id == basePart || id == replacement ? Bsp(1f) : null,
|
|
PoseResolver());
|
|
LiveEntityCollisionRegistration initial =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [basePart], spawn, record, Vector3.Zero));
|
|
var registry = new ShadowObjectRegistry();
|
|
LiveEntityCollisionBuilder.Register(registry, initial);
|
|
LiveEntityCollisionRegistration changed =
|
|
Assert.IsType<LiveEntityCollisionRegistration>(builder.Build(
|
|
entity, setup, [replacement], spawn, record, Vector3.Zero))
|
|
with
|
|
{
|
|
LandblockId = 0u,
|
|
SeedCellId = 0u,
|
|
};
|
|
|
|
LiveEntityCollisionBuilder.ReconcileAppearance(
|
|
registry, entity.Id, changed, suspendIfNew: false);
|
|
|
|
ShadowEntry entry = Assert.Single(
|
|
registry.GetObjectsInCell(Cell),
|
|
candidate => candidate.EntityId == entity.Id);
|
|
Assert.Equal(replacement, entry.GfxObjId);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShapelessSetup_ProducesNoRegistration()
|
|
{
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var record = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
WorldEntity entity = Entity();
|
|
record.WorldEntity = entity;
|
|
|
|
Assert.Null(Builder().Build(
|
|
entity,
|
|
new Setup(),
|
|
Array.Empty<uint>(),
|
|
spawn,
|
|
record,
|
|
Vector3.Zero));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_RejectsDifferentRecordIncarnation()
|
|
{
|
|
WorldSession.EntitySpawn spawn = Spawn(scale: 1f);
|
|
var expected = LiveEntityTestFixture.CreateExactProjectionRecord(spawn);
|
|
var other = LiveEntityTestFixture.CreateExactProjectionRecord(
|
|
spawn with { InstanceSequence = 2 });
|
|
WorldEntity entity = Entity();
|
|
expected.WorldEntity = entity;
|
|
other.WorldEntity = entity;
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Builder().Build(
|
|
entity,
|
|
new Setup { Radius = 1f },
|
|
Array.Empty<uint>(),
|
|
spawn,
|
|
other,
|
|
Vector3.Zero));
|
|
}
|
|
|
|
private static LiveEntityCollisionBuilder Builder() => new(
|
|
_ => null,
|
|
PoseResolver());
|
|
|
|
/// <summary>
|
|
/// A physics-BSP root bounding sphere. DELIBERATELY OFF-CENTRE by
|
|
/// default: a GfxObj's BSP is authored in the GfxObj's own coordinates
|
|
/// and its root sphere is usually NOT centred on that origin (376 of the
|
|
/// 973 installed physics-BSP parts sit further from it than half their
|
|
/// radius). A fixture pinned at <c>Vector3.Zero</c> cannot observe the
|
|
/// centre at all — which is how AP-156's discarded origin stayed green.
|
|
/// </summary>
|
|
private static FlatCollisionSphere? Bsp(float radius, float centerZ = 1.25f)
|
|
=> new FlatCollisionSphere(new Vector3(0f, 0f, centerZ), radius);
|
|
|
|
private static LiveEntityDefaultPoseResolver PoseResolver() => new(
|
|
_ => null,
|
|
new NullAnimationLoader(),
|
|
dumpMotion: false);
|
|
|
|
private static WorldEntity Entity() => new()
|
|
{
|
|
Id = 101u,
|
|
ServerGuid = Guid,
|
|
SourceGfxObjOrSetupId = 0x02000100u,
|
|
Position = new Vector3(4f, 5f, 6f),
|
|
Rotation = Quaternion.Identity,
|
|
MeshRefs = Array.Empty<MeshRef>(),
|
|
ParentCellId = Cell,
|
|
};
|
|
|
|
private static WorldSession.EntitySpawn Spawn(
|
|
float scale,
|
|
uint? itemType = null,
|
|
uint? descriptionFlags = null) =>
|
|
new(
|
|
Guid,
|
|
new CreateObject.ServerPosition(Cell, 4f, 5f, 6f, 1f, 0f, 0f, 0f),
|
|
0x02000100u,
|
|
Array.Empty<CreateObject.AnimPartChange>(),
|
|
Array.Empty<CreateObject.TextureChange>(),
|
|
Array.Empty<CreateObject.SubPaletteSwap>(),
|
|
BasePaletteId: null,
|
|
ObjScale: scale,
|
|
Name: "collision fixture",
|
|
ItemType: itemType,
|
|
MotionState: null,
|
|
MotionTableId: null,
|
|
PhysicsState: 0u,
|
|
ObjectDescriptionFlags: descriptionFlags,
|
|
InstanceSequence: 1);
|
|
|
|
private sealed class NullAnimationLoader : IAnimationLoader
|
|
{
|
|
public Animation? LoadAnimation(uint id) => null;
|
|
}
|
|
}
|