feat(battlenode): per-session charaId + single-active-engine gate (Phase 2 N2 carried-risk B)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-06 16:35:42 -04:00
parent 6e8af4e68b
commit eb52890251
3 changed files with 89 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
namespace SVSim.BattleNode.Sessions.Engine;
/// <summary>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.</summary>
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);
}