Session teardown (PlayerModeController.Exit/ResetSession -> CameraController.ExitChaseMode) fell back to the dev free-fly camera, and CameraPointerInputController.ApplyCursorForCameraMode faithfully applies CursorMode.Raw (GLFW disabled cursor: hidden + captured) for fly mode — so the character-select screen after an in-world logoff had no mouse. Fresh boot starts in Orbit and never fires a mode change, which is why only the post-logout path was affected. Teardown now lands on Mode.Orbit — the exact state a fresh boot presents at character select — and always notifies, so the pointer controller restores CursorMode.Normal even when torn down from the dev fly camera. The dev fly<->chase flow is untouched (it rides ToggleFly, never ExitChaseMode). Proven live both directions with a driven logout (UI probe 0x100000FA -> dialog accept 0x17) under Win32 GetCursorInfo sampling: before, flags flipped 1->0 exactly at the roster re-push that re-shows character select and stayed hidden; after, zero hidden samples across the full timeline. Files #415: the UI-probe 'wait world-visible' verb reads the reset transit snapshot and is dead after reveal completion (test apparatus only). App tests 5564/3 skips (+3), Runtime 1756/0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
170 lines
6.3 KiB
C#
170 lines
6.3 KiB
C#
// src/AcDream.App/Rendering/CameraController.cs
|
|
using AcDream.Core.Rendering;
|
|
|
|
namespace AcDream.App.Rendering;
|
|
|
|
public sealed class CameraController
|
|
{
|
|
internal readonly record struct CameraState(
|
|
int ModeCode,
|
|
ChaseCamera? Chase,
|
|
RetailChaseCamera? RetailChase);
|
|
|
|
public OrbitCamera Orbit { get; }
|
|
public FlyCamera Fly { get; }
|
|
public ChaseCamera? Chase { get; private set; }
|
|
public RetailChaseCamera? RetailChase { get; private set; }
|
|
|
|
/// <summary>
|
|
/// The renderer-facing active camera. Both the legacy and retail
|
|
/// chase cameras are held simultaneously so that flipping
|
|
/// <see cref="CameraDiagnostics.UseRetailChaseCamera"/> takes effect
|
|
/// on the very next access to this property — no re-entry required,
|
|
/// no notification mechanism, no stale state.
|
|
/// </summary>
|
|
public ICamera Active
|
|
{
|
|
get
|
|
{
|
|
if (_mode == Mode.Fly) return Fly;
|
|
if (_mode == Mode.Chase)
|
|
{
|
|
if (CameraDiagnostics.UseRetailChaseCamera && RetailChase is not null)
|
|
return RetailChase;
|
|
if (Chase is not null) return Chase;
|
|
}
|
|
return Orbit;
|
|
}
|
|
}
|
|
|
|
public bool IsFlyMode => _mode == Mode.Fly;
|
|
public bool IsChaseMode => _mode == Mode.Chase;
|
|
|
|
public event Action<bool>? ModeChanged;
|
|
|
|
private enum Mode { Orbit, Fly, Chase }
|
|
private Mode _mode = Mode.Orbit;
|
|
|
|
/// <summary>Retail <c>m_fGameFOV</c> (#389): the user-facing FOV the Config
|
|
/// slider sets in degrees, default 90°. The APPLIED per-camera vertical FOV
|
|
/// is derived from it and the current aspect via
|
|
/// <see cref="RetailFieldOfView.TryAppliedVerticalFov"/> — see that class's
|
|
/// doc for the decomp anchors.</summary>
|
|
public float GameFovRadians { get; private set; } = RetailFieldOfView.DefaultGameFovRadians;
|
|
|
|
private float _aspect = 16f / 9f;
|
|
|
|
public CameraController(OrbitCamera orbit, FlyCamera fly)
|
|
{
|
|
Orbit = orbit;
|
|
Fly = fly;
|
|
ApplyProjection();
|
|
}
|
|
|
|
public void ToggleFly()
|
|
{
|
|
_mode = IsFlyMode ? Mode.Orbit : Mode.Fly;
|
|
ModeChanged?.Invoke(IsFlyMode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Store both cameras simultaneously; <see cref="Active"/> picks
|
|
/// between them per-read via the flag — no re-entry needed on flip.
|
|
/// </summary>
|
|
public void EnterChaseMode(ChaseCamera legacy, RetailChaseCamera retail)
|
|
{
|
|
Chase = legacy;
|
|
RetailChase = retail;
|
|
// #389: freshly attached chase cameras carry their own initialiser
|
|
// aspect/FOV — bring them onto the controller's current aspect +
|
|
// smartbox FOV immediately (before this, a resize while chase cameras
|
|
// were attached never reached them at all: SetAspect only updated
|
|
// Orbit/Fly, so the world rendered at the creation-time aspect
|
|
// stretched onto the new viewport — the 2026-08-13 "squished" gate
|
|
// report's second mechanism).
|
|
ApplyProjection();
|
|
_mode = Mode.Chase;
|
|
ModeChanged?.Invoke(IsChaseMode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Player-mode teardown (logout, session reset). Lands on the neutral
|
|
/// orbit camera — the same state a fresh boot presents at character
|
|
/// select — NOT the dev free-fly camera: fly mode raw-captures the OS
|
|
/// cursor (<c>CameraPointerInputController.ApplyCursorForCameraMode</c>
|
|
/// sets <c>CursorMode.Raw</c>), and the old <c>Mode.Fly</c> fallback
|
|
/// left the character-select screen after an in-world logoff with a
|
|
/// hidden, captured mouse. The dev fly↔chase flow is unaffected — it
|
|
/// rides <see cref="ToggleFly"/>, never this teardown path.
|
|
/// </summary>
|
|
public void ExitChaseMode()
|
|
{
|
|
Chase = null;
|
|
RetailChase = null;
|
|
if (_mode == Mode.Orbit)
|
|
return;
|
|
_mode = Mode.Orbit;
|
|
ModeChanged?.Invoke(false);
|
|
}
|
|
|
|
public void SetAspect(float aspect)
|
|
{
|
|
_aspect = aspect;
|
|
ApplyProjection();
|
|
}
|
|
|
|
/// <summary>Sets retail's <c>m_fGameFOV</c> (#389) and recomputes every
|
|
/// camera's applied FOV. Driven by the Config tab's Field of View value
|
|
/// through <c>RuntimeSettingsStartupTargets.ApplyFieldOfView</c>.</summary>
|
|
public void SetGameFov(float gameFovRadians)
|
|
{
|
|
GameFovRadians = gameFovRadians;
|
|
ApplyProjection();
|
|
}
|
|
|
|
/// <summary>Pushes the current aspect + smartbox-derived vertical FOV onto
|
|
/// every attached camera. When the law's result fails retail's
|
|
/// <c>SetFOVRad</c> gate (see <see cref="RetailFieldOfView.TryAppliedVerticalFov"/>),
|
|
/// the cameras keep their previous FOV — retail's exact behavior — but the
|
|
/// aspect still propagates (retail's viewport aspect is likewise updated
|
|
/// independently of the FOV gate).</summary>
|
|
private void ApplyProjection()
|
|
{
|
|
bool fovAccepted = RetailFieldOfView.TryAppliedVerticalFov(
|
|
GameFovRadians, _aspect, out float fovY);
|
|
|
|
Orbit.Aspect = _aspect;
|
|
Fly.Aspect = _aspect;
|
|
if (Chase is { } chase) chase.Aspect = _aspect;
|
|
if (RetailChase is { } retailChase) retailChase.Aspect = _aspect;
|
|
|
|
if (!fovAccepted)
|
|
return;
|
|
Orbit.FovY = fovY;
|
|
Fly.FovY = fovY;
|
|
if (Chase is { } chaseFov) chaseFov.FovY = fovY;
|
|
if (RetailChase is { } retailChaseFov) retailChaseFov.FovY = fovY;
|
|
}
|
|
|
|
internal CameraState CaptureState() =>
|
|
new((int)_mode, Chase, RetailChase);
|
|
|
|
/// <summary>
|
|
/// Restores a previously captured camera lifetime before notifying
|
|
/// subscribers. State remains restored even when a subscriber throws.
|
|
/// </summary>
|
|
internal void RestoreState(CameraState state)
|
|
{
|
|
if (state.ModeCode < (int)Mode.Orbit || state.ModeCode > (int)Mode.Chase)
|
|
throw new ArgumentOutOfRangeException(nameof(state));
|
|
|
|
Chase = state.Chase;
|
|
RetailChase = state.RetailChase;
|
|
// #389: the aspect/game-FOV may have changed while these cameras were
|
|
// captured (a resize during a reset) — reconverge them before anyone
|
|
// reads a projection.
|
|
ApplyProjection();
|
|
_mode = (Mode)state.ModeCode;
|
|
ModeChanged?.Invoke(IsFlyMode || IsChaseMode);
|
|
}
|
|
}
|