feat(chargen): Campaign CC slice CC6b-MOUNT — Appearance page + preview mount

The page-mount half CC6b-PRE deferred: CharacterCreationAppearancePage
(gender buttons, Face/Clothes sub-tabs, nine spin controls with retail's
decrement/increment/select-as-current-part OnClickAt zones, nine color
swatches, shade scrollbar, zoom/rotate wiring) plus ChargenPreviewController,
which bridges the ChargenPreviewRenderer/ChargenPreviewZoomController
camera-injection gap CC6a/CC6b-PRE left open and mounts as the third private
creature viewport beside paperdoll/creature-appraisal.

Color-wheel scouting (campaign risk item 4): live-DAT probe found every
color-wheel-family id resolves through existing DatWidgetFactory mappings
(Button/Scrollbar/generic fallback) — no new widget type needed.

The @140355 gender-flip-on-init oddity (risk item 5): resolved via decomp
alone — gmCharGenMainUI's own ctor calls CharGenState::RandomizeCharacter
before any page constructs, so retail's chargen screen is never actually
blank on open; the Appearance page's gender-flip code always fires against
a real, randomly-rolled gender. Filed AP-214 (acdream doesn't port
RandomizeCharacter this round, so it opens honestly blank instead) and
AP-215 (two narrow visual substitutions: swatch .Selected highlight vs
retail's separate overlay, ordinal labels vs retail's icon-only spins).

AD-101 retired: the Heritage page's auto-gender-select interim default is
deleted now that the Appearance page's real gender buttons exist. TS-82
narrowed to Summary-only.

Scope addendum: ChargenPreviewRotationController's parameterless-constructor
default changes from 0f to a new RetailDefaultHeadingDegrees=180f constant
(retail's InitializePage override, not the ctor's raw 0) — every real
gmCG3DView owner converges on 180 before its first frame, so a controller
defaulting to 0 was a trap for future consumers.

Runtime 1713/0, Core 4786/1 skip, Content 147/0, App 5220/3 skips (Release,
ACDREAM_PROBE_LIVE_MOUNT=1) — zero failures across two clean full-solution
runs; the one Core.Net.Tests NakEmissionTests flake observed on a third run
is the same pre-existing, previously-documented timing flake (zero files
under src/AcDream.Core.Net/ touched, passes 100% in isolation).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-15 21:00:10 +02:00
parent 11374484dc
commit 34c6fceab0
20 changed files with 2109 additions and 57 deletions

View file

@ -0,0 +1,283 @@
using System.Numerics;
using AcDream.App.Rendering;
using AcDream.Content;
using AcDream.Content.CharGen;
using AcDream.Content.Vfx;
using AcDream.Core.CharGen;
using AcDream.Core.Physics.Motion;
using AcDream.Core.World;
using DatReaderWriter;
using DatReaderWriter.Options;
using Xunit;
using Xunit.Abstractions;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Campaign CC slice CC6b-MOUNT — installed-DAT gate for
/// <see cref="ChargenPreviewController"/>'s rebuild/render logic, using fake
/// <see cref="IChargenPreviewRenderer"/>/<see cref="IChargenPreviewFrameView"/>
/// implementations (no live GPU device needed — mirrors
/// <c>PaperdollFramePresenterTests</c>'s recording-fake pattern) against a
/// REAL dat-backed <see cref="ChargenOptions"/>/<see cref="ChargenAppearanceCatalog"/>
/// so <c>ChargenAppearanceFactory.TryCompose</c> and
/// <c>ChargenPreviewEntityBuilder.TryBuildAnimated</c> actually run.
/// </summary>
public sealed class ChargenPreviewControllerTests
{
private readonly ITestOutputHelper _out;
public ChargenPreviewControllerTests(ITestOutputHelper output) => _out = output;
private const uint AluvianId = 1u;
private const uint GearknightId = 6u;
[Fact]
public void Rebuild_SameSelectionTwice_IsANoOpSecondTime()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView();
var controller = new ChargenPreviewController(
renderer, new ChargenPreviewCamera(), view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
ChargenAppearanceSelection selection = DefaultSelection(options, AluvianId, 1);
Assert.True(controller.Rebuild(options, AluvianId, 1, selection));
Assert.True(controller.Rebuild(options, AluvianId, 1, selection));
Assert.Equal(1, renderer.SetPreviewCallCount);
}
}
[Fact]
public void Rebuild_HeritageChange_ResetsCameraToTheNewHeritagesDefaultEye()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView();
var camera = new ChargenPreviewCamera();
var controller = new ChargenPreviewController(
renderer, camera, view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
Assert.True(controller.Rebuild(
options, AluvianId, 1, DefaultSelection(options, AluvianId, 1)));
// Poke the SAME camera instance the controller shares (this is
// exactly the injection seam ChargenPreviewController's own doc
// comment describes) — simulates the camera having drifted away
// from the heritage default (e.g. mid zoom-out tween).
camera.Eye = new Vector3(0f, -99f, 99f);
if (!options.TryGetHeritage(GearknightId, out ChargenHeritageOptions? gearknight)
|| gearknight!.GendersByKey.Count == 0)
{
_out.WriteLine("SKIP: installed dat has no Gearknight gender to switch to.");
return;
}
int gearknightGender = gearknight.GendersByKey.Keys.First();
Assert.True(controller.Rebuild(
options, GearknightId, gearknightGender,
DefaultSelection(options, GearknightId, gearknightGender)));
Assert.Equal(ChargenPreviewCamera.ResolveDefaultEye(GearknightId), controller.CameraEye);
}
}
/// <summary>
/// Decomp-cited (<c>gmCGAppearancePage::Update</c>'s two confirmed direct
/// call sites — <c>InitializePage</c> and the gender-button handlers —
/// vs the narrower <c>SetSelection</c>/<c>SetColor</c>/<c>SetShade</c>
/// every spin/color/shade change goes through instead): a rebuild that
/// changes ONLY the appearance selection (same heritage, same gender)
/// must NOT snap the camera back to the heritage default.
/// </summary>
[Fact]
public void Rebuild_AppearanceOnlyChange_LeavesTheCameraUntouched()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView();
var camera = new ChargenPreviewCamera();
var controller = new ChargenPreviewController(
renderer, camera, view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
ChargenAppearanceSelection first = DefaultSelection(options, AluvianId, 1);
Assert.True(controller.Rebuild(options, AluvianId, 1, first));
var pokedEye = new Vector3(0f, -99f, 99f);
camera.Eye = pokedEye;
ChargenAppearanceSelection second = first with { SkinShade = 0.9 };
Assert.True(controller.Rebuild(options, AluvianId, 1, second));
Assert.Equal(pokedEye, controller.CameraEye);
}
}
[Fact]
public void Rebuild_PreservesZoomState_AcrossAnAppearanceOnlyChange()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView();
var controller = new ChargenPreviewController(
renderer, new ChargenPreviewCamera(), view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
ChargenAppearanceSelection first = DefaultSelection(options, AluvianId, 1);
Assert.True(controller.Rebuild(options, AluvianId, 1, first));
controller.ZoomIn();
Assert.True(controller.IsZoomedIn);
// A DIFFERENT selection, same heritage/gender — retail's
// gmCGAppearancePage::Update only resets the camera POSITION on
// heritage/gender change; m_bZoomedIn is untouched by spin/color/
// shade edits.
ChargenAppearanceSelection second = first with { SkinShade = 0.9 };
Assert.True(controller.Rebuild(options, AluvianId, 1, second));
Assert.True(controller.IsZoomedIn);
}
}
[Fact]
public void Rebuild_ThenRender_SeedsTheEntityHeadingToTheRetailDefault180Degrees()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView();
var controller = new ChargenPreviewController(
renderer, new ChargenPreviewCamera(), view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
Assert.True(controller.Rebuild(
options, AluvianId, 1, DefaultSelection(options, AluvianId, 1)));
Assert.NotNull(renderer.LastEntity);
controller.Render();
Quaternion expected = MoveToMath.SetHeading(
Quaternion.Identity, ChargenPreviewRotationController.RetailDefaultHeadingDegrees);
Quaternion actual = renderer.LastEntity!.Rotation;
Assert.Equal(expected.X, actual.X, 4);
Assert.Equal(expected.Y, actual.Y, 4);
Assert.Equal(expected.Z, actual.Z, 4);
Assert.Equal(expected.W, actual.W, 4);
}
}
[Fact]
public void Render_WhilePageInvisible_SkipsRenderAndTexturePublication()
{
if (!TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter))
return;
using (dats)
using (adapter)
{
(ChargenOptions options, ChargenAppearanceCatalog catalog) = LoadFixture(adapter!);
var renderer = new FakeChargenRenderer();
var view = new FakeChargenView { Visible = false };
var controller = new ChargenPreviewController(
renderer, new ChargenPreviewCamera(), view,
adapter!, new RetailAnimationLoader(adapter!), catalog, catalog, new object());
Assert.True(controller.Rebuild(
options, AluvianId, 1, DefaultSelection(options, AluvianId, 1)));
controller.Render();
Assert.Equal(0, renderer.RenderCallCount);
Assert.Null(view.LastTextureHandle);
}
}
private static ChargenAppearanceSelection DefaultSelection(
ChargenOptions options, uint heritageId, int genderKey)
{
Assert.True(options.TryGetHeritage(heritageId, out ChargenHeritageOptions? heritage));
Assert.True(heritage!.GendersByKey.TryGetValue(genderKey, out ChargenGenderOptions? gender));
return ChargenAppearanceSelection.Default with
{
HairStyle = gender!.HairStyles.Count > 0 ? 0u : ChargenAppearanceSelection.Unset,
SkinShade = 0.5,
};
}
private static (ChargenOptions, ChargenAppearanceCatalog) LoadFixture(IDatReaderWriter dats) =>
(ChargenTableReader.Load(dats), new ChargenAppearanceCatalog(dats));
private bool TryOpen(out DatCollection? dats, out DatCollectionAdapter? adapter)
{
string? datDir = CornerFloodReplayTests.ResolveDatDir();
if (datDir is null)
{
_out.WriteLine("SKIP: dats unavailable");
dats = null;
adapter = null;
return false;
}
dats = new DatCollection(datDir, DatAccessType.Read);
adapter = new DatCollectionAdapter(dats);
return true;
}
private sealed class FakeChargenRenderer : IChargenPreviewRenderer
{
public WorldEntity? LastEntity { get; private set; }
public int SetPreviewCallCount { get; private set; }
public int RenderCallCount { get; private set; }
public void SetPreview(WorldEntity? entity)
{
LastEntity = entity;
SetPreviewCallCount++;
}
public uint Render(int width, int height)
{
RenderCallCount++;
return 42u;
}
}
private sealed class FakeChargenView : IChargenPreviewFrameView
{
public bool Visible { get; set; } = true;
public int Width { get; set; } = 128;
public int Height { get; set; } = 128;
public uint? LastTextureHandle { get; private set; }
public bool TryGetVisibleSize(out int width, out int height)
{
width = Width;
height = Height;
return Visible;
}
public void SetTextureHandle(uint textureHandle) => LastTextureHandle = textureHandle;
}
}

View file

@ -11,10 +11,32 @@ namespace AcDream.App.Tests.Rendering;
/// </summary>
public sealed class ChargenPreviewRotationControllerTests
{
/// <summary>
/// CC6b-MOUNT: retail's OPERATIVE starting heading is 180, not the ctor's
/// raw 0 — <c>gmCGAppearancePage::gmCGAppearancePage @0x0047CDAC</c> sets
/// <c>m_fCurHeading = 0f</c>, but <c>InitializePage @0x0047FDD0</c> always
/// runs immediately afterward (before the page is ever visible) and
/// overrides it to <c>180f</c> at <c>0x00480235</c>, pushed via
/// <c>SetPlayerHeading</c> at <c>0x0048023F</c>. No player-visible chargen
/// Appearance frame is ever rendered at 0°. This is the seam a real mount
/// site experiences (the parameterless constructor), pinned here so a
/// future consumer can't silently regress to facing the character away
/// from the camera. See <see cref="ChargenPreviewRotationController.RetailDefaultHeadingDegrees"/>
/// for the full citation, including the cross-confirming
/// <c>gmCGSummaryPage</c>/<c>gmBarberUI</c> sibling call sites.
/// </summary>
[Fact]
public void DefaultConstructor_StartsAtRetailsOperative180DegreeHeading()
{
var controller = new ChargenPreviewRotationController();
Assert.Equal(180f, controller.HeadingDegrees);
}
[Fact]
public void Toggle_StartsRotatingInTheGivenDirection()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
Assert.True(controller.IsRotating);
@ -24,7 +46,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Toggle_SameDirectionWhileRotating_Stops()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Toggle(ChargenRotateDirection.Clockwise);
@ -34,7 +56,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Toggle_OppositeDirectionWhileRotating_SwitchesDirectionAndKeepsRotating()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Toggle(ChargenRotateDirection.CounterClockwise);
@ -45,7 +67,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Tick_WhileNotRotating_IsANoOp()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Tick(100.0);
Assert.Equal(0f, controller.HeadingDegrees);
@ -57,7 +79,7 @@ public sealed class ChargenPreviewRotationControllerTests
// Rotate() invalidates m_dLastRotateTime so the very first DoRotation
// tick resets it to "now" rather than computing a huge jump from a
// stale/never-set timestamp.
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(1000.0);
@ -71,8 +93,10 @@ public sealed class ChargenPreviewRotationControllerTests
// Seed "now" nonzero (0.0 collides with the <= 0 reset-if-invalid
// guard, same as retail's own sentinel check would if Timer::cur_time
// could ever read exactly zero — never in practice, so tests avoid
// it too).
var controller = new ChargenPreviewRotationController();
// it too). Explicit 0f baseline keeps the relative-delta assertion
// below simple; the retail-default seam has its own dedicated test
// above.
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(10.0); // seeds lastRotateTime = 10, zero delta.
controller.Tick(11.5); // half a revolution at 3 s/rev.
@ -83,7 +107,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Tick_CounterClockwiseAdvance_SubtractsAndWrapsPositive()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.CounterClockwise);
controller.Tick(10.0);
controller.Tick(11.5); // would go to -180, wraps to +180.
@ -94,7 +118,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Tick_AccumulatesAcrossMultipleTicks()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(10.0);
controller.Tick(10.5); // +60 deg.
@ -113,7 +137,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void Tick_ClockwiseAdvancePast360_ClampsBackBySubtracting360()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(10.0); // seeds lastRotateTime = 10, zero delta.
controller.Tick(10.0 + 3.5); // 3.5s at 3s/rev = 420 deg -> 420, clamped to 60.
@ -124,7 +148,7 @@ public sealed class ChargenPreviewRotationControllerTests
[Fact]
public void ToOrientation_AtZeroHeading_IsIdentity()
{
var controller = new ChargenPreviewRotationController();
var controller = new ChargenPreviewRotationController(0f);
Quaternion orientation = controller.ToOrientation();
Assert.Equal(Quaternion.Identity.X, orientation.X, 4);