Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/ToolboxGame.cs
gamer147 c789d836f1 feat(engine-ambient): delete static fallbacks; add MultiInstanceEngineTests
Step 8 (final) of multi-instancing migration. All per-battle statics now
require a BattleAmbient scope — unwrapped writes throw InvalidOperationException
(fail-fast forcing function). MultiInstanceEngineTests proves correctness:
two parallel battles resolve independently, N=4/8/16 stress matches sequential
baseline, GameMgr.GetIns throws without scope.

Migration complete. EngineSessionGate gone. Suite fully green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-06-07 23:19:37 -04:00

97 lines
2.5 KiB
C#

using System.Collections;
using UnityEngine;
namespace Wizard;
public static class ToolboxGame
{
private enum SYSTEM_INIT
{
SYSTEM_NOT_READY,
SYSTEM_READY
}
public static SetUp SetUp = null;
public static UIManager UIManager = null;
public static GameMgr GameManager = null;
public static bool isLoadFromLocal = false;
public static bool isLoadLocalSound = false;
public static bool bDebugLogMode = true;
private static Transform _gameTransform = null;
public static RealTimeNetworkAgent RealTimeNetworkAgent
{
// Soft read: returns null when no scope is active, mirroring GetIns. Engine code reads this
// via `ToolboxGame.RealTimeNetworkAgent?.Foo`-style patterns (network-send paths gated on a
// non-null agent), so a null on the unwrapped path is the correct degrade — not a throw.
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.NetworkAgent;
}
public static Transform GameTransform
{
get
{
if (!_gameTransform)
{
GameObject gameObject = GameObject.Find("_Game");
if ((bool)gameObject)
{
_gameTransform = gameObject.transform;
}
}
return _gameTransform;
}
}
public static void Clear()
{
UIManager = null;
GameManager = null;
}
public static void ClearUIManager()
{
UIManager = null;
}
public static void SetRealTimeNetworkBattle(RealTimeNetworkAgent agent)
{
// Strict: must be inside a scope to set the per-session agent. Forcing-function — any
// historical unwrapped caller (no production callsite remains) now fails fast.
SVSim.BattleEngine.Ambient.BattleAmbient.Require().NetworkAgent = agent;
}
public static void DestroyNetworkAgent()
{
var c = SVSim.BattleEngine.Ambient.BattleAmbient.Current;
var current = c?.NetworkAgent;
if (current != null)
{
Object.DestroyImmediate(current.gameObject);
c.NetworkAgent = null;
}
}
public static IEnumerator CreateRealTimeNetworkBattleAgent(Matching matching = null)
{
string loadObjectPath = "TurnBase/_TurnBaseManager";
if (GameMgr.GetIns().IsAINetwork)
{
loadObjectPath = "TurnBase/_AINetworkBaseManager";
}
yield return BattleCoroutine.GetInstance().StartCoroutine(GameMgr.GetIns().GetPrefabMgr().LoadAync(loadObjectPath));
NGUITools.AddChild(GameObject.Find("_Game"), GameMgr.GetIns().GetPrefabMgr().Get(loadObjectPath));
yield return null;
if (matching != null)
{
RealTimeNetworkAgent.SettingMatchingClass(matching);
}
}
}