Refactor scripts: dedup remainder, remove dead code, perf hardening

Iteration 4 over Assets/Scripts (no component/file splits, no Unity assets touched):

Dedup:
- Route inline cursor-release, material guards, Ctrl-held and undo/redo
  input through existing InputUtil / SetMatFloat helpers
- Add ungated InputUtil.KeyPressedThisFrame; GameplayKeyPressed builds on it
- Unify FindDeep/FindDeepChild into GeometryUtil.FindDeep

Dead code / stale docs:
- Remove unused code-gen bake path (HsvColorPicker.Build, PaintHud factory)
- Drop unreferenced symbols (SubPhaseChanged event, LocalPhaseDuration,
  IsLocalSceneMain, MouseSensitivity.Changed, IsPaused, InSession,
  NetworkControlled, PreviousPose, JointCount, voxel-count accessors)
- Fix incorrect PlayerRole / PaintHud / Pick / PlayerPose docs

Perf / robustness (behaviour-neutral):
- ConcealmentMeter.Evaluate: reuse vertex/topology buffers, two-pointer
  crossing count
- BuildMeshCaches: alloc-free vertex copy, cached topology/UVs
- Guard all PlayerPaintSync LogSync sites behind logSync
- Cache LocalViewerIsHunter / controller / CanShoot / TypingGuard lookups;
  dedup LocalIsHunter with MatchHud
- Change-guard RefreshEmissionColor and HeroCutout.Disarm
- Cache scene/countdown string comparisons per frame
- Grow NonAlloc buffers and log-once on saturation

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-07-02 13:33:18 +02:00
1 parent 2243cc823e
commit 382bfb36df
32 files changed
+292 -348

No files matched your search

+24 -17
View File
@@ -139,7 +139,6 @@ public class MatchManager : MonoBehaviour
// The countdown is cosmetic/local; the authoritative transition is server-driven, so drift self-corrects.
private MatchSubPhase _subPhase = MatchSubPhase.None;
private float _phaseEndTime; // Time.time when the current sub-phase ends (for the HUD countdown)
private float _phaseDuration;
private MatchMode _localMode = MatchMode.Classic; // mirror of the server's matchMode, carried in the phase message
private const string PreMatchTag = "PreMatch"; // scene props destroyed when seek starts
@@ -152,10 +151,6 @@ public class MatchManager : MonoBehaviour
public MatchMode LocalMatchMode => _localMode;
/// <summary>Seconds left in the current sub-phase for the HUD (clamped to 0; cosmetic).</summary>
public float LocalPhaseRemaining => Mathf.Max(0f, _phaseEndTime - Time.time);
/// <summary>Total length of the current sub-phase (for a HUD progress bar, if wanted).</summary>
public float LocalPhaseDuration => _phaseDuration;
/// <summary>Raised after the local sub-phase changes (argument = the new sub-phase). HUD/visibility follow it.</summary>
public event System.Action<MatchSubPhase> SubPhaseChanged;
private NetworkManager _net;
private GameObject _playerPrefab; // captured from NetworkConfig.PlayerPrefab; auto-spawn is then disabled so we spawn manually into a loaded scene
@@ -508,21 +503,16 @@ public class MatchManager : MonoBehaviour
BroadcastPhase(phase, duration, matchMode, 0, true);
}
// Sets this machine's sub-phase mirror + countdown + mode and notifies followers (HUD / visibility).
// Sets this machine's sub-phase mirror + countdown + mode (followers poll LocalSubPhase).
// Shared by the server's SetPhaseServer and a client's OnPhaseMessage handler.
private void ApplyPhaseLocal(MatchSubPhase phase, float duration, MatchMode mode)
{
bool changed = _subPhase != phase;
_subPhase = phase;
_phaseDuration = duration;
_phaseEndTime = Time.time + duration;
_localMode = mode;
if (changed)
{
SubPhaseChanged?.Invoke(phase);
// Props staged only for the hide phase are gone the instant seek begins.
if (phase == MatchSubPhase.Seek) DestroyPreMatchObjects();
}
// Props staged only for the hide phase are gone the instant seek begins.
if (changed && phase == MatchSubPhase.Seek) DestroyPreMatchObjects();
}
// Runs on every machine (server directly, clients via the phase message); the tagged props are plain
@@ -801,7 +791,7 @@ public class MatchManager : MonoBehaviour
/// <summary>Ends the running match for everyone (back to the Lobby), routed through authority: the
/// host/server ends directly; a remote authority client asks the server. No-op if this machine is not
/// the authority or no match is running. Replaces the old Esc handler - now driven by the panel button.</summary>
/// the authority or no match is running.</summary>
public void RequestEndMatch()
{
if (_net == null) return;
@@ -811,9 +801,26 @@ public class MatchManager : MonoBehaviour
// Local active-scene kind. Every peer sets its active scene to Lobby/Map as those load (see OnSceneEvent)
// and back to Main on teardown, so a local UI can tell where it is without the server-local Phase.
public bool IsLocalSceneMain => SceneManager.GetActiveScene().name == mainSceneName;
public bool IsLocalSceneLobby => SceneManager.GetActiveScene().name == lobbySceneName;
public bool IsLocalSceneMap => SceneManager.GetActiveScene().name == matchSceneName;
// Scene.name allocates a fresh string per call and these are polled per frame -> cached per scene handle.
public bool IsLocalSceneLobby => ActiveSceneName == lobbySceneName;
public bool IsLocalSceneMap => ActiveSceneName == matchSceneName;
private int _activeSceneHandle;
private string _activeSceneName;
private string ActiveSceneName
{
get
{
Scene s = SceneManager.GetActiveScene();
if (_activeSceneName == null || s.handle != _activeSceneHandle)
{
_activeSceneHandle = s.handle;
_activeSceneName = s.name;
}
return _activeSceneName;
}
}
// Sends a named message whose payload carries no information (a named message still needs a buffer,
// so a single dummy byte is written).