Files
SVSimServer/SVSim.BattleEngine/Shim/GodObjects/GodObjects.cs
gamer147 2d9a6eea4b 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>
2026-07-03 19:18:54 -04:00

136 lines
9.6 KiB
C#

// AUTHORED SHIM (not copied). The god-object singletons the engine reaches for
// presentation/scene/effects/sound/data. These are the M0 "stop the bleed" types:
// copying them re-explodes the closure into the whole app (audio, scene, UI, net),
// so we shim a minimal surface. Manager GETTERS return the (copied) manager types as
// null fields -- the engine only dereferences them inside never-run VFX (IsForecast
// suppresses VFX) or non-battle code paths, so a null is harmless headless and avoids
// constructing copied types with heavy ctors. Member signatures mirror the decomp
// exactly (extracted, not guessed) so call sites compile unchanged.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EffectMgr
{
public enum EffectType
{
NONE, CMN_CARD_DRAW_2, CMN_CARD_SET_1, CMN_CARD_SET_2, CMN_CARD_SET_3, CMN_CARD_ACCELERATE_1, CMN_CARD_CRYSTALLIZE_1, CMN_CARD_TARGET_1, CMN_CARD_TARGET_2, CMN_CARD_SELECT_3, CMN_UI_TURN_1, CMN_UI_TURN_5, CMN_UI_TURN_6, CMN_FRAME_BTN_1, CMN_RESULT_TITLE_2, CMN_RESULT_TITLE_3, CMN_FIELD_SET_1, CMN_FIELD_SET_2, CMN_FIELD_SET_3, CMN_FIELD_SET_4, CMN_FIELD_SET_5, CMN_FIELD_SET_6, CMN_FIELD_SET_7, CMN_FIELD_SET_8, CMN_FIELD_SET_9, CMN_FIELD_SET_10, CMN_FIELD_SET_20, CMN_FIELD_SET_21, CMN_FIELD_SET_22, CMN_FIELD_SET_23, CMN_FIELD_SET_30, CMN_FIELD_SET_31, CMN_FIELD_SET_32, CMN_FIELD_SET_33, CMN_FIELD_SET_34, CMN_FIELD_SET_41, CMN_FIELD_SET_42, CMN_FIELD_SET_43, CMN_FIELD_SET_51, CMN_FIELD_SET_52, CMN_FIELD_SET_61, CMN_FIELD_SET_62, CMN_FIELD_SET_71, CMN_FIELD_SET_72, CMN_FIELD_SET_74, CMN_FIELD_SET_76, CMN_FIELD_SET_1001, CMN_FIELD_SET_1002, CMN_FIELD_SET_1003, CMN_FIELD_SET_1004, CMN_FIELD_SET_1005, CMN_FIELD_SET_1006, CMN_FIELD_SET_1007, CMN_FIELD_SET_1008, CMN_FIELD_SET_1009, CMN_FIELD_SET_1010, CMN_FIELD_SET_1011, CMN_FIELD_SET_1012, CMN_FIELD_TAP_1_1, CMN_FIELD_TAP_1_2, CMN_FIELD_TAP_2_1, CMN_FIELD_TAP_3_1, CMN_FIELD_TAP_3_2, CMN_FIELD_TAP_4_1, CMN_FIELD_TAP_4_2, CMN_FIELD_TAP_5_1, CMN_FIELD_TAP_6_1, CMN_FIELD_TAP_6_2, CMN_FIELD_TAP_7_1, CMN_FIELD_TAP_8_1, CMN_FIELD_TAP_9_1, CMN_FIELD_TAP_10_1, CMN_FIELD_TAP_10_2, CMN_FIELD_TAP_20_1, CMN_FIELD_TAP_20_2, CMN_FIELD_TAP_21_1, CMN_FIELD_TAP_21_2, CMN_FIELD_TAP_22_1, CMN_FIELD_TAP_23_1, CMN_FIELD_TAP_23_2, CMN_FIELD_TAP_30_1, CMN_FIELD_TAP_31_1, CMN_FIELD_TAP_31_2, CMN_FIELD_TAP_32_1, CMN_FIELD_TAP_33_1, CMN_FIELD_TAP_33_2, CMN_FIELD_TAP_34_1, CMN_FIELD_TAP_41_1, CMN_FIELD_TAP_42_1, CMN_FIELD_TAP_43_1, CMN_FIELD_TAP_51_1, CMN_FIELD_TAP_52_1, CMN_FIELD_TAP_61_1, CMN_FIELD_TAP_61_2, CMN_FIELD_TAP_62_1, CMN_FIELD_TAP_71_1, CMN_FIELD_TAP_72_1, CMN_FIELD_TAP_74_1, CMN_FIELD_TAP_76_1, CMN_FIELD_TAP_1001_1, CMN_FIELD_TAP_1002_1, CMN_FIELD_TAP_1003_1, CMN_FIELD_TAP_1004_1, CMN_FIELD_TAP_1005_1, CMN_FIELD_TAP_1006_1, CMN_FIELD_TAP_1007_1, CMN_FIELD_TAP_1007_2, CMN_FIELD_TAP_1008_1, CMN_FIELD_TAP_1009_1, CMN_FIELD_TAP_1010_1, CMN_FIELD_TAP_1011_1, CMN_FIELD_TAP_1012_1, CMN_TUTORIAL_TAP_1, CMN_CRAFT_CARD_1, CMN_CRAFT_CARD_2, CMN_CRAFT_ICON_1, CMN_CRAFT_TRACK_1, CMN_CRAFT_SPLASH_1, CMN_CRAFT_SPLASH_2, CMN_CRAFT_SPLASH_3, CMN_CRAFT_SPLASH_4, CMN_MAP_CHAPTER_1, CMN_MAP_MAPICON_CLEARED, CMN_MAP_MAPICON_NOTCLEARED, CMN_MAP_PLAYERICON, }
public static System.Collections.IEnumerator LoadAndInstantiate2dEffectCoroutine(string effectName, System.Action<UnityEngine.GameObject, System.Collections.Generic.List<string>> finishCallback) { yield break; }
public enum MoveType
{
NONE, SKIP, DIRECT, DIRECT_HAND, DIRECT_DECK, DIRECT_LEADER, CENTER }
public enum TargetType { NONE, NONE_WAIT, SINGLE, SINGLE_ONLY_OPPONENT, AREA_ALL, AREA_OPPONENT, AREA_SELF }
public enum EngineType { NONE, SHURIKEN}
public bool IsFieldEffectReady => true;
public bool IsBattleUIEffectReady => true;
public Effect Start(EffectType type, Vector3 pos, Quaternion rot, int layer = -1) => null;
public Effect Start(EffectType type, Vector3 pos, GameObject obj = null) => null;
public Effect Start(EffectType type, float posX, float posY) => null;
public Effect Start(EffectType type) => null;
public Effect StartBuff(EffectType type, GameObject obj) => null;
public Effect StopBuff(EffectType type, GameObject obj) => null;
public Effect Stop(EffectType type) => null;
public List<string> InitCommonEffect(string filePath, bool isBattle = false, bool isField = false, bool isBattleEffect = false, Action callback = null) => new List<string>();
public List<string> SetUIParticleShader(List<GameObject> effectObjList, Action callback, bool isBattle = false, bool isField = false) => new List<string>();
public List<string> SetUIParticleShader(GameObject effectObj, Action callback, bool isBattle = false, bool isField = false) => new List<string>();
public void ChangeMaskShader(GameObject effectObj, int stencil = 1) { }
public void DisposeLatestMadeEffects() { }
public void ClearLastCacheEffect() { }
public void DestroyBattleEffectContainer() { }
public void ImmediateDestroyBattleEffectContainer() { }
public void ClearBattleFeildEffect() { }
public void RestUnneededEffect() { }
public EffectBattle GetEffectBattle(string key) => null;
public EffectBattle GetEnemyEffectBattle(string key) => null;
public static MoveType ToStrMoveType(string str) => MoveType.NONE;
public static EngineType ToStrEngineType(string str) => EngineType.NONE;
public static TargetType ToStrTargetType(string str) => TargetType.NONE;
}
public partial class GameObjMgr { public GameObjMgr() { } }
public class GameMgr
{
// Phase-5 chunk 47: the ambient is gone. GameMgr.GetIns() has no scope-based mechanism —
// BattleManagerBase.GetIns() returns null unconditionally, and every direct engine consumer
// was migrated to per-mgr reads through the mgr's own `.GameMgr` property. The residual
// static throws to catch any straggler that still calls it; MultiInstanceEngineTests pins
// the null-null-throw shape.
public static GameMgr GetIns() =>
throw new System.InvalidOperationException(
"GameMgr.GetIns() is retired. Read via `mgr.GameMgr` on a BattleManagerBase instance.");
public GameObject m_GameManagerObj;
public float ScreenAspect = 1.777f;
public DateTime AnnounceTime;
// Six mode flags collapsed to const-false getters in Phase 4 (2026-07-02): headless
// is neither watching, replaying, admin-watching, an AI-network client, a puzzle
// quest, nor a "new replay" — every branch guarded on `!IsWatchBattle` etc. was a
// tautology, and every branch guarded on the positive was dead code. Setters
// dropped: pre-Phase-4 callers wrote `false` at end-of-battle cleanup which is now
// unnecessary.
public bool IsAdminWatch => false;
public bool IsWatchBattle => false;
public bool IsReplayBattle => false;
public bool IsAINetwork => false;
public bool IsPuzzleQuest => false;
public bool IsNewReplayBattle => false;
public bool IsAdmin => false;
// IsNetworkBattle stays writable — headless PvP battles set true; SingleBattleMgr paths stay false.
public bool IsNetworkBattle { get; set; }
private EffectMgr _effect;
private DataMgr _data;
private GameObjMgr _gameObj = new GameObjMgr();
private PrefabMgr _prefab;
private InputMgr _input;
private BattleControl _battleCtrl;
private NetworkUserInfoData _netUser;
public EffectMgr GetEffectMgr() => _effect ??= new EffectMgr();
// Headless: hand back non-null no-op instances. The copied manager types are pure
// data/dictionary/no-op holders (no Unity in their ctors); the resolution-path ctor
// dereferences these immediately (CreateBackgroundId / CreateManager / UnityEventAgent wiring).
public DataMgr GetDataMgr() => _data ??= new DataMgr();
public GameObjMgr GetGameObjMgr() => _gameObj;
public PrefabMgr GetPrefabMgr() => _prefab ??= new PrefabMgr();
public InputMgr GetInputMgr() => _input ??= new InputMgr();
public BattleControl GetBattleCtrl() => _battleCtrl ??= new BattleControl();
public NetworkUserInfoData GetNetworkUserInfoData() => _netUser;
public void SetNetworkUserInfoData(NetworkUserInfoData infoData) => _netUser = infoData;
public Wizard.MailTopTask GetMailTopTask() => null;
public Wizard.DeckUpdateTask GetDeckUpdateTask() => null;
public Wizard.CardDestructTask GetCardDestructTask() => null;
public Wizard.CardCreateTask GetCardCreateTask() => null;
public Wizard.MissionInfoTask GetMissionInfoTask() => null;
public void DestroyBattleManagements() { }
public bool IsUseUnapprovedList(bool isPlayer) => false;
}
// UIManager surface (members, ViewScene enum, ChangeViewSceneParam) is generated from
// decomp into Shim/Generated/UIManager*.g.cs. This partial keeps only the singleton +
// MonoBehaviour base (gameObject/transform/StartCoroutine/StopCoroutine come from the base).
public partial class UIManager : UnityEngine.MonoBehaviour
{
private static UIManager _ins;
public static UIManager GetInstance() => _ins ??= new UIManager();
}
// VideoHostingHUD (members + HUDMode enum) provided by Generated/VideoHostingHUD.g.cs
namespace Wizard
{
// RankWinnerReward, CardDestructTask, CardCreateTask, MissionInfoTask already exist
// in the copied set (declared in other files) -- only these three were missing.
public partial class MailTopTask { }
public partial class DeckUpdateTask { }
// UIManager no-op return types (empty stubs; methods returning them return null)
public partial class LoadingViewManager { }
public partial class AccountTransferHelper { }
public class DialogManager { public DialogBase CreateDialogBaseOpenCardDetail(CardDetailUI detailUI) => default!; }
public partial class ApplicationFinishManager { }
}