acdream/tests/AcDream.App.Tests/Rendering/ChargenPreviewRotationControllerTests.cs
Erik 34c6fceab0 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>
2026-08-15 21:00:10 +02:00

159 lines
6.2 KiB
C#

using System.Numerics;
using AcDream.App.Rendering;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Pure (no dat access) tests for <see cref="ChargenPreviewRotationController"/>
/// — the port of <c>gmCGAppearancePage::Rotate</c>/<c>DoRotation</c>
/// (<c>0x0047CB50</c>/<c>0x0047CA80</c>).
/// </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(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
Assert.True(controller.IsRotating);
Assert.Equal(ChargenRotateDirection.Clockwise, controller.Direction);
}
[Fact]
public void Toggle_SameDirectionWhileRotating_Stops()
{
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Toggle(ChargenRotateDirection.Clockwise);
Assert.False(controller.IsRotating);
}
[Fact]
public void Toggle_OppositeDirectionWhileRotating_SwitchesDirectionAndKeepsRotating()
{
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Toggle(ChargenRotateDirection.CounterClockwise);
Assert.True(controller.IsRotating);
Assert.Equal(ChargenRotateDirection.CounterClockwise, controller.Direction);
}
[Fact]
public void Tick_WhileNotRotating_IsANoOp()
{
var controller = new ChargenPreviewRotationController(0f);
controller.Tick(100.0);
Assert.Equal(0f, controller.HeadingDegrees);
}
[Fact]
public void Tick_FirstCallAfterToggle_ContributesZeroDelta()
{
// 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(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(1000.0);
Assert.Equal(0f, controller.HeadingDegrees);
}
[Fact]
public void Tick_ClockwiseAdvance_AddsTheExactPerTickFormula()
{
// deltaDegrees = ((now - last) / RotationSecondsPerRevolution) * 360.
// 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). 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.
Assert.Equal(180f, controller.HeadingDegrees, 3);
}
[Fact]
public void Tick_CounterClockwiseAdvance_SubtractsAndWrapsPositive()
{
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.CounterClockwise);
controller.Tick(10.0);
controller.Tick(11.5); // would go to -180, wraps to +180.
Assert.Equal(180f, controller.HeadingDegrees, 3);
}
[Fact]
public void Tick_AccumulatesAcrossMultipleTicks()
{
var controller = new ChargenPreviewRotationController(0f);
controller.Toggle(ChargenRotateDirection.Clockwise);
controller.Tick(10.0);
controller.Tick(10.5); // +60 deg.
controller.Tick(11.0); // +60 deg more.
Assert.Equal(120f, controller.HeadingDegrees, 3);
}
/// <summary>
/// F7: exercises the <c>&gt;360 -&gt; -360</c> clamp arm (pseudo-C
/// ~0x0047cb1e-0x0047cb31), the one with readable decomp polarity —
/// unlike the CCW-branch FPU-stack artifact F3 documents, this branch's
/// test/subtract shape is unambiguous. One large clockwise tick pushes
/// heading past 360 in a single call.
/// </summary>
[Fact]
public void Tick_ClockwiseAdvancePast360_ClampsBackBySubtracting360()
{
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.
Assert.Equal(60f, controller.HeadingDegrees, 3);
}
[Fact]
public void ToOrientation_AtZeroHeading_IsIdentity()
{
var controller = new ChargenPreviewRotationController(0f);
Quaternion orientation = controller.ToOrientation();
Assert.Equal(Quaternion.Identity.X, orientation.X, 4);
Assert.Equal(Quaternion.Identity.Y, orientation.Y, 4);
Assert.Equal(Quaternion.Identity.Z, orientation.Z, 4);
Assert.Equal(Quaternion.Identity.W, orientation.W, 4);
}
}