fix #203: preserve animation on appearance updates

This commit is contained in:
Erik 2026-07-11 00:25:29 +02:00
parent ff06aa3107
commit c7607f019c
9 changed files with 237 additions and 22 deletions

View file

@ -0,0 +1,65 @@
using System.Numerics;
using AcDream.App.Rendering;
using AcDream.Core.Physics;
using AcDream.Core.World;
using DatReaderWriter.DBObjs;
namespace AcDream.App.Tests.Rendering;
public sealed class LiveAppearanceAnimationTests
{
[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 GameWindow.AnimatedEntity
{
Entity = oldEntity,
Setup = setup,
Animation = animation,
LowFrame = 2,
HighFrame = 9,
Framerate = 30f,
Scale = 1f,
PartTemplate = [(0x01000001u, null)],
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: []);
GameWindow.RebindAnimatedEntityForAppearance(
state, oldEntity, setup, 1.25f, dressedParts);
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));
}
private static WorldEntity Entity(uint id, uint gfxObjId) => new()
{
Id = id,
ServerGuid = 0x50000001u,
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;
}
}

View file

@ -232,13 +232,11 @@ public class EntityClassificationCacheTests
}
[Fact]
public void DespawnRespawn_UnderReusedId_RepopulatesFresh()
public void InvalidateRepopulate_UnderReusedId_RepopulatesFresh()
{
// Pins the audit's ObjDescEvent contract (audit section 1):
// ObjDescEvent is despawn + respawn (with a NEW local entity.Id),
// never an in-place mutation. Even when an id IS reused
// (theoretical — _liveEntityIdCounter is monotonic in practice),
// the cache must serve fresh data after invalidation.
// Appearance updates preserve the entity Id and invalidate this cache
// before the updated MeshRefs are classified. This lower-level test
// pins invalidate-then-repopulate behavior for any reused Id.
var cache = new EntityClassificationCache();
var batchesV1 = new[] { MakeCachedBatch(1, 0, 6, 0xAA) };
var batchesV2 = new[] { MakeCachedBatch(2, 6, 12, 0xCC) };