// ============================================================================ // RynthCore.Engine - Compatibility/CastStopRules.cs // // The cast drain's question about the action ring: is a movement stop queued at or // before the pending cast? (AcMainThreadQueue.StopQueuedAtOrBefore: such a stop runs // first, so the cast's own stop is not sent while AC's locomotion is still on.) // // Every queued entry is checked. An entry's time is taken before ActionRing's producer // lock, so two producers can land slightly out of time order, and a walk that stopped // at the first entry newer than the cast could miss an older stop queued behind it. // // Pure: no engine state. Consumer side of the ring only (AC's main thread). Compiled // into tools\EngineRobustnessTests. // ============================================================================ using System; namespace RynthCore.Engine.Compatibility; internal static class CastStopRules { /// /// True when any entry in was queued at or before /// (by ) and is a movement stop /// (by ). Pass static lambdas: nothing is allocated per call. /// public static bool AnyStopAtOrBefore(ActionRing ring, long castQueuedAt, Func queuedAt, Func isStop) where T : struct { int count = ring.Count; for (int i = 0; i < count; i++) { if (!ring.TryPeekAt(i, out T e)) break; if (queuedAt(e) <= castQueuedAt && isStop(e)) return true; } return false; } }