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

309 lines
6.1 KiB
C#

using System;
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("NGUI/UI/NGUI Texture")]
public class UITexture : UIBasicSprite
{
[HideInInspector]
[SerializeField]
private Rect mRect = new Rect(0f, 0f, 1f, 1f);
[HideInInspector]
[SerializeField]
private Texture mTexture;
[HideInInspector]
[SerializeField]
private Material mMat;
[HideInInspector]
[SerializeField]
private Shader mShader;
[HideInInspector]
[SerializeField]
private Vector4 mBorder = Vector4.zero;
[HideInInspector]
[SerializeField]
private bool mFixedAspect;
[NonSerialized]
private int mPMA = -1;
public override Texture mainTexture
{
get
{
if (mTexture != null)
{
return mTexture;
}
if (mMat != null)
{
return mMat.mainTexture;
}
return null;
}
set
{
if (mTexture != value)
{
if (drawCall != null && drawCall.widgetCount == 1 && mMat == null)
{
mTexture = value;
drawCall.mainTexture = value;
return;
}
RemoveFromPanel();
mTexture = value;
mPMA = -1;
MarkAsChanged();
}
}
}
public override Material material
{
get
{
return mMat;
}
set
{
if (mMat != value)
{
RemoveFromPanel();
mShader = null;
mMat = value;
mPMA = -1;
MarkAsChanged();
}
}
}
public override Shader shader
{
get
{
if (mMat != null)
{
return mMat.shader;
}
if (mShader == null)
{
mShader = Shader.Find("Unlit/Transparent Colored");
}
return mShader;
}
set
{
if (mShader != value)
{
if (drawCall != null && drawCall.widgetCount == 1 && mMat == null)
{
mShader = value;
drawCall.shader = value;
return;
}
RemoveFromPanel();
mShader = value;
mPMA = -1;
mMat = null;
MarkAsChanged();
}
}
}
public override bool premultipliedAlpha
{
get
{
if (mPMA == -1)
{
Material material = this.material;
mPMA = ((material != null && material.shader != null && material.shader.name.Contains("Premultiplied")) ? 1 : 0);
}
return mPMA == 1;
}
}
public override Vector4 border
{
get
{
return mBorder;
}
set
{
if (mBorder != value)
{
mBorder = value;
MarkAsChanged();
}
}
}
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 (mTexture != null && mType != Type.Tiled)
{
int num5 = mTexture.width;
int num6 = mTexture.height;
int num7 = 0;
int num8 = 0;
float num9 = 1f;
float num10 = 1f;
if (num5 > 0 && num6 > 0 && (mType == Type.Simple || mType == Type.Filled))
{
if ((num5 & 1) != 0)
{
num7++;
}
if ((num6 & 1) != 0)
{
num8++;
}
num9 = 1f / (float)num5 * (float)mWidth;
num10 = 1f / (float)num6 * (float)mHeight;
}
if (mFlip == Flip.Horizontally || mFlip == Flip.Both)
{
num += (float)num7 * num9;
}
else
{
num3 -= (float)num7 * num9;
}
if (mFlip == Flip.Vertically || mFlip == Flip.Both)
{
num2 += (float)num8 * num10;
}
else
{
num4 -= (float)num8 * num10;
}
}
float num11;
float num12;
if (mFixedAspect)
{
num11 = 0f;
num12 = 0f;
}
else
{
Vector4 vector2 = border;
num11 = vector2.x + vector2.z;
num12 = vector2.y + vector2.w;
}
float x = Mathf.Lerp(num, num3 - num11, mDrawRegion.x);
float y = Mathf.Lerp(num2, num4 - num12, mDrawRegion.y);
float z = Mathf.Lerp(num + num11, num3, mDrawRegion.z);
float w = Mathf.Lerp(num2 + num12, num4, mDrawRegion.w);
return new Vector4(x, y, z, w);
}
}
public override void MakePixelPerfect()
{
base.MakePixelPerfect();
if (mType == Type.Tiled)
{
return;
}
Texture texture = mainTexture;
if (!(texture == null) && (mType == Type.Simple || mType == Type.Filled || !base.hasBorder) && texture != null)
{
int num = texture.width;
int num2 = texture.height;
if ((num & 1) == 1)
{
num++;
}
if ((num2 & 1) == 1)
{
num2++;
}
base.width = num;
base.height = num2;
}
}
protected override void OnUpdate()
{
base.OnUpdate();
if (!mFixedAspect)
{
return;
}
Texture texture = mainTexture;
if (texture != null)
{
int num = texture.width;
int num2 = texture.height;
if ((num & 1) == 1)
{
num++;
}
if ((num2 & 1) == 1)
{
num2++;
}
float num3 = mWidth;
float num4 = mHeight;
float num5 = num3 / num4;
float num6 = (float)num / (float)num2;
if (num6 < num5)
{
float num7 = (num3 - num4 * num6) / num3 * 0.5f;
base.drawRegion = new Vector4(num7, 0f, 1f - num7, 1f);
}
else
{
float num8 = (num4 - num3 / num6) / num4 * 0.5f;
base.drawRegion = new Vector4(0f, num8, 1f, 1f - num8);
}
}
}
public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
Texture texture = mainTexture;
if (!(texture == null))
{
Rect rect = new Rect(mRect.x * (float)texture.width, mRect.y * (float)texture.height, (float)texture.width * mRect.width, (float)texture.height * mRect.height);
Rect inner = rect;
Vector4 vector = border;
inner.xMin += vector.x;
inner.yMin += vector.y;
inner.xMax -= vector.z;
inner.yMax -= vector.w;
float num = 1f / (float)texture.width;
float num2 = 1f / (float)texture.height;
rect.xMin *= num;
rect.xMax *= num;
rect.yMin *= num2;
rect.yMax *= num2;
inner.xMin *= num;
inner.xMax *= num;
inner.yMin *= num2;
inner.yMax *= num2;
int size = verts.size;
Fill(verts, uvs, cols, rect, inner);
if (onPostFill != null)
{
onPostFill(this, size, verts, uvs, cols);
}
}
}
}