using System;
namespace AcDream.Core.Physics.Motion;
///
/// R2-Q5 — the that dispatches the
/// CMotionInterp funnel's retail-ordered motion events STRAIGHT into the
/// entity's motion-table stack via
/// (lazy initialize_state +
/// MotionTableManager::PerformMovement 0x0051c0b0).
///
///
/// This replaces the App-side RemoteMotionSink (deleted): no axis
/// collection, no single-cycle priority pick, no Commit pass, no HasCycle
/// probe, no Run→Walk→Ready missing-cycle chain — retail's
/// GetObjectSequence (0x00522860) + is_allowed decide what
/// plays. Forward locomotion installs the substate cycle (Branch 2);
/// sidesteps resolve by the dat (cycle when authored, else modifier);
/// turns are Branch-4 physics-only modifiers blended over the substate via
/// combine_motion/re_modify — the composition the retired
/// AP-73 row approximated with one cycle.
///
///
public sealed class MotionTableDispatchSink : IInterpretedMotionSink
{
private readonly AnimationSequencer _sequencer;
public MotionTableDispatchSink(AnimationSequencer sequencer)
{
ArgumentNullException.ThrowIfNull(sequencer);
_sequencer = sequencer;
}
public bool ApplyMotion(uint motion, float speed)
{
uint result = _sequencer.PerformMovement(MotionTableMovement.Interpreted(motion, speed));
// Bug A probe ([remote-landing-after], ACDREAM_PROBE_REMOTE_LANDING):
// the MotionTableManagerError code is discarded by this bool return,
// so hand it to the diagnostic latch before it is lost. Self-guarded
// — one flag test when the probe is off, no behaviour change either
// way. TEMPORARY, strips with the rest of the probe family.
PhysicsDiagnostics.RecordRemoteLandingDispatch(motion, result);
return result == MotionTableManagerError.Success;
}
public bool StopMotion(uint motion)
{
uint result = _sequencer.PerformMovement(MotionTableMovement.StopInterpreted(motion, 1f));
return result == MotionTableManagerError.Success;
}
///
/// R4-V5 wedge fix — retail CPartArray::StopCompletelyInternal
/// (0x00518890): MotionTableManager::PerformMovement(type 5).
/// The manager stops everything and queues its Ready-sentinel
/// pending_animations entry UNCONDITIONALLY — the completable partner
/// of the interp's A9 pending_motions node.
///
public bool StopCompletely()
{
uint result = _sequencer.PerformMovement(MotionTableMovement.StopCompletely());
return result == MotionTableManagerError.Success;
}
}