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:
gamer147
2026-07-03 19:18:54 -04:00
parent 5c1db83967
commit 2d9a6eea4b
2045 changed files with 11704 additions and 158495 deletions

View File

@@ -17,8 +17,6 @@ public class SideLogControl : MonoBehaviour
public BattleCardBase Card { get; private set; }
public bool IsPlayer => Card.IsPlayer;
public bool IsSelect { get; private set; }
public SideLog(BattleCardBase card, SkillBase skill, bool isSelect)
@@ -45,120 +43,18 @@ public class SideLogControl : MonoBehaviour
}
return false;
}
public bool CheckShowSideLogNewReplay(int skillHashCode, BattleCardBase ownerCard)
{
_skillHashCodes.Add(skillHashCode);
int num = _skillHashCodes.Where((int s) => skillHashCode == s).Count();
if (num > _repeatCount)
{
_repeatCount = num;
return true;
}
if (ownerCard.BaseParameter.BaseCardId == 900241110)
{
return true;
}
return false;
}
public bool IsContain(BattleCardBase card, bool isTransformSelect = false)
{
if (isTransformSelect)
{
BattleCardBase battleCardBase = ((Card.TransformInfo.Type != BattleCardBase.TransformType.Metamorphose) ? Card.TransformInfo.OriginalCard : null);
if (IsSelect && battleCardBase != null)
{
return battleCardBase.BaseParameter.BaseCardId == card.BaseParameter.BaseCardId;
}
return false;
}
return Card == card;
}
}
private const int PANEL_MAX = 6;
private const int LABEL_INDEX_CARDNAME = 0;
private const int LABEL_INDEX_SKILLDESC = 1;
private static readonly int DEFAULT_SPACING_Y = 12;
private static readonly int SPACING_START_LINE = 4;
private static readonly int SPACING_Y_MARGIN = 4;
private IList<NguiObjs> PanelList;
private IList<NguiObjs> PanelOnList;
private IList<bool> PanelOnFlagList;
private Vector3 BasePos;
private Vector2 PanelSize;
private List<SideLog> LogShowingList;
private SideLog _lastSideLog;
private void Start()
{
PanelList = new List<NguiObjs>();
PanelOnList = new List<NguiObjs>();
PanelOnFlagList = new List<bool>();
LogShowingList = new List<SideLog>();
for (int i = 0; i < 6; i++)
{
GameObject gameObject;
if (i == 0)
{
gameObject = base.transform.Find("Panel").gameObject;
}
else
{
gameObject = UnityEngine.Object.Instantiate(PanelList[0].gameObject);
if (null == gameObject)
{
continue;
}
gameObject.transform.parent = base.transform;
gameObject.transform.localScale = Vector3.one;
}
PanelList.Add(gameObject.GetComponent<NguiObjs>());
LogShowingList.Add(null);
PanelList[i].gameObject.SetActive(value: false);
}
BasePos = PanelList[0].transform.localPosition;
PanelSize = PanelList[0].sprites[0].localSize;
}
private void Update()
{
for (int i = 0; i < PanelOnList.Count; i++)
{
int index = PanelList.IndexOf(PanelOnList[i]);
if (LogShowingList[index] != null)
{
Vector3 vector = (LogShowingList[index].IsPlayer ? ((!PanelOnFlagList[i]) ? (new Vector3(0f - PanelSize.x, (PanelSize.y + 10f) * (float)i, 0f) + BasePos) : (new Vector3(0f, (PanelSize.y + 10f) * (float)i, 0f) + BasePos)) : ((!PanelOnFlagList[i]) ? (new Vector3(PanelSize.x, (0f - (PanelSize.y + 10f)) * (float)i, 0f) + BasePos) : (new Vector3(0f, (0f - (PanelSize.y + 10f)) * (float)i, 0f) + BasePos)));
PanelOnList[i].transform.localPosition += (vector - PanelOnList[i].transform.localPosition) * 0.5f;
}
}
}
public void SetWrapTextForSideLog(UILabel label, string s)
{
label.spacingY = DEFAULT_SPACING_Y;
label.SetWrapText(s);
int num = label.text.Length - label.text.Replace("\n", "").Length + 1;
if (num >= SPACING_START_LINE)
{
label.spacingY = Math.Max(DEFAULT_SPACING_Y - (num - SPACING_START_LINE + 1) * SPACING_Y_MARGIN, 0);
label.SetWrapText(s);
}
}
public bool IsOnSummonOrReturnTimingSkill(SkillBase skill)
{
if (skill == null)
@@ -184,120 +80,6 @@ public class SideLogControl : MonoBehaviour
});
}
public bool ShowLog(BattleCardBase card, SkillBase skill, string skillDesc, string cardName, bool isEvolSelect, bool isSelect, NetworkBattleReceiver.SideLogSkillInfo newReplaySkillInfo)
{
NguiObjs nguiObjs = null;
int index = 0;
SideLog sideLog = null;
if (!isSelect)
{
if (LogShowingList.Any((SideLog l) => l?.IsContain(card) ?? false) && !isEvolSelect)
{
SideLog sideLog2 = LogShowingList.Where((SideLog l) => l?.IsContain(card) ?? false).First();
if (!((newReplaySkillInfo != null) ? sideLog2.CheckShowSideLogNewReplay(newReplaySkillInfo.SkillHashCode, card) : sideLog2.CheckShowSideLog(skill)))
{
return false;
}
sideLog = sideLog2;
}
if (IsOnSummonOrReturnTimingSkill(skill) || (newReplaySkillInfo != null && newReplaySkillInfo.IsOnSummonSkill))
{
bool flag = newReplaySkillInfo?.IsInvoked ?? skill.IsInvoked;
if (_lastSideLog != null && _lastSideLog.Card.EquelsID(card) && _lastSideLog.Card.CardId == card.CardId && !_lastSideLog.IsSelect && !flag)
{
return false;
}
}
}
for (int num = 0; num < PanelList.Count; num++)
{
if (!PanelList[num].gameObject.activeSelf)
{
nguiObjs = PanelList[num];
index = num;
break;
}
}
if (nguiObjs == null)
{
nguiObjs = PanelOnList[PanelOnList.Count - 1];
RemoveLog(PanelOnList.Count - 1);
for (int num2 = 0; num2 < PanelList.Count; num2++)
{
if (nguiObjs == PanelList[num2])
{
index = num2;
break;
}
}
}
nguiObjs.labels[0].text = cardName;
SetWrapTextForSideLog(nguiObjs.labels[1], skillDesc);
if (card.IsPlayer)
{
nguiObjs.transform.localPosition = new Vector3(0f - PanelSize.x, 0f, 0f) + BasePos;
}
else
{
nguiObjs.transform.localPosition = new Vector3(PanelSize.x, 0f, 0f) + BasePos;
}
if (sideLog == null)
{
sideLog = new SideLog(card, skill, isSelect);
if (newReplaySkillInfo != null)
{
sideLog.CheckShowSideLogNewReplay(newReplaySkillInfo.SkillHashCode, card);
}
}
_lastSideLog = sideLog;
LogShowingList[index] = sideLog;
nguiObjs.gameObject.SetActive(value: true);
PanelOnList.Insert(0, nguiObjs);
PanelOnFlagList.Insert(0, item: true);
return true;
}
public void HideLog(BattleCardBase card, bool isTransformSelect)
{
for (int num = PanelOnList.Count - 1; num >= 0; num--)
{
int index = PanelList.IndexOf(PanelOnList[num]);
if (LogShowingList[index] != null && LogShowingList[index].IsContain(card, isTransformSelect))
{
PanelOnFlagList[num] = false;
break;
}
}
}
public void RemoveLog(BattleCardBase card, bool isTransformSelect)
{
for (int num = PanelOnList.Count - 1; num >= 0; num--)
{
int index = PanelList.IndexOf(PanelOnList[num]);
if (LogShowingList[index] != null && LogShowingList[index].IsContain(card, isTransformSelect))
{
PanelOnList[num].gameObject.SetActive(value: false);
PanelOnList.RemoveAt(num);
PanelOnFlagList.RemoveAt(num);
LogShowingList[index] = null;
break;
}
}
}
public void RemoveLog(int idx)
{
if (PanelOnList.Count >= 1)
{
int index = PanelList.IndexOf(PanelOnList[idx]);
PanelOnList[idx].gameObject.SetActive(value: false);
PanelOnList.RemoveAt(idx);
PanelOnFlagList.RemoveAt(idx);
LogShowingList[index] = null;
}
}
public void RemoveAllLog()
{
if (PanelOnList.Count >= 1)