F1 (BLOCKING, doc-only) — the idle-by-default rationale rested on an unsound "uninitialized C++ member defaults to 0" argument (heap operator-new memory is indeterminate, not zero). Verified and replaced with the real evidence: gmCGAppearancePage::InitializePage @0x0047FDD0 writes an EXPLICIT this->m_bZoomedIn = 0; at 0x004802C3, immediately after that same function points the camera at the zoomed-IN per-heritage eye (0x00480286-0x0048029E). Fixed in all three places: the register's TS-83 retirement clause, ChargenPreviewAnimator's class doc, ChargenPreviewZoomController.IsZoomedIn's doc. Recorded the retail quirk this implies: the character starts framed close-up while not-zoomed-in, so the first Zoom In click (once mounted) tweens close-eye->close-eye (visually null) while still freezing the animation — the port reproduces this faithfully. F2 — ChargenPreviewZoomController and ChargenPreviewAnimator kept independent _zoomedIn bools synced only via a nullable animator parameter, risking desync. Retail's m_bZoomedIn is a single field gating both camera and animation, so the fix makes the animator the sole state owner: ChargenPreviewZoomController now takes its ChargenPreviewAnimator as a required constructor dependency, IsZoomedIn reads straight through to it, and ZoomIn/ZoomOut no longer take a parameter at all — there is no second bool left to disagree. F3 — documented the DoRotation counter-clockwise branch's x87-stack decompiler artifact (BN renders x87_r7_1 = x87_r6_3 at 0x0047CAEB, which would store delta-degrees instead of the timestamp for CCW only); the port already stores "now" in both branches, cited against feedback_bn_decomp_field_names.md. F4 — ChargenPreviewAnimator.ApplyIdleFrame now double-buffers two List<MeshRef> instead of allocating fresh every 30fps tick. F5 — filed docs/ISSUES.md #402 tracking the RetailAnimationCyclePlayback / LiveEntityAnimationPresenter duplication as an owned post-CC follow-up, referenced from the new type's own doc. F6 — reworded the ChargenPreviewEntityBuilder.TryBuild "byte-identical" claim to result-identical (TryBuildAnimated now also resolves the idle DID and loads the idle Animation before the wrapper discards them). F7 — added the missing clockwise >360 clamp test (readable decomp polarity, unlike F3's CCW artifact). ALSO — rewrote the CC6b ledger row's m_alternateSetupID MUST-COVER note per the reviewer's F11 concession: all five write sites belong to gmBarberUI (the post-creation barber shop), not gmCGAppearancePage, which has no option-checkbox-equivalent field at all. Added the enclosing-function citations and an explicit directive that CC6b-mount must NOT build a crown/no-flame checkbox on the Appearance page. Tests: ChargenPreviewRotationControllerTests +1 (10 total), ChargenPreviewZoomControllerTests +2 and every case rewritten for the required-animator constructor (9 total). Core.Tests 4786/1 skip (unchanged), Content.Tests 147/0, App.Tests 5152/6 skips (+3) — zero failures in isolation, full solution Release build green. Two pre-existing flakes observed across repeated full-solution runs, neither caused by this round and neither reproducing standalone: Core.Net.Tests' NakEmissionTests loss soak, and Content.Tests' DecodedTextureCacheTests concurrency race. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
126 lines
5.6 KiB
C#
126 lines
5.6 KiB
C#
using System.Numerics;
|
|
using AcDream.Core.Physics.Motion;
|
|
|
|
namespace AcDream.App.Rendering;
|
|
|
|
/// <summary>
|
|
/// Retail's toggle direction enum
|
|
/// (<c>gmBarberUI::ERotateDirection</c>/<c>gmCGAppearancePage::ERotateDirection</c>
|
|
/// typedef alias, <c>acclient.h:6848-6852,6960</c>): <c>Invalid=0</c>,
|
|
/// <c>Clockwise=1</c>, <c>CounterClockwise=2</c>.
|
|
/// </summary>
|
|
internal enum ChargenRotateDirection
|
|
{
|
|
Invalid = 0,
|
|
Clockwise = 1,
|
|
CounterClockwise = 2,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Presentation-free port of <c>gmCGAppearancePage::Rotate</c>
|
|
/// (<c>0x0047CB50</c>) + <c>DoRotation</c> (<c>0x0047CA80</c>) — the
|
|
/// button-toggled continuous rotation retail applies to the preview
|
|
/// CHARACTER's heading (<c>CPhysicsObj::set_heading</c> inside
|
|
/// <c>gmCG3DView::Update</c>, pseudo-C ~0x0047eecf1), not the camera (see
|
|
/// <see cref="ChargenPreviewCamera"/>'s own doc comment on why rotation
|
|
/// lives here instead). Retail drives <see cref="Tick"/> once per frame from
|
|
/// a global-message-3 tick while <see cref="IsRotating"/> is set
|
|
/// (<c>gmCGAppearancePage::ListenToGlobalMessage @ 0x0047CED0</c>); the
|
|
/// CC6b page-mount half will bind the Rotate Clockwise/Counter-Clockwise
|
|
/// buttons to <see cref="Toggle"/> and the render loop to <see cref="Tick"/>.
|
|
/// </summary>
|
|
internal sealed class ChargenPreviewRotationController
|
|
{
|
|
/// <summary>
|
|
/// <c>Rotate</c>'s explicit sentinel write
|
|
/// (<c>this->m_dLastRotateTime = -1.0</c>, pseudo-C ~0x0047cba7/0x0047cbb1
|
|
/// — the high dword <c>0xbff00000</c> paired with a zero low dword is the
|
|
/// exact IEEE-754 bit pattern for <c>-1.0</c>) — invalidates the
|
|
/// timestamp so the very next <see cref="Tick"/> resets it to "now"
|
|
/// (a zero-length first delta) instead of computing a huge jump from a
|
|
/// stale or never-set value.
|
|
/// </summary>
|
|
private const double InvalidTimeSentinel = -1.0;
|
|
|
|
private double _lastRotateTime = InvalidTimeSentinel;
|
|
private ChargenRotateDirection _direction = ChargenRotateDirection.Invalid;
|
|
private bool _rotating;
|
|
|
|
public bool IsRotating => _rotating;
|
|
public ChargenRotateDirection Direction => _direction;
|
|
|
|
/// <summary>Retail's <c>m_fCurHeading</c>, degrees, ctor default 0 —
|
|
/// applied to the preview entity via <c>MoveToMath.SetHeading</c>
|
|
/// (<c>CPhysicsObj::set_heading</c>'s exact port).</summary>
|
|
public float HeadingDegrees { get; private set; }
|
|
|
|
/// <summary>
|
|
/// <c>gmCGAppearancePage::Rotate @ 0x0047CB50</c>: pressing the SAME
|
|
/// direction a second time while already rotating STOPS rotation
|
|
/// (retail's button-toggle UX); any other press (opposite direction, or
|
|
/// starting from stopped) sets that direction and (re)starts,
|
|
/// invalidating <c>m_dLastRotateTime</c> per this class's own sentinel
|
|
/// doc.
|
|
/// </summary>
|
|
public void Toggle(ChargenRotateDirection direction)
|
|
{
|
|
if (_rotating && direction == _direction)
|
|
{
|
|
_rotating = false;
|
|
return;
|
|
}
|
|
_direction = direction;
|
|
_lastRotateTime = InvalidTimeSentinel;
|
|
_rotating = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// <c>gmCGAppearancePage::DoRotation @ 0x0047CA80</c>: per-tick
|
|
/// <c>deltaDegrees = ((now - lastRotateTime) / RotationSecondsPerRevolution)
|
|
/// * 360</c>, added for <see cref="ChargenRotateDirection.Clockwise"/>
|
|
/// and subtracted for every other direction (pseudo-C ~0x0047cacd:
|
|
/// <c>if (m_eRotateDir != ECG_ROTATE_CLOCKWISE) heading -= delta; else
|
|
/// heading += delta;</c>), then a SINGLE-PASS clamp back into
|
|
/// <c>[0, 360)</c> — not a full modulo loop; retail's own tail only
|
|
/// adds/subtracts 360 once (pseudo-C ~0x0047caf3-0x0047cb31), which is
|
|
/// exactly enough for any realistic per-frame delta and is reproduced
|
|
/// here verbatim rather than "improved" into a `%=`. Fix round F3: Binary
|
|
/// Ninja literally renders <c>x87_r7_1 = x87_r6_3</c> at <c>0x0047CAEB</c>
|
|
/// inside the counter-clockwise branch — reassigning the local that held
|
|
/// the "now" timestamp to the just-computed delta-degrees value — which
|
|
/// would make the <c>0x0047CB3D</c> store into <c>m_dLastRotateTime</c>
|
|
/// write delta-degrees instead of the timestamp for CCW only; that is an
|
|
/// x87-FPU-stack modeling artifact of the decompiler, not real retail
|
|
/// behavior (a shipped feature where every counter-clockwise rotation
|
|
/// visibly diverges from clockwise is implausible, and
|
|
/// <c>claude-memory/feedback_bn_decomp_field_names.md</c> names exactly
|
|
/// this x87-stack-register mislabeling as a known decompiler artifact
|
|
/// class), so this port stores <c>now</c> into <c>_lastRotateTime</c>
|
|
/// unconditionally in BOTH directions.
|
|
/// </summary>
|
|
public void Tick(double now)
|
|
{
|
|
if (!_rotating)
|
|
return;
|
|
if (_lastRotateTime <= 0d)
|
|
_lastRotateTime = now;
|
|
|
|
double deltaDegrees = ((now - _lastRotateTime) / ChargenPreviewCamera.RotationSecondsPerRevolution) * 360.0;
|
|
HeadingDegrees = _direction == ChargenRotateDirection.Clockwise
|
|
? HeadingDegrees + (float)deltaDegrees
|
|
: HeadingDegrees - (float)deltaDegrees;
|
|
|
|
if (HeadingDegrees < 0f)
|
|
HeadingDegrees += 360f;
|
|
if (HeadingDegrees > 360f)
|
|
HeadingDegrees -= 360f;
|
|
|
|
_lastRotateTime = now;
|
|
}
|
|
|
|
/// <summary><c>CPhysicsObj::set_heading</c>'s exact quaternion
|
|
/// construction — the SAME shared Core primitive retail movement already
|
|
/// ports (<see cref="MoveToMath.SetHeading"/>).</summary>
|
|
public Quaternion ToOrientation() =>
|
|
MoveToMath.SetHeading(Quaternion.Identity, HeadingDegrees);
|
|
}
|