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

@@ -10,11 +10,6 @@ using Wizard.UI.Profile;
public class DeckIntroduction : MonoBehaviour
{
private const int MAX_WIDTH_ANNOTATION_LABEL = 210;
private const Format DEFAULT_FORMAT = Format.Rotation;
private static readonly Vector2 FORMAT_CHANGE_UI_POSITION = new Vector2(-466f, 246f);
private static readonly Dictionary<Format, FormatChangeUI.FormatCategory> FORMAT_TO_FORMAT_CATEGORY = new Dictionary<Format, FormatChangeUI.FormatCategory>
{
@@ -35,78 +30,21 @@ public class DeckIntroduction : MonoBehaviour
[SerializeField]
private TabList _tabList;
[SerializeField]
private UISprite _classIcon;
[SerializeField]
private UITexture _classCharaTexture;
[SerializeField]
private UILabel _className;
[SerializeField]
private UITexture _classBG;
private Format _formatState;
[SerializeField]
private UILabel _labelAnnotation;
private UIAtlas _classIconAtlas;
private List<string> _resourceList = new List<string>();
private List<string> _loadTopCardAssetList = new List<string>();
private List<string> _loadCardAssetList;
private List<DeckIntroductionItem> _deckIntroductionItem = new List<DeckIntroductionItem>();
[SerializeField]
private GameObject _dialogAttachRoot;
[SerializeField]
private GameObject _deckViewPrefab;
[SerializeField]
private GameObject _cardDetailPrefab;
[SerializeField]
private GameObject _introductionItemPrefab;
[SerializeField]
private UIGrid _deckListGrid;
[SerializeField]
private UIScrollView _scrollView;
[SerializeField]
private GameObject _confirmLabelForRotation;
private DialogBase _dialog;
private DeckIntroductionTask _introductionTask;
private GameObject _deckViewObj;
private UICardList _cardList;
private GameObject _cardDetailObj;
private CardDetailUI _cardDetail;
private CardBasePrm.ClanType _classType = CardBasePrm.ClanType.NONE;
private bool _isUpdateDeckList = true;
private FormatChangeUI _formatChangeUI;
private Vector3 _anotationLabelDefaultPosition;
private int _seriesId;
public const int LATEST_SERIES_ID = -1;
public static void Create(GameObject prefab, GameObject parent, int seriesId = -1, Format format = Format.Max)
{
GameObject obj = NGUITools.AddChild(parent, prefab);
@@ -115,7 +53,7 @@ public class DeckIntroduction : MonoBehaviour
component._formatState = format;
DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
dialogBase.AddButton(DialogBase.ButtonType.Gray, isReflect: false, Data.SystemText.Get("OtherTop_0065"));
dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_DECIDE;
dialogBase.ClickSe_Btn1 = 0;
dialogBase.isNotCloseWindowButton1 = true;
dialogBase.onPushButton1 = component.CreateSelectSeriesIdDialog;
dialogBase.AddButton(DialogBase.ButtonType.Close);
@@ -136,27 +74,6 @@ public class DeckIntroduction : MonoBehaviour
_seriesId = seriesId;
}
private IEnumerator Start()
{
_anotationLabelDefaultPosition = _labelAnnotation.transform.localPosition;
yield return LoadAtlas();
yield return StartCoroutine(StartDeckIntroductionTask());
SetSeriesId(_introductionTask.DisplaySeriesId);
yield return LoadResource();
_dialog.gameObject.SetActive(value: true);
if (_formatState == Format.Max)
{
_formatState = _introductionTask.DisplayFormat;
}
InitFormatBtn(_formatState);
InitClassTab(_introductionTask);
}
private void OnDestroy()
{
ReleaseResource();
}
private IEnumerator StartDeckIntroductionTask()
{
_introductionTask = new DeckIntroductionTask();
@@ -175,282 +92,6 @@ public class DeckIntroduction : MonoBehaviour
}
}
private void ReleaseResource()
{
Toolbox.ResourcesManager.RemoveAssetGroup(_resourceList);
_resourceList.Clear();
RemoveTopCardResource();
}
private IEnumerator LoadAtlas()
{
string sceneAssetPath = UIManager.GetInstance().GetSceneAssetPath(UIAtlasManager.AssetBundleNames.Profile, null);
_resourceList.Add(sceneAssetPath);
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetAsync(sceneAssetPath, null));
sceneAssetPath = UIManager.GetInstance().GetSceneAssetPath(UIAtlasManager.AssetBundleNames.Profile, null, isload: true);
_classIconAtlas = Toolbox.ResourcesManager.LoadObject<GameObject>(sceneAssetPath).GetComponent<UIAtlas>();
}
private static string GetClassBGPath(CardBasePrm.ClanType classType, bool isFetch)
{
int num = (int)classType;
return Toolbox.ResourcesManager.GetAssetTypePath("bg_deck_info_" + num.ToString("00"), ResourcesManager.AssetLoadPathType.Background, isFetch);
}
private string GetClassCharaPath(CardBasePrm.ClanType classType, bool isFetch)
{
string charaTexName = ClassPage.GetCharaTexName(GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId((int)classType, isCurrentChara: false)
.skin_id);
return Toolbox.ResourcesManager.GetAssetTypePath(charaTexName, ResourcesManager.AssetLoadPathType.ClassCharaProfile, isFetch);
}
private IEnumerator LoadResource()
{
List<string> loadList = new List<string>();
int num = 9;
for (int i = 1; i < num; i++)
{
loadList.Add(GetClassCharaPath((CardBasePrm.ClanType)i, isFetch: false));
loadList.Add(GetClassBGPath((CardBasePrm.ClanType)i, isFetch: false));
}
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(loadList, null));
_resourceList.AddRange(loadList);
}
private IEnumerator LoadTopCardResource(CardBasePrm.ClanType classType, Action<CardBasePrm.ClanType> onFinish)
{
UIManager.GetInstance().createInSceneCenterLoading();
List<string> tempLoadList = new List<string>(_loadTopCardAssetList);
_loadTopCardAssetList.Clear();
for (int i = 0; i < _introductionTask._result.Count; i++)
{
DeckIntroductionTask.IntroductionData introductionData = _introductionTask._result[i];
string cardMaterialPath = DeckIntroductionItem.GetCardMaterialPath(introductionData.TopCardId);
if (introductionData.Deck.Format == _formatState && introductionData.Deck.GetDeckClassID() == (int)classType && !_loadTopCardAssetList.Contains(cardMaterialPath))
{
_loadTopCardAssetList.Add(cardMaterialPath);
}
}
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(_loadTopCardAssetList, null));
Toolbox.ResourcesManager.RemoveAssetGroup(tempLoadList);
onFinish.Call(classType);
UIManager.GetInstance().closeInSceneCenterLoading();
}
private void RemoveTopCardResource()
{
Toolbox.ResourcesManager.RemoveAssetGroup(_loadTopCardAssetList);
_loadTopCardAssetList.Clear();
}
private void InitClassTab(DeckIntroductionTask task)
{
_classIcon.atlas = _classIconAtlas;
int num = 9;
CardBasePrm.ClanType clanType = CardBasePrm.ClanType.NONE;
for (int i = 1; i < num; i++)
{
CardBasePrm.ClanType classType = (CardBasePrm.ClanType)i;
Tab tab = _tabList.AddTab(delegate
{
ChangePage(classType);
}, "class_tab_" + i.ToString("00"));
if (task.IsExistClass(classType, _formatState))
{
if (clanType == CardBasePrm.ClanType.NONE)
{
clanType = classType;
}
}
else
{
_tabList.SetTabToGrayByIndex(i - 1, disable: true);
}
tab.name = "Class_" + i + "(Clone)";
}
_tabList.Reset();
_tabList.SelectTabByIndex((int)(clanType - 1), isForceSet: true);
}
private bool NeedResurgentConfirmLabel()
{
if ((_seriesId == 34 || _seriesId == 33 || _seriesId == 9) && _formatState == Format.Rotation)
{
return true;
}
return false;
}
private void ChangePage(CardBasePrm.ClanType classType)
{
if (_classType == classType && !_isUpdateDeckList)
{
return;
}
_classType = classType;
_isUpdateDeckList = false;
ClassCharacterMasterData charaPrmByClassId = GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId((int)classType, isCurrentChara: false);
_className.text = charaPrmByClassId._className;
ClassCharaPrm.SetClassLabelSetting(_className, classType);
_classCharaTexture.mainTexture = Toolbox.ResourcesManager.LoadObject(GetClassCharaPath(classType, isFetch: true)) as Texture;
_classBG.mainTexture = Toolbox.ResourcesManager.LoadObject(GetClassBGPath(classType, isFetch: true)) as Texture;
_confirmLabelForRotation.SetActive(NeedResurgentConfirmLabel());
_labelAnnotation.transform.localPosition = _anotationLabelDefaultPosition;
string value;
if (IsNotCopyToUnlimited(classType) && _formatState == Format.Rotation)
{
_labelAnnotation.gameObject.SetActive(value: false);
}
else if (_introductionTask.AlternativeFormatAndSeries != null && _introductionTask.AlternativeFormatAndSeries.TryGetValue(_formatState, out value))
{
_labelAnnotation.gameObject.SetActive(value: true);
SetAnnotationText(value);
if (NeedResurgentConfirmLabel())
{
_labelAnnotation.transform.localPosition = new Vector3(_anotationLabelDefaultPosition.x, 209f, _anotationLabelDefaultPosition.z);
}
}
else
{
_labelAnnotation.gameObject.SetActive(value: false);
}
StartCoroutine(LoadTopCardResource(classType, InitDeckList));
}
private bool IsNotCopyToUnlimited(CardBasePrm.ClanType classType)
{
for (int i = 0; i < _introductionTask._result.Count; i++)
{
DeckData deck = _introductionTask._result[i].Deck;
if (deck.HasResurgentCard() && deck.IsOutOfRotationFormat && deck.GetDeckClassID() == (int)classType)
{
return true;
}
}
return false;
}
private void InitDeckList(CardBasePrm.ClanType classType)
{
for (int i = 0; i < _deckIntroductionItem.Count; i++)
{
_deckIntroductionItem[i].gameObject.SetActive(value: false);
}
List<DeckIntroductionTask.IntroductionData> list = new List<DeckIntroductionTask.IntroductionData>();
for (int j = 0; j < _introductionTask._result.Count; j++)
{
DeckIntroductionTask.IntroductionData introductionData = _introductionTask._result[j];
if (introductionData.Deck.GetDeckClassID() == (int)classType && introductionData.Deck.Format == _formatState)
{
list.Add(introductionData);
}
}
for (int k = 0; k < list.Count; k++)
{
DeckIntroductionItem deckIntroductionItem = null;
if (k < _deckIntroductionItem.Count)
{
deckIntroductionItem = _deckIntroductionItem[k];
deckIntroductionItem.gameObject.SetActive(value: true);
}
else
{
deckIntroductionItem = NGUITools.AddChild(_deckListGrid.gameObject, _introductionItemPrefab).GetComponent<DeckIntroductionItem>();
_deckIntroductionItem.Add(deckIntroductionItem);
}
deckIntroductionItem.Initialize(list[k]);
deckIntroductionItem.OnClick = delegate(DeckIntroductionTask.IntroductionData data)
{
OnClickDeck(data);
};
}
_deckListGrid.Reposition();
_scrollView.ResetPosition();
}
private void InitFormatBtn(Format format)
{
_formatState = format;
FormatChangeUI.FormatCategory defaultFormatCategory = FORMAT_TO_FORMAT_CATEGORY[_formatState];
FormatChangeUI.FormatCategory anotherFormatCategory = (_introductionTask.IsExistFormat(Format.Crossover) ? FORMAT_TO_FORMAT_CATEGORY[Format.Crossover] : FormatChangeUI.FormatCategory.Invalid);
_formatChangeUI = FormatChangeUI.Create(defaultFormatCategory, anotherFormatCategory, OnClickFormatBtn);
_formatChangeUI.ShowOldRotationIcon();
_dialog.SetObj(_formatChangeUI.gameObject, FORMAT_CHANGE_UI_POSITION);
}
private void SetAnnotationText(string serieasName)
{
_labelAnnotation.overflowMethod = UILabel.Overflow.ResizeFreely;
_labelAnnotation.text = Data.SystemText.Get("OtherTop_0068", serieasName);
_labelAnnotation.ProcessText();
if (_labelAnnotation.width > 210)
{
_labelAnnotation.overflowMethod = UILabel.Overflow.ShrinkContent;
_labelAnnotation.width = 210;
}
}
private void OnClickDeck(DeckIntroductionTask.IntroductionData data)
{
ShowDeckView(data.Deck);
}
private void ShowDeckView(DeckData deck)
{
string text = "Detail";
if (_cardDetailObj == null)
{
_cardDetailObj = NGUITools.AddChild(base.gameObject, _cardDetailPrefab);
_cardDetail = _cardDetailObj.GetComponent<CardDetailUI>();
_cardDetail.Initialize(LayerMask.NameToLayer(text), CardMaster.CardMasterId.Default);
_cardDetailObj.SetActive(value: false);
}
if (_deckViewObj == null)
{
_deckViewObj = UnityEngine.Object.Instantiate(_deckViewPrefab);
_cardList = _deckViewObj.GetComponent<UICardList>();
_cardList.Init(base.gameObject, _cardDetail, null, OnCloseDeckView, text, in_DetailCameraUse: true, null, 40);
_deckViewObj.SetActive(value: false);
}
_scrollView.DisableSpring();
UIManager.GetInstance().createInSceneCenterLoading();
StartCoroutine(CardLoadCoroutine(deck));
}
private IEnumerator CardLoadCoroutine(DeckData deck)
{
IList<int> cardIdList = deck.GetCardIdList();
_cardList.RemoveData();
_loadCardAssetList = _cardList.GetLoadFileList(cardIdList as List<int>);
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(_loadCardAssetList, null));
_cardList.IsEnableMyRotationDisplay = false;
_cardList.IsConventionDeckIntroduction = true;
_cardList.SetDeck(deck, null);
if (deck.Format == Format.Rotation)
{
_cardList.SetFormatIcon("icon_rotation_s");
}
_cardList.UpdateShortageRedEther();
_cardList.SetShortageCardVisible(_cardList.IsEnableShortageCardVisible);
_cardList.SetActiveDeckIntroductionObj(isActive: true);
yield return null;
_dialog.SetDisp(inDisp: false);
_deckViewObj.SetActive(value: true);
UIManager.GetInstance().closeInSceneCenterLoading();
}
private void OnCloseDeckView()
{
_dialog.SetDisp(inDisp: true);
_deckViewObj.SetActive(value: false);
_scrollView.UpdatePosition();
if (_loadCardAssetList != null)
{
Toolbox.ResourcesManager.RemoveAssetGroup(_loadCardAssetList);
_loadCardAssetList.Clear();
}
}
private void CreateSelectSeriesIdDialog()
{
int prevSeriesId = _seriesId;
@@ -471,7 +112,7 @@ public class DeckIntroduction : MonoBehaviour
}
dialogBase.SetTitleLabel(Data.SystemText.Get("OtherTop_0066"));
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.DecisionBtn);
dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_DECIDE;
dialogBase.ClickSe_Btn1 = 0;
dialogBase.onPushButton1 = delegate
{
if (_seriesId != prevSeriesId)
@@ -516,17 +157,6 @@ public class DeckIntroduction : MonoBehaviour
_tabList.SelectTabByIndex((int)(clanType - 1), isForceSet: true);
}
private void OnClickFormatBtn(FormatChangeUI.FormatCategory formatCategory)
{
GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON);
Format key = FORMAT_TO_FORMAT_CATEGORY.First((KeyValuePair<Format, FormatChangeUI.FormatCategory> data) => data.Value == formatCategory).Key;
if (_formatState != key)
{
_formatState = key;
UpdateClassTab();
}
}
private void UpdateFormatChangeUI()
{
bool flag = _introductionTask.IsExistFormat(Format.Rotation);