acdream/tests/AcDream.App.Tests/Rendering/LiveAppearanceAnimationTests.cs
Erik 55b07f6a62
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
refactor(physics): hoist the live-entity collision builder to Runtime (#330 groundwork)
LiveEntityCollisionBuilder and LiveEntityDefaultPoseResolver move from
AcDream.App.Physics to AcDream.Runtime.Physics with no behaviour change
— diff-verified byte-identical shape math by both review lenses. The
Build signature's App-record parameter is replaced by presentation-free
primitives with identical guard semantics, INCLUDING the
FinalPhysicsState read the contract had missed and the implementer
surfaced rather than dropped. Visibility stays internal: Runtime's
existing InternalsVisibleTo grants already cover every consumer, so the
implementation's public widening is reverted per the architecture
review's finding 11.

The registration WIRING is deliberately WITHHELD. Both Opus lenses
failed it, converging: a shadow registered at spawn freezes there
(RuntimeRemotePhysicsUpdater is Runtime-homed but App-driven — nothing
headless ticks it), so a walking NPC becomes a phantom obstacle at its
spawn point while the real NPC still passes through the bot; three of
five shadow-lifetime edges leaked (pickup leaves a permanent invisible
collider, supersession orphans a duplicate, generation reset never
unregisters and the K-ledger convergence oracle only checks retained
shadows AFTER disposal clears them); and headless cannot resolve BSP
collision assets at all, so doors and chests would still be
walk-through. The frozen-shadow root was the SESSION LEAD's contract
error (fact 3), not the implementer's.

#330 stays OPEN, rewritten as the seven-point scope map the reviews
produced — the honest overnight deliverable is that map, not a
half-mechanism carrying new divergences.

Suite 11,235 passed / 4 skipped / 0 failed (the withheld seam's two
tests account for the delta from the implementation run's 11,237).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 01:49:13 +02:00

209 lines
7.5 KiB
C#

using System.Numerics;
using AcDream.App.Rendering;
using AcDream.App.Streaming;
using AcDream.App.World;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
using AcDream.Core.Physics;
using AcDream.Core.World;
using AcDream.Runtime.Physics;
using DatReaderWriter.DBObjs;
namespace AcDream.App.Tests.Rendering;
public sealed class LiveAppearanceAnimationTests
{
[Fact]
public void Capture_UsesCanonicalRecordEntityAndAnimationOwner()
{
const uint guid = 0x70000002u;
var runtime = LiveEntityRuntimeFixture.Create(
new AcDream.App.Streaming.GpuWorldState(),
new AcDream.App.World.DelegateLiveEntityResourceLifecycle(_ => { }, _ => { }));
var spawn = new AcDream.Core.Net.WorldSession.EntitySpawn(
guid,
Position: null,
SetupTableId: null,
AnimPartChanges: Array.Empty<AcDream.Core.Net.Messages.CreateObject.AnimPartChange>(),
TextureChanges: Array.Empty<AcDream.Core.Net.Messages.CreateObject.TextureChange>(),
SubPalettes: Array.Empty<AcDream.Core.Net.Messages.CreateObject.SubPaletteSwap>(),
BasePaletteId: null,
ObjScale: null,
Name: "appearance fixture",
ItemType: null,
MotionState: null,
MotionTableId: null,
InstanceSequence: 1).WithConsistentPhysics();
LiveEntityRecord record = runtime.RegisterAndMaterializeProjection(
spawn,
id => Entity(id, 0x01000001u, guid));
WorldEntity entity = Assert.IsType<WorldEntity>(record.WorldEntity);
var state = new LiveEntityAnimationState
{
Entity = entity,
Setup = new Setup(),
Animation = new Animation(),
LowFrame = 0,
HighFrame = 0,
Framerate = 0f,
Scale = 1f,
PartTemplate = Array.Empty<LiveAnimationPartTemplate>(),
PartAvailability = Array.Empty<bool>(),
};
record.AnimationRuntime = state;
LiveEntityAppearanceUpdateState captured = Assert.IsType<LiveEntityAppearanceUpdateState>(
LiveEntityAppearanceBinding.Capture(runtime, guid));
Assert.Same(entity, captured.Entity);
Assert.Same(state, captured.Animation);
}
[Fact]
public void RebindAppearance_PreservesEntitySequencerAndPlaybackState()
{
var setup = new Setup();
var animation = new Animation();
var sequencer = new AnimationSequencer(setup, new MotionTable(), new NullLoader());
var oldEntity = Entity(0x70000001u, 0x01000001u);
var state = new LiveEntityAnimationState
{
Entity = oldEntity,
Setup = setup,
Animation = animation,
LowFrame = 2,
HighFrame = 9,
Framerate = 30f,
Scale = 1f,
PartTemplate = [new LiveAnimationPartTemplate(0x01000001u, null, true)],
PartAvailability = [true],
CurrFrame = 6.5f,
Sequencer = sequencer,
};
IReadOnlyList<MeshRef> dressedParts =
[
new MeshRef(0x01000002u, Matrix4x4.Identity),
new MeshRef(0x01000003u, Matrix4x4.CreateTranslation(1f, 2f, 3f)),
];
oldEntity.ApplyAppearance(dressedParts, paletteOverride: null, partOverrides: []);
LiveEntityAppearanceBinding.RebindAnimation(
state,
oldEntity,
setup,
1.25f,
[
new LiveAnimationPartTemplate(0x01000002u, null, true),
new LiveAnimationPartTemplate(0x01000003u, null, true),
],
[true, true]);
Assert.Same(oldEntity, state.Entity);
Assert.Same(dressedParts, state.Entity.MeshRefs);
Assert.Same(sequencer, state.Sequencer);
Assert.Equal(6.5f, state.CurrFrame);
Assert.Equal((2, 9, 30f), (state.LowFrame, state.HighFrame, state.Framerate));
Assert.Equal(1.25f, state.Scale);
Assert.Equal(new[] { 0x01000002u, 0x01000003u },
state.PartTemplate.Select(part => part.GfxObjId));
}
[Fact]
public void CollisionCommit_DelayedOldIncarnationCannotMutateGuidReplacement()
{
const uint guid = 0x70000010u;
const uint cell = 0x01010001u;
var spatial = new GpuWorldState();
spatial.AddLandblock(new LoadedLandblock(
0x0101FFFFu,
new LandBlock(),
Array.Empty<WorldEntity>()));
var runtime = LiveEntityRuntimeFixture.Create(
spatial,
new DelegateLiveEntityResourceLifecycle(_ => { }, _ => { }));
WorldSession.EntitySpawn first = Spawn(guid, cell, instance: 1);
runtime.RegisterLiveEntity(first);
WorldEntity oldEntity = runtime.MaterializeLiveEntity(
guid,
cell,
id => new WorldEntity
{
Id = id,
ServerGuid = guid,
SourceGfxObjOrSetupId = 0x02000010u,
Position = Vector3.One,
Rotation = Quaternion.Identity,
MeshRefs = Array.Empty<MeshRef>(),
ParentCellId = cell,
})!;
var registry = new ShadowObjectRegistry();
registry.Register(
oldEntity.Id,
0x01000010u,
oldEntity.Position,
oldEntity.Rotation,
radius: 0.5f,
worldOffsetX: 0f,
worldOffsetY: 0f,
landblockId: cell,
seedCellId: cell,
isStatic: false);
var builder = new LiveEntityCollisionBuilder(
_ => null,
new LiveEntityDefaultPoseResolver(
_ => null,
new NullLoader(),
dumpMotion: false));
LiveEntityAppearanceCollisionUpdate update =
Assert.IsType<LiveEntityAppearanceCollisionUpdate>(
LiveEntityAppearanceBinding.PrepareCollision(
runtime,
builder,
oldEntity,
new Setup(),
Array.Empty<uint>(),
first,
Vector3.Zero));
runtime.RegisterLiveEntity(Spawn(guid, cell, instance: 2));
Assert.False(LiveEntityAppearanceBinding.CommitCollision(
runtime,
registry,
update));
Assert.Equal(1, registry.RetainedRegistrationCount);
}
private static WorldSession.EntitySpawn Spawn(uint guid, uint cell, ushort instance) => new WorldSession.EntitySpawn(
guid,
new CreateObject.ServerPosition(cell, 1f, 1f, 1f, 1f, 0f, 0f, 0f),
0x02000010u,
Array.Empty<CreateObject.AnimPartChange>(),
Array.Empty<CreateObject.TextureChange>(),
Array.Empty<CreateObject.SubPaletteSwap>(),
BasePaletteId: null,
ObjScale: 1f,
Name: "appearance collision fixture",
ItemType: null,
MotionState: null,
MotionTableId: null,
InstanceSequence: instance).WithConsistentPhysics();
private static WorldEntity Entity(
uint id,
uint gfxObjId,
uint serverGuid = 0x50000001u) => new()
{
Id = id,
ServerGuid = serverGuid,
SourceGfxObjOrSetupId = 0x02000001u,
Position = Vector3.Zero,
Rotation = Quaternion.Identity,
MeshRefs = [new MeshRef(gfxObjId, Matrix4x4.Identity)],
};
private sealed class NullLoader : IAnimationLoader
{
public Animation? LoadAnimation(uint id) => null;
}
}