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

@@ -143,81 +143,35 @@ public class ResourcesManager : MonoBehaviour, IManager
private enum ProgressDebugType
{
Progress_NONE,
Progress_DOWNLOAD,
Progress_LOAD
}
public enum BackgroundDownloadState
{
None,
Init,
Download,
StopRequest
}
public enum StopResult
{
Paused,
Stopped,
Finished
}
public List<string> Card3DAssetPathList = new List<string>();
public List<string> Card2DAssetPathList = new List<string>();
public List<string> CardListAssetPathList = new List<string>();
public List<string> SleeveListAssetPathList = new List<string>();
public List<string> BattleListAssetPathList = new List<string>();
private bool downloadSemaphore;
private AssetRequestContext downloadRequestContext = new AssetRequestContext(null, new Utility.LeanSemaphore(0), new AssetErrorState());
private bool loadSemaphore;
private AssetRequestContext loadRequestContext = new AssetRequestContext(null, new Utility.LeanSemaphore(0), new AssetErrorState());
private bool useAssetBundle = true;
public static int fixedParallelTasks;
private int _preferredParallelLoadTasks = -1;
private int _preferredParallelDownloadTasks = -1;
private List<string> downloadList;
public BackgroundDownloadState BgDownloadState;
private bool _stopForMovie;
public static float TextureScaleRatio
{
get
{
if (QualityManager.GetAssetQualityLevel() == QualityManager.AssetQualityLevel.Level_1)
{
return 2f;
}
return 1f;
}
}
public static float AtlasValueRatio
{
get
{
if (QualityManager.GetAssetQualityLevel() == QualityManager.AssetQualityLevel.Level_1)
{
return 0.5f;
}
return 1f;
}
}
public string GetAssetTypePath(string path, AssetLoadPathType type, bool isfetch = false)
{
if (string.IsNullOrEmpty(path))
@@ -934,12 +888,6 @@ public class ResourcesManager : MonoBehaviour, IManager
return sleeveId;
}
public bool IsExistSleeveNormalMap(long sleeveId)
{
string assetTypePath = GetAssetTypePath(sleeveId.ToString(), AssetLoadPathType.SleeveTextureNormalMap);
return ExistsAssetBundleManifest(assetTypePath);
}
private void AddAssetNotFoundLog(string path)
{
string text = "asset not found : " + path;
@@ -947,11 +895,6 @@ public class ResourcesManager : MonoBehaviour, IManager
LocalLog.AccumulateTraceLog(text);
}
public string GetLoadFontFilePath(string fileName)
{
return "f/" + fileName;
}
public Material FindCardMaterial(int cardId, AssetLoadPathType type, bool isEvol = false, bool isMutation = false, CardBasePrm.CharaType originalType = CardBasePrm.CharaType.NORMAL, bool isChoiceBrave = false)
{
string text = ((cardId / 1000000000 == 1) ? GetAssetTypePath($"{cardId}_M", AssetLoadPathType.UnitCardMaterial, isfetch: true) : ((isEvol && type == AssetLoadPathType.UnitCardMaterial) ? GetAssetTypePath($"{cardId}1_M", type, isfetch: true) : ((!(isMutation || isChoiceBrave)) ? GetAssetTypePath($"{cardId}0_M", type, isfetch: true) : ((originalType != CardBasePrm.CharaType.NORMAL) ? GetAssetTypePath($"{cardId}0_M", AssetLoadPathType.SpellCardMaterial, isfetch: true) : GetAssetTypePath($"{cardId}0_M", AssetLoadPathType.UnitCardMaterial, isfetch: true)))));
@@ -963,19 +906,6 @@ public class ResourcesManager : MonoBehaviour, IManager
return obj;
}
public int GetPreferredParallelDownloadNum()
{
if (fixedParallelTasks > 0)
{
return fixedParallelTasks;
}
if (_preferredParallelDownloadTasks < 0)
{
_preferredParallelDownloadTasks = 4;
}
return _preferredParallelDownloadTasks;
}
public int GetPreferredParallelLoadNum()
{
if (fixedParallelTasks > 0)
@@ -993,177 +923,6 @@ public class ResourcesManager : MonoBehaviour, IManager
{
}
private void Start()
{
downloadList = new List<string>();
Toolbox.ResourcesManager = this;
}
public void RequestDownloadStopForMovie()
{
if (BgDownloadState == BackgroundDownloadState.Download)
{
BgDownloadState = BackgroundDownloadState.StopRequest;
_stopForMovie = true;
}
}
public void RequestDownloadStopForMainDownload()
{
if (BgDownloadState == BackgroundDownloadState.Download)
{
BgDownloadState = BackgroundDownloadState.StopRequest;
}
}
private IEnumerator WaitBgDownloadStopRequestFulfilled()
{
while (!Toolbox.AssetManager.IsDownloadJobIdle())
{
yield return null;
}
BgDownloadState = BackgroundDownloadState.None;
}
public StopResult Stop()
{
if (BgDownloadState == BackgroundDownloadState.StopRequest)
{
BgDownloadState = BackgroundDownloadState.None;
if (_stopForMovie)
{
_stopForMovie = false;
return StopResult.Paused;
}
return StopResult.Stopped;
}
if (BgDownloadState == BackgroundDownloadState.Download)
{
BgDownloadState = BackgroundDownloadState.None;
return StopResult.Finished;
}
return StopResult.Stopped;
}
public bool CanStartBgDownload()
{
if (CanStartDownload())
{
return !Toolbox.MovieManager.IsPlaying();
}
return false;
}
public bool CanStartDownload()
{
if (BgDownloadState == BackgroundDownloadState.None && !downloadSemaphore)
{
return Toolbox.AssetManager.IsDownloadJobIdle();
}
return false;
}
public IEnumerator DownloadAssetGroupBackground(List<string> assetList, Action callback, bool isProgress = true, bool isSavePlayerPrefs = true)
{
if (BgDownloadState == BackgroundDownloadState.Init)
{
BgDownloadState = BackgroundDownloadState.Download;
yield return _DownloadAssetGroup(assetList, callback, isProgress, isSavePlayerPrefs);
}
}
public IEnumerator DownloadAssetGroup(List<string> assetList, Action callback, bool isProgress = true, bool isSavePlayerPrefs = true)
{
while (BgDownloadState == BackgroundDownloadState.Init)
{
yield return null;
}
if (BgDownloadState == BackgroundDownloadState.Download)
{
BgDownloadState = BackgroundDownloadState.StopRequest;
}
while (BgDownloadState == BackgroundDownloadState.StopRequest)
{
yield return WaitBgDownloadStopRequestFulfilled();
}
Action callback2 = delegate
{
if (callback != null)
{
callback();
}
};
yield return _DownloadAssetGroup(assetList, callback2, isProgress, isSavePlayerPrefs);
}
private IEnumerator _DownloadAssetGroup(List<string> assetList, Action callback, bool isProgress = true, bool isSavePlayerPrefs = true)
{
if (assetList == null || assetList.Count == 0)
{
callback?.Invoke();
yield break;
}
while (downloadSemaphore)
{
yield return null;
}
SetDownloadProcessLock(enable_lock: true);
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 60;
if (downloadList.Count > 0)
{
downloadList.Clear();
}
bool isDownloadVoiceUse = Toolbox.AudioManager.isDownloadVoiceUse;
for (int i = 0; i < assetList.Count; i++)
{
AssetHandle assetHandle = Toolbox.AssetManager.GetAssetHandle(assetList[i]);
if (assetHandle != null && (!assetHandle.IsSoundVoice() || isDownloadVoiceUse) && assetHandle.isReDownloadAsset(CustomPreference.IsNormalResource))
{
downloadList.Add(assetList[i]);
}
}
if (downloadList.Count > 0)
{
Toolbox.AssetManager.AddDownloadMaxCount(downloadList.Count);
yield return StartCoroutine(DownloadAssetGroupSub(downloadList, isProgress));
yield return new WaitForFixedUpdate();
if (isSavePlayerPrefs)
{
Toolbox.SavedataManager.Save();
}
}
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = Toolbox.QualityManager.GetFrameRate();
SetDownloadProcessLock(enable_lock: false);
callback?.Invoke();
}
private IEnumerator DownloadAssetGroupSub(List<string> assetList, bool isProgress = true)
{
if (isProgress)
{
UIManager.GetInstance().LoadingViewManager.UpdateLoadingNum(0);
}
if (BgDownloadState != BackgroundDownloadState.StopRequest)
{
downloadRequestContext.callback = null;
yield return StartCoroutine(ParallelAssetListExec(assetList, GetPreferredParallelDownloadNum(), downloadRequestContext, DownloadAssetSub, isProgress ? ProgressDebugType.Progress_DOWNLOAD : ProgressDebugType.Progress_NONE));
UIManager.GetInstance().LoadingViewManager.UpdateLoadingNum(100);
}
}
public IEnumerator DownloadAsset(string assetName, Action callback, bool isSavePlayerPrefs = true)
{
List<string> assetList = new List<string> { assetName };
yield return StartCoroutine(DownloadAssetGroup(assetList, callback, isProgress: true, isSavePlayerPrefs));
}
private void DownloadAssetSub(string assetName, AssetRequestContext requestContext)
{
Toolbox.AssetManager.DownloadAsset(assetName, requestContext);
}
private List<string> FilterAssetList(List<string> assetList, ref List<string> duplicateList)
{
if (assetList.Count < 2)
@@ -1305,17 +1064,6 @@ public class ResourcesManager : MonoBehaviour, IManager
LocalLog.UpdateLoadResourceLog("FinishLoad");
}
public IEnumerator DownloadAssetGroupWithLoadAsset(List<string> assetList, Action callback, bool isProgress = true)
{
if (assetList == null || assetList.Count == 0)
{
callback?.Invoke();
yield break;
}
yield return StartCoroutine(DownloadAssetGroup(assetList, null, isProgress));
yield return StartCoroutine(LoadAssetGroupAsync(assetList, null, isProgress));
}
private bool QuickLoadAsset(string assetName)
{
AssetHandle assetHandle = Toolbox.AssetManager.GetAssetHandle(assetName);
@@ -1395,23 +1143,6 @@ public class ResourcesManager : MonoBehaviour, IManager
Toolbox.AssetManager.CacheAsset(assetName, requestContext);
}
public void StartCoroutine_DownloadAssetGroupWithLoadAsset(List<string> assetList, Action callback, bool isProgress = true)
{
if (assetList == null || assetList.Count == 0)
{
callback?.Invoke();
}
else
{
StartCoroutine(DownloadAssetGroupWithLoadAsset(assetList, callback, isProgress));
}
}
public void StartCoroutine_DownloadAssetGroupWithLoadAsset(string asset, Action callback, bool isProgress = true)
{
StartCoroutine_DownloadAssetGroupWithLoadAsset(new List<string> { asset }, callback, isProgress);
}
public void StartCoroutine_LoadAssetGroupAsync(List<string> assetList, Action callback, bool isProgress = true)
{
if (assetList == null || assetList.Count == 0)
@@ -1441,11 +1172,6 @@ public class ResourcesManager : MonoBehaviour, IManager
}
}
public void StartCoroutine_LoadAssetGroupSync(string asset, Action callback, bool isProgress = true)
{
StartCoroutine(LoadAssetGroupSync(new List<string> { asset }, callback, isProgress));
}
public void RemoveAssetGroup(List<string> assetList)
{
for (int i = 0; i < assetList.Count; i++)
@@ -1459,39 +1185,6 @@ public class ResourcesManager : MonoBehaviour, IManager
Toolbox.AssetManager.UnloadAsset(assetName);
}
public void RemoveAssetForceCommon()
{
Toolbox.AssetManager.UnloadCommonAssetAll();
}
public void RemoveAssetCommon(string assetName)
{
Toolbox.AssetManager.UnloadCommonAsset(assetName);
}
public void RegistCommonAsset(List<string> assetList)
{
for (int i = 0; i < assetList.Count; i++)
{
Toolbox.AssetManager.RegistCommonAsset(assetList[i]);
}
}
public void RemoveAssetForceTemporary()
{
Toolbox.AssetManager.UnloadTemporaryAssetAll();
}
public void RemoveAssetTemporary(string assetName)
{
Toolbox.AssetManager.UnloadTemporaryAsset(assetName);
}
public void RegistTemporaryAsset(string assetName)
{
Toolbox.AssetManager.RegistTemporaryAsset(assetName);
}
public bool ExistsAssetBundleManifest(string assetName)
{
if (Toolbox.AssetManager.GetAssetHandle(assetName) != null)
@@ -1501,43 +1194,6 @@ public class ResourcesManager : MonoBehaviour, IManager
return false;
}
public bool CheckBeforeFileRequeset(string assetName)
{
return Toolbox.AssetManager.IsEnableAssetName(assetName);
}
public bool IsLoadedAssetBundle(string assetName)
{
if (Toolbox.AssetManager == null)
{
return false;
}
if (Toolbox.AssetManager.GetAssetBundleObject(assetName) != null)
{
return true;
}
return false;
}
public bool IsLoadedAssetBundleAndObjectArrayExist(string assetName)
{
if (IsLoadedAssetBundle(assetName))
{
return Toolbox.AssetManager.GetAssetBundleObject(assetName).objectArray.Count > 0;
}
return false;
}
public void UseAssetBundle(bool bEnabled)
{
useAssetBundle = bEnabled;
}
public bool IsUseAssetBundle()
{
return useAssetBundle;
}
public UnityEngine.Object LoadObject(string objectName, bool isServerResources = true, bool isIfFindLoad = false)
{
return LoadObject<UnityEngine.Object>(objectName, isServerResources);
@@ -1561,147 +1217,8 @@ public class ResourcesManager : MonoBehaviour, IManager
return Resources.Load<T>(objectName);
}
public UnityEngine.Object LoadObject(string assetName, string objectName, bool isServerResources = true)
{
return LoadObject<UnityEngine.Object>(assetName, objectName, isServerResources);
}
public T LoadObject<T>(string assetName, string objectName, bool isServerResources = true) where T : UnityEngine.Object
{
if (!isServerResources)
{
return Resources.Load<T>(objectName);
}
AssetManager assetManager = Toolbox.AssetManager;
if (assetManager != null)
{
UnityEngine.Object obj = assetManager.LoadObject(assetName, objectName, typeof(T));
if (obj != null)
{
return (T)obj;
}
}
return Resources.Load<T>(objectName);
}
private void SetDownloadProcessLock(bool enable_lock)
{
downloadSemaphore = enable_lock;
}
private void SetLoadProcessLock(bool enable_lock)
{
loadSemaphore = enable_lock;
}
public IEnumerator GameInitialize()
{
Toolbox.BootNetwork.SetupNetwork();
while (!Toolbox.BootNetwork.IsDoneGameStartCheck)
{
yield return 0;
}
yield return StartCoroutine(Toolbox.AssetManager.InitializeManifest(null, !Data.Load.data._userTutorial.NeedAllResource));
}
public static int calcTextureSize(int x)
{
return (int)(TextureScaleRatio * (float)x);
}
public static Vector2 calcTextureSize(Vector2 vec)
{
return vec * TextureScaleRatio;
}
public static int calcAtlasValue(int x, float rate)
{
return (int)(rate * (float)x + 0.5f);
}
public static void ResizeUISprite(UISprite _sprite)
{
_sprite.MakePixelPerfect();
int w = calcTextureSize(_sprite.width);
int h = calcTextureSize(_sprite.height);
_sprite.SetDimensions(w, h);
}
public static void ResizeUISpriteSliced(UISprite _sprite)
{
}
public static void resizeUIAtlas(UIAtlas atlas, GameObject parentObject, Material material = null)
{
if (atlas == null || atlas.replacement != null || QualityManager.GetAssetQualityLevel() != QualityManager.AssetQualityLevel.Level_1)
{
return;
}
string text = atlas.name;
UIAtlas uIAtlas = UnityEngine.Object.Instantiate(atlas);
uIAtlas.transform.parent = parentObject.transform;
uIAtlas.name = text + "_half";
atlas.replacement = uIAtlas;
if (material != null)
{
uIAtlas.spriteMaterial = material;
}
List<UISpriteData> spriteList = uIAtlas.spriteList;
if (spriteList != null)
{
for (int i = 0; i < spriteList.Count; i++)
{
UISpriteData uISpriteData = spriteList[i];
int width = uISpriteData.width;
int height = uISpriteData.height;
uISpriteData.x = calcAtlasValue(uISpriteData.x, AtlasValueRatio);
uISpriteData.y = calcAtlasValue(uISpriteData.y, AtlasValueRatio);
uISpriteData.width = calcAtlasValue(uISpriteData.width, AtlasValueRatio);
uISpriteData.height = calcAtlasValue(uISpriteData.height, AtlasValueRatio);
uISpriteData.borderLeft = uISpriteData.width - calcAtlasValue(width - uISpriteData.borderLeft, AtlasValueRatio);
uISpriteData.borderRight = calcAtlasValue(uISpriteData.borderRight, AtlasValueRatio);
uISpriteData.borderTop = calcAtlasValue(uISpriteData.borderTop, AtlasValueRatio);
uISpriteData.borderBottom = uISpriteData.height - calcAtlasValue(height - uISpriteData.borderBottom, AtlasValueRatio);
uISpriteData.paddingLeft = calcAtlasValue(uISpriteData.paddingLeft, AtlasValueRatio);
uISpriteData.paddingRight = calcAtlasValue(uISpriteData.paddingRight, AtlasValueRatio);
uISpriteData.paddingTop = calcAtlasValue(uISpriteData.paddingTop, AtlasValueRatio);
uISpriteData.paddingBottom = calcAtlasValue(uISpriteData.paddingBottom, AtlasValueRatio);
}
}
}
public void ClearLoadCount()
{
Toolbox.AssetManager.ResetDownloadCount();
}
public int GetDownLoadMax()
{
return Toolbox.AssetManager.GetDownloadMaxCount();
}
public int GetDownLoadCompleted()
{
return Toolbox.AssetManager.GetDownloadCurrentCount();
}
public float GetDownloadCompletedSize()
{
return Toolbox.AssetManager.GetDownloadCompletedSize();
}
public float GetDownloadMaxSize()
{
return Toolbox.AssetManager.GetDownloadSize(CustomPreference.IsNormalResource);
}
public int GetLoadingMax()
{
return Toolbox.AssetManager.GetLoadingMaxCount();
}
public int GetLoadingCompleted()
{
return Toolbox.AssetManager.GetLoadingCurrentCount();
}
}