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

@@ -13,464 +13,7 @@ public class UIAtlasManager
MypageComon,
Battle,
BattleLang,
RoomMatch,
AreaSelect,
DeckEdit,
Arena,
Gacha,
Profile,
Ranking,
Friend,
CardFrame,
CardFramePhantom,
Tournament,
Quest,
Scenario,
Bingo,
RedEtherCampaign,
NeutralPopularityVote,
BossRush,
Max
}
private List<UIAtlas> _atlasList = new List<UIAtlas>();
private List<UIAtlas> _residentAtlasList = new List<UIAtlas>();
private List<string> _loadPath;
private bool _isLoadFinish;
private HashSet<AssetBundleNames> _loadedAtlasHash = new HashSet<AssetBundleNames>();
private bool IsTutorialFinish()
{
if (Data.Load != null && Data.Load.data != null && Data.Load.data._userTutorial.tutorial_step != 100)
{
return true;
}
return false;
}
public void LoadCurrentScene(Action callback = null)
{
if (_isLoadFinish && callback != null)
{
callback();
return;
}
if (_loadPath == null)
{
_loadPath = new List<string>();
_atlasList = new List<UIAtlas>();
}
else
{
_loadPath.Clear();
_atlasList.Clear();
}
HashSet<AssetBundleNames> assetBundleNameSet = GetLoadTargetSet(UIManager.GetInstance().GetCurrentScene());
if (IsTutorialFinish())
{
assetBundleNameSet.Add(AssetBundleNames.AreaSelect);
assetBundleNameSet.Add(AssetBundleNames.Battle);
}
UpdateAssetPathFromAssetBundleNames(assetBundleNameSet);
UIManager.GetInstance().StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(_loadPath, delegate
{
foreach (AssetBundleNames item in assetBundleNameSet)
{
UnityEngine.Object listData = Toolbox.ResourcesManager.LoadObject<GameObject>(GetAtlasPath(item, null, isload: true));
AddAssetObjList(listData);
}
_isLoadFinish = true;
foreach (AssetBundleNames item2 in assetBundleNameSet)
{
_loadedAtlasHash.Add(item2);
}
if (callback != null)
{
callback();
}
}));
}
public void RemoveSceneAtlas(UIManager.ViewScene inLeaveScene)
{
HashSet<AssetBundleNames> loadTargetSet = GetLoadTargetSet(inLeaveScene);
HashSet<AssetBundleNames> hashSet = new HashSet<AssetBundleNames>(_loadedAtlasHash);
hashSet.ExceptWith(loadTargetSet);
List<string> list = new List<string>(hashSet.ToList().Count);
foreach (AssetBundleNames item in hashSet)
{
list.Add(GetAtlasPath(item, null));
}
if (list.Count != 0)
{
Toolbox.ResourcesManager.RemoveAssetGroup(list);
}
foreach (AssetBundleNames loop_name in hashSet)
{
_loadedAtlasHash.RemoveWhere((AssetBundleNames x) => (x == loop_name) ? true : false);
}
}
public string GetAtlasPath(AssetBundleNames assetname, string singlebundlename = "", bool isload = false)
{
string result = "";
if (isload)
{
if (string.IsNullOrEmpty(singlebundlename))
{
switch (assetname)
{
case AssetBundleNames.MypageComon:
result = "Ui/TextureAtlas/MyPageSubTextureAtlas/" + assetname;
break;
case AssetBundleNames.Battle:
result = "Ui/TextureAtlas/BattleTextureAtlas/" + assetname;
break;
case AssetBundleNames.BattleLang:
result = "Uilang/TextureAtlas/BattleLangTextureAtlas/" + assetname;
break;
case AssetBundleNames.RoomMatch:
result = "Ui/TextureAtlas/RoomMatchAtlas/" + assetname;
break;
case AssetBundleNames.AreaSelect:
result = "Ui/TextureAtlas/AreaSelectTextureAtlas/" + assetname;
break;
case AssetBundleNames.DeckEdit:
result = "Ui/TextureAtlas/DeckEditTextureAtlas/" + assetname;
break;
case AssetBundleNames.Arena:
result = "Ui/TextureAtlas/ArenaTextureAtlas/" + assetname;
break;
case AssetBundleNames.Gacha:
result = "Ui/TextureAtlas/GachaTextureAtlas/" + assetname;
break;
case AssetBundleNames.Profile:
result = "Ui/TextureAtlas/Profile/" + assetname;
break;
case AssetBundleNames.Ranking:
result = "Ui/TextureAtlas/Ranking/" + assetname;
break;
case AssetBundleNames.Friend:
result = "Ui/TextureAtlas/Friend/" + assetname;
break;
case AssetBundleNames.CardFrame:
result = "Ui/TextureAtlas/CardFrame/" + assetname;
break;
case AssetBundleNames.CardFramePhantom:
result = "Ui/TextureAtlas/CardFramePhantom/" + assetname;
break;
case AssetBundleNames.Tournament:
result = "Ui/TextureAtlas/Tournament/" + assetname;
break;
case AssetBundleNames.Quest:
result = "Ui/TextureAtlas/Quest/" + assetname;
break;
case AssetBundleNames.Scenario:
result = "Ui/TextureAtlas/Scenario/" + assetname;
break;
case AssetBundleNames.Bingo:
result = "Ui/TextureAtlas/BingoTextureAtlas/" + assetname;
break;
case AssetBundleNames.RedEtherCampaign:
result = "Ui/TextureAtlas/RedEtherCampaign/" + assetname;
break;
case AssetBundleNames.NeutralPopularityVote:
result = $"Ui/TextureAtlas/PopularityVote/{assetname}";
break;
case AssetBundleNames.BossRush:
result = $"Ui/TextureAtlas/BossRush/{assetname}";
break;
}
}
else
{
switch (assetname)
{
case AssetBundleNames.MypageComon:
result = "Ui/TextureAtlas/MyPageSubTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.Battle:
result = "Ui/TextureAtlas/BattleTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.BattleLang:
result = "Uilang/TextureAtlas/BattleLangTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.RoomMatch:
result = "Ui/TextureAtlas/RoomMatchAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.AreaSelect:
result = "Ui/TextureAtlas/AreaSelectTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.Arena:
result = "Ui/TextureAtlas/ArenaTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.Gacha:
result = "Ui/TextureAtlas/GachaTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.Profile:
result = "Ui/TextureAtlas/Profile/" + singlebundlename.ToString();
break;
case AssetBundleNames.Ranking:
result = "Ui/TextureAtlas/Ranking/" + singlebundlename.ToString();
break;
case AssetBundleNames.Friend:
result = "Ui/TextureAtlas/Friend/" + singlebundlename.ToString();
break;
case AssetBundleNames.Tournament:
result = "Ui/TextureAtlas/Tournament/" + singlebundlename.ToString();
break;
case AssetBundleNames.Quest:
result = "Ui/TextureAtlas/Quest/" + singlebundlename.ToString();
break;
case AssetBundleNames.Scenario:
result = "Ui/TextureAtlas/Scenario/" + singlebundlename.ToString();
break;
case AssetBundleNames.Bingo:
result = "Ui/TextureAtlas/BingoTextureAtlas/" + singlebundlename.ToString();
break;
case AssetBundleNames.RedEtherCampaign:
result = "Ui/TextureAtlas/RedEtherCampaign/" + singlebundlename.ToString();
break;
case AssetBundleNames.NeutralPopularityVote:
result = "Ui/TextureAtlas/PopularityVote/" + singlebundlename;
break;
case AssetBundleNames.BossRush:
result = "Ui/TextureAtlas/BossRush/" + singlebundlename;
break;
}
}
}
else
{
string text = "ui_";
string text2 = "";
if (string.IsNullOrEmpty(singlebundlename))
{
if (assetname == AssetBundleNames.BattleLang)
{
text = "uilang_";
}
text2 = assetname.ToString().ToLower();
}
else
{
if (singlebundlename.ToString().ToLower().Contains("battlelang"))
{
text = "uilang_";
}
text2 = singlebundlename.ToString().ToLower();
}
result = text + text2 + ".unity3d";
}
return result;
}
public void AddResidentAtlas(AssetBundleNames atlasName)
{
string atlasPath = GetAtlasPath(atlasName, null, isload: true);
UIAtlas component = Toolbox.ResourcesManager.LoadObject<GameObject>(atlasPath).GetComponent<UIAtlas>();
_residentAtlasList.Add(component);
}
public void RemoveResidentAtlas(AssetBundleNames atlasName)
{
string name = atlasName.ToString();
int num = _residentAtlasList.FindIndex((UIAtlas atlas) => atlas.name == name);
if (num < 0)
{
Debug.LogError("not found in resident atlas list : " + name);
}
else
{
_residentAtlasList.RemoveAt(num);
}
}
private HashSet<AssetBundleNames> GetLoadTargetSet(UIManager.ViewScene scene)
{
HashSet<AssetBundleNames> hashSet = new HashSet<AssetBundleNames>();
switch (scene)
{
case UIManager.ViewScene.MyPage:
hashSet.Add(AssetBundleNames.MypageComon);
break;
case UIManager.ViewScene.Battle:
case UIManager.ViewScene.RankMatch:
hashSet.Add(AssetBundleNames.Battle);
hashSet.Add(AssetBundleNames.BattleLang);
hashSet.Add(AssetBundleNames.Arena);
break;
case UIManager.ViewScene.Room:
hashSet.Add(AssetBundleNames.RoomMatch);
break;
case UIManager.ViewScene.StorySelectPage:
case UIManager.ViewScene.StorySelectionWorld:
case UIManager.ViewScene.AreaSelect:
case UIManager.ViewScene.StoryChapterSelectionFlowChart:
hashSet.Add(AssetBundleNames.AreaSelect);
break;
case UIManager.ViewScene.RedEtherCampaignLobby:
hashSet.Add(AssetBundleNames.AreaSelect);
hashSet.Add(AssetBundleNames.RedEtherCampaign);
break;
case UIManager.ViewScene.DeckCardEdit:
case UIManager.ViewScene.CardAllList:
case UIManager.ViewScene.CardDestruct:
case UIManager.ViewScene.SealedDeckEdit:
hashSet.Add(AssetBundleNames.DeckEdit);
break;
case UIManager.ViewScene.TwoPick:
hashSet.Add(AssetBundleNames.MypageComon);
hashSet.Add(AssetBundleNames.Arena);
break;
case UIManager.ViewScene.Sealed:
case UIManager.ViewScene.Colosseum:
case UIManager.ViewScene.CompetitionLobby:
hashSet.Add(AssetBundleNames.Arena);
break;
case UIManager.ViewScene.SealedCardPackOpen:
case UIManager.ViewScene.Gacha:
case UIManager.ViewScene.BuildDeckPurchasePage:
case UIManager.ViewScene.CardSleevePurchasePage:
case UIManager.ViewScene.ClassSkinPurchasePage:
hashSet.Add(AssetBundleNames.Gacha);
break;
case UIManager.ViewScene.Bingo:
hashSet.Add(AssetBundleNames.Bingo);
hashSet.Add(AssetBundleNames.Quest);
break;
case UIManager.ViewScene.Profile:
case UIManager.ViewScene.CrossoverPortal:
hashSet.Add(AssetBundleNames.Profile);
break;
case UIManager.ViewScene.Ranking:
hashSet.Add(AssetBundleNames.Ranking);
break;
case UIManager.ViewScene.Gathering:
hashSet.Add(AssetBundleNames.Friend);
hashSet.Add(AssetBundleNames.Ranking);
hashSet.Add(AssetBundleNames.Tournament);
break;
case UIManager.ViewScene.Guild:
case UIManager.ViewScene.Friend:
hashSet.Add(AssetBundleNames.Friend);
hashSet.Add(AssetBundleNames.Ranking);
break;
case UIManager.ViewScene.LotteryPage:
hashSet.Add(AssetBundleNames.Arena);
hashSet.Add(AssetBundleNames.Quest);
break;
case UIManager.ViewScene.QuestSelectionPage:
hashSet.Add(AssetBundleNames.Quest);
hashSet.Add(AssetBundleNames.BossRush);
break;
case UIManager.ViewScene.Scenario:
case UIManager.ViewScene.Scenario2:
hashSet.Add(AssetBundleNames.Scenario);
break;
case UIManager.ViewScene.NeutralPopularityVote:
hashSet.Add(AssetBundleNames.NeutralPopularityVote);
break;
case UIManager.ViewScene.BossRushLobby:
hashSet.Add(AssetBundleNames.BossRush);
hashSet.Add(AssetBundleNames.Arena);
hashSet.Add(AssetBundleNames.Quest);
break;
case UIManager.ViewScene.FreePackCampaign:
hashSet.Add(AssetBundleNames.Arena);
break;
}
return hashSet;
}
private void UpdateAssetPathFromAssetBundleNames(HashSet<AssetBundleNames> assetBundleNameSet)
{
_loadPath.Clear();
foreach (AssetBundleNames item in assetBundleNameSet)
{
string atlasPath = GetAtlasPath(item);
_loadPath.Add(atlasPath);
}
}
private void AddAssetObjList(UnityEngine.Object listData)
{
try
{
UIAtlas component = ((GameObject)listData).GetComponent<UIAtlas>();
if (component != null)
{
_atlasList.Add(component);
}
}
catch
{
}
}
public List<UIAtlas> GetAtlasList()
{
return _residentAtlasList.Union(_atlasList).ToList();
}
public bool getAssetBundleEnd()
{
return _isLoadFinish;
}
public void setAssetBundleEnd(bool flag)
{
_isLoadFinish = flag;
}
public void OnDestroyView(UIManager.ViewScene scene)
{
foreach (AssetBundleNames item in GetLoadTargetSet(scene))
{
string atlasPath = GetAtlasPath(item);
Toolbox.AssetManager.UnloadAsset(atlasPath);
}
}
public void AttachAtlas(List<GameObject> obj_list, bool isTargetChildren = true)
{
List<UIAtlas> atlasList = GetAtlasList();
if (atlasList == null || atlasList.Count <= 0)
{
return;
}
List<UISprite> list = new List<UISprite>();
for (int i = 0; i < obj_list.Count; i++)
{
UISprite[] collection = (isTargetChildren ? obj_list[i].GetComponentsInChildren<UISprite>(includeInactive: true) : UnityEngine.Object.FindObjectsOfType<UISprite>());
list.AddRange(collection);
}
for (int j = 0; j < list.Count; j++)
{
UISprite uISprite = list[j];
string spriteName = uISprite.spriteName;
if (uISprite.atlas != null || string.IsNullOrEmpty(spriteName) || spriteName == "collider")
{
continue;
}
foreach (UIAtlas item in atlasList)
{
foreach (UISpriteData sprite in item.spriteList)
{
if (spriteName == sprite.name)
{
uISprite.atlas = item;
goto end_IL_00f1;
}
}
continue;
end_IL_00f1:
break;
}
}
}
CardFramePhantom}
}