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

@@ -95,8 +95,6 @@ public static class NGUIText
public static bool useSymbols = false;
private static Color mInvisible = new Color(0f, 0f, 0f, 0f);
private static BetterList<Color> mColors = new BetterList<Color>();
private static float mAlpha = 1f;
@@ -105,12 +103,6 @@ public static class NGUIText
private static BetterList<float> mSizes = new BetterList<float>();
private static Color32 s_c0;
private static Color32 s_c1;
private static float[] mBoldOffset = new float[8] { -0.25f, 0f, 0.25f, 0f, 0f, -0.25f, 0f, 0.25f };
public static void Update(UIWidget.Pivot piv)
{
Update(request: true, piv);
@@ -288,20 +280,6 @@ public static class NGUIText
return glyph;
}
[DebuggerHidden]
[DebuggerStepThrough]
public static float ParseAlpha(string text, int index)
{
return Mathf.Clamp01((float)((NGUIMath.HexToDecimal(text[index + 1]) << 4) | NGUIMath.HexToDecimal(text[index + 2])) / 255f);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static Color ParseColor(string text, int offset)
{
return ParseColor24(text, offset);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static Color ParseColor24(string text, int offset)
@@ -332,20 +310,6 @@ public static class NGUIText
return EncodeColor24(c);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeColor(string text, Color c)
{
return "[c][" + EncodeColor24(c) + "]" + text + "[-][/c]";
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeAlpha(float a)
{
return NGUIMath.DecimalToHex8(Mathf.Clamp(Mathf.RoundToInt(a * 255f), 0, 255));
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeColor24(Color c)
@@ -386,184 +350,6 @@ public static class NGUIText
return true;
}
public static bool ParseSymbol(string text, ref int index, BetterList<Color> colors, bool premultiply, ref int sub, ref bool bold, ref bool italic, ref bool underline, ref bool strike, ref bool ignoreColor)
{
int length = text.Length;
if (index + 3 > length || text[index] != '[')
{
return false;
}
if (text[index + 2] == ']')
{
if (text[index + 1] == '-')
{
if (colors != null && colors.size > 1)
{
colors.RemoveAt(colors.size - 1);
}
index += 3;
return true;
}
switch (text.Substring(index, 3))
{
case "[b]":
bold = true;
index += 3;
return true;
case "[i]":
italic = true;
index += 3;
return true;
case "[u]":
underline = true;
index += 3;
return true;
case "[s]":
strike = true;
index += 3;
return true;
case "[c]":
ignoreColor = true;
index += 3;
return true;
}
}
if (index + 4 > length)
{
return false;
}
if (text[index + 3] == ']')
{
switch (text.Substring(index, 4))
{
case "[/b]":
bold = false;
index += 4;
return true;
case "[/i]":
italic = false;
index += 4;
return true;
case "[/u]":
underline = false;
index += 4;
return true;
case "[/s]":
strike = false;
index += 4;
return true;
case "[/c]":
ignoreColor = false;
index += 4;
return true;
}
char ch = text[index + 1];
char ch2 = text[index + 2];
if (IsHex(ch) && IsHex(ch2))
{
mAlpha = (float)((NGUIMath.HexToDecimal(ch) << 4) | NGUIMath.HexToDecimal(ch2)) / 255f;
index += 4;
return true;
}
}
if (index + 5 > length)
{
return false;
}
if (text[index + 4] == ']')
{
switch (text.Substring(index, 5))
{
case "[sub]":
sub = 1;
index += 5;
return true;
case "[sup]":
sub = 2;
index += 5;
return true;
}
}
if (index + 6 > length)
{
return false;
}
if (text[index + 5] == ']')
{
switch (text.Substring(index, 6))
{
case "[/sub]":
sub = 0;
index += 6;
return true;
case "[/sup]":
sub = 0;
index += 6;
return true;
case "[/url]":
index += 6;
return true;
}
}
if (text[index + 1] == 'u' && text[index + 2] == 'r' && text[index + 3] == 'l' && text[index + 4] == '=')
{
int num = text.IndexOf(']', index + 4);
if (num != -1)
{
index = num + 1;
return true;
}
index = text.Length;
return true;
}
if (index + 8 > length)
{
return false;
}
if (text[index + 7] == ']')
{
Color color = ParseColor24(text, index + 1);
if (EncodeColor24(color) != text.Substring(index + 1, 6).ToUpper())
{
return false;
}
if (colors != null)
{
color.a = colors[colors.size - 1].a;
if (premultiply && color.a != 1f)
{
color = Color.Lerp(mInvisible, color, color.a);
}
colors.Add(color);
}
index += 8;
return true;
}
if (index + 10 > length)
{
return false;
}
if (text[index + 9] == ']')
{
Color color2 = ParseColor32(text, index + 1);
if (EncodeColor32(color2) != text.Substring(index + 1, 8).ToUpper())
{
return false;
}
if (colors != null)
{
if (premultiply && color2.a != 1f)
{
color2 = Color.Lerp(mInvisible, color2, color2.a);
}
colors.Add(color2);
}
index += 10;
return true;
}
return false;
}
public static string StripSymbols(string text)
{
if (text != null)
@@ -738,36 +524,6 @@ public static class NGUIText
return indices[i];
}
public static int GetNearCharacterIndex(BetterList<Vector3> verts, BetterList<int> indices, Vector2 pos, List<int[]> rangeList)
{
int i = 0;
float num = float.MaxValue;
bool flag = false;
for (int j = 0; j < verts.size; j++)
{
flag = false;
for (int k = 0; k < rangeList.Count; k++)
{
if (rangeList[k][0] <= indices[j] && rangeList[k][1] >= indices[j])
{
flag = true;
break;
}
}
if (flag)
{
Vector2 vector = new Vector2(verts[j].x, verts[j].y);
float sqrMagnitude = (pos - vector).sqrMagnitude;
if (sqrMagnitude < num)
{
num = sqrMagnitude;
i = j;
}
}
}
return indices[i];
}
[DebuggerHidden]
[DebuggerStepThrough]
private static bool IsSpace(int ch)
@@ -937,13 +693,6 @@ public static class NGUIText
return num4;
}
public static string GetEndOfLineThatFits(string text)
{
int length = text.Length;
int num = CalculateOffsetToFit(text);
return text.Substring(num, length - num);
}
public static bool WrapText(string text, out string finalText, bool wrapLineColors = false)
{
return WrapText(text, out finalText, keepCharCount: false, wrapLineColors);
@@ -1257,433 +1006,6 @@ public static class NGUIText
return false;
}
public static void Print(string text, BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
if (string.IsNullOrEmpty(text))
{
return;
}
int size = verts.size;
Prepare(text);
mColors.Add(Color.white);
mAlpha = 1f;
int num = 0;
int prev = 0;
float num2 = 0f;
float num3 = 0f;
float num4 = 0f;
float num5 = finalSize;
Color a = tint * gradientBottom;
Color b = tint * gradientTop;
Color32 color = tint;
int length = text.Length;
Rect rect = default(Rect);
float num6 = 0f;
float num7 = 0f;
float num8 = num5 * pixelDensity;
bool flag = false;
int sub = 0;
bool bold = false;
bool italic = false;
bool underline = false;
bool strike = false;
bool ignoreColor = false;
float num9 = 0f;
if (bitmapFont != null)
{
rect = bitmapFont.uvRect;
num6 = rect.width / (float)bitmapFont.texWidth;
num7 = rect.height / (float)bitmapFont.texHeight;
}
for (int i = 0; i < length; i++)
{
num = text[i];
num9 = num2;
if (num == 10)
{
if (num2 > num4)
{
num4 = num2;
}
if (alignment != Alignment.Left)
{
Align(verts, size, num2 - finalSpacingX);
size = verts.size;
}
num2 = 0f;
num3 += finalLineHeight;
prev = 0;
continue;
}
if (num < 32)
{
prev = num;
continue;
}
if (encoding && RubyText.ParseSymbol(text, ref i, mColors, premultiply, ref sub, ref bold, ref italic, ref underline, ref strike, ref ignoreColor))
{
Color color2;
if (ignoreColor)
{
color2 = mColors[mColors.size - 1];
color2.a *= mAlpha * tint.a;
}
else
{
color2 = tint * mColors[mColors.size - 1];
color2.a *= mAlpha;
}
color = color2;
int j = 0;
for (int num10 = mColors.size - 2; j < num10; j++)
{
color2.a *= mColors[j].a;
}
if (gradient)
{
a = gradientBottom * color2;
b = gradientTop * color2;
}
i--;
continue;
}
BMSymbol bMSymbol = (useSymbols ? GetSymbol(text, i, length) : null);
float num11;
float num12;
float num14;
float num13;
if (bMSymbol != null)
{
num11 = num2 + (float)bMSymbol.offsetX * fontScale;
num12 = num11 + (float)bMSymbol.width * fontScale;
num13 = 0f - (num3 + (float)bMSymbol.offsetY * fontScale);
num14 = num13 - (float)bMSymbol.height * fontScale;
if (Mathf.RoundToInt(num2 + (float)bMSymbol.advance * fontScale) > regionWidth)
{
if (num2 == 0f)
{
return;
}
if (alignment != Alignment.Left && size < verts.size)
{
Align(verts, size, num2 - finalSpacingX);
size = verts.size;
}
num11 -= num2;
num12 -= num2;
num14 -= finalLineHeight;
num13 -= finalLineHeight;
num2 = 0f;
num3 += finalLineHeight;
num9 = 0f;
}
verts.Add(new Vector3(num11, num14));
verts.Add(new Vector3(num11, num13));
verts.Add(new Vector3(num12, num13));
verts.Add(new Vector3(num12, num14));
num2 += finalSpacingX + (float)bMSymbol.advance * fontScale;
i += bMSymbol.length - 1;
prev = 0;
if (uvs != null)
{
Rect uvRect = bMSymbol.uvRect;
float xMin = uvRect.xMin;
float yMin = uvRect.yMin;
float xMax = uvRect.xMax;
float yMax = uvRect.yMax;
uvs.Add(new Vector2(xMin, yMin));
uvs.Add(new Vector2(xMin, yMax));
uvs.Add(new Vector2(xMax, yMax));
uvs.Add(new Vector2(xMax, yMin));
}
if (cols == null)
{
continue;
}
if (symbolStyle == SymbolStyle.Colored)
{
for (int k = 0; k < 4; k++)
{
cols.Add(color);
}
continue;
}
Color32 item = Color.white;
item.a = color.a;
for (int l = 0; l < 4; l++)
{
cols.Add(item);
}
continue;
}
GlyphInfo glyphInfo = GetGlyph(num, prev);
if (glyphInfo == null)
{
continue;
}
prev = num;
if (sub != 0)
{
glyphInfo.v0.x *= 0.75f;
glyphInfo.v0.y *= 0.75f;
glyphInfo.v1.x *= 0.75f;
glyphInfo.v1.y *= 0.75f;
if (sub == 1)
{
glyphInfo.v0.y -= fontScale * (float)fontSize * 0.4f;
glyphInfo.v1.y -= fontScale * (float)fontSize * 0.4f;
}
else
{
glyphInfo.v0.y += fontScale * (float)fontSize * 0.05f;
glyphInfo.v1.y += fontScale * (float)fontSize * 0.05f;
}
}
num11 = glyphInfo.v0.x + num2;
num14 = glyphInfo.v0.y - num3;
num12 = glyphInfo.v1.x + num2;
num13 = glyphInfo.v1.y - num3;
float num15 = glyphInfo.advance;
if (finalSpacingX < 0f)
{
num15 += finalSpacingX;
}
if (Mathf.RoundToInt(num2 + num15) > regionWidth)
{
if (num2 == 0f)
{
return;
}
if (alignment != Alignment.Left && size < verts.size)
{
Align(verts, size, num2 - finalSpacingX);
size = verts.size;
}
num11 -= num2;
num12 -= num2;
num14 -= finalLineHeight;
num13 -= finalLineHeight;
num2 = 0f;
num3 += finalLineHeight;
num9 = 0f;
}
if (IsSpace(num))
{
if (underline)
{
num = 95;
}
else if (strike)
{
num = 45;
}
}
num2 += ((sub == 0) ? (finalSpacingX + glyphInfo.advance) : ((finalSpacingX + glyphInfo.advance) * 0.75f));
if (IsSpace(num))
{
continue;
}
if (uvs != null)
{
if (bitmapFont != null)
{
glyphInfo.u0.x = rect.xMin + num6 * glyphInfo.u0.x;
glyphInfo.u2.x = rect.xMin + num6 * glyphInfo.u2.x;
glyphInfo.u0.y = rect.yMax - num7 * glyphInfo.u0.y;
glyphInfo.u2.y = rect.yMax - num7 * glyphInfo.u2.y;
glyphInfo.u1.x = glyphInfo.u0.x;
glyphInfo.u1.y = glyphInfo.u2.y;
glyphInfo.u3.x = glyphInfo.u2.x;
glyphInfo.u3.y = glyphInfo.u0.y;
}
int m = 0;
for (int num16 = ((!bold) ? 1 : 4); m < num16; m++)
{
uvs.Add(glyphInfo.u0);
uvs.Add(glyphInfo.u1);
uvs.Add(glyphInfo.u2);
uvs.Add(glyphInfo.u3);
}
}
if (cols != null)
{
if (glyphInfo.channel == 0 || glyphInfo.channel == 15)
{
if (gradient)
{
float num17 = num8 + glyphInfo.v0.y / fontScale;
float num18 = num8 + glyphInfo.v1.y / fontScale;
num17 /= num8;
num18 /= num8;
s_c0 = Color.Lerp(a, b, num17);
s_c1 = Color.Lerp(a, b, num18);
int n = 0;
for (int num19 = ((!bold) ? 1 : 4); n < num19; n++)
{
cols.Add(s_c0);
cols.Add(s_c1);
cols.Add(s_c1);
cols.Add(s_c0);
}
}
else
{
int num20 = 0;
for (int num21 = (bold ? 16 : 4); num20 < num21; num20++)
{
cols.Add(color);
}
}
}
else
{
Color color3 = color;
color3 *= 0.49f;
switch (glyphInfo.channel)
{
case 1:
color3.b += 0.51f;
break;
case 2:
color3.g += 0.51f;
break;
case 4:
color3.r += 0.51f;
break;
case 8:
color3.a += 0.51f;
break;
}
Color32 item2 = color3;
int num22 = 0;
for (int num23 = (bold ? 16 : 4); num22 < num23; num22++)
{
cols.Add(item2);
}
}
}
if (!bold)
{
if (!italic)
{
verts.Add(new Vector3(num11, num14));
verts.Add(new Vector3(num11, num13));
verts.Add(new Vector3(num12, num13));
verts.Add(new Vector3(num12, num14));
}
else
{
float num24 = (float)fontSize * 0.1f * ((num13 - num14) / (float)fontSize);
verts.Add(new Vector3(num11 - num24, num14));
verts.Add(new Vector3(num11 + num24, num13));
verts.Add(new Vector3(num12 + num24, num13));
verts.Add(new Vector3(num12 - num24, num14));
}
}
else
{
for (int num25 = 0; num25 < 4; num25++)
{
float num26 = mBoldOffset[num25 * 2];
float num27 = mBoldOffset[num25 * 2 + 1];
float num28 = (italic ? ((float)fontSize * 0.1f * ((num13 - num14) / (float)fontSize)) : 0f);
verts.Add(new Vector3(num11 + num26 - num28, num14 + num27));
verts.Add(new Vector3(num11 + num26 + num28, num13 + num27));
verts.Add(new Vector3(num12 + num26 + num28, num13 + num27));
verts.Add(new Vector3(num12 + num26 - num28, num14 + num27));
}
}
if (!(underline || strike))
{
continue;
}
GlyphInfo glyphInfo2 = GetGlyph(strike ? 45 : 95, prev);
if (glyphInfo2 == null)
{
continue;
}
if (uvs != null)
{
if (bitmapFont != null)
{
glyphInfo2.u0.x = rect.xMin + num6 * glyphInfo2.u0.x;
glyphInfo2.u2.x = rect.xMin + num6 * glyphInfo2.u2.x;
glyphInfo2.u0.y = rect.yMax - num7 * glyphInfo2.u0.y;
glyphInfo2.u2.y = rect.yMax - num7 * glyphInfo2.u2.y;
}
float x = (glyphInfo2.u0.x + glyphInfo2.u2.x) * 0.5f;
int num29 = 0;
for (int num30 = ((!bold) ? 1 : 4); num29 < num30; num29++)
{
uvs.Add(new Vector2(x, glyphInfo2.u0.y));
uvs.Add(new Vector2(x, glyphInfo2.u2.y));
uvs.Add(new Vector2(x, glyphInfo2.u2.y));
uvs.Add(new Vector2(x, glyphInfo2.u0.y));
}
}
if (flag && strike)
{
num14 = (0f - num3 + glyphInfo2.v0.y) * 0.75f;
num13 = (0f - num3 + glyphInfo2.v1.y) * 0.75f;
}
else
{
num14 = 0f - num3 + glyphInfo2.v0.y;
num13 = 0f - num3 + glyphInfo2.v1.y;
}
if (bold)
{
for (int num31 = 0; num31 < 4; num31++)
{
float num32 = mBoldOffset[num31 * 2];
float num33 = mBoldOffset[num31 * 2 + 1];
verts.Add(new Vector3(num9 + num32, num14 + num33));
verts.Add(new Vector3(num9 + num32, num13 + num33));
verts.Add(new Vector3(num2 + num32, num13 + num33));
verts.Add(new Vector3(num2 + num32, num14 + num33));
}
}
else
{
verts.Add(new Vector3(num9, num14));
verts.Add(new Vector3(num9, num13));
verts.Add(new Vector3(num2, num13));
verts.Add(new Vector3(num2, num14));
}
if (gradient)
{
float num34 = num8 + glyphInfo2.v0.y / fontScale;
float num35 = num8 + glyphInfo2.v1.y / fontScale;
num34 /= num8;
num35 /= num8;
s_c0 = Color.Lerp(a, b, num34);
s_c1 = Color.Lerp(a, b, num35);
int num36 = 0;
for (int num37 = ((!bold) ? 1 : 4); num36 < num37; num36++)
{
cols.Add(s_c0);
cols.Add(s_c1);
cols.Add(s_c1);
cols.Add(s_c0);
}
}
else
{
int num38 = 0;
for (int num39 = (bold ? 16 : 4); num38 < num39; num38++)
{
cols.Add(color);
}
}
}
if (alignment != Alignment.Left && size < verts.size)
{
Align(verts, size, num2 - finalSpacingX);
size = verts.size;
}
mColors.Clear();
}
public static void PrintApproximateCharacterPositions(string text, BetterList<Vector3> verts, BetterList<int> indices)
{
if (string.IsNullOrEmpty(text))