fix(anim): stop ACE echo from clobbering player's speedMod; synthesize sequencer velocity

Two related bugs in the motion/animation pipeline:

1. Player's local animation was getting reset to speedMod=1.0 every ~100ms.
   ACE's BroadcastMovement echoes the player's own motion back via
   UpdateMotion. When ACE's ForwardSpeed == 1.0, the ForwardSpeed flag is
   omitted (InterpretedMotionState.BuildMovementFlags), so our wire parser
   returns null and we default to speedMod=1.0 — clobbering the
   locally-authoritative 2.375 × runRate that UpdatePlayerAnimation just
   set. Legs would crank up to full cadence for one frame then get slammed
   back to walking rate.

   Fix: for the player's own guid, skip the wire-echo SetCycle entirely.
   UpdatePlayerAnimation is the authoritative driver for the local
   player's animation; the server echo is only useful for observers of
   other characters. User-confirmed: legs now hold their full cadence.

2. Remote entities teleported between UpdatePositions because the
   sequencer's CurrentVelocity was always zero (Humanoid dat ships every
   locomotion MotionData with Flags=0x00, so EnqueueMotionData leaves
   CurrentVelocity at Vector3.Zero). Dead-reckoning's Priority 1
   (sequencer velocity) never triggered, falling through to EMA which
   has bootstrap lag + gets polluted by teleport-class server snaps.

   Fix: synthesize CurrentVelocity in SetCycle from the retail locomotion
   constants (WalkAnimSpeed=3.12, RunAnimSpeed=4.0, SidestepAnimSpeed=1.25)
   × speedMod, matching the decompiled get_state_velocity (FUN_00528960)
   which uses these same constants directly instead of MotionData.Velocity.
   The dat's HasVelocity field is reserved for non-locomotion motions
   (kick-off velocities, flying creatures, etc).

   Diag confirmed synthesis fires and DR picks it up with src=seq and
   correct magnitude. More visual polish may still be needed for the
   "lagging remote" symptom — see follow-up.

Also adds `PlayerMovementController.BodyVelocity` utility getter for HUD/
debug use, and `ACDREAM_ANIM_SPEED_SCALE` env var as a tunable knob for
visual pacing overrides.

All 717 tests green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-19 16:22:35 +02:00
parent 795d9c8a88
commit 00c8a4feb5
3 changed files with 110 additions and 2 deletions

View file

@ -117,6 +117,9 @@ public sealed class PlayerMovementController
/// </summary>
public float VerticalVelocity => _body.Velocity.Z;
/// <summary>Full 3D world-space velocity of the physics body. Exposed for diagnostic logging.</summary>
public Vector3 BodyVelocity => _body.Velocity;
// Jump charge state.
private bool _jumpCharging;
private float _jumpExtent;

View file

@ -1661,7 +1661,32 @@ public sealed class GameWindow : IDisposable
// No-op if same; the sequencer's fast path guards against that.
uint priorMotion = ae.Sequencer.CurrentMotion;
ae.Sequencer.SetCycle(fullStyle, fullMotion, speedMod);
// CRITICAL: for the local player, UpdatePlayerAnimation is the
// authoritative driver of the sequencer. ACE's BroadcastMovement
// echoes the player's own motion back, but:
// (a) ACE's own ForwardSpeed is `creature.GetRunRate()`, which
// may differ from our locally-computed runRate (ACDREAM_RUN_SKILL
// vs real server-side skills).
// (b) ACE omits the ForwardSpeed flag when speed == 1.0 (per
// InterpretedMotionState.BuildMovementFlags). When omitted,
// our wire parser returns null and we'd default to 1.0 —
// clobbering our locally-authoritative 2.375 × animScale
// and leaving the legs at 30 fps cadence regardless of
// actual run rate.
// So: for the player's own guid, skip the wire-echo SetCycle.
// UpdatePlayerAnimation has already set the correct cycle with
// our locally-chosen speedMod, and that value should persist
// until the next local motion change.
if (update.Guid == _playerServerGuid)
{
// Still update the stance echo (_playerMotionTableId, etc) via
// the paths above, but don't stomp the animation sequencer.
}
else
{
ae.Sequencer.SetCycle(fullStyle, fullMotion, speedMod);
}
// CRITICAL: when we enter a locomotion cycle (Walk/Run/etc),
// stamp the _remoteLastMove timestamp to "now". Without this,
@ -4063,7 +4088,20 @@ public sealed class GameWindow : IDisposable
{
animSpeed = fs;
}
ae.Sequencer.SetCycle(fullStyle, animCommand, animSpeed);
// ACDREAM_ANIM_SPEED_SCALE: optional visual-pacing knob. Retail's
// animation framerate scales linearly with speedMod (r03 §8.3),
// and our speedMod = runRate. If the visual feel doesn't match
// retail, override via env var (default 1.0 = no change).
float animScale = 1.0f;
if (float.TryParse(
Environment.GetEnvironmentVariable("ACDREAM_ANIM_SPEED_SCALE"),
System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture,
out var s) && s > 0f)
{
animScale = s;
}
ae.Sequencer.SetCycle(fullStyle, animCommand, animSpeed * animScale);
}
// Legacy path: update the manual slerp fields (for entities without sequencer)