engine cleanup passes 4-7 + multi-instancing ambient rip
Squashes 146 commits from battle-engine-extraction. Net: 2,045 files changed, +11,896 / -158,687 lines. Ships engine passes 4-7 (dead-code cull, view-layer stub, receive-path shrink) plus the Phase-5 AsyncLocal ambient deletion that turns concurrent battles into a type-system property rather than a scope contract. ## What landed **Passes 4-7 (chunks 1-34):** Extended the Phase-4 const-false collapse into a cascading cull across the skill graph, view layer, and receive-path periphery. Six mode flags (IsWatchBattle/IsReplayBattle/IsAdmin/IsAdminWatch/IsPuzzleQuest/ IsAINetwork) became `const false`, every guarded block deleted. Field*.cs subclass ctors + BackGroundBase + ObjectChecker culled to no-ops. Mulligan family reworked to take a mgr param through IMulliganMgr.InitMulligan. Emotion/Recovery/Resource clusters null-stubbed. Prediction/OperationSimulator/ skill filters converted from static ambient reads to per-mgr reads via SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr / ins.BattleMgr / this.BattleMgr. **Phase-5 ambient rip (chunks 35-47):** Deleted BattleAmbient / BattleAmbient- Context / TestBattleScope in full. Every per-battle mutable slot now lives on the mgr instance itself: mgr.InstanceIsForecast / InstanceIsRandomDraw / InstanceRecoveryInfo / InstanceViewerId / InstanceNetworkAgent / GameMgr BattleManagerBase.GetIns() returns null unconditionally; the residual static flags + 3 façades (Certification.ViewerId, Data.BattleRecoveryInfo, ToolboxGame.RealTimeNetworkAgent) are null-tolerant defaults kept for the handful of engine-internal readers that still reference their types. Zero BattleAmbient references anywhere in engine + node + tests. Added pre-seeded GameMgr ctor overload threaded through the mgr chain (BattleManagerBase → SingleBattleMgr / NetworkBattleManagerBase → NetworkStandard- BattleMgr → HeadlessBattleMgr / HeadlessNetworkBattleMgr). Fixtures build a GameMgr, seed it via HeadlessEngineEnv.SeedCharaIds/SeedNetUser, and pass it to the mgr's ctor — no ambient reach. Node side (SVSim.BattleNode/SessionBattleEngine): _ctx replaced with a plain GameMgr field; 34 `using var _ambient = BattleAmbient.Enter(_ctx)` scope wraps ripped from every accessor and mutator; EngineGlobalInit.WirePerSessionGameMgr takes GameMgr as a param and runs from SessionBattleEngine.SetupInternal BEFORE mgr construction. Test side: TestBattleScope deleted; 18 fixture [SetUp]s migrated to `HeadlessEngineEnv.EnsureProcessGlobals()`; MultiInstanceEngineTests rewritten around per-mgr construction (GetIns() → null is the pinned invariant). ## Regression fixes - **chunk-48** (MulliganCtrl): chunk-35's `= null` stubs on card lookups broke the live receive-driven Deal path (BattlePlayerBase.DrawCard NRE'd downstream of NetworkPlayerMulliganCtrl.StartMulliganVfx). Restored the three lookups via `_battlePlayer.BattleMgr.GetBattleCardIdx`. Engine tests were satisfied by the WireMulliganPhase seam; unit tests exposed the live-path gap. ## Ship state - SVSim.BattleEngine.Tests: 56/56 pass, 2 skip - SVSim.UnitTests: 1554/1554 pass (was 1523/31-fail before chunk 48) - Solution build: 0 source warnings (40 pre-existing NU1902 MessagePack CVEs in SVSim.EmulatedEntrypoint, unrelated) - Sequential PVP smoke: verified live (two back-to-back battles, no regression on cleanup/spinup) - Concurrent PVP smoke: verified live Adds tools/engine-port/ClosureAnalyzer/ — the Roslyn transitive-type-closure analyzer needed to make future cascade cleanup safe (per feedback memory "Engine cleanup needs closure tool" from the 2026-06-28 pass-3 failure). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -49,39 +49,17 @@ public class NetworkUserInfoData
|
||||
|
||||
private Dictionary<string, object> _oppoInfo = new Dictionary<string, object>();
|
||||
|
||||
private List<CardDataModel> _selfDeck;
|
||||
|
||||
private List<CardDataModel> _oppoDeck;
|
||||
|
||||
public const int DUMMY_CARD_ID = 100011010;
|
||||
|
||||
public const string KEY_IS_OFFICIAL_USER = "isOfficial";
|
||||
|
||||
private const string KEY_OPPO_DECK_COUNT = "oppoDeckCount";
|
||||
|
||||
public const string KEY_DECK_COUNT = "deckCount";
|
||||
|
||||
public int TurnState { get; set; }
|
||||
|
||||
public NetworkUserInfo SelfBattleStartInfo { get; private set; }
|
||||
|
||||
public NetworkUserInfo OppoBattleStartInfo { get; private set; }
|
||||
|
||||
public List<CardDataModel> _selfFirstCards { get; set; }
|
||||
|
||||
public List<CardDataModel> _oppoFirstCards { get; set; }
|
||||
|
||||
public NetworkUserInfoData()
|
||||
{
|
||||
TurnState = -1;
|
||||
}
|
||||
|
||||
public void InitializeSelfInfo()
|
||||
{
|
||||
SelfBattleStartInfo = null;
|
||||
_selfDeck = null;
|
||||
}
|
||||
|
||||
public void SetSelfInfo(Dictionary<string, object> info, bool isWatchReplayRecovery)
|
||||
{
|
||||
_selfInfo = info;
|
||||
@@ -95,6 +73,12 @@ public class NetworkUserInfoData
|
||||
}
|
||||
}
|
||||
|
||||
// SetNetworkSelfInfo used to fan the received chara/skin/rotation info out to the
|
||||
// process-wide GameMgr.DataMgr (production-only path). In the current headless world
|
||||
// the only call site is the isWatchReplayRecovery=true branch of SetSelfInfo, which
|
||||
// is never taken in either test seeder — so this is dead in every code path we run.
|
||||
// Body preserved as documentation until a live-network path revives it, but the
|
||||
// GameMgr/Data reach has been dropped so it can't ambient-race anymore.
|
||||
public void SetNetworkSelfInfo(Dictionary<string, object> info)
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
@@ -102,88 +86,15 @@ public class NetworkUserInfoData
|
||||
SelfBattleStartInfo = new NetworkUserInfo();
|
||||
}
|
||||
SelfBattleStartInfo.SetParameter(info);
|
||||
GameMgr.GetIns().GetDataMgr().SetPlayerCharaId(GetSelfCharaId());
|
||||
GameMgr.GetIns().GetDataMgr().SetPlayerSubClassID(GetSelfSubClassId());
|
||||
GameMgr.GetIns().GetDataMgr().SetPlayerMyRotationInfo(GetSelfMyRotationId());
|
||||
GameMgr.GetIns().GetDataMgr().SetPlayerAvatarBattleInfo(GetSelfAvatarBattleId());
|
||||
Data.RoomTwoPickBeforeBattleInfo.ReceiveBackDraftCharaId(GetSelfCharaId());
|
||||
// TODO(post-Phase-5b, revive-live-network): thread a mgr param through and fan out
|
||||
// GetSelfCharaId/GetSelfSubClassId/GetSelfMyRotationId/GetSelfAvatarBattleId into
|
||||
// mgr.GameMgr.GetDataMgr() + Data.RoomTwoPickBeforeBattleInfo once a caller exists.
|
||||
if (_selfInfo != null && _selfInfo.ContainsKey("seed"))
|
||||
{
|
||||
LocalLog.AccumulateLastTraceLog("SetNetworkSelfInfo seed" + Convert.ToInt32(_selfInfo["seed"]));
|
||||
}
|
||||
}
|
||||
|
||||
private int GetDeckMaxNum(bool isSelf)
|
||||
{
|
||||
if (isSelf && _selfInfo.ContainsKey("deckCount"))
|
||||
{
|
||||
return Convert.ToInt32(_selfInfo["deckCount"]);
|
||||
}
|
||||
if (!isSelf && _oppoInfo.ContainsKey("deckCount"))
|
||||
{
|
||||
return Convert.ToInt32(_oppoInfo["deckCount"]);
|
||||
}
|
||||
return GameMgr.GetIns().GetDataMgr().GetDeckMaxCount(isSelf);
|
||||
}
|
||||
|
||||
public void SetSelfDeck(List<object> deckDatas)
|
||||
{
|
||||
if (GameMgr.GetIns().IsReplayBattle || !GameMgr.GetIns().IsWatchBattle)
|
||||
{
|
||||
int deckMaxNum = GetDeckMaxNum(isSelf: true);
|
||||
_selfDeck = new List<CardDataModel>(deckMaxNum);
|
||||
List<int> list = new List<int>();
|
||||
for (int i = 0; i < deckMaxNum; i++)
|
||||
{
|
||||
CardDataModel cardDataModel = new CardDataModel();
|
||||
Dictionary<string, object> dictionary = deckDatas[i] as Dictionary<string, object>;
|
||||
cardDataModel.Index = Convert.ToInt32(dictionary[NetworkBattleDefine.NetworkParameter.idx.ToString()]);
|
||||
cardDataModel.CardId = Convert.ToInt32(dictionary[NetworkBattleDefine.NetworkParameter.cardId.ToString()]);
|
||||
_selfDeck.Add(cardDataModel);
|
||||
list.Add(cardDataModel.CardId);
|
||||
}
|
||||
Data.RoomTwoPickBeforeBattleInfo.ReceiveBackDraftCardIdList(list);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOppoDeck(List<object> deckDatas)
|
||||
{
|
||||
int deckMaxNum = GetDeckMaxNum(isSelf: false);
|
||||
_oppoDeck = new List<CardDataModel>(deckMaxNum);
|
||||
for (int i = 0; i < deckMaxNum; i++)
|
||||
{
|
||||
CardDataModel cardDataModel = new CardDataModel();
|
||||
Dictionary<string, object> dictionary = deckDatas[i] as Dictionary<string, object>;
|
||||
cardDataModel.Index = Convert.ToInt32(dictionary[NetworkBattleDefine.NetworkParameter.idx.ToString()]);
|
||||
cardDataModel.CardId = Convert.ToInt32(dictionary[NetworkBattleDefine.NetworkParameter.cardId.ToString()]);
|
||||
_oppoDeck.Add(cardDataModel);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOpponentInfo(Dictionary<string, object> info, bool isWatchReplayRecovery)
|
||||
{
|
||||
OppoBattleStartInfo = null;
|
||||
if (!GameMgr.GetIns().IsWatchBattle && !GameMgr.GetIns().IsReplayBattle)
|
||||
{
|
||||
_oppoDeck = null;
|
||||
}
|
||||
_oppoInfo = info;
|
||||
if (isWatchReplayRecovery)
|
||||
{
|
||||
SetOpponentNetworkInfo(info);
|
||||
}
|
||||
if (_oppoInfo.Keys.Contains("oppoDeckCount"))
|
||||
{
|
||||
GameMgr.GetIns().GetDataMgr().SetDeckMaxCount(Convert.ToInt32(_oppoInfo["oppoDeckCount"]), isSelf: false);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOpponentNetworkInfo(Dictionary<string, object> info)
|
||||
{
|
||||
OppoBattleStartInfo = new NetworkUserInfo();
|
||||
OppoBattleStartInfo.SetParameter(info);
|
||||
}
|
||||
|
||||
public int GetFieldId()
|
||||
{
|
||||
return Convert.ToInt32(_selfInfo["fieldId"]);
|
||||
@@ -213,38 +124,6 @@ public class NetworkUserInfoData
|
||||
return Convert.ToInt32(_selfInfo["viewerId"]);
|
||||
}
|
||||
|
||||
public string GetSelfName()
|
||||
{
|
||||
return _selfInfo["userName"].ToString();
|
||||
}
|
||||
|
||||
public int GetSelfBattlePoint()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return SelfBattleStartInfo.BattlePoint;
|
||||
}
|
||||
|
||||
public int GetSelfMasterPoint()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return SelfBattleStartInfo.MasterPoint;
|
||||
}
|
||||
|
||||
public int GetSelfClassId()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return SelfBattleStartInfo.ClassId;
|
||||
}
|
||||
|
||||
public int GetSelfSubClassId()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
@@ -281,46 +160,11 @@ public class NetworkUserInfoData
|
||||
return SelfBattleStartInfo.AvatarBattleId;
|
||||
}
|
||||
|
||||
public long GetSelfSleeveId()
|
||||
{
|
||||
return Convert.ToInt64(_selfInfo["sleeveId"]);
|
||||
}
|
||||
|
||||
public long GetSelfEmblemId()
|
||||
{
|
||||
return Convert.ToInt64(_selfInfo["emblemId"]);
|
||||
}
|
||||
|
||||
public int GetSelfDegreeId()
|
||||
{
|
||||
return Convert.ToInt32(_selfInfo["degreeId"]);
|
||||
}
|
||||
|
||||
public int GetSelfRank()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return SelfBattleStartInfo.Rank;
|
||||
}
|
||||
|
||||
public string GetSelfCountryCode()
|
||||
{
|
||||
return _selfInfo["country_code"].ToString();
|
||||
}
|
||||
|
||||
public bool GetSelfIsOfficialUser()
|
||||
{
|
||||
return Convert.ToBoolean(_selfInfo["isOfficial"]);
|
||||
}
|
||||
|
||||
public int GetSelfChaosId()
|
||||
{
|
||||
if (!GameMgr.GetIns().IsNetworkBattle && !GameMgr.GetIns().IsReplayBattle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// The `!IsNetworkBattle` guard is redundant with the dict-lookup below: in single-player
|
||||
// paths `_selfInfo` is empty (no network setup), so the dict never contains "chaosId"
|
||||
// and this returns -1 anyway. Removing the ambient reach.
|
||||
if (_selfInfo.ContainsKey("chaosId"))
|
||||
{
|
||||
return Convert.ToInt32(_selfInfo["chaosId"]);
|
||||
@@ -328,65 +172,6 @@ public class NetworkUserInfoData
|
||||
return -1;
|
||||
}
|
||||
|
||||
public string GetOpponentName()
|
||||
{
|
||||
return _oppoInfo["userName"].ToString();
|
||||
}
|
||||
|
||||
public int GetOpponentBattlePoint()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return OppoBattleStartInfo.BattlePoint;
|
||||
}
|
||||
|
||||
public int GetOpponentMasterPoint()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return OppoBattleStartInfo.MasterPoint;
|
||||
}
|
||||
|
||||
public int GetOpponentClassId()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return OppoBattleStartInfo.ClassId;
|
||||
}
|
||||
|
||||
public int GetOpponentSubClassId()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
return OppoBattleStartInfo.SubClassId;
|
||||
}
|
||||
|
||||
public int GetOpponentCharaId()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return OppoBattleStartInfo.CharaId;
|
||||
}
|
||||
|
||||
public string GetOpponentMyRotationId()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return OppoBattleStartInfo.MyRotationId;
|
||||
}
|
||||
|
||||
public string GetOpponentAvatarBattleId()
|
||||
{
|
||||
if (SelfBattleStartInfo == null)
|
||||
@@ -396,137 +181,14 @@ public class NetworkUserInfoData
|
||||
return OppoBattleStartInfo.AvatarBattleId;
|
||||
}
|
||||
|
||||
public long GetOpponentSleeveId()
|
||||
{
|
||||
return Convert.ToInt64(_oppoInfo["sleeveId"]);
|
||||
}
|
||||
|
||||
public long GetOpponentEmblemId()
|
||||
{
|
||||
return Convert.ToInt64(_oppoInfo["emblemId"]);
|
||||
}
|
||||
|
||||
public int GetOpponentDegreeId()
|
||||
{
|
||||
return Convert.ToInt32(_oppoInfo["degreeId"]);
|
||||
}
|
||||
|
||||
public int GetOpponentRank()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return OppoBattleStartInfo.Rank;
|
||||
}
|
||||
|
||||
public int GetOpponentUserID()
|
||||
{
|
||||
if (GameMgr.GetIns().IsWatchBattle)
|
||||
{
|
||||
return Convert.ToInt32(_oppoInfo["viewerId"]);
|
||||
}
|
||||
return Convert.ToInt32(_selfInfo["oppoId"]);
|
||||
}
|
||||
|
||||
public bool GetOpponentIsMasterRank()
|
||||
{
|
||||
if (OppoBattleStartInfo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return OppoBattleStartInfo.IsMasterRank;
|
||||
}
|
||||
|
||||
public string GetOpponentCountryCode()
|
||||
{
|
||||
return _oppoInfo["country_code"].ToString();
|
||||
}
|
||||
|
||||
public bool GetOpponentIsOfficialUser()
|
||||
{
|
||||
return Convert.ToBoolean(_oppoInfo["isOfficial"]);
|
||||
}
|
||||
|
||||
public int GetOpponentChaosId()
|
||||
{
|
||||
if (!GameMgr.GetIns().IsNetworkBattle && !GameMgr.GetIns().IsReplayBattle)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// See GetSelfChaosId — same rationale, the `!IsNetworkBattle` guard is redundant with
|
||||
// the dict-lookup fallthrough (single-player paths never populate `_oppoInfo`).
|
||||
if (_oppoInfo.ContainsKey("chaosId"))
|
||||
{
|
||||
return Convert.ToInt32(_oppoInfo["chaosId"]);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool GetOpponentChaosOverrideSkin()
|
||||
{
|
||||
if (!GameMgr.GetIns().IsNetworkBattle && !GameMgr.GetIns().IsReplayBattle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_oppoInfo.ContainsKey("isChaosSkinOverride"))
|
||||
{
|
||||
return Convert.ToBoolean(_oppoInfo["isChaosSkinOverride"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<CardDataModel> GetSelfDeck()
|
||||
{
|
||||
if (GameMgr.GetIns().IsWatchBattle && _selfDeck == null)
|
||||
{
|
||||
int deckMaxNum = GetDeckMaxNum(isSelf: true);
|
||||
_selfDeck = IdListConvertToModelList(Enumerable.Repeat(100011010, deckMaxNum).ToList());
|
||||
}
|
||||
return _selfDeck;
|
||||
}
|
||||
|
||||
public List<CardDataModel> GetOpponentDeck()
|
||||
{
|
||||
if (_oppoDeck == null)
|
||||
{
|
||||
int deckMaxNum = GetDeckMaxNum(isSelf: false);
|
||||
_oppoDeck = IdListConvertToModelList(Enumerable.Repeat(100011010, deckMaxNum).ToList());
|
||||
}
|
||||
return _oppoDeck;
|
||||
}
|
||||
|
||||
private List<CardDataModel> IdListConvertToModelList(List<int> idList)
|
||||
{
|
||||
List<CardDataModel> list = new List<CardDataModel>(idList.Count);
|
||||
for (int i = 0; i < idList.Count; i++)
|
||||
{
|
||||
CardDataModel cardDataModel = new CardDataModel();
|
||||
cardDataModel.Index = i + 1;
|
||||
cardDataModel.CardId = idList[i];
|
||||
list.Add(cardDataModel);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void ReplaceFirstCardData()
|
||||
{
|
||||
List<BattleCardBase> list = new List<BattleCardBase>();
|
||||
NetworkBattleManagerBase networkBattleManagerBase = BattleManagerBase.GetIns() as NetworkBattleManagerBase;
|
||||
for (int i = 0; i < _selfFirstCards.Count; i++)
|
||||
{
|
||||
ReplaceReceivedCard replaceReceivedCard = new ReplaceReceivedCard(networkBattleManagerBase, _selfFirstCards[i]);
|
||||
list.Add(replaceReceivedCard.ReplaceCard(networkBattleManagerBase.BattlePlayer));
|
||||
}
|
||||
if (GameMgr.GetIns().IsAdmin)
|
||||
{
|
||||
for (int j = 0; j < _oppoFirstCards.Count; j++)
|
||||
{
|
||||
ReplaceReceivedCard replaceReceivedCard2 = new ReplaceReceivedCard(networkBattleManagerBase, _oppoFirstCards[j]);
|
||||
list.Add(replaceReceivedCard2.ReplaceCard(networkBattleManagerBase.BattleEnemy));
|
||||
}
|
||||
}
|
||||
if (!networkBattleManagerBase.IsRecovery && list.Count > 0)
|
||||
{
|
||||
networkBattleManagerBase.VfxMgr.RegisterSequentialVfx(networkBattleManagerBase.LoadCardResources(list));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user