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,6 +13,10 @@ using Wizard.Scripts.Network.Data.TaskData.Ranking;
using Wizard.Scripts.Network.Data.TaskData.SkinPurchase;
using Wizard.Scripts.Network.Data.TaskData.SleevePurchase;
using Wizard.Story;
// TODO(engine-cleanup-pass2): 156 of 165 methods unrun in baseline
// Type: Wizard.Data
// See data_dumps/reports/engine-cleanup/live-methods.baseline.txt
namespace Wizard;
@@ -20,32 +24,12 @@ public static class Data
{
private static Format _currentFormat;
public const int SERVER_FORMAT_NONE = 0;
public const int SERVER_FORMAT_ROTATION = 1;
public const int SERVER_FORMAT_UNLIMITED = 2;
public const int SERVER_FORMAT_PRE_ROTATION = 3;
public const int SERVER_FORMAT_CROSSOVER = 4;
public const int SERVER_FORMAT_TWO_PICK = 10;
public const int SERVER_FORMAT_SEALED = 20;
public const int SERVER_FORMAT_HOF = 31;
public const int SERVER_FORMAT_WIND_FALL = 33;
public static Master Master { get; set; }
public static Mastershop ShopMaster { get; set; }
public static SystemText SystemText { get; set; }
public static EncryptData EncryptData { get; set; }
public static Load Load { get; set; }
public static MyPage MyPage { get; set; }
@@ -66,12 +50,6 @@ public static class Data
public static AIBattleStartData AIBattleStartData { get; set; }
public static RoomMatchFinish RoomMatchFinish { get; set; }
public static string LastRoomBattleId { get; set; }
public static RoomBattleMatching RoomBattleMatching { get; set; }
public static SelectedStoryInfo SelectedStoryInfo { get; set; }
public static StoryWorldDataManager StoryWorldDataManager { get; set; }
@@ -166,8 +144,6 @@ public static class Data
public static GenerateDeckCode GenerateDeckCode { get; set; }
public static GetDeckDataFromCode DeckDataFromDeckCode { get; set; }
public static InviteFriendBattle InviteFriendBattle { get; set; }
public static InitializeRoomBattle InitializeRoomBattle { get; set; }
@@ -178,14 +154,13 @@ public static class Data
public static BattleRecoveryInfo BattleRecoveryInfo
{
// Soft read: returns null when no scope is active. The MulliganMgrBase.StartDeal call site
// reads this with a null-tolerant ??=-style pattern, so a null degrade is the historical
// fallback. Inside a scope, returns the per-session RecoveryInfo (SessionBattleEngine
// pre-seeds an uninitialized BattleRecoveryInfo on its ctx field initializer).
get => SVSim.BattleEngine.Ambient.BattleAmbient.Current?.RecoveryInfo;
// Strict setter: writes must land on the per-session ctx. No historical production caller
// writes this outside a scope; an unwrapped write now fails fast (forcing function).
set => SVSim.BattleEngine.Ambient.BattleAmbient.Require().RecoveryInfo = value;
// Instance-backed via BattleManagerBase.InstanceRecoveryInfo (Phase 5, chunk 40 — ambient
// fallback dropped after chunk 39 converted the last direct consumer).
get => BattleManagerBase.GetIns()?.InstanceRecoveryInfo;
set {
var m = BattleManagerBase.GetIns();
if (m is not null) m.InstanceRecoveryInfo = value;
}
}
public static VoteData VoteInfo { get; set; }
@@ -223,78 +198,6 @@ public static class Data
public static bool IsBattlePassPeriod { get; private set; }
public static void Initialize()
{
Master = new Master();
ShopMaster = new Mastershop();
SystemText = new SystemText();
Load = new Load();
MyPage = new MyPage();
MyPageNotifications = new MyPageNotifications();
RankMatchFinish = new RankMatchFinish();
FreeMatchFinish = new FreeMatchFinish();
DoMatchingDetail = new DoMatchingData();
AIBattleStartData = new AIBattleStartData();
ColosseumBattleFinish = new ColosseumBattleFinish();
CompetitionBattleFinish = new CompetitionBattleFinish();
RoomMatchFinish = new RoomMatchFinish();
RoomBattleMatching = new RoomBattleMatching();
SelectedStoryInfo = null;
StoryWorldDataManager = new StoryWorldDataManager();
StoryInfo = new StoryInfo();
StoryFinish = new StoryFinish();
StoryLeaderSelect = new StoryLeaderSelect();
QuestMissionInfo = new QuestMissionInfo();
QuestFinish = new QuestFinish();
ArenaData = new ArenaData();
MailTop = new MailTop();
ReadMail = new ReadMail();
PackInfo = new PackInfo();
PackOpen = new PackOpen();
SleevePurchaseInfo = new SleevePurchaseInfo();
SkinPurchaseInfo = new SkinPurchaseInfo();
BuildDeckPurchaseInfo = new BuildDeckPurchaseInfo();
ItemPurchaseInfo = new ItemPurchaseInfo();
EmptyDeckInfo = new EmptyDeckInfo();
FriendInfo = new FriendInfo();
PlayedTogetherInfo = new PlayedTogetherInfo();
ReceiveFriendApplyInfo = new ReceiveFriendApplyInfo();
SendFriendApplyInfo = new SendFriendApplyInfo();
User = new User();
UserConfig = new UserConfig();
UserTutorial = new UserTutorial();
MissionInfo = new MissionInfo();
AchievementInfo = new AchievementInfo();
EmblemInfo = new EmblemInfo();
DegreeInfo = new DegreeInfo();
SearchUserInfo = new SearchUserInfo();
RankingRankMatchClassInfo = new Dictionary<Format, MonthlyRanking>();
RankingMasterInfo = new Dictionary<Format, MonthlyRanking>();
RankingMasterMyHistories = new Dictionary<int, MyMasterPointHistories>();
TwoPickInfo = new TwoPickInfo();
TwoPickEntry = new Entry();
TwoPickDoMatching = new DoMatchingResponse();
ArenaBattleFinish = new Finish();
RoomTwoPickInfo = new RoomTwoPickInfo();
RoomTwoPickBeforeBattleInfo = new RoomTwoPickBeforeBattleInfo();
RoomTwoPickMultiDeckInfo = new RoomTwoPickMultiDeckInfo();
PracticeDataMgr = new PracticeDataMgr(null);
PracticeFinish = new PracticeFinish();
PracticePuzzleFinishData = new PracticePuzzleFinishData();
ItemAcquireHistoryInfo = new ItemAcquireHistoryInfo();
GenerateDeckCode = new GenerateDeckCode();
DeckDataFromDeckCode = new GetDeckDataFromCode();
InviteFriendBattle = new InviteFriendBattle();
InitializeRoomBattle = new InitializeRoomBattle();
ReplayInfo = new ReplayInfo();
CurrentFormat = Format.Max;
MaintenanceCodeList = null;
DeckGroupDataBase = new List<DeckGroup>();
Crossover = new Crossover();
MyRotationAllInfo = new MyRotationAllInfo();
TreasureBoxCp = new TreasureBoxCp();
}
public static void Clear()
{
Master = null;
@@ -430,15 +333,6 @@ public static class Data
}
}
public static void ParseMaintenance(JsonData mentenanceList)
{
MaintenanceCodeList = new List<NetworkDefine.MAINTENANCE_TYPE>();
for (int i = 0; i < mentenanceList.Count; i++)
{
MaintenanceCodeList.Add((NetworkDefine.MAINTENANCE_TYPE)mentenanceList[i].ToInt());
}
}
public static void UpdateMaintenance(List<NetworkDefine.MAINTENANCE_TYPE> checkList, List<NetworkDefine.MAINTENANCE_TYPE> maintenanceList)
{
for (int i = 0; i < checkList.Count; i++)
@@ -450,9 +344,4 @@ public static class Data
}
}
}
public static void ParseIsBattlePassPeriod(JsonData data)
{
IsBattlePassPeriod = data["is_battle_pass_period"].ToBoolean();
}
}