using System.Numerics; using AcDream.App.Rendering.Wb; using AcDream.Core.World; namespace AcDream.App.Tests.Rendering.Wb; public sealed class WbDrawDispatcherCompositeWarmupTests { private const uint Destination = 0x1234FFFFu; [Fact] public void NewlyPublishedEntitySnapshotRequiresRebuildAfterPriorSnapshotWasReady() { IReadOnlyList emptyReadySnapshot = Array.Empty(); IReadOnlyList publishedDestinationSnapshot = [CreateEntity(parentCell: Destination, withPalette: true)]; Assert.True(WbDrawDispatcher.RequiresCompositeWarmupRebuild( emptyReadySnapshot, Destination, currentRadius: 0, currentGeneration: 0, publishedDestinationSnapshot, nextGeneration: 1, Destination, nextRadius: 0)); } [Fact] public void MutatedStableEntityViewRequiresRebuildWhenGenerationChanges() { IReadOnlyList stableView = new List(); Assert.True(WbDrawDispatcher.RequiresCompositeWarmupRebuild( stableView, Destination, currentRadius: 0, currentGeneration: 41, stableView, nextGeneration: 42, Destination, nextRadius: 0)); } [Fact] public void PaletteEntityInsideDestinationRadiusIsCandidate() { WorldEntity entity = CreateEntity(parentCell: 0x1235FFFEu, withPalette: true); Assert.True(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 1)); } [Fact] public void EntityOutsideDestinationRadiusIsExcluded() { WorldEntity entity = CreateEntity(parentCell: 0x1236FFFEu, withPalette: true); Assert.False(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 1)); } [Fact] public void CellLessEntityIsExcludedFromKnownDestination() { WorldEntity entity = CreateEntity(parentCell: null, withPalette: true); Assert.False(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 1)); } [Fact] public void SameLandblockIndoorCellIsCandidateAtZeroRadius() { WorldEntity entity = CreateEntity(parentCell: 0x1234012Au, withPalette: true); Assert.True(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 0)); } [Fact] public void EntityWithoutPaletteOrSurfaceOverridesIsExcluded() { WorldEntity entity = CreateEntity(parentCell: Destination, withPalette: false); Assert.False(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 0)); } [Fact] public void SurfaceOverrideEntityIsCandidateWithoutPalette() { WorldEntity entity = CreateEntity(parentCell: Destination, withPalette: false); entity.MeshRefs = [ new MeshRef(0x01000001u, Matrix4x4.Identity) { SurfaceOverrides = new Dictionary { [0x08000001u] = 0x05000001u }, }, ]; Assert.True(WbDrawDispatcher.IsCompositeWarmupCandidate(entity, Destination, radius: 0)); } private static WorldEntity CreateEntity(uint? parentCell, bool withPalette) => new() { Id = 1, SourceGfxObjOrSetupId = 0x01000001u, Position = Vector3.Zero, Rotation = Quaternion.Identity, MeshRefs = [new MeshRef(0x01000001u, Matrix4x4.Identity)], ParentCellId = parentCell, PaletteOverride = withPalette ? new PaletteOverride(0x04000001u, Array.Empty()) : null, }; }