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

242 lines
7.1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
public class MotionUtils
{
public enum EaseType
{
linear,
easeInSine,
easeInQuad,
easeInCubic,
easeInQuart,
easeInQuint,
easeInExpo,
easeInBack,
easeInBounce,
easeInElastic,
easeOutSine,
easeOutQuad,
easeOutCubic,
easeOutQuart,
easeOutQuint,
easeOutExpo,
easeOutBack,
easeOutBounce,
easeOutElastic,
easeInOutSine,
easeInOutQuad,
easeInOutCubic,
easeInOutQuart,
easeInOutQuint,
easeInOutExpo,
easeInOutBack,
easeInOutBounce,
easeInOutElastic
}
public static float GetEase(float t, EaseType e)
{
float num = 1f - t;
switch (e)
{
case EaseType.linear:
return t;
case EaseType.easeInSine:
return 1f - Mathf.Cos(t * (float)Math.PI / 2f);
case EaseType.easeInQuad:
return t * t;
case EaseType.easeInCubic:
return t * t * t;
case EaseType.easeInQuart:
return t * t * t * t;
case EaseType.easeInQuint:
return t * t * t * t * t;
case EaseType.easeInExpo:
return Mathf.Pow(2f, 10f * (t - 1f));
case EaseType.easeInBack:
return t * t * (2.70158f * t - 1.70158f);
case EaseType.easeInBounce:
if (num < 0.36363637f)
{
return 1f - 7.5625f * num * num;
}
if (num < 0.72727275f)
{
return 1f - (7.5625f * (num - 0.54545456f) * (num - 0.54545456f) + 0.75f);
}
if (num < 0.90909094f)
{
return 1f - (7.5625f * (num - 0.8181818f) * (num - 0.8181818f) + 0.9375f);
}
return 1f - (7.5625f * (num - 21f / 22f) * (num - 21f / 22f) + 63f / 64f);
case EaseType.easeInElastic:
{
float num2 = 0.3f;
if (t == 0f)
{
return 0f;
}
if (t == 1f)
{
return 1f;
}
float num3 = num2 / ((float)Math.PI * 2f) * Mathf.Asin(1f);
return 0f - t * Mathf.Pow(2f, 10f * (t -= 1f)) * Mathf.Sin((t - num3) * ((float)Math.PI * 2f) / num2);
}
case EaseType.easeOutSine:
return Mathf.Sin(t * (float)Math.PI / 2f);
case EaseType.easeOutQuad:
return 1f - num * num;
case EaseType.easeOutCubic:
return 1f - num * num * num;
case EaseType.easeOutQuart:
return 1f - num * num * num * num;
case EaseType.easeOutQuint:
return 1f - num * num * num * num * num;
case EaseType.easeOutExpo:
return 0f - Mathf.Pow(2f, -10f * t) + 1f;
case EaseType.easeOutBack:
return 1f - num * num * (2.70158f * num - 1.70158f);
case EaseType.easeOutBounce:
if (t < 0.36363637f)
{
return 7.5625f * t * t;
}
if (t < 0.72727275f)
{
return 7.5625f * (t - 0.54545456f) * (t - 0.54545456f) + 0.75f;
}
if (t < 0.90909094f)
{
return 7.5625f * (t - 0.8181818f) * (t - 0.8181818f) + 0.9375f;
}
return 7.5625f * (t - 21f / 22f) * (t - 21f / 22f) + 63f / 64f;
case EaseType.easeOutElastic:
{
float num2 = 0.3f;
if (t == 0f)
{
return 0f;
}
if (t == 1f)
{
return 1f;
}
float num3 = num2 / ((float)Math.PI * 2f) * Mathf.Asin(1f);
return Mathf.Pow(2f, -10f * t) * Mathf.Sin((t - num3) * ((float)Math.PI * 2f) / num2) + 1f;
}
case EaseType.easeInOutSine:
return (1f - Mathf.Cos(t * (float)Math.PI)) * 0.5f;
case EaseType.easeInOutQuad:
return (t < 0.5f) ? (t * t * 2f) : (1f - num * num * 2f);
case EaseType.easeInOutCubic:
return (t < 0.5f) ? (t * t * t * 2f) : (1f - num * num * num * 2f);
case EaseType.easeInOutQuart:
return (t < 0.5f) ? (t * t * t * t * 2f) : (1f - num * num * num * num * 2f);
case EaseType.easeInOutQuint:
return (t < 0.5f) ? (t * t * t * t * t * 2f) : (1f - num * num * num * num * num * 2f);
case EaseType.easeInOutExpo:
return (t < 0.5f) ? Mathf.Pow(2f, 10f * (t * 2f - 1f)) : (0.5f * (0f - Mathf.Pow(2f, -10f * (t * 2f - 1f)) + 2f));
case EaseType.easeInOutBack:
return (t < 0.5f) ? (0.5f * (t * 2f) * (t * 2f) * (2.525f * t * 2f - 1.525f)) : (1f - 0.5f * (num * 2f) * (num * 2f) * (2.525f * num * 2f - 1.525f));
case EaseType.easeInOutBounce:
if (t < 0.5f)
{
return GetEase(t * 2f, EaseType.easeInBounce) * 0.5f;
}
return GetEase(t * 2f - 1f, EaseType.easeOutBounce) * 0.5f + 0.5f;
case EaseType.easeInOutElastic:
if (t < 0.5f)
{
return GetEase(t * 2f, EaseType.easeInElastic) * 0.5f;
}
return GetEase(t * 2f - 1f, EaseType.easeOutElastic) * 0.5f + 0.5f;
default:
return t;
}
}
public static Vector3[] GetBezierQuad(Vector3 p0, Vector3 p1, Vector3 p2, int div)
{
Vector3[] array = new Vector3[div];
for (int i = 0; i < div; i++)
{
float num = (float)i / (float)(div - 1);
float num2 = 1f - num;
array[i] = new Vector3(num2 * num2 * p0.x + 2f * num2 * num * p1.x + num * num * p2.x, num2 * num2 * p0.y + 2f * num2 * num * p1.y + num * num * p2.y, num2 * num2 * p0.z + 2f * num2 * num * p1.z + num * num * p2.z);
}
return array;
}
public static Vector3[] GetBezierCubic(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, int div)
{
Vector3[] array = new Vector3[div];
for (int i = 0; i < div; i++)
{
float num = (float)i / (float)(div - 1);
float num2 = 1f - num;
array[i] = new Vector3(num2 * num2 * num2 * p0.x + 3f * num2 * num2 * num * p1.x + 3f * num2 * num * num * p2.x + num * num * num * p3.x, num2 * num2 * num2 * p0.y + 3f * num2 * num2 * num * p1.y + 3f * num2 * num * num * p2.y + num * num * num * p3.y, num2 * num2 * num2 * p0.z + 3f * num2 * num2 * num * p1.z + 3f * num2 * num * num * p2.z + num * num * num * p3.z);
}
return array;
}
public static void SetLayerAll(GameObject obj, int layer)
{
obj.layer = layer;
for (int i = 0; i < obj.transform.childCount; i++)
{
GameObject gameObject = obj.transform.GetChild(i).gameObject;
if (gameObject.transform.childCount > 0)
{
SetLayerAll(gameObject, layer);
}
else
{
gameObject.layer = layer;
}
}
}
public static void SetActiveAll(GameObject obj, bool flg)
{
obj.SetActive(flg);
for (int i = 0; i < obj.transform.childCount; i++)
{
GameObject gameObject = obj.transform.GetChild(i).gameObject;
if (gameObject.transform.childCount > 0)
{
SetActiveAll(gameObject, flg);
}
else
{
gameObject.SetActive(flg);
}
}
}
public static void ChangeParticleSystemColor(GameObject particleSystemRootObject, Color newColor, Action<ParticleSystem> actionOnChildrenParticleSytems = null)
{
ParticleSystem[] componentsInChildren = particleSystemRootObject.GetComponentsInChildren<ParticleSystem>();
foreach (ParticleSystem particleSystem in componentsInChildren)
{
ParticleSystem.MainModule main = particleSystem.main;
main.startColor = newColor;
ParticleSystem.Particle[] array = new ParticleSystem.Particle[particleSystem.particleCount];
int particles = particleSystem.GetParticles(array);
for (int j = 0; j < array.Length; j++)
{
array[j].startColor = newColor;
}
particleSystem.SetParticles(array, particles);
actionOnChildrenParticleSytems?.Invoke(particleSystem);
}
}
public static float CalculateFrameRateIndependantDampingConstant(float smoothingAmount, float decayMultiplier)
{
return 1f - Mathf.Pow(smoothingAmount, Time.smoothDeltaTime * decayMultiplier);
}
}