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

@@ -37,30 +37,12 @@ public class AssetHandle
private string _cryptFilename;
private const byte MultipleHandleIgnor = 2;
private const byte SubManifest = 4;
private byte _HandleAttribute;
private const float BACKGROUND_DOWNLOAD_WAIT_BEFORE_RETRY_SECONDS = 5f;
private Action phase;
private RequestType requestType;
public const int MANIFEST_INDEX_FILE_NAME = 0;
public const int MANIFEST_INDEX_DATA_HASH = 1;
private const int MANIFEST_INDEX_CATEGORY = 2;
private const int MANIFEST_INDEX_FILE_SIZE = 3;
private const int MANIFEST_INDEX_SMALL_HASH = 4;
private const int MANIFEST_INDEX_SMALL_SIZE = 5;
public string manifestDataHash { get; set; }
public string SmallDataHash { get; private set; }
@@ -305,14 +287,6 @@ public class AssetHandle
ManifestSmallDataSize = ((!flag2) ? 0.1f : result2);
}
private void PhaseNone()
{
if (requestType != RequestType.None)
{
Debug.LogError("need initialize");
}
}
private void PhaseIdle()
{
if (requestType == RequestType.Download)
@@ -514,7 +488,7 @@ public class AssetHandle
dialogBase.SetReturnMsg(UIManager.GetInstance().gameObject, "CommonRetry", "CommonResetGame");
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_GrayBtn);
dialogBase.SetButtonText(Data.SystemText.Get("Battle_0301"), Data.SystemText.Get("System_0006"));
dialogBase.ClickSe_Btn2 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
dialogBase.ClickSe_Btn2 = 0;
dialogBase.SetPanelDepth(6000);
}
UIManager.GetInstance().isNoAvailMemory = true;
@@ -656,7 +630,7 @@ public class AssetHandle
dialogBase2.SetReturnMsg(UIManager.GetInstance().gameObject, "CommonResetGame", "CommonResetGame", "CommonResetGame", "CommonResetGame");
dialogBase2.SetButtonLayout(DialogBase.ButtonLayout.GrayBtn);
dialogBase2.SetButtonText(Data.SystemText.Get("System_0006"));
dialogBase2.ClickSe_Btn1 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
dialogBase2.ClickSe_Btn1 = 0;
dialogBase2.SetPanelDepth(6000);
}
UIManager.GetInstance().isNoAvailMemory = true;
@@ -711,11 +685,9 @@ public class AssetHandle
case AssetType.TemporarySound:
if (filename.Substring(filename.Length - 4).Equals(".awb"))
{
Toolbox.AudioManager.RemoveCueSheet(filename);
}
else
{
Toolbox.AudioManager.AddCueSheet(filename, Path.GetFileName(filename), directory);
}
Toolbox.AssetManager.AddLoadingCurrentCount(filename);
break;
@@ -841,124 +813,6 @@ public class AssetHandle
Fin();
}
private IEnumerator _LoadStreamingAsset()
{
if (requestContext != null)
{
Utility.LeanSemaphore semaphore = requestContext.semaphore;
if (semaphore != null)
{
AssetErrorState errorState = requestContext.errorState;
while (!semaphore.TryWait())
{
yield return 0;
}
if (errorState != null && errorState.canceled)
{
errorState.Report(filename, AssetErrorState.Code.CANCELED);
Fin();
yield break;
}
}
}
if (assetType == AssetType.Manifests)
{
_LoadPostProcess();
Fin();
yield break;
}
Toolbox.AssetManager.AddLoadingCurrentCount(filename);
if (assetType == AssetType.AssetBundle && ++reference == 1)
{
int RetryCount = 0;
while (true)
{
string errorMessage = "";
string localCachePath = BuildLocalCachePath();
using (UnityWebRequest www = UnityWebRequest.Get(localCachePath))
{
if (www == null)
{
break;
}
yield return www.SendWebRequest();
bool isTimeOut = false;
float noProgressTime = Time.realtimeSinceStartup;
float oldProgress = 0f;
float timeOut = 30f;
while (!www.isDone)
{
float downloadProgress = www.downloadProgress;
if (downloadProgress <= oldProgress)
{
if (Time.realtimeSinceStartup - noProgressTime > timeOut)
{
isTimeOut = true;
break;
}
}
else
{
oldProgress = downloadProgress;
noProgressTime = Time.realtimeSinceStartup;
}
yield return null;
}
if (!string.IsNullOrEmpty(www.error) || isTimeOut)
{
string text = errorMessage + " : " + localCachePath;
Debug.LogError("_LoadStreamingAsset 01 load error:" + text);
Toolbox.AssetManager.AddLoadingCurrentCount(filename);
if (RetryCount > 5)
{
Fin();
disposeWebRequest(www);
yield break;
}
RetryCount++;
disposeWebRequest(www);
continue;
}
AssetBundle content = DownloadHandlerAssetBundle.GetContent(www);
if (content == null)
{
string text2 = errorMessage + " : " + localCachePath;
Debug.LogError("_LoadStreamingAsset02 load error:" + text2);
Toolbox.AssetManager.AddLoadingCurrentCount(filename);
Fin();
disposeWebRequest(www);
yield break;
}
Toolbox.AssetManager.SetAssetBundle(filename, content, isMultipleHandleIgnorAsset);
AssetBundle assetBundle = Toolbox.AssetManager.GetAssetBundleObject(filename).assetBundle;
string[] allAssetNames = assetBundle.GetAllAssetNames();
UnityEngine.Object[] array = assetBundle.LoadAllAssets();
int num = allAssetNames.Length;
int num2 = array.Length;
List<AssetObject> list = new List<AssetObject>();
for (int i = 0; i < num2; i++)
{
for (int j = 0; j < num; j++)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(allAssetNames[j]);
if (array[i].name.ToLower().Equals(fileNameWithoutExtension.ToLower()))
{
string path = Path.ChangeExtension(allAssetNames[j], ".any");
list.Add(new AssetObject(path, array[i]));
break;
}
}
}
Toolbox.AssetManager.SetObjectList(filename, list);
disposeWebRequest(www);
}
break;
}
}
_LoadPostProcess();
Fin();
}
private void _LoadCancel()
{
}
@@ -986,60 +840,6 @@ public class AssetHandle
}
if (IsSound())
{
Toolbox.AudioManager.RemoveCueSheet(filename);
}
return true;
}
private bool _UnloadTemporary()
{
if (--reference == 0)
{
if (assetType == AssetType.AssetBundle)
{
if (unloadTemporary)
{
Toolbox.AssetManager.UnloadAssetBundle(filename);
unloadTemporary = false;
}
else
{
int num = reference + 1;
reference = num;
}
}
}
else if (reference < 0)
{
reference = 0;
}
if (IsSound())
{
Toolbox.AudioManager.RemoveCueSheet(filename);
}
return true;
}
private bool _UnloadCommon()
{
if (--reference == 0)
{
if (assetType == AssetType.AssetBundle)
{
if (unloadCommon)
{
Toolbox.AssetManager.UnloadAssetBundle(filename);
}
else
{
int num = reference + 1;
reference = num;
}
}
}
else if (reference < 0)
{
reference = 0;
}
return true;
}
@@ -1057,19 +857,6 @@ public class AssetHandle
action?.Invoke(this);
}
public bool Download(AssetRequestContext requestContext)
{
requestType = RequestType.Download;
this.requestContext = requestContext;
phase();
return true;
}
public bool Download(Action<AssetHandle> callback)
{
return Download(new AssetRequestContext(callback));
}
public void Unload()
{
if (_Unload())
@@ -1079,24 +866,6 @@ public class AssetHandle
requestType = RequestType.None;
}
public void UnloadCommon()
{
if (_UnloadCommon())
{
phase = PhaseIdle;
}
requestType = RequestType.None;
}
public void UnloadTemporary()
{
if (_UnloadTemporary())
{
phase = PhaseIdle;
}
requestType = RequestType.None;
}
public bool Load(AssetRequestContext requestContext)
{
requestType = RequestType.Load;
@@ -1105,11 +874,6 @@ public class AssetHandle
return true;
}
public bool Load(Action<AssetHandle> callback)
{
return Load(new AssetRequestContext(callback));
}
public bool QuickLoadIfPossible()
{
if (phase != new Action(PhaseIdle))
@@ -1151,24 +915,6 @@ public class AssetHandle
return flag;
}
public bool IsAssetBundle()
{
if (assetType != AssetType.AssetBundle)
{
return false;
}
return true;
}
public bool IsManifests()
{
if (assetType != AssetType.Manifests)
{
return false;
}
return true;
}
public bool IsSound()
{
if (assetType != AssetType.Sound && assetType != AssetType.TemporarySound)
@@ -1178,24 +924,6 @@ public class AssetHandle
return true;
}
public bool IsSoundVoice()
{
if (IsSound() && (filename.Substring(0, 1).Equals("v") || filename.Substring(0, 1).Equals("c")))
{
return true;
}
return false;
}
public bool IsMovie()
{
if (assetType != AssetType.Movie)
{
return false;
}
return true;
}
public static string GenCryptoAssetFileName(string name)
{
if (sha1 == null)