Files
SVSimServer/SVSim.BattleEngine/Engine/UISprite.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

382 lines
8.4 KiB
C#

using System;
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("NGUI/UI/NGUI Sprite")]
public class UISprite : UIBasicSprite
{
[HideInInspector]
[SerializeField]
private UIAtlas mAtlas;
[HideInInspector]
[SerializeField]
private string mSpriteName;
[HideInInspector]
[SerializeField]
private bool mFillCenter = true;
[NonSerialized]
protected UISpriteData mSprite;
[NonSerialized]
private bool mSpriteSet;
public override Material material
{
get
{
if (!(mAtlas != null))
{
return null;
}
return mAtlas.spriteMaterial;
}
}
public UIAtlas atlas
{
get
{
return mAtlas;
}
set
{
if (mAtlas != value)
{
RemoveFromPanel();
mAtlas = value;
mSpriteSet = false;
mSprite = null;
if (string.IsNullOrEmpty(mSpriteName) && mAtlas != null && mAtlas.spriteList.Count > 0)
{
SetAtlasSprite(mAtlas.spriteList[0]);
mSpriteName = mSprite.name;
}
if (!string.IsNullOrEmpty(mSpriteName))
{
string text = mSpriteName;
mSpriteName = "";
spriteName = text;
MarkAsChanged();
}
}
}
}
public string spriteName
{
get
{
return mSpriteName;
}
set
{
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(mSpriteName))
{
mSpriteName = "";
mSprite = null;
mChanged = true;
mSpriteSet = false;
}
}
else if (mSpriteName != value)
{
mSpriteName = value;
mSprite = null;
mChanged = true;
mSpriteSet = false;
}
}
}
public bool isValid => GetAtlasSprite() != null;
public override Vector4 border
{
get
{
UISpriteData atlasSprite = GetAtlasSprite();
if (atlasSprite == null)
{
return base.border;
}
return new Vector4(atlasSprite.borderLeft, atlasSprite.borderBottom, atlasSprite.borderRight, atlasSprite.borderTop);
}
}
public override float pixelSize
{
get
{
if (!(mAtlas != null))
{
return 1f;
}
return mAtlas.pixelSize;
}
}
public override int minWidth
{
get
{
if (type == Type.Sliced || type == Type.Advanced)
{
float num = pixelSize;
Vector4 vector = border * pixelSize;
int num2 = Mathf.RoundToInt(vector.x + vector.z);
UISpriteData atlasSprite = GetAtlasSprite();
if (atlasSprite != null)
{
num2 += Mathf.RoundToInt(num * (float)(atlasSprite.paddingLeft + atlasSprite.paddingRight));
}
return Mathf.Max(base.minWidth, ((num2 & 1) == 1) ? (num2 + 1) : num2);
}
return base.minWidth;
}
}
public override int minHeight
{
get
{
if (type == Type.Sliced || type == Type.Advanced)
{
float num = pixelSize;
Vector4 vector = border * pixelSize;
int num2 = Mathf.RoundToInt(vector.y + vector.w);
UISpriteData atlasSprite = GetAtlasSprite();
if (atlasSprite != null)
{
num2 += Mathf.RoundToInt(num * (float)(atlasSprite.paddingTop + atlasSprite.paddingBottom));
}
return Mathf.Max(base.minHeight, ((num2 & 1) == 1) ? (num2 + 1) : num2);
}
return base.minHeight;
}
}
public override Vector4 drawingDimensions
{
get
{
Vector2 vector = base.pivotOffset;
float num = (0f - vector.x) * (float)mWidth;
float num2 = (0f - vector.y) * (float)mHeight;
float num3 = num + (float)mWidth;
float num4 = num2 + (float)mHeight;
if (GetAtlasSprite() != null && mType != Type.Tiled)
{
int num5 = mSprite.paddingLeft;
int num6 = mSprite.paddingBottom;
int num7 = mSprite.paddingRight;
int num8 = mSprite.paddingTop;
if (mType != Type.Simple)
{
float num9 = pixelSize;
if (num9 != 1f)
{
num5 = Mathf.RoundToInt(num9 * (float)num5);
num6 = Mathf.RoundToInt(num9 * (float)num6);
num7 = Mathf.RoundToInt(num9 * (float)num7);
num8 = Mathf.RoundToInt(num9 * (float)num8);
}
}
int num10 = mSprite.width + num5 + num7;
int num11 = mSprite.height + num6 + num8;
float num12 = 1f;
float num13 = 1f;
if (num10 > 0 && num11 > 0 && (mType == Type.Simple || mType == Type.Filled))
{
if ((num10 & 1) != 0)
{
num7++;
}
if ((num11 & 1) != 0)
{
num8++;
}
num12 = 1f / (float)num10 * (float)mWidth;
num13 = 1f / (float)num11 * (float)mHeight;
}
if (mFlip == Flip.Horizontally || mFlip == Flip.Both)
{
num += (float)num7 * num12;
num3 -= (float)num5 * num12;
}
else
{
num += (float)num5 * num12;
num3 -= (float)num7 * num12;
}
if (mFlip == Flip.Vertically || mFlip == Flip.Both)
{
num2 += (float)num8 * num13;
num4 -= (float)num6 * num13;
}
else
{
num2 += (float)num6 * num13;
num4 -= (float)num8 * num13;
}
}
Vector4 vector2 = ((mAtlas != null) ? (border * pixelSize) : Vector4.zero);
float num14 = vector2.x + vector2.z;
float num15 = vector2.y + vector2.w;
float x = Mathf.Lerp(num, num3 - num14, mDrawRegion.x);
float y = Mathf.Lerp(num2, num4 - num15, mDrawRegion.y);
float z = Mathf.Lerp(num + num14, num3, mDrawRegion.z);
float w = Mathf.Lerp(num2 + num15, num4, mDrawRegion.w);
return new Vector4(x, y, z, w);
}
}
public override bool premultipliedAlpha
{
get
{
if (mAtlas != null)
{
return mAtlas.premultipliedAlpha;
}
return false;
}
}
public UISpriteData GetAtlasSprite()
{
if (!mSpriteSet)
{
mSprite = null;
}
if (mSprite == null && mAtlas != null)
{
if (!string.IsNullOrEmpty(mSpriteName))
{
UISpriteData sprite = mAtlas.GetSprite(mSpriteName);
if (sprite == null)
{
return null;
}
SetAtlasSprite(sprite);
}
if (mSprite == null && mAtlas.spriteList.Count > 0)
{
UISpriteData uISpriteData = mAtlas.spriteList[0];
if (uISpriteData == null)
{
return null;
}
SetAtlasSprite(uISpriteData);
if (mSprite == null)
{
Debug.LogError(mAtlas.name + " seems to have a null sprite!");
return null;
}
mSpriteName = mSprite.name;
}
}
return mSprite;
}
protected void SetAtlasSprite(UISpriteData sp)
{
mChanged = true;
mSpriteSet = true;
if (sp != null)
{
mSprite = sp;
mSpriteName = mSprite.name;
}
else
{
mSpriteName = ((mSprite != null) ? mSprite.name : "");
mSprite = sp;
}
}
public override void MakePixelPerfect()
{
if (!isValid)
{
return;
}
base.MakePixelPerfect();
if (mType == Type.Tiled)
{
return;
}
UISpriteData atlasSprite = GetAtlasSprite();
if (atlasSprite == null)
{
return;
}
Texture texture = mainTexture;
if (!(texture == null) && (mType == Type.Simple || mType == Type.Filled || !atlasSprite.hasBorder) && texture != null)
{
int num = Mathf.RoundToInt(pixelSize * (float)(atlasSprite.width + atlasSprite.paddingLeft + atlasSprite.paddingRight));
int num2 = Mathf.RoundToInt(pixelSize * (float)(atlasSprite.height + atlasSprite.paddingTop + atlasSprite.paddingBottom));
if ((num & 1) == 1)
{
num++;
}
if ((num2 & 1) == 1)
{
num2++;
}
base.width = num;
base.height = num2;
}
}
protected override void OnInit()
{
if (!mFillCenter)
{
mFillCenter = true;
centerType = AdvancedType.Invisible;
}
base.OnInit();
}
protected override void OnUpdate()
{
base.OnUpdate();
if (mChanged || !mSpriteSet)
{
mSpriteSet = true;
mSprite = null;
mChanged = true;
}
}
public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
if (mainTexture == null)
{
return;
}
if (mSprite == null)
{
mSprite = atlas.GetSprite(spriteName);
}
if (mSprite != null)
{
Rect rect = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height);
Rect rect2 = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop, mSprite.width - mSprite.borderLeft - mSprite.borderRight, mSprite.height - mSprite.borderBottom - mSprite.borderTop);
rect = NGUIMath.ConvertToTexCoords(rect, atlas.atlasWidth, atlas.atlasHeight);
rect2 = NGUIMath.ConvertToTexCoords(rect2, atlas.atlasWidth, atlas.atlasHeight);
int size = verts.size;
Fill(verts, uvs, cols, rect, rect2);
if (onPostFill != null)
{
onPostFill(this, size, verts, uvs, cols);
}
}
}
}