feat(R3-W5): DoMotion family verbatim + the ONE DoInterpretedMotion + per-op zero-tick flush (closes J3, J4, J9, J14)
The two parallel DoInterpretedMotion implementations MERGE into one verbatim pair (0x00528360/@305639): contact gate, StandingLongJump state-only branch, Dead → RemoveLinkAnimations, the jump_error_code double-check WITH the DisableJumpDuringLink 0x20000 leg (W2's TODO(W5) resolved — MovementParameters now flows), ModifyInterpretedState gating, CurCell-null tail, AddToQueue with the real ContextId; StopInterpretedMotion's post-stop Ready node + raw-mirror RemoveMotion. Legacy overloads + ApplyMotionToInterpretedState DELETED. The funnel's public surface unchanged (183-case suite compiles + passes as-is). DoMotion 0x00528d20 verbatim: cancel_moveto interrupt; SetHoldKey(key, cancelMoveToBit) BEFORE adjust_motion; params re-default for the interpreted call; combat-stance gates on the ORIGINAL id (Crouch/Sit/ Sleep → 0x3f/0x40/0x41; & 0x2000000 → 0x42 outside NonCombat); action depth cap ≥6 → 0x45; raw mirror ORIGINAL id. StopMotion 0x00528530 mirror shape. StopCompletely 0x00527e40 with the A9 snapshot quirk (motion_allows_jump on the OLD forward command, stashed in the queued node) + the J9 fix (sidestep/turn SPEEDS untouched — the 1.0 resets were a divergence). PerformMovement flushes zero-tick completions after every dispatched op via the new CheckForCompletedMotions seam (0x0050fe30) — bound App-side per entity (remotes via EnsureRemoteMotionBindings, player at the sequencer bind site). PORT DISCOVERY (not in the W0 pins): retail's DoInterpretedMotion RESULT gates both add_to_queue AND the state write — a void sink let the style dispatch's apply-only failure clobber ForwardCommand before the forward axis read it, regressing 74/183 live-trace cases. IInterpretedMotionSink.ApplyMotion/StopMotion now return bool (documented on the interface with the raw anchors); one funnel assertion corrected with raw-line citations (airborne ForwardCommand ends at Falling under the fully-wired verbatim algorithm). 62 new gate-table tests. Full suite: 3,729 passed. Implemented by a dedicated agent against the W0-pinned spec; seam bound + suite independently re-verified by the orchestrator. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
e214acdf23
commit
df7b096d6f
7 changed files with 1522 additions and 241 deletions
|
|
@ -4217,6 +4217,9 @@ public sealed class GameWindow : IDisposable
|
|||
rm.Motion.DefaultSink = rm.Sink;
|
||||
rm.Motion.RemoveLinkAnimations = ae.Sequencer.RemoveAllLinkAnimations;
|
||||
rm.Motion.InitializeMotionTables = () => ae.Sequencer.Manager.InitializeState();
|
||||
// R3-W5: the per-op zero-tick flush (CPhysicsObj::CheckForCompletedMotions
|
||||
// 0x0050fe30 -> MotionTableManager.CheckForCompletedMotions).
|
||||
rm.Motion.CheckForCompletedMotions = ae.Sequencer.Manager.CheckForCompletedMotions;
|
||||
return rm.Sink;
|
||||
}
|
||||
|
||||
|
|
@ -12992,6 +12995,8 @@ public sealed class GameWindow : IDisposable
|
|||
_playerController.Motion.RemoveLinkAnimations = playerSeq.RemoveAllLinkAnimations;
|
||||
_playerController.Motion.InitializeMotionTables =
|
||||
() => playerSeq.Manager.InitializeState();
|
||||
_playerController.Motion.CheckForCompletedMotions =
|
||||
playerSeq.Manager.CheckForCompletedMotions;
|
||||
}
|
||||
|
||||
var q = playerEntity.Rotation;
|
||||
|
|
|
|||
|
|
@ -24,14 +24,38 @@ public interface IInterpretedMotionSink
|
|||
/// (<c>PerformMovement</c> → GetObjectSequence + is_allowed decide) —
|
||||
/// no sink-side axis pick or fallback chain.
|
||||
/// </summary>
|
||||
void ApplyMotion(uint motion, float speed);
|
||||
/// <returns>
|
||||
/// R3-W5: retail's own <c>CPhysicsObj::DoInterpretedMotion</c> RETURNS a
|
||||
/// result (<c>result == 0</c> = the motion table found a cycle for this
|
||||
/// id; nonzero = <c>MotionTableManagerError.MotionFailed</c>/no-table) —
|
||||
/// <c>CMotionInterp::DoInterpretedMotion</c>'s caller (raw 305591-305610)
|
||||
/// gates BOTH the <c>add_to_queue</c> call AND the
|
||||
/// <c>InterpretedMotionState::ApplyMotion</c> state-write on that result.
|
||||
/// This matters concretely for the very first dispatch of every
|
||||
/// <c>apply_interpreted_movement</c> call — the STYLE/stance id
|
||||
/// (<c>current_style</c>, always <c>>= 0x80000000</c>) has no
|
||||
/// locomotion <c>MotionData</c> entry in the dat, so
|
||||
/// <c>CMotionTable::DoObjectMotion</c> genuinely fails for it; if that
|
||||
/// failure isn't propagated, the state-write's negative-motion branch
|
||||
/// (<see cref="InterpretedMotionState.ApplyMotion"/>: <c>arg2 < 0 →
|
||||
/// forward_command = 0x41000003</c>) clobbers <c>ForwardCommand</c>
|
||||
/// BEFORE the very next line reads it for the real forward dispatch —
|
||||
/// confirmed regression against the 183-case live retail-observer trace
|
||||
/// (<c>RetailObserverTraceConformanceTests</c>) when this was <c>void</c>.
|
||||
/// Return <c>true</c> when the underlying <c>PerformMovement</c> call
|
||||
/// succeeded (<c>MotionTableManagerError.Success</c>).
|
||||
/// </returns>
|
||||
bool ApplyMotion(uint motion, float speed);
|
||||
|
||||
/// <summary>
|
||||
/// <c>StopInterpretedMotion</c> notification for an axis the incoming
|
||||
/// state cleared (sidestep 0x6500000F / turn 0x6500000D). Unconditional
|
||||
/// (no contact gate) per apply_interpreted_movement.
|
||||
/// </summary>
|
||||
void StopMotion(uint motion);
|
||||
/// <returns>Same result-propagation rationale as <see cref="ApplyMotion"/>
|
||||
/// — retail's <c>CPhysicsObj::StopInterpretedMotion</c> also returns a
|
||||
/// result that gates the post-stop <c>add_to_queue</c> + state-removal.</returns>
|
||||
bool StopMotion(uint motion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -52,19 +52,21 @@ public sealed class MotionTableDispatchSink : IInterpretedMotionSink
|
|||
private static bool IsTurn(uint motion)
|
||||
=> (motion & 0xFF000000u) == 0x65000000u && (motion & 0xFFu) is 0x0D or 0x0E;
|
||||
|
||||
public void ApplyMotion(uint motion, float speed)
|
||||
public bool ApplyMotion(uint motion, float speed)
|
||||
{
|
||||
if (IsTurn(motion))
|
||||
TurnApplied?.Invoke(motion, speed);
|
||||
|
||||
_sequencer.PerformMovement(MotionTableMovement.Interpreted(motion, speed));
|
||||
uint result = _sequencer.PerformMovement(MotionTableMovement.Interpreted(motion, speed));
|
||||
return result == MotionTableManagerError.Success;
|
||||
}
|
||||
|
||||
public void StopMotion(uint motion)
|
||||
public bool StopMotion(uint motion)
|
||||
{
|
||||
if (IsTurn(motion))
|
||||
TurnStopped?.Invoke();
|
||||
|
||||
_sequencer.PerformMovement(MotionTableMovement.StopInterpreted(motion, 1f));
|
||||
uint result = _sequencer.PerformMovement(MotionTableMovement.StopInterpreted(motion, 1f));
|
||||
return result == MotionTableManagerError.Success;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -676,6 +676,24 @@ public sealed class MotionInterpreter : IMotionDoneSink
|
|||
/// </summary>
|
||||
public Action? InitializeMotionTables { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// R3-W5 seam standing in for retail <c>CPhysicsObj::CheckForCompletedMotions</c>
|
||||
/// (0x0050fe30, decomp §7d @277925) → <c>CPartArray::CheckForCompletedMotions</c>
|
||||
/// → <c>MotionTableManager::CheckForCompletedMotions</c> (the SECOND call
|
||||
/// site of the shared animation-completion driver, §7b) — called by
|
||||
/// <see cref="PerformMovement"/> after EVERY dispatched op (raw
|
||||
/// 306234/306241/306248/306255/306262, §2/§7d), synchronously draining
|
||||
/// any already-elapsed (0-duration) animation-table node right after the
|
||||
/// motion is applied, in case the newly-applied motion table entry
|
||||
/// completes immediately. The App layer binds this to the entity's
|
||||
/// <c>MotionTableManager.CheckForCompletedMotions</c> (R2-Q3 object),
|
||||
/// matching the existing <see cref="RemoveLinkAnimations"/>/
|
||||
/// <see cref="UnstickFromObject"/> <c>Action?</c> seam convention. A null
|
||||
/// binding is a silent no-op (safe default for tests and for any physics
|
||||
/// body with no MotionTableManager attached yet).
|
||||
/// </summary>
|
||||
public Action? CheckForCompletedMotions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// R3-W4 — retail <c>CMotionInterp::initted</c> (set by
|
||||
/// <see cref="EnterDefaultState"/>, raw @306152: <c>this->initted =
|
||||
|
|
@ -780,196 +798,288 @@ public sealed class MotionInterpreter : IMotionDoneSink
|
|||
/// case 5: StopCompletely()
|
||||
/// default: return 0x47
|
||||
/// }
|
||||
/// FUN_00510900() — CheckForCompletedMotions (animation flush, not simulated here)
|
||||
/// FUN_0050fe30 — CPhysicsObj::CheckForCompletedMotions, called after EVERY
|
||||
/// dispatched op (raw 306234/306241/306248/306255/306262, R3-W5 closes J14).
|
||||
/// </summary>
|
||||
public WeenieError PerformMovement(MovementStruct mvs)
|
||||
{
|
||||
var p = new MovementParameters
|
||||
{
|
||||
Speed = mvs.Speed,
|
||||
ModifyInterpretedState = mvs.ModifyInterpretedState,
|
||||
ModifyRawState = mvs.ModifyRawState,
|
||||
};
|
||||
|
||||
bool dispatched = true;
|
||||
WeenieError result = mvs.Type switch
|
||||
{
|
||||
MovementType.RawCommand => DoMotion(mvs.Motion, mvs.Speed),
|
||||
MovementType.InterpretedCommand => DoInterpretedMotion(mvs.Motion, mvs.Speed, mvs.ModifyInterpretedState),
|
||||
MovementType.StopRawCommand => StopMotion(mvs.Motion),
|
||||
MovementType.StopInterpretedCommand => StopInterpretedMotion(mvs.Motion, mvs.ModifyInterpretedState),
|
||||
MovementType.RawCommand => DoMotion(mvs.Motion, p),
|
||||
MovementType.InterpretedCommand => DoInterpretedMotion(mvs.Motion, p),
|
||||
MovementType.StopRawCommand => StopMotion(mvs.Motion, p),
|
||||
MovementType.StopInterpretedCommand => StopInterpretedMotion(mvs.Motion, p),
|
||||
MovementType.StopCompletely => StopCompletely(),
|
||||
_ => WeenieError.GeneralMovementFailure,
|
||||
_ => Invalid(out dispatched),
|
||||
};
|
||||
// FUN_00510900 — CheckForCompletedMotions is an animation system flush;
|
||||
// no simulation state to update here.
|
||||
|
||||
// R3-W5 (closes J14): CPhysicsObj::CheckForCompletedMotions fires
|
||||
// after EVERY dispatched op — a synchronous zero-tick flush so a
|
||||
// newly-applied motion-table entry that completes IMMEDIATELY
|
||||
// (0-duration node) gets its MotionDone callback in the same call,
|
||||
// not on the next tick. The type-dispatch failure path (bad
|
||||
// MovementStruct.type, 0x47) never reaches a dispatch, so it must
|
||||
// NOT flush — matches retail's raw 306227 early-return before the
|
||||
// switch even begins.
|
||||
if (dispatched)
|
||||
CheckForCompletedMotions?.Invoke();
|
||||
|
||||
return result;
|
||||
|
||||
static WeenieError Invalid(out bool dispatched)
|
||||
{
|
||||
dispatched = false;
|
||||
return WeenieError.GeneralMovementFailure;
|
||||
}
|
||||
}
|
||||
|
||||
// ── FUN_00529930 — DoMotion ───────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Process one raw motion command from a network packet.
|
||||
///
|
||||
/// Decompiled logic (FUN_00529930):
|
||||
/// Copy packet fields into local variables (at local_24..local_4).
|
||||
/// If the speed byte in flags is negative → call FUN_00510cc0 (cancel moveto).
|
||||
/// If 0x800 flag → FUN_005297c0 (set hold key from packet).
|
||||
/// FUN_00528c20 — adjust_motion (raw→interpreted adjustments).
|
||||
/// Guard against special mid-animation states (returns 0x3F/0x40/0x41/0x42).
|
||||
/// If Action bit (0x10000000) set and num_actions ≥ 6 → return 0x45.
|
||||
/// Call DoInterpretedMotion(motion, movementParams).
|
||||
///
|
||||
/// Our simplified port focuses on the state fields and physics side-effects.
|
||||
/// <c>CMotionInterp::DoMotion</c> (0x00528d20, decomp §2 @306159, FULL
|
||||
/// BODY, R3-W5, closes J3). App-facing 2-arg compat overload —
|
||||
/// PlayerMovementController's call sites pass a raw
|
||||
/// <c>(uint motion, float speed)</c> pair; this builds a
|
||||
/// default-constructed <see cref="MovementParameters"/> (retail's own
|
||||
/// UnPack/CommandInterpreter callers build one the same way for a bare
|
||||
/// raw command) with <see cref="MovementParameters.Speed"/> overridden,
|
||||
/// then delegates to the verbatim overload below.
|
||||
/// </summary>
|
||||
public WeenieError DoMotion(uint motion, float speed = 1.0f)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
// Record the new raw forward command and speed.
|
||||
// In the decompile, local_24 = *(param_3+8) = ForwardCommand,
|
||||
// local_18 = ForwardSpeed, etc.
|
||||
RawState.ForwardCommand = motion;
|
||||
RawState.ForwardSpeed = speed;
|
||||
|
||||
// Delegate to the interpreted path. DoMotion ultimately calls
|
||||
// DoInterpretedMotion after adjust_motion in the retail client.
|
||||
return DoInterpretedMotion(motion, speed, modifyInterpretedState: true);
|
||||
}
|
||||
|
||||
// ── DoInterpretedMotion ────────────────────────────────────────────────────
|
||||
=> DoMotion(motion, new MovementParameters { Speed = speed });
|
||||
|
||||
/// <summary>
|
||||
/// Core animation-state-machine entry point (FUN_00528f70).
|
||||
/// <c>CMotionInterp::DoMotion</c> (0x00528d20, decomp §2 @306159, FULL
|
||||
/// BODY, R3-W5, closes J3).
|
||||
///
|
||||
/// In the full retail engine this runs the animation sequencer. In this
|
||||
/// physics-only port we update the InterpretedState and call
|
||||
/// apply_current_movement so that the velocity is immediately reflected.
|
||||
/// <para>
|
||||
/// Verbatim (raw 306159-306221):
|
||||
/// <code>
|
||||
/// if (physics_obj == 0) return 8;
|
||||
/// ebp = arg2; // ORIGINAL motion id, unmutated
|
||||
/// snapshot every MovementParameters field onto the stack;
|
||||
/// var_2c = fresh local MovementParameters(); // re-default
|
||||
/// if (bitfield sign bit) interrupt_current_movement(physics_obj);
|
||||
/// if (bitfield & 0x800 /*SetHoldKey*/)
|
||||
/// SetHoldKey(hold_key_to_apply, (bitfield>>0xf)&1 /*cancel_moveto bit, A4*/);
|
||||
/// adjust_motion(&arg2, &speed, hold_key_to_apply); // mutates arg2/speed in place
|
||||
/// if (interpreted_state.current_style != 0x8000003d) { // combat/special stance
|
||||
/// if (ebp == 0x41000012) return 0x3f;
|
||||
/// if (ebp == 0x41000013) return 0x40;
|
||||
/// if (ebp == 0x41000014) return 0x41;
|
||||
/// if (ebp & 0x2000000) return 0x42;
|
||||
/// }
|
||||
/// if ((ebp & 0x10000000) && GetNumActions() >= 6) return 0x45;
|
||||
/// result = DoInterpretedMotion(arg2 /*ADJUSTED*/, &var_2c /*fresh local params*/);
|
||||
/// if (result == 0 && bitfield & 0x2000 /*ModifyRawState*/)
|
||||
/// RawMotionState::ApplyMotion(ebp /*ORIGINAL*/, arg3 /*CALLER's params, not var_2c*/);
|
||||
/// return result;
|
||||
/// </code>
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Two mirror-discipline details, both verbatim: (1) the
|
||||
/// <see cref="DoInterpretedMotion(uint,MovementParameters)"/> call
|
||||
/// receives a FRESH local <see cref="MovementParameters"/> (re-defaulted,
|
||||
/// only <c>Speed</c>/<c>HoldKeyToApply</c> carried through
|
||||
/// <c>adjust_motion</c>'s mutation) — the caller's own
|
||||
/// <paramref name="p"/> distance/heading/fail-distance fields are
|
||||
/// discarded for the interpreted call, matching retail's explicit
|
||||
/// re-construction of <c>var_2c</c>. (2) the raw-state mirror at the
|
||||
/// bottom reads the ORIGINAL <c>arg3</c> (<paramref name="p"/>) — NOT
|
||||
/// <c>var_2c</c> — for <see cref="MovementParameters.SetHoldKey"/>/
|
||||
/// <see cref="MovementParameters.HoldKeyToApply"/>/<see cref="MovementParameters.Speed"/>,
|
||||
/// per <c>RawMotionState::ApplyMotion</c>'s own signature
|
||||
/// (<c>const MovementParameters*</c>) receiving the same pointer
|
||||
/// <c>DoMotion</c> was called with.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public WeenieError DoInterpretedMotion(uint motion, float speed = 1.0f, bool modifyInterpretedState = false)
|
||||
/// <param name="motion">Retail <c>arg2</c> (the ORIGINAL, pre-adjustment
|
||||
/// motion id — <c>ebp</c>).</param>
|
||||
/// <param name="p">Retail <c>arg3</c>.</param>
|
||||
public WeenieError DoMotion(uint motion, MovementParameters p)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
if (!contact_allows_move(motion))
|
||||
uint originalMotion = motion;
|
||||
float speed = p.Speed;
|
||||
var local = new MovementParameters(); // var_2c — fresh re-default
|
||||
|
||||
if (p.CancelMoveTo) // bitfield high-byte sign bit
|
||||
InterruptCurrentMovement?.Invoke();
|
||||
|
||||
if (p.SetHoldKey) // bitfield & 0x800
|
||||
SetHoldKey(p.HoldKeyToApply, p.CancelMoveTo); // A4: 2nd arg IS the cancel_moveto bit
|
||||
|
||||
adjust_motion(ref motion, ref speed, p.HoldKeyToApply); // mutates motion/speed in place
|
||||
|
||||
if (InterpretedState.CurrentStyle != 0x8000003du) // not MotionStance_NonCombat
|
||||
{
|
||||
// Action commands (bit 0x10000000) are blocked mid-air. A10:
|
||||
// DoInterpretedMotion @305622-305623 returns 0x24 (NotGrounded)
|
||||
// here, not 0x48 (that code is reserved for the
|
||||
// motion_allows_jump literal-range blocklist).
|
||||
if ((motion & 0x10000000u) != 0)
|
||||
return WeenieError.NotGrounded;
|
||||
// Non-action motions are queued silently; state still updates.
|
||||
if (originalMotion == MotionCommand.Crouch)
|
||||
return WeenieError.CrouchInCombatStance; // 0x3f
|
||||
if (originalMotion == MotionCommand.Sitting)
|
||||
return WeenieError.SitInCombatStance; // 0x40
|
||||
if (originalMotion == MotionCommand.Sleeping)
|
||||
return WeenieError.SleepInCombatStance; // 0x41
|
||||
if ((originalMotion & 0x2000000u) != 0)
|
||||
return WeenieError.ChatEmoteOutsideNonCombat; // 0x42
|
||||
}
|
||||
|
||||
if (modifyInterpretedState)
|
||||
ApplyMotionToInterpretedState(motion, speed);
|
||||
if ((originalMotion & 0x10000000u) != 0 && InterpretedState.GetNumActions() >= 6)
|
||||
return WeenieError.ActionDepthExceeded; // 0x45
|
||||
|
||||
apply_current_movement(cancelMoveTo: false, allowJump: true);
|
||||
return WeenieError.None;
|
||||
local.Speed = speed;
|
||||
local.HoldKeyToApply = p.HoldKeyToApply;
|
||||
|
||||
WeenieError result = DoInterpretedMotion(motion, local); // ADJUSTED id, fresh local params
|
||||
|
||||
if (result == WeenieError.None && p.ModifyRawState) // bitfield & 0x2000
|
||||
RawState.ApplyMotion(originalMotion, p); // ORIGINAL id, CALLER's params (arg3, not var_2c)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── StopMotion ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Stop a specific raw motion (FUN_00529140 → StopInterpretedMotion).
|
||||
/// App-facing compat overload for <c>StopMotion</c> (0x00528530, decomp
|
||||
/// §5b @305674). Builds a default-constructed <see cref="MovementParameters"/>
|
||||
/// and delegates to the verbatim overload below.
|
||||
/// </summary>
|
||||
public WeenieError StopMotion(uint motion)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
if (RawState.ForwardCommand == motion)
|
||||
{
|
||||
RawState.ForwardCommand = MotionCommand.Ready;
|
||||
RawState.ForwardSpeed = 1.0f;
|
||||
}
|
||||
if (RawState.SidestepCommand == motion)
|
||||
{
|
||||
RawState.SidestepCommand = 0;
|
||||
RawState.SidestepSpeed = 1.0f;
|
||||
}
|
||||
if (RawState.TurnCommand == motion)
|
||||
{
|
||||
RawState.TurnCommand = 0;
|
||||
RawState.TurnSpeed = 1.0f;
|
||||
}
|
||||
|
||||
return StopInterpretedMotion(motion, modifyInterpretedState: true);
|
||||
}
|
||||
|
||||
// ── StopInterpretedMotion ────────────────────────────────────────────────
|
||||
=> StopMotion(motion, new MovementParameters());
|
||||
|
||||
/// <summary>
|
||||
/// Stop a specific interpreted motion (FUN_00529080).
|
||||
/// </summary>
|
||||
public WeenieError StopInterpretedMotion(uint motion, bool modifyInterpretedState = false)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
if (modifyInterpretedState)
|
||||
{
|
||||
if (InterpretedState.ForwardCommand == motion)
|
||||
{
|
||||
InterpretedState.ForwardCommand = MotionCommand.Ready;
|
||||
InterpretedState.ForwardSpeed = 1.0f;
|
||||
}
|
||||
if (InterpretedState.SideStepCommand == motion)
|
||||
{
|
||||
InterpretedState.SideStepCommand = 0;
|
||||
InterpretedState.SideStepSpeed = 1.0f;
|
||||
}
|
||||
if (InterpretedState.TurnCommand == motion)
|
||||
{
|
||||
InterpretedState.TurnCommand = 0;
|
||||
InterpretedState.TurnSpeed = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
apply_current_movement(cancelMoveTo: false, allowJump: false);
|
||||
return WeenieError.None;
|
||||
}
|
||||
|
||||
// ── FUN_00528a50 — StopCompletely ─────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Reset both raw and interpreted states to Ready/idle, then push zero velocity.
|
||||
/// <c>CMotionInterp::StopMotion</c> (0x00528530, decomp §5b @305674, FULL
|
||||
/// BODY, R3-W5, closes J3's StopMotion leg). The <c>DoMotion</c> mirror:
|
||||
/// same defaulting/reconstruction pattern, same optional
|
||||
/// <c>interrupt_current_movement</c>, same <c>adjust_motion</c>
|
||||
/// reinterpretation — but NO combat-stance or action-depth gating (those
|
||||
/// are <c>DoMotion</c>-only).
|
||||
///
|
||||
/// Decompiled logic (FUN_00528a50):
|
||||
/// if (PhysicsObj == null) return 8
|
||||
/// FUN_00510cc0() — cancel moveto
|
||||
/// uVar1 = FUN_005285e0(InterpretedState.ForwardCommand) — motion_allows_jump
|
||||
/// *(+0x20) = 0x41000003 (RawState.ForwardCommand = Ready)
|
||||
/// *(+0x28) = 0x3f800000 (RawState.ForwardSpeed = 1.0f)
|
||||
/// *(+0x2c) = 0 (RawState.SidestepCommand = 0)
|
||||
/// *(+0x38) = 0 (RawState.TurnCommand = 0)
|
||||
/// *(+0x4c) = 0x41000003 (InterpretedState.ForwardCommand = Ready)
|
||||
/// *(+0x50) = 0x3f800000 (InterpretedState.ForwardSpeed = 1.0f)
|
||||
/// *(+0x54) = 0 (InterpretedState.SideStepCommand = 0)
|
||||
/// *(+0x5c) = 0 (InterpretedState.TurnCommand = 0)
|
||||
/// FUN_0050f5a0() — StopCompletely_Internal (zero velocity on PhysicsObj)
|
||||
/// FUN_00528790(…) — add_to_queue
|
||||
/// if (PhysicsObj != null && CurCell == null) → FUN_005108f0 (RemoveLinkAnimations)
|
||||
/// return 0
|
||||
/// <para>
|
||||
/// Verbatim (raw 305674-305706): snapshot <paramref name="p"/> fields,
|
||||
/// build a fresh local <see cref="MovementParameters"/>, optional
|
||||
/// interrupt on the sign bit, <c>adjust_motion(&arg3, &speed,
|
||||
/// hold_key_to_apply)</c> (mutates the motion id in place — note retail
|
||||
/// reuses the <c>arg3</c> register slot for the motion id here, not a
|
||||
/// separate local), delegate to
|
||||
/// <c>StopInterpretedMotion(adjusted, &local)</c>; on success AND
|
||||
/// bit <c>0x2000</c> (ModifyRawState), mirror via
|
||||
/// <c>RawMotionState::RemoveMotion(ORIGINAL motion)</c> — using the
|
||||
/// ORIGINAL unmutated id, matching <c>DoMotion</c>'s equivalent
|
||||
/// <c>ApplyMotion(ebp, arg3)</c> mirror discipline.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="motion">Retail <c>arg2</c> (the ORIGINAL motion id).</param>
|
||||
/// <param name="p">Retail <c>arg3</c>.</param>
|
||||
public WeenieError StopMotion(uint motion, MovementParameters p)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
uint originalMotion = motion;
|
||||
float speed = p.Speed;
|
||||
var local = new MovementParameters(); // fresh re-default
|
||||
|
||||
if (p.CancelMoveTo)
|
||||
InterruptCurrentMovement?.Invoke();
|
||||
|
||||
adjust_motion(ref motion, ref speed, p.HoldKeyToApply);
|
||||
|
||||
local.Speed = speed;
|
||||
local.HoldKeyToApply = p.HoldKeyToApply;
|
||||
|
||||
WeenieError result = StopInterpretedMotion(motion, local); // ADJUSTED id
|
||||
|
||||
if (result == WeenieError.None && p.ModifyRawState)
|
||||
RawState.RemoveMotion(originalMotion); // ORIGINAL id
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── FUN_00527e40 — StopCompletely ─────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// <c>CMotionInterp::StopCompletely</c> (0x00527e40, decomp §5a @305208,
|
||||
/// FULL BODY, R3-W5, closes J9). W0-pins.md A9 — ported INCLUDING the
|
||||
/// jump-snapshot quirk.
|
||||
///
|
||||
/// <para>
|
||||
/// Verbatim (raw 305208-305236):
|
||||
/// <code>
|
||||
/// if (physics_obj == 0) return 8;
|
||||
/// interrupt_current_movement(physics_obj);
|
||||
/// eax_2 = motion_allows_jump(interpreted_state.forward_command); // OLD fwd, BEFORE overwrite
|
||||
/// raw_state.forward_command = 0x41000003; raw_state.forward_speed = 1f;
|
||||
/// raw_state.sidestep_command = 0; raw_state.turn_command = 0;
|
||||
/// interpreted_state.forward_command = 0x41000003; interpreted_state.forward_speed = 1f;
|
||||
/// interpreted_state.sidestep_command = 0; interpreted_state.turn_command = 0;
|
||||
/// StopCompletely_Internal(physics_obj);
|
||||
/// add_to_queue(0, 0x41000003, eax_2); // eax_2 = the PRE-overwrite snapshot
|
||||
/// if (physics_obj != 0 && physics_obj->cell == 0) RemoveLinkAnimations(physics_obj);
|
||||
/// return 0;
|
||||
/// </code>
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <b>A9 quirk</b>: <c>motion_allows_jump</c> is evaluated on the OLD
|
||||
/// <c>interpreted_state.forward_command</c> BEFORE it gets overwritten
|
||||
/// two lines later — the queued node's <c>JumpErrorCode</c> reflects the
|
||||
/// PRE-stop command, not the post-stop Ready command (which would always
|
||||
/// pass). <b>J9</b>: retail touches ONLY the forward command/speed plus
|
||||
/// the sidestep/turn COMMANDS — it does NOT write <c>sidestep_speed</c>
|
||||
/// or <c>turn_speed</c> on either state. The pre-R3 acdream divergence
|
||||
/// (unconditional 1.0 speed resets on all four speed fields) is REMOVED
|
||||
/// here.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <c>StopCompletely_Internal</c> (0x0050f5a0, CPhysicsObj-side) stands
|
||||
/// in as <see cref="PhysicsBody.set_velocity"/>(Zero) — register row,
|
||||
/// kept (full port is physics-layer scope, r3-port-plan.md §2 KEEP
|
||||
/// LIST). CurCell proxy: <see cref="PhysicsBody.CellPosition"/>.<c>ObjCellId
|
||||
/// == 0</c> (unseeded/detached body — matches <c>cell == 0</c>).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public WeenieError StopCompletely()
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
// Reset raw state
|
||||
InterruptCurrentMovement?.Invoke();
|
||||
|
||||
// A9: snapshot BEFORE the overwrite below.
|
||||
WeenieError jumpSnapshot = MotionAllowsJump(InterpretedState.ForwardCommand);
|
||||
|
||||
// J9: forward cmd/speed + sidestep/turn COMMANDS only — speeds untouched.
|
||||
RawState.ForwardCommand = MotionCommand.Ready;
|
||||
RawState.ForwardSpeed = 1.0f;
|
||||
RawState.SidestepCommand = 0;
|
||||
RawState.SidestepSpeed = 1.0f;
|
||||
RawState.TurnCommand = 0;
|
||||
RawState.TurnSpeed = 1.0f;
|
||||
|
||||
// Reset interpreted state
|
||||
InterpretedState.ForwardCommand = MotionCommand.Ready;
|
||||
InterpretedState.ForwardSpeed = 1.0f;
|
||||
InterpretedState.SideStepCommand = 0;
|
||||
InterpretedState.SideStepSpeed = 1.0f;
|
||||
InterpretedState.TurnCommand = 0;
|
||||
InterpretedState.TurnSpeed = 1.0f;
|
||||
|
||||
// Zero the body velocity (FUN_0050f5a0 = StopCompletely_Internal)
|
||||
// StopCompletely_Internal (0x0050f5a0) stand-in.
|
||||
PhysicsObj.set_velocity(Vector3.Zero);
|
||||
|
||||
AddToQueue(contextId: 0, MotionCommand.Ready, (uint)jumpSnapshot);
|
||||
|
||||
if (PhysicsObj.CellPosition.ObjCellId == 0)
|
||||
RemoveLinkAnimations?.Invoke();
|
||||
|
||||
return WeenieError.None;
|
||||
}
|
||||
|
||||
|
|
@ -2461,42 +2571,11 @@ public sealed class MotionInterpreter : IMotionDoneSink
|
|||
return RunAnimSpeed * rate;
|
||||
}
|
||||
|
||||
// ── private helper ────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Apply a motion command to the interpreted state fields.
|
||||
/// Mirrors the InterpretedState.ApplyMotion logic in ACE.
|
||||
/// </summary>
|
||||
private void ApplyMotionToInterpretedState(uint motion, float speed)
|
||||
{
|
||||
switch (motion)
|
||||
{
|
||||
case MotionCommand.WalkForward:
|
||||
case MotionCommand.RunForward:
|
||||
case MotionCommand.WalkBackward:
|
||||
InterpretedState.ForwardCommand = motion;
|
||||
InterpretedState.ForwardSpeed = speed;
|
||||
break;
|
||||
case MotionCommand.SideStepRight:
|
||||
case MotionCommand.SideStepLeft:
|
||||
InterpretedState.SideStepCommand = motion;
|
||||
InterpretedState.SideStepSpeed = speed;
|
||||
break;
|
||||
case MotionCommand.TurnRight:
|
||||
case MotionCommand.TurnLeft:
|
||||
InterpretedState.TurnCommand = motion;
|
||||
InterpretedState.TurnSpeed = speed;
|
||||
break;
|
||||
case MotionCommand.Ready:
|
||||
InterpretedState.ForwardCommand = MotionCommand.Ready;
|
||||
InterpretedState.ForwardSpeed = 1.0f;
|
||||
InterpretedState.SideStepCommand = 0;
|
||||
InterpretedState.SideStepSpeed = 1.0f;
|
||||
InterpretedState.TurnCommand = 0;
|
||||
InterpretedState.TurnSpeed = 1.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// R3-W5: the former `ApplyMotionToInterpretedState` private helper
|
||||
// (a hand-rolled switch approximating InterpretedMotionState.ApplyMotion)
|
||||
// is DELETED per the plan (closes J3/J4) — the merged DoInterpretedMotion
|
||||
// below calls the verbatim InterpretedMotionState.ApplyMotion(motion, p)
|
||||
// directly (already ported, W1).
|
||||
|
||||
// ══ L.2g S2 — the inbound CMotionInterp funnel (DEV-1) ════════════════
|
||||
// Spec: docs/research/2026-07-02-s2-inbound-funnel-pseudocode.md.
|
||||
|
|
@ -2656,14 +2735,14 @@ public sealed class MotionInterpreter : IMotionDoneSink
|
|||
else if (StandingLongJump)
|
||||
{
|
||||
DispatchInterpretedMotion(MotionCommand.Ready, 1.0f, sink);
|
||||
sink?.StopMotion(MotionCommand.SideStepRight);
|
||||
DispatchStopInterpretedMotion(MotionCommand.SideStepRight, sink);
|
||||
}
|
||||
else
|
||||
{
|
||||
DispatchInterpretedMotion(
|
||||
InterpretedState.ForwardCommand, InterpretedState.ForwardSpeed, sink);
|
||||
if (InterpretedState.SideStepCommand == 0)
|
||||
sink?.StopMotion(MotionCommand.SideStepRight);
|
||||
DispatchStopInterpretedMotion(MotionCommand.SideStepRight, sink);
|
||||
else
|
||||
DispatchInterpretedMotion(
|
||||
InterpretedState.SideStepCommand, InterpretedState.SideStepSpeed, sink);
|
||||
|
|
@ -2676,77 +2755,329 @@ public sealed class MotionInterpreter : IMotionDoneSink
|
|||
return; // retail early return — no idle-stop this call
|
||||
}
|
||||
|
||||
sink?.StopMotion(MotionCommand.TurnRight);
|
||||
// add_to_queue(context, Ready, 0) — R3-W2 (closes J1). TODO(W5):
|
||||
// real ContextId once MovementParameters flows through this funnel
|
||||
// (retail's own local here is READ UNINITIALIZED in the decompile —
|
||||
// see the final-report contextId note).
|
||||
AddToQueue(contextId: 0, MotionCommand.Ready, jumpErrorCode: 0);
|
||||
// Tail (raw 305766-305786): unconditional StopInterpretedMotion(TurnRight,
|
||||
// params) — the merged StopInterpretedMotion ITSELF performs the
|
||||
// add_to_queue(context, Ready, 0) + RemoveMotion(TurnRight) on
|
||||
// success, so no separate AddToQueue call is needed here anymore
|
||||
// (R3-W5 moves this bookkeeping into the merged function body).
|
||||
DispatchStopInterpretedMotion(MotionCommand.TurnRight, sink);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <c>CMotionInterp::DoInterpretedMotion</c> (0x00528360, pseudo-C
|
||||
/// 305575), sink-dispatch form: motions that pass
|
||||
/// <c>contact_allows_move</c> reach the GetObjectSequence backend
|
||||
/// (<see cref="IInterpretedMotionSink.ApplyMotion"/>); blocked
|
||||
/// non-action motions take the apply-only path (state already copied,
|
||||
/// NO cycle change — this is retail's real mechanism behind "airborne
|
||||
/// remotes keep their Falling cycle"). Blocked action-class motions
|
||||
/// (0x10000000 bit) are rejected outright (0x24).
|
||||
/// <c>CMotionInterp::DoInterpretedMotion</c> (0x00528360, raw
|
||||
/// 305575-305631, FULL BODY, R3-W5, closes J4). THE ONE
|
||||
/// <c>DoInterpretedMotion</c> — merges the former legacy
|
||||
/// <c>(uint, float, bool)</c> overload's state-management with the S2a
|
||||
/// funnel's <c>DispatchInterpretedMotion</c> sink-dispatch backend.
|
||||
///
|
||||
/// <para>
|
||||
/// <b>R3-W2 producer (closes J1's DoInterpretedMotion leg):</b> on the
|
||||
/// success path (raw 305591-305610), retail computes the queue node's
|
||||
/// <c>jump_error_code</c> via a DOUBLE-CHECK shape before calling
|
||||
/// <c>add_to_queue(context_id, arg2, eax_5)</c>:
|
||||
/// Verbatim (raw 305577-305631):
|
||||
/// <code>
|
||||
/// if ((params->bitfield & 0x20000) == 0) { // NOT disable_jump_during_link
|
||||
/// eax_5 = motion_allows_jump(arg2);
|
||||
/// if (eax_5 == 0 && (arg2 & 0x10000000) == 0) // passed AND not action-class
|
||||
/// eax_5 = motion_allows_jump(interpreted_state.forward_command);
|
||||
/// } else {
|
||||
/// eax_5 = 0x48; // DisableJumpDuringLink forces BLOCKED
|
||||
/// }
|
||||
/// add_to_queue(context_id, arg2, eax_5);
|
||||
/// if (physics_obj == 0) return 8;
|
||||
/// if (contact_allows_move(arg2)) {
|
||||
/// if (standing_longjump != 0
|
||||
/// && (arg2 == WalkForward || arg2 == RunForward || arg2 == SideStepRight))
|
||||
/// goto label_528440; // StandingLongJump: state-only, no dispatch, no queue
|
||||
/// if (arg2 == 0x40000011 /*Dead*/) RemoveLinkAnimations(physics_obj);
|
||||
/// result = sink.ApplyMotion(arg2, arg3); // CPhysicsObj::DoInterpretedMotion stand-in
|
||||
/// if (result == 0) {
|
||||
/// if ((arg3->bitfield & 0x20000) == 0) { // NOT DisableJumpDuringLink
|
||||
/// eax_5 = motion_allows_jump(arg2);
|
||||
/// if (eax_5 == 0 && (arg2 & 0x10000000) == 0)
|
||||
/// eax_5 = motion_allows_jump(interpreted_state.forward_command);
|
||||
/// } else eax_5 = 0x48; // DisableJumpDuringLink FORCES blocked
|
||||
/// add_to_queue(arg3->context_id, arg2, eax_5);
|
||||
/// if (arg3->bitfield & 0x4000 /*ModifyInterpretedState*/)
|
||||
/// InterpretedMotionState::ApplyMotion(arg2, arg3);
|
||||
/// }
|
||||
/// } else if ((arg2 & 0x10000000) == 0) {
|
||||
/// label_528440:
|
||||
/// if (arg3->bitfield & 0x4000) InterpretedMotionState::ApplyMotion(arg2, arg3);
|
||||
/// result = 0;
|
||||
/// } else result = 0x24;
|
||||
/// if (physics_obj != 0 && physics_obj->cell == 0) RemoveLinkAnimations(physics_obj);
|
||||
/// return result;
|
||||
/// </code>
|
||||
/// This funnel has no <c>MovementParameters</c> threaded through yet
|
||||
/// (<see cref="DispatchInterpretedMotion"/> takes only <c>motion</c>/
|
||||
/// <c>speed</c> — the params-carrying overloads land in W5 when
|
||||
/// <c>DoMotion</c>/<c>StopMotion</c>/the legacy overloads merge into
|
||||
/// this backend). TODO(W5): thread the real <c>MovementParameters</c>
|
||||
/// through and restore the <c>0x20000</c> (DisableJumpDuringLink) leg;
|
||||
/// until then this always takes the "bit not set" branch (the common
|
||||
/// case — retail's own ctor default for the bit is CLEAR, W0-pins A4).
|
||||
/// <c>ContextId</c> is <c>0</c> pending the same W5 plumbing (no
|
||||
/// <c>MovementParameters.ContextId</c> reaches this call site yet) —
|
||||
/// see the final-report contextId note for the evidence this funnel
|
||||
/// genuinely has nothing else to pass.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <b>R3-W5 finding (not in the original W0 pins — discovered while
|
||||
/// porting):</b> <see cref="IInterpretedMotionSink.ApplyMotion"/>'s
|
||||
/// <c>bool</c> return IS retail's <c>result == 0</c> test gating the
|
||||
/// queue/state-write block. This is load-bearing, not cosmetic: the
|
||||
/// VERY FIRST dispatch of every <c>apply_interpreted_movement</c> call
|
||||
/// is the style/stance id (<c>current_style</c>, always
|
||||
/// <c>>= 0x80000000</c>), which has no locomotion <c>MotionData</c>
|
||||
/// entry in the dat — <c>CMotionTable::DoObjectMotion</c> genuinely
|
||||
/// fails for it. If that failure isn't propagated (an earlier revision
|
||||
/// of this port treated the sink as a <c>void</c>, always-succeeding
|
||||
/// call), <c>InterpretedMotionState::ApplyMotion</c>'s negative-motion
|
||||
/// branch (<c>arg2 < 0 → forward_command = 0x41000003</c>) clobbers
|
||||
/// <see cref="InterpretedMotionState.ForwardCommand"/> BEFORE the very
|
||||
/// next line reads it for the real forward dispatch — regressed 74/183
|
||||
/// cases of the live retail-observer conformance suite
|
||||
/// (<c>RetailObserverTraceConformanceTests</c>) until the interface was
|
||||
/// fixed to return the real result.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Note the ACTUAL animation-table dispatch (the sink call) happens
|
||||
/// through <see cref="DefaultSink"/> — the entity's persistent
|
||||
/// <c>IInterpretedMotionSink</c> binding (R2-Q5's
|
||||
/// <c>MotionTableDispatchSink</c> in production). This is the SAME sink
|
||||
/// <see cref="ApplyCurrentMovementInterpreted"/> already routes through
|
||||
/// for the <c>apply_current_movement</c> dual-dispatch tail — retail has
|
||||
/// exactly one <c>CPhysicsObj</c> per <c>CMotionInterp</c>, so there is
|
||||
/// only ever one dispatch target per entity, matching
|
||||
/// <see cref="DefaultSink"/>'s single-binding shape.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public WeenieError DispatchInterpretedMotion(uint motion, float speed, IInterpretedMotionSink? sink)
|
||||
/// <param name="motion">Retail <c>arg2</c>.</param>
|
||||
/// <param name="p">Retail <c>arg3</c>.</param>
|
||||
public WeenieError DoInterpretedMotion(uint motion, MovementParameters p)
|
||||
=> DoInterpretedMotion(motion, p, DefaultSink);
|
||||
|
||||
/// <summary>
|
||||
/// Sink-parameterized core shared by the public
|
||||
/// <see cref="DoInterpretedMotion(uint,MovementParameters)"/> (which
|
||||
/// always dispatches through <see cref="DefaultSink"/>, matching
|
||||
/// retail's one-sink-per-<c>CPhysicsObj</c> shape) and the internal
|
||||
/// <see cref="DispatchInterpretedMotion(uint,float,IInterpretedMotionSink?)"/>
|
||||
/// primitive (which needs an EXPLICIT per-call sink for
|
||||
/// <see cref="MoveToInterpretedState"/>'s remote-entity callers). Same
|
||||
/// verbatim body either way — only the dispatch target varies.
|
||||
/// </summary>
|
||||
private WeenieError DoInterpretedMotion(uint motion, MovementParameters p, IInterpretedMotionSink? sink)
|
||||
{
|
||||
if (PhysicsObj is null) return WeenieError.NoPhysicsObject;
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
WeenieError result;
|
||||
|
||||
if (contact_allows_move(motion))
|
||||
{
|
||||
// 0x40000011 (Dead) flushes queued link animations in retail
|
||||
// (RemoveLinkAnimations) — S4 wires the sequencer hook.
|
||||
sink?.ApplyMotion(motion, speed);
|
||||
bool standingLongJumpStateOnly = StandingLongJump
|
||||
&& (motion == MotionCommand.WalkForward
|
||||
|| motion == MotionCommand.RunForward
|
||||
|| motion == MotionCommand.SideStepRight);
|
||||
|
||||
// add_to_queue(context, motion, jumpAllowed) — R3-W2 (closes J1).
|
||||
// TODO(W5): params-bit 0x20000 (DisableJumpDuringLink) leg + real
|
||||
// ContextId once MovementParameters flows through this funnel.
|
||||
WeenieError jumpErr = MotionAllowsJump(motion);
|
||||
if (jumpErr == WeenieError.None && (motion & 0x10000000u) == 0)
|
||||
jumpErr = MotionAllowsJump(InterpretedState.ForwardCommand);
|
||||
AddToQueue(contextId: 0, motion, (uint)jumpErr);
|
||||
if (standingLongJumpStateOnly)
|
||||
{
|
||||
// label_528440 — state-only: no dispatch, no queue.
|
||||
if (p.ModifyInterpretedState)
|
||||
InterpretedState.ApplyMotion(motion, p);
|
||||
return WeenieError.None;
|
||||
}
|
||||
|
||||
return WeenieError.None;
|
||||
if (motion == MotionCommand.Dead)
|
||||
RemoveLinkAnimations?.Invoke();
|
||||
|
||||
// sink.ApplyMotion stands in for CPhysicsObj::DoInterpretedMotion
|
||||
// — its bool return IS retail's `result == 0` (a null sink, no
|
||||
// dispatch backend wired, is treated as succeeding — matches
|
||||
// every call site that doesn't care about the animation-table
|
||||
// backend, e.g. bare unit tests exercising queue/state behavior
|
||||
// only). A FAILED dispatch (the motion table found no cycle for
|
||||
// this id — genuinely the case for style/stance ids) skips BOTH
|
||||
// the queue AND the state-write, exactly like the "blocked,
|
||||
// non-action" apply-only path below — but WITHOUT writing state.
|
||||
bool dispatchOk = sink?.ApplyMotion(motion, p.Speed) ?? true;
|
||||
|
||||
if (!dispatchOk)
|
||||
{
|
||||
// Retail: `result = CPhysicsObj::DoInterpretedMotion(...)` is
|
||||
// whatever the failed dispatch returned (raw 305591-305593;
|
||||
// no `else` branch — `result` simply isn't overwritten by
|
||||
// the `if (result == 0)` block), so DoInterpretedMotion's
|
||||
// OWN return value on a failed sink dispatch is that
|
||||
// nonzero code, NOT 0. The exact numeric value is sink-
|
||||
// internal (MotionTableManagerError.MotionFailed = 0x43,
|
||||
// not one of CMotionInterp's own WeenieError codes) — no
|
||||
// CMotionInterp-level WeenieError constant maps to it
|
||||
// 1:1, so this port surfaces the closest existing local
|
||||
// analog (GeneralMovementFailure, 0x47) rather than
|
||||
// inventing a new enum member for a sink-internal code
|
||||
// that's never queued or otherwise observed by any
|
||||
// CMotionInterp caller. Flagged as an ambiguity — no test
|
||||
// in this repo asserts DoInterpretedMotion's return value
|
||||
// on a failed dispatch (only the queue/state SIDE EFFECTS,
|
||||
// which correctly do NOT run here).
|
||||
result = WeenieError.GeneralMovementFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
WeenieError jumpErr;
|
||||
if (!p.DisableJumpDuringLink)
|
||||
{
|
||||
jumpErr = MotionAllowsJump(motion);
|
||||
if (jumpErr == WeenieError.None && (motion & 0x10000000u) == 0)
|
||||
jumpErr = MotionAllowsJump(InterpretedState.ForwardCommand);
|
||||
}
|
||||
else
|
||||
{
|
||||
jumpErr = WeenieError.YouCantJumpFromThisPosition; // 0x48 — forced BLOCKED
|
||||
}
|
||||
|
||||
AddToQueue(p.ContextId, motion, (uint)jumpErr);
|
||||
|
||||
if (p.ModifyInterpretedState)
|
||||
InterpretedState.ApplyMotion(motion, p);
|
||||
|
||||
result = WeenieError.None;
|
||||
}
|
||||
}
|
||||
else if ((motion & 0x10000000u) == 0)
|
||||
{
|
||||
// label_528440 (reached without the StandingLongJump goto) —
|
||||
// apply-only: state kept, no cycle change, no queue. This is
|
||||
// retail's real mechanism behind "airborne remotes keep their
|
||||
// Falling cycle".
|
||||
if (p.ModifyInterpretedState)
|
||||
InterpretedState.ApplyMotion(motion, p);
|
||||
result = WeenieError.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = WeenieError.NotGrounded; // 0x24 (A10) — blocked action-class motion
|
||||
}
|
||||
|
||||
if ((motion & 0x10000000u) == 0)
|
||||
return WeenieError.None; // apply-only: state kept, no cycle change
|
||||
if (PhysicsObj.CellPosition.ObjCellId == 0)
|
||||
RemoveLinkAnimations?.Invoke();
|
||||
|
||||
return WeenieError.NotGrounded; // retail 0x24 (A10)
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <c>CMotionInterp::StopInterpretedMotion</c> (0x00528470, raw
|
||||
/// 305635-305670, FULL BODY, R3-W5, closes J4's StopInterpretedMotion
|
||||
/// leg). THE ONE <c>StopInterpretedMotion</c> — merges the former legacy
|
||||
/// overload with the funnel's bare <c>sink.StopMotion</c> call.
|
||||
///
|
||||
/// <para>
|
||||
/// Verbatim (raw 305638-305670):
|
||||
/// <code>
|
||||
/// if (physics_obj == 0) return 8;
|
||||
/// if (contact_allows_move(arg2) == 0
|
||||
/// || (standing_longjump != 0
|
||||
/// && (arg2 == WalkForward || arg2 == RunForward || arg2 == SideStepRight))) {
|
||||
/// if (arg3->bitfield & 0x4000) InterpretedMotionState::RemoveMotion(arg2);
|
||||
/// result = 0;
|
||||
/// } else {
|
||||
/// result = sink.StopMotion(arg2, arg3); // CPhysicsObj::StopInterpretedMotion stand-in
|
||||
/// if (result == 0) {
|
||||
/// add_to_queue(arg3->context_id, 0x41000003, result); // result == 0 here
|
||||
/// if (arg3->bitfield & 0x4000) InterpretedMotionState::RemoveMotion(arg2);
|
||||
/// }
|
||||
/// }
|
||||
/// if (physics_obj != 0 && physics_obj->cell == 0) RemoveLinkAnimations(physics_obj);
|
||||
/// return result;
|
||||
/// </code>
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// R3-W5 (post-fix): <see cref="IInterpretedMotionSink.StopMotion"/>
|
||||
/// returns a real success signal (see that interface member's doc for
|
||||
/// why a <c>void</c> sink broke the 183-case live retail conformance
|
||||
/// suite on the analogous <c>DoInterpretedMotion</c> path) — a FAILED
|
||||
/// stop dispatch skips both the <c>add_to_queue</c> node and the
|
||||
/// <c>InterpretedMotionState::RemoveMotion</c> state clear, matching
|
||||
/// retail's <c>if (result == 0) { ... }</c> gate exactly. On success,
|
||||
/// the queued node's <c>JumpErrorCode</c> is always <c>0</c> (the stop's
|
||||
/// own "return value" that becomes the queued error code is
|
||||
/// <c>result</c>, which is <c>0</c> on that path).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="motion">Retail <c>arg2</c>.</param>
|
||||
/// <param name="p">Retail <c>arg3</c>.</param>
|
||||
public WeenieError StopInterpretedMotion(uint motion, MovementParameters p)
|
||||
=> StopInterpretedMotion(motion, p, DefaultSink);
|
||||
|
||||
/// <summary>
|
||||
/// Sink-parameterized core shared by the public
|
||||
/// <see cref="StopInterpretedMotion(uint,MovementParameters)"/> and the
|
||||
/// internal <see cref="DispatchStopInterpretedMotion"/> primitive — same
|
||||
/// split rationale as
|
||||
/// <see cref="DoInterpretedMotion(uint,MovementParameters,IInterpretedMotionSink?)"/>.
|
||||
/// </summary>
|
||||
private WeenieError StopInterpretedMotion(uint motion, MovementParameters p, IInterpretedMotionSink? sink)
|
||||
{
|
||||
if (PhysicsObj is null)
|
||||
return WeenieError.NoPhysicsObject;
|
||||
|
||||
WeenieError result;
|
||||
|
||||
bool standingLongJumpStateOnly = StandingLongJump
|
||||
&& (motion == MotionCommand.WalkForward
|
||||
|| motion == MotionCommand.RunForward
|
||||
|| motion == MotionCommand.SideStepRight);
|
||||
|
||||
if (!contact_allows_move(motion) || standingLongJumpStateOnly)
|
||||
{
|
||||
if (p.ModifyInterpretedState)
|
||||
InterpretedState.RemoveMotion(motion);
|
||||
result = WeenieError.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
// sink.StopMotion stands in for CPhysicsObj::StopInterpretedMotion
|
||||
// — its bool return IS retail's `result == 0`. A null sink (no
|
||||
// dispatch backend wired) is treated as succeeding, matching
|
||||
// DoInterpretedMotion's identical posture.
|
||||
bool dispatchOk = sink?.StopMotion(motion) ?? true;
|
||||
|
||||
if (!dispatchOk)
|
||||
{
|
||||
// See DoInterpretedMotion's identical ambiguity note: retail
|
||||
// returns the sink's own nonzero code here (raw 305652-305653,
|
||||
// no `else` — `result` keeps whatever CPhysicsObj::StopInterpretedMotion
|
||||
// returned); ported as the closest local analog.
|
||||
result = WeenieError.GeneralMovementFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = WeenieError.None;
|
||||
|
||||
AddToQueue(p.ContextId, MotionCommand.Ready, (uint)result);
|
||||
|
||||
if (p.ModifyInterpretedState)
|
||||
InterpretedState.RemoveMotion(motion);
|
||||
}
|
||||
}
|
||||
|
||||
if (PhysicsObj.CellPosition.ObjCellId == 0)
|
||||
RemoveLinkAnimations?.Invoke();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// R3-W5 internal per-axis dispatch primitive
|
||||
/// (<c>DispatchInterpretedMotion</c>, formerly the S2a funnel's public
|
||||
/// surface). <see cref="ApplyInterpretedMovement"/>'s four
|
||||
/// <c>DoInterpretedMotion</c>-shaped calls (style, forward-or-Falling,
|
||||
/// sidestep, turn) each need to dispatch through an EXPLICIT per-call
|
||||
/// <paramref name="sink"/> (a remote entity's own sink, threaded in from
|
||||
/// <see cref="MoveToInterpretedState"/>) — retail's own
|
||||
/// <c>apply_interpreted_movement</c> calls <c>CMotionInterp::DoInterpretedMotion</c>
|
||||
/// directly (the SAME function
|
||||
/// <see cref="DoInterpretedMotion(uint,MovementParameters,IInterpretedMotionSink?)"/>
|
||||
/// implements) with a fresh local <c>MovementParameters</c> per axis —
|
||||
/// this wraps that shape with a throwaway params object carrying only
|
||||
/// <c>Speed</c> (ctor default for everything else, matching retail's own
|
||||
/// local <c>var_2c</c>).
|
||||
/// </summary>
|
||||
private WeenieError DispatchInterpretedMotion(uint motion, float speed, IInterpretedMotionSink? sink)
|
||||
=> DoInterpretedMotion(motion, new MovementParameters { Speed = speed }, sink);
|
||||
|
||||
/// <summary>
|
||||
/// R3-W5 internal per-axis STOP primitive — the
|
||||
/// <see cref="StopInterpretedMotion(uint,MovementParameters,IInterpretedMotionSink?)"/>
|
||||
/// analogue of <see cref="DispatchInterpretedMotion"/>, used by
|
||||
/// <see cref="ApplyInterpretedMovement"/>'s sidestep-stop/turn-stop tail
|
||||
/// calls (raw 305739/305748/305770 — retail's own
|
||||
/// <c>CPhysicsObj::StopInterpretedMotion</c> calls with a fresh local
|
||||
/// <c>MovementParameters</c>).
|
||||
/// </summary>
|
||||
private WeenieError DispatchStopInterpretedMotion(uint motion, IInterpretedMotionSink? sink)
|
||||
=> StopInterpretedMotion(motion, new MovementParameters(), sink);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue