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:
1 parent
2243cc823e
commit
382bfb36df
32 files changed
+292
-348
No files matched your search
@@ -156,7 +156,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
if (!IsServer)
|
||||
{
|
||||
_awaitingSnapshot = true;
|
||||
LogSync("late joiner: requesting baseline snapshot");
|
||||
if (logSync) LogSync("late joiner: requesting baseline snapshot");
|
||||
RequestSnapshotRpc();
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,8 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Call sites are guarded with `if (logSync)` so the interpolated message string is never
|
||||
// built when logging is off (some sites run per frame while stamps are flushing).
|
||||
private void LogSync(string msg)
|
||||
{
|
||||
if (logSync) Debug.Log($"{SyncTag} {msg}", this);
|
||||
@@ -223,7 +225,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
{
|
||||
_snapReadyToApply = false;
|
||||
_painter.ApplyPaintSnapshot(_snapBuffer, _snapBaselineId);
|
||||
LogSync($"applied snapshot baseline {_snapBaselineId}; replaying buffered events");
|
||||
if (logSync) LogSync($"applied snapshot baseline {_snapBaselineId}; replaying buffered events");
|
||||
FlushBuffered();
|
||||
_snapBuffer = null;
|
||||
_awaitingSnapshot = false;
|
||||
@@ -255,7 +257,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
_pendingCarry = null;
|
||||
if (_painter.LoadPaintFromSnapshot(carry))
|
||||
{
|
||||
LogSync($"carried painting onto respawned avatar ({carry.Length} bytes); rebroadcasting to peers");
|
||||
if (logSync) LogSync($"carried painting onto respawned avatar ({carry.Length} bytes); rebroadcasting to peers");
|
||||
BroadcastLoadedPaint();
|
||||
}
|
||||
}
|
||||
@@ -330,12 +332,12 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
if (kind == OutKind.Restore)
|
||||
{
|
||||
SubmitRestoreServerRpc(seq, id);
|
||||
LogSync($"sent RESTORE to checkpoint {id} (seq {seq})");
|
||||
if (logSync) LogSync($"sent RESTORE to checkpoint {id} (seq {seq})");
|
||||
}
|
||||
else
|
||||
{
|
||||
SubmitCheckpointServerRpc(seq, id);
|
||||
LogSync($"sent checkpoint {id} (seq {seq})");
|
||||
if (logSync) LogSync($"sent checkpoint {id} (seq {seq})");
|
||||
}
|
||||
consumed++;
|
||||
}
|
||||
@@ -345,7 +347,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
_outgoing.RemoveRange(0, consumed);
|
||||
|
||||
if (!unlimited && _outgoing.Count > 0)
|
||||
LogSync($"stamp cap ({cap}) reached; {_outgoing.Count} command(s) carried over to next frame");
|
||||
if (logSync) LogSync($"stamp cap ({cap}) reached; {_outgoing.Count} command(s) carried over to next frame");
|
||||
}
|
||||
|
||||
// ---- Stamp / checkpoint / restore commands (owner -> server -> remotes) ----
|
||||
@@ -396,7 +398,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
return;
|
||||
|
||||
_painter.RemoteCommitCheckpoint(id);
|
||||
LogSync($"committed checkpoint {id} (seq {seq})");
|
||||
if (logSync) LogSync($"committed checkpoint {id} (seq {seq})");
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
@@ -409,11 +411,11 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
// undo past this peer's join point), fetch a fresh snapshot of the resulting state instead.
|
||||
if (_painter.RemoteRestoreTo(id))
|
||||
{
|
||||
LogSync($"reproduced RESTORE to checkpoint {id} (seq {seq})");
|
||||
if (logSync) LogSync($"reproduced RESTORE to checkpoint {id} (seq {seq})");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogSync($"cannot reproduce checkpoint {id} (not in local history, seq {seq}) -> owner snapshot fallback");
|
||||
if (logSync) LogSync($"cannot reproduce checkpoint {id} (not in local history, seq {seq}) -> owner snapshot fallback");
|
||||
RequestSnapshotFallback();
|
||||
}
|
||||
}
|
||||
@@ -441,7 +443,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
if (!_painter.RemoteRestoreTo(ev.id))
|
||||
{
|
||||
// Can't reproduce -> the fresh snapshot we request next supersedes the rest.
|
||||
LogSync($"buffered RESTORE to checkpoint {ev.id} not reproducible -> owner snapshot fallback");
|
||||
if (logSync) LogSync($"buffered RESTORE to checkpoint {ev.id} not reproducible -> owner snapshot fallback");
|
||||
_buffered.Clear();
|
||||
RequestSnapshotFallback();
|
||||
return;
|
||||
@@ -479,7 +481,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
|
||||
ulong requester = p.Receive.SenderClientId;
|
||||
int baselineId = _painter.CurrentCheckpointId;
|
||||
LogSync($"serving fallback snapshot to client {requester} (cutoff {_seq}, baseline {baselineId}, {data.Length} bytes)");
|
||||
if (logSync) LogSync($"serving fallback snapshot to client {requester} (cutoff {_seq}, baseline {baselineId}, {data.Length} bytes)");
|
||||
StartCoroutine(UploadSnapshot(data, _seq, baselineId, broadcast: false, target: requester));
|
||||
}
|
||||
|
||||
@@ -495,7 +497,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
// last message this replica applied). The checkpoint id tags the baseline the joiner adopts.
|
||||
int capturedSeq = IsOwner ? _seq : _seqHorizon;
|
||||
int baselineId = _painter.CurrentCheckpointId;
|
||||
LogSync($"serving late-join snapshot to client {p.Receive.SenderClientId} (cutoff {capturedSeq}, baseline {baselineId}, {data.Length} bytes)");
|
||||
if (logSync) LogSync($"serving late-join snapshot to client {p.Receive.SenderClientId} (cutoff {capturedSeq}, baseline {baselineId}, {data.Length} bytes)");
|
||||
StartCoroutine(SendSnapshot(new[] { p.Receive.SenderClientId }, data, capturedSeq, baselineId));
|
||||
}
|
||||
|
||||
@@ -539,7 +541,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
// racing the carry). Equal cutoff is allowed so the owner-snapshot heal still lands.
|
||||
if (capturedSeq < _acceptedCutoffFloor)
|
||||
{
|
||||
LogSync($"ignoring stale snapshot #{xferId} (cutoff {capturedSeq} < accepted {_acceptedCutoffFloor})");
|
||||
if (logSync) LogSync($"ignoring stale snapshot #{xferId} (cutoff {capturedSeq} < accepted {_acceptedCutoffFloor})");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -550,7 +552,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
_snapBaselineId = baselineId;
|
||||
_snapReadyToApply = false;
|
||||
_awaitingSnapshot = true;
|
||||
LogSync($"receiving snapshot #{xferId} ({totalBytes} bytes, cutoff {capturedSeq}, baseline {baselineId})");
|
||||
if (logSync) LogSync($"receiving snapshot #{xferId} ({totalBytes} bytes, cutoff {capturedSeq}, baseline {baselineId})");
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
@@ -603,7 +605,7 @@ public class PlayerPaintSync : NetworkBehaviour
|
||||
int cutoff = ++_seq; // every event up to here is now superseded by the loaded baseline
|
||||
_seqHorizon = cutoff;
|
||||
int baselineId = _painter.CurrentCheckpointId; // the load's fresh baseline id
|
||||
LogSync($"broadcasting loaded painting to all peers (cutoff {cutoff}, baseline {baselineId}, {data.Length} bytes)");
|
||||
if (logSync) LogSync($"broadcasting loaded painting to all peers (cutoff {cutoff}, baseline {baselineId}, {data.Length} bytes)");
|
||||
StartCoroutine(UploadSnapshot(data, cutoff, baselineId, broadcast: true, target: 0));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user