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

@@ -1,276 +1,14 @@
using System;
using System.Collections;
using System.IO;
using Cute;
using UnityEngine;
using UnityEngine.Networking;
using Wizard;
using Wizard.ErrorDialog;
// Post-Phase-5b (2026-07-03) UI stub. Twitter was the deck-share-to-Twitter
// coroutine driver — dialog display, deck-image download, browser-open of an
// intent URL. Nothing headless runs. Kept as a MonoBehaviour type with the one
// externally-called method (TweetDataFromPortal, from UICardList) preserved as
// a no-op so the stub compiles cleanly with the rest of the culled UI cluster.
public class Twitter : MonoBehaviour
{
private const string UNITY_CLASS = "com.unity3d.player.UnityPlayer";
private const string UNITY_ACTIVITY = "currentActivity";
private const string TWITTER_URL = "http://twitter.com/intent/tweet?text={0}&url={1}&hashtags={2}";
private const string SAVED_IMAGE_NAME = "image_saved.png";
private const int ERROR_CODE_UNKNOWN = 102;
public const int REQUEST_CODE = 555;
private const float TIMEOUT = 20f;
private GenerateDeckImageTask _task;
private const string OBJECT_NAME = "TwitterShareObject";
private void Start()
{
base.gameObject.name = "TwitterShareObject";
}
public static void Logout(Action callback = null)
{
}
public void TweetWithoutImage(string text, string url, string tags)
{
Post(text, url, tags, null);
}
public void TweetWithScreenshot(string text, string url, string tags)
{
ScreenCapture.CaptureScreenshot("image_saved.png");
string imageFilename = GetImagePath();
UIManager.GetInstance().createInSceneCenterLoading(notBlack: true);
StartCoroutine(CheckFileExistsAndExecute(delegate
{
Post(text, url, tags, imageFilename);
UIManager.GetInstance().closeInSceneCenterLoading();
}, imageFilename, delegate(bool isTimeout)
{
CloseLoadingAndShowErrorDialog(isTimeout);
}));
}
public void TweetWithDownloadImage(string text, string url, string tags, string imageUrl, Action callback = null)
{
string imageFilename = GetImagePath();
UIManager.GetInstance().createInSceneCenterLoading(notBlack: true);
Action action = delegate
{
StartCoroutine(CheckFileExistsAndExecute(delegate
{
Post(text, url, tags, imageFilename);
UIManager.GetInstance().closeInSceneCenterLoading();
if (callback != null)
{
callback();
}
}, imageFilename, delegate(bool isTimeout)
{
CloseLoadingAndShowErrorDialog(isTimeout);
}));
};
StartCoroutine(DownloadImage(imageUrl, imageFilename, action, CloseLoadingAndShowErrorDialog));
}
public void TweetWithSavedImage(string text, string hashtags, string imagePath, Action callback = null)
{
UIManager.GetInstance().createInSceneCenterLoading(notBlack: true);
StartCoroutine(CheckFileExistsAndExecute(delegate
{
Post(text, "", hashtags, imagePath);
UIManager.GetInstance().closeInSceneCenterLoading();
if (callback != null)
{
callback();
}
}, imagePath, delegate(bool isTimeout)
{
CloseLoadingAndShowErrorDialog(isTimeout);
}));
}
private static string MakeIntentUrl(string text, string url, string tags)
{
return $"http://twitter.com/intent/tweet?text={UnityWebRequest.EscapeURL(text)}&url={UnityWebRequest.EscapeURL(url)}&hashtags={UnityWebRequest.EscapeURL(tags)}";
}
private static string FormatText(string text, string url, string tags)
{
if (!string.IsNullOrEmpty(url))
{
text = text + " " + url;
}
if (!string.IsNullOrEmpty(tags))
{
string[] array = tags.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string text2 in array)
{
text = text + " #" + text2;
}
}
return text;
}
private void ShowDialogUrl(string text, string url, string tags)
{
bool isBackKeyEnable = GameMgr.GetIns().GetInputMgr().isBackKeyEnable;
GameMgr.GetIns().GetInputMgr().isBackKeyEnable = true;
SystemText systemText = Wizard.Data.SystemText;
DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
dialogBase.SetTitleLabel(systemText.Get("Card_0161"));
dialogBase.SetText(systemText.Get("Common_0208"));
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
dialogBase.SetButtonText(systemText.Get("Dia_Web_001_Button"));
dialogBase.onPushButton1 = delegate
{
BrowserURL.Open(MakeIntentUrl(text, url, tags));
};
dialogBase.OnClose = delegate
{
GameMgr.GetIns().GetInputMgr().isBackKeyEnable = isBackKeyEnable;
};
}
public void Post(string text, string url, string tags, string imageFilename)
{
ShowDialogUrl(text, url, tags);
}
private IEnumerator DownloadImage(string url, string filename, Action action, Action<bool> onError)
{
using UnityWebRequest request = UnityWebRequestTexture.GetTexture(url);
yield return request.SendWebRequest();
bool isTimeout = false;
float startDownloadTime = Time.time;
while (!request.isDone && !isTimeout)
{
isTimeout = Time.time - startDownloadTime > 20f;
yield return null;
}
if (request.error != null || isTimeout)
{
onError(isTimeout);
request.Dispose();
yield break;
}
Texture2D content = DownloadHandlerTexture.GetContent(request);
request.Dispose();
byte[] bytes = content.EncodeToPNG();
UnityEngine.Object.Destroy(content);
File.WriteAllBytes(filename, bytes);
action();
}
private IEnumerator CheckFileExistsAndExecute(Action onFileExists, string filePath, Action<bool> onError)
{
bool isFileTimeout = false;
float startWaitTime = Time.time;
while (!File.Exists(filePath) && !isFileTimeout)
{
isFileTimeout = Time.time - startWaitTime > 20f;
yield return null;
}
if (File.Exists(filePath))
{
onFileExists();
}
else
{
onError(obj: false);
}
}
private static string GetImagePath()
{
return "" + "image_saved.png";
}
private void CloseLoadingAndShowErrorDialog(bool isTimeout)
{
UIManager.GetInstance().closeInSceneCenterLoading();
if (isTimeout)
{
Dialog.Create("TIMEOUT_NORETRY");
}
else
{
Dialog.Create(102);
}
}
public void TweetDataFromPortal(int[] cardIds, ClassSet classSet, GenerateDeckCodeTask.SubmitDeckType submitType, int[] phantomCardIdList, string rotationId)
{
GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
StartTweet(cardIds, classSet, submitType, phantomCardIdList, rotationId);
}
private void StartTweet(int[] cardIds, ClassSet classSet, GenerateDeckCodeTask.SubmitDeckType submitType, int[] phantomCardIdList, string rotationId)
{
UIManager.GetInstance().createInSceneCenterLoading();
Action<NetworkTask.ResultCode> callbackOnSuccess = delegate
{
if (CardBasePrm.ClanTypeIsUseable(classSet.SubClass))
{
_task = new GenerateDeckImageTask();
_task.SetParameter((int)classSet.MainClass, (int)classSet.SubClass, submitType, cardIds, phantomCardIdList);
StartCoroutine(Toolbox.NetworkManager.Connect(_task, GetImageResponse, null, null, encrypt: false));
}
else
{
_task = new GenerateDeckImageTask();
_task.SetParameter((int)classSet.MainClass, submitType, cardIds, rotationId, phantomCardIdList);
StartCoroutine(Toolbox.NetworkManager.Connect(_task, GetImageResponse, null, null, encrypt: false));
}
};
GenerateDeckImageMaintenanceTask task = new GenerateDeckImageMaintenanceTask();
StartCoroutine(Toolbox.NetworkManager.Connect(task, callbackOnSuccess));
}
private void GetImageResponse(NetworkTask.ResultCode error)
{
string imageFilename = GetImagePath();
File.WriteAllBytes(imageFilename, _task.ImageBytes);
string text = _task.TwitterMessage;
_task = null;
StartCoroutine(CheckFileExistsAndExecute(delegate
{
Post(text, "", "", imageFilename);
UIManager.GetInstance().closeInSceneCenterLoading();
}, imageFilename, delegate(bool isTimeout)
{
CloseLoadingAndShowErrorDialog(isTimeout);
}));
}
public void OnResult(string result)
{
bool isBackKeyEnable = GameMgr.GetIns().GetInputMgr().isBackKeyEnable;
GameMgr.GetIns().GetInputMgr().isBackKeyEnable = true;
DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
SystemText systemText = Wizard.Data.SystemText;
dialogBase.SetTitleLabel(systemText.Get("Dia_Share_005"));
string[] array = result.Split(',');
if (array.Length <= 1 || int.Parse(array[1]) == 555)
{
if (int.Parse(array[0]) == 1)
{
dialogBase.SetText(systemText.Get("Dia_Share_001"));
}
else
{
dialogBase.SetText(systemText.Get("Dia_Share_002"));
}
dialogBase.OnClose = delegate
{
GameMgr.GetIns().GetInputMgr().isBackKeyEnable = isBackKeyEnable;
};
}
}
}