acdream/tests/AcDream.App.Tests/Rendering/SkyPesFrameControllerTests.cs
Erik 18fce7bb5a fix #28: port retail's sky default-script playback (aurora) and the particle facing law
The aurora was never missing data — it was a missing mechanism plus a
misread. New decompile evidence closes the April-2026 contradiction:
retail plays the sky carriers' PES through the Setup's own DefaultScript
(GameSky::MakeObject @0x00506EE0 -> CPhysicsObj::makeObject @0x00513970
sets state|=0x80000; animate_static_object @0x00513DF0 ticks
ScriptManager + ParticleManager). The pes_id column stays dead — that
half of the April finding stands; the ids are byte-equal mirrors.

- SkyPesFrameController is now the production owner (ACDREAM_ENABLE_SKY_PES
  deleted): script ids resolve from the Setup DefaultScript
  (SkyObjectData.DefaultScriptId; the pes_id column is a one-time-logged
  cross-check), slots persist by (index, gfx id, properties) per
  CreateDeletePhysicsObjects @0x005073C0 — a day-group swap keeping the
  carrier no longer restarts its emitters — and stale slots stop before
  replacements claim the slot-derived owner id.
- RetailParticleFacing ports calc_draw_frame @0x0050DFA0: degrade mode 2
  faces the viewer roll-free (set_vector_heading) instead of the camera
  plane; modes 3/4/5 spin the authored frame around one local axis
  (rotate_around_axis_to_vector) — Dereth authors 54 mode-5 emitters that
  previously got no facing at all; 1,583 mode-2 emitters get the exact
  law; authored/mode-1 paths are unchanged.
- The 2026-08-23 'whole-sky tint' was the Rainy-group lightning/thunder
  PES playing at the debug anchor inside their 0.03-0.19 window, not the
  aurora: the aurora is nine faint viewer-facing glows pulsing on
  6.7/15/55-minute rebirth cycles, in every day group, all day.

Research: docs/research/2026-08-23-sky-default-script-port.md.
Register: AD-112 filed (camera-anchored synthetic owners vs sky-cell
physics objects). ISSUES #2 corrected (the playback ban is lifted by the
new evidence); #28 fix landed pending the connected night gate.
Tests: RetailParticleFacingTests (16), SkyPesFrameControllerTests (6);
hermetic suites App 6,076/0, Core 4,905/0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 15:28:59 +02:00

172 lines
5.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Numerics;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Vfx;
using AcDream.Core.Vfx;
using AcDream.Core.World;
using DatReaderWriter.Types;
using Xunit;
using DatPhysicsScript = DatReaderWriter.DBObjs.PhysicsScript;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Production sky default-script lifecycle per
/// <c>GameSky::CreateDeletePhysicsObjects @0x005073C0</c>: a slot keeps its
/// running script while (gfx id, properties) are unchanged — across day-group
/// swaps included — and a mismatch or window exit stops it. Research:
/// <c>docs/research/2026-08-23-sky-default-script-port.md</c>.
/// </summary>
public sealed class SkyPesFrameControllerTests
{
private const uint AuroraSetup = 0x02000714u;
private const uint AuroraScript = 0x330007DBu;
private sealed class Harness
{
public readonly List<uint> ResolvedScriptIds = [];
public readonly List<string> Diagnostics = [];
public readonly PhysicsScriptRunner Runner;
public readonly SkyPesFrameController Controller;
public Harness()
{
var registry = new EmitterDescRegistry();
var system = new ParticleSystem(registry, new Random(42));
var poses = new EntityEffectPoseRegistry();
var sink = new ParticleHookSink(system, poses);
Runner = new PhysicsScriptRunner(
id =>
{
ResolvedScriptIds.Add(id);
var script = new DatPhysicsScript();
script.ScriptData.Add(new PhysicsScriptData
{
StartTime = 0.0,
Hook = new SoundHook(),
});
return script;
},
sink);
Controller = new SkyPesFrameController(
Runner,
sink,
poses,
effects: null,
Diagnostics.Add);
}
}
private static SkyObjectData Carrier(
uint gfxObjId = AuroraSetup,
uint scriptId = AuroraScript,
uint pesColumn = AuroraScript,
uint properties = 0u,
float begin = 0f,
float end = 0f) => new()
{
GfxObjId = gfxObjId,
DefaultScriptId = scriptId,
PesObjectId = pesColumn,
Properties = properties,
BeginTime = begin,
EndTime = end,
};
private static DayGroupData Group(params SkyObjectData[] objects) => new()
{
Name = "Test",
SkyObjects = objects,
};
[Fact]
public void PlaysOncePerSlotAndPersistsAcrossEquivalentDayGroups()
{
var h = new Harness();
h.Controller.Update(0.1f, Group(Carrier()), Vector3.Zero);
Assert.Equal([AuroraScript], h.ResolvedScriptIds);
Assert.Equal(1, h.Runner.ActiveScriptCount);
// A different DayGroupData instance with the SAME slot identity is
// retail's midnight day-group swap keeping the aurora carrier: the
// running script must survive, not restart. The runner caches
// resolved scripts, so the replay probe is ActiveScriptCount —
// PlayDirect stacks one scheduled script per play.
h.Controller.Update(0.9f, Group(Carrier()), Vector3.One * 10f);
Assert.Equal(1, h.Runner.ActiveScriptCount);
}
[Fact]
public void SlotIdentityChangeStopsTheOldScriptAndPlaysTheNew()
{
var h = new Harness();
h.Controller.Update(0.1f, Group(Carrier()), Vector3.Zero);
h.Controller.Update(
0.1f,
Group(Carrier(gfxObjId: 0x02000589u, scriptId: 0x3300042Cu, pesColumn: 0x3300042Cu)),
Vector3.Zero);
Assert.Equal([AuroraScript, 0x3300042Cu], h.ResolvedScriptIds);
Assert.Equal(1, h.Runner.ActiveScriptCount);
}
[Fact]
public void LeavingTheVisibilityWindowStopsTheScriptAndReentryReplays()
{
var h = new Harness();
SkyObjectData windowed() => Carrier(begin: 0.2f, end: 0.4f);
h.Controller.Update(0.3f, Group(windowed()), Vector3.Zero);
Assert.Equal(1, h.Runner.ActiveScriptCount);
h.Controller.Update(0.5f, Group(windowed()), Vector3.Zero);
Assert.Equal(0, h.Runner.ActiveScriptCount);
// Re-entry replays (the runner's script cache absorbs the resolver
// call; the fresh scheduled script is the observable).
h.Controller.Update(0.25f, Group(windowed()), Vector3.Zero);
Assert.Equal(1, h.Runner.ActiveScriptCount);
}
[Fact]
public void SetupDefaultScriptIsTheSourceAndAMismatchedPesColumnLogsOnce()
{
var h = new Harness();
var group = Group(Carrier(scriptId: AuroraScript, pesColumn: 0x33000999u));
h.Controller.Update(0.1f, group, Vector3.Zero);
h.Controller.Update(0.2f, group, Vector3.Zero);
Assert.Equal([AuroraScript], h.ResolvedScriptIds);
string diagnostic = Assert.Single(h.Diagnostics);
Assert.Contains("0x330007DB", diagnostic, StringComparison.Ordinal);
Assert.Contains("0x33000999", diagnostic, StringComparison.Ordinal);
}
[Fact]
public void CarriersWithoutADefaultScriptNeverPlay()
{
var h = new Harness();
h.Controller.Update(
0.1f,
Group(Carrier(gfxObjId: 0x010015F0u, scriptId: 0u, pesColumn: 0u)),
Vector3.Zero);
Assert.Empty(h.ResolvedScriptIds);
Assert.Equal(0, h.Runner.ActiveScriptCount);
}
[Fact]
public void NullDayGroupStopsEverything()
{
var h = new Harness();
h.Controller.Update(0.1f, Group(Carrier()), Vector3.Zero);
Assert.Equal(1, h.Runner.ActiveScriptCount);
h.Controller.Update(0.1f, null, Vector3.Zero);
Assert.Equal(0, h.Runner.ActiveScriptCount);
}
}