feat(world): port retail portal-space viewport

Replace the opaque teleport cover with the DAT-authored CreatureMode tunnel, exact retail camera/light/animation timing and easing, and animation-hook audio routing. Compose portal and fade passes below retained UI so gameplay windows and input remain active through F751 travel.

Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-15 21:59:23 +02:00
parent 0eab7497c1
commit eab23cbdd1
14 changed files with 983 additions and 45 deletions

View file

@ -0,0 +1,116 @@
using AcDream.App.Rendering;
using AcDream.App.UI;
using AcDream.Content.Vfx;
using AcDream.Core.World;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
using DatReaderWriter.Enums;
using DatReaderWriter.Options;
using Xunit.Sdk;
namespace AcDream.App.Tests.Rendering;
public sealed class PortalTunnelAssetTests
{
[Fact]
public void InstalledDat_ResolvesRetailPortalSetupAndAnimation()
{
string? datDir = ResolveDatDir();
if (datDir is null)
throw SkipException.ForSkip(
"Installed client_portal.dat is required for the portal-space asset gate.");
using var dats = new DatCollection(datDir, DatAccessType.Read);
uint setupDid = RetailDataIdResolver.Resolve(
dats,
PortalTunnelPresentation.SetupClientEnum,
PortalTunnelPresentation.ClientEnumCategory);
uint animationDid = RetailDataIdResolver.Resolve(
dats,
PortalTunnelPresentation.AnimationClientEnum,
PortalTunnelPresentation.ClientEnumCategory);
Assert.NotEqual(0u, setupDid);
Assert.NotEqual(0u, animationDid);
Assert.Equal(0x02000306u, setupDid);
Assert.Equal(0x030005ACu, animationDid);
Setup setup = Assert.IsType<Setup>(dats.Get<Setup>(setupDid));
Animation animation = Assert.IsType<Animation>(
new RetailAnimationLoader(dats).LoadAnimation(animationDid));
Assert.NotEmpty(setup.Parts);
Assert.True(
animation.PartFrames.Count >= TeleportAnimSequencer.TunnelEndFrame,
$"Retail tunnel timing samples frame {TeleportAnimSequencer.TunnelEndFrame}, "
+ $"but animation 0x{animationDid:X8} has only {animation.PartFrames.Count} frames.");
Assert.All(
setup.Parts,
part => Assert.Equal(0x01u, ((uint)part >> 24) & 0xFFu));
Assert.Equal(0u, (uint)setup.DefaultAnimation);
Assert.Equal(0u, (uint)setup.DefaultScript);
Assert.Equal(0u, (uint)setup.DefaultScriptTable);
var hook = Assert.Single(animation.PartFrames.SelectMany(frame => frame.Hooks));
Assert.Equal(DatReaderWriter.Enums.AnimationHookType.SoundTweaked, hook.HookType);
}
[Fact]
public void PortalTunnelCamera_UsesRetailEyeAndRotatesAroundAcUpAxis()
{
var camera = new PortalTunnelCamera
{
DirectionDegrees = 0f,
Aspect = 1f,
};
Assert.True(System.Numerics.Matrix4x4.Invert(camera.View, out var world));
Assert.Equal(PortalTunnelCamera.RetailEye.X, world.Translation.X, precision: 5);
Assert.Equal(PortalTunnelCamera.RetailEye.Y, world.Translation.Y, precision: 5);
Assert.Equal(PortalTunnelCamera.RetailEye.Z, world.Translation.Z, precision: 5);
camera.DirectionDegrees = 90f;
Assert.True(System.Numerics.Matrix4x4.Invert(camera.View, out var rotatedWorld));
System.Numerics.Vector3 up = System.Numerics.Vector3.Normalize(
System.Numerics.Vector3.TransformNormal(System.Numerics.Vector3.UnitY, rotatedWorld));
Assert.Equal(0f, up.X, precision: 5);
Assert.Equal(0f, up.Y, precision: 5);
Assert.Equal(1f, up.Z, precision: 5);
}
[Theory]
[InlineData(45f)]
[InlineData(60f)]
[InlineData(90f)]
public void PortalTunnelCamera_UsesActiveSmartBoxFieldOfView(float degrees)
{
float expected = degrees * (MathF.PI / 180f);
var smartBoxProjection = System.Numerics.Matrix4x4.CreatePerspectiveFieldOfView(
expected,
16f / 9f,
0.1f,
5000f);
var camera = new PortalTunnelCamera();
camera.UseSmartBoxFov(smartBoxProjection);
Assert.Equal(expected, camera.FovRadians, precision: 5);
}
private static string? ResolveDatDir()
{
string? configured = System.Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR");
if (!string.IsNullOrWhiteSpace(configured)
&& File.Exists(Path.Combine(configured, "client_portal.dat")))
return configured;
const string installed = @"C:\Turbine\Asheron's Call";
if (File.Exists(Path.Combine(installed, "client_portal.dat")))
return installed;
string conventional = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile),
"Documents",
"Asheron's Call");
return File.Exists(Path.Combine(conventional, "client_portal.dat"))
? conventional
: null;
}
}

View file

@ -73,7 +73,12 @@ public sealed class TeleportAnimSequencerTests
// Helper: drive the sequencer forward by total elapsed time using small fixed steps.
private static (TeleportAnimSnapshot snap, List<TeleportAnimEvent> allEvents)
DriveSeconds(TeleportAnimSequencer seq, float seconds, bool worldReady, float step = 0.016f)
DriveSeconds(
TeleportAnimSequencer seq,
float seconds,
bool worldReady,
float step = 0.016f,
int tunnelAnimationFrame = 72)
{
var allEvts = new List<TeleportAnimEvent>();
float remaining = seconds;
@ -81,7 +86,7 @@ public sealed class TeleportAnimSequencerTests
while (remaining > 0f)
{
float dt = Math.Min(step, remaining);
var (snap, evts) = seq.Tick(dt, worldReady);
var (snap, evts) = seq.Tick(dt, worldReady, tunnelAnimationFrame);
last = snap;
allEvts.AddRange(evts);
remaining -= dt;
@ -193,11 +198,54 @@ public sealed class TeleportAnimSequencerTests
seq.Tick(0.016f, worldReady: true); // -> TunnelContinue
// Drive MaxContinue + ε with worldReady=false (simulating "world never loaded")
DriveSeconds(seq, TeleportAnimSequencer.MaxContinue + 0.05f, worldReady: false);
DriveSeconds(
seq,
TeleportAnimSequencer.MaxContinue + 0.05f,
worldReady: false,
tunnelAnimationFrame: 0);
Assert.Equal(TeleportAnimState.TunnelFadeOut, seq.State);
}
[Theory]
[InlineData(68, false)] // retail uses an open interval at 1.30 seconds
[InlineData(69, true)] // 1.275 seconds remaining
[InlineData(72, true)] // 1.20 seconds remaining
[InlineData(75, true)] // 1.125 seconds remaining
[InlineData(76, false)] // retail uses an open interval at 1.10 seconds
[InlineData(77, false)] // 1.075 seconds remaining
[InlineData(121, false)] // retail unsigned subtraction after the endpoint
public void TunnelContinue_UsesRetailAnimationExitWindow(int frame, bool shouldFade)
{
var seq = new TeleportAnimSequencer();
seq.Begin(TeleportEntryKind.Portal);
seq.Tick(0f, worldReady: false, tunnelAnimationFrame: frame);
seq.Tick(0.016f, worldReady: true, tunnelAnimationFrame: frame);
DriveSeconds(
seq,
TeleportAnimSequencer.MinContinue + 0.01f,
worldReady: true,
tunnelAnimationFrame: frame);
Assert.Equal(
shouldFade ? TeleportAnimState.TunnelFadeOut : TeleportAnimState.TunnelContinue,
seq.State);
}
[Theory]
[InlineData(0.00f, 0)]
[InlineData(0.01f, 0)]
[InlineData(0.25f, 146)]
[InlineData(0.50f, 512)]
[InlineData(0.75f, 877)]
[InlineData(0.99f, 1024)]
[InlineData(1.00f, 1024)]
public void RetailAnimationLevel_MatchesGoldenTable(float t, short expected)
{
Assert.Equal(expected, TeleportAnimSequencer.GetRetailAnimationLevel(t));
}
// --- TunnelFadeOut -> WorldFadeIn: PlayExitSound edge event ---
[Fact]
@ -245,7 +293,7 @@ public sealed class TeleportAnimSequencerTests
var seq = new TeleportAnimSequencer();
seq.Begin(TeleportEntryKind.Logout);
var (snap, _) = seq.Tick(dt: 0f, worldReady: false);
// At elapsed=0 in WorldFadeOut: smoothstep(0)=0 => alpha=0 (world fully visible).
// At elapsed=0 in WorldFadeOut: retail animation level 0 => fully visible.
Assert.Equal(0f, snap.FadeAlpha, precision: 4);
}
@ -261,7 +309,7 @@ public sealed class TeleportAnimSequencerTests
Assert.Equal(TeleportAnimState.WorldFadeOut, seq.State);
var (snap, _) = seq.Tick(0f, worldReady: false);
// smoothstep(clamp((1.0-0.02)/1.0,0,1)) should be close to 1
// The retail animation table should be close to fully opaque here.
Assert.True(snap.FadeAlpha > 0.95f, $"Expected FadeAlpha near 1, got {snap.FadeAlpha}");
}