namespace SVSim.BattleNode.Sessions.Engine; /// Process-wide single-active-engine gate. The engine's process-global turn state /// (ToolboxGame.RealTimeNetworkAgent, GameMgr) cannot safely back two concurrent battles, so exactly /// one BattleSession may own the engine at a time (AskUserQuestion 2026-06-06: serialize + document). /// A session that cannot acquire runs WITHOUT the engine and logs it loudly — NOT a silent fallback /// (the operator sees the limitation). Per-session isolation (removing this gate) is the tracked /// follow-up. Non-blocking TryAcquire keeps it out of the synchronous dispatch path; in local /// single-user dev battles are sequential, so contention never arises. internal static class EngineSessionGate { private static int _owned; // 0 = free, 1 = owned public static bool TryAcquire() => System.Threading.Interlocked.CompareExchange(ref _owned, 1, 0) == 0; public static void Release() => System.Threading.Interlocked.Exchange(ref _owned, 0); }