Refactor: extract shared helpers across scripts, trim remaining doc redundancy
Deduplication pass (44 extractions): - New SmoothedLook: shared smoothed yaw/pitch look tick + view seeding (FirstPersonController, FreeCamController) - New CharacterTeleport: disable-CC-around-teleport idiom (rescue, owner position apply, free-cam sync) - New GeometryUtil: RescaleToUnitScale + TransformBounds (concealment meter/volume, skinned collider baker) - Paint family: canonical map read/write shared between Net and Persistence, snapshot decode, backend stroke dispatch, RebuildBackend, ResolveSeed, chunked RPC send/gate/copy, CamoKnobs/HeightKnobs aggregates, SanitizeFileKey, NewMaskTexture, AdoptAlbedo, FindSlider - Player/modes: GameMode SetPlayerControl/SetPainting/SetOrbitInputEnabled, InputUtil.GameplayKeyPressed, NearestClimbHit, ComputeXRay delegates to ComputeResolutionFreeze, FingerIK TryInPlaneAngle - Match/misc: UnhookSessionCallbacks, SendEmptyNamedMessage, SwapScenes, RunSessionOpAsync, CovarianceEigen, CollectClusterPoints, MatchHud GUIStyle cache, HsvColorPicker rehook, VoxelCenter Documentation pass: remove 6 triplicated doc blocks and 2 restating inline comments left after the previous reduction. Behavior-neutral; hot-path rasterizer loops intentionally untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
066e308cde
commit
2243cc823e
40 files changed
+681
-724
No files matched your search
@@ -233,20 +233,26 @@ public class MatchManager : MonoBehaviour
|
||||
_net.OnClientStarted -= OnClientStarted;
|
||||
_net.OnServerStopped -= OnNetStopped;
|
||||
_net.OnClientStopped -= OnNetStopped;
|
||||
_net.OnClientConnectedCallback -= OnClientConnected;
|
||||
_net.OnClientDisconnectCallback -= OnClientDisconnected;
|
||||
if (_net.SceneManager != null) _net.SceneManager.OnSceneEvent -= OnSceneEvent;
|
||||
if (_net.CustomMessagingManager != null)
|
||||
{
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgAuthorityGranted);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgRequestEndMatch);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgPhase);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgReportHit);
|
||||
}
|
||||
UnhookSessionCallbacks();
|
||||
}
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
// Unhooks the per-session callbacks and named-message handlers (shared by OnDisable and OnNetStopped).
|
||||
private void UnhookSessionCallbacks()
|
||||
{
|
||||
_net.OnClientConnectedCallback -= OnClientConnected;
|
||||
_net.OnClientDisconnectCallback -= OnClientDisconnected;
|
||||
if (_net.SceneManager != null) _net.SceneManager.OnSceneEvent -= OnSceneEvent;
|
||||
if (_net.CustomMessagingManager != null)
|
||||
{
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgAuthorityGranted);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgRequestEndMatch);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgPhase);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgReportHit);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnServerStarted()
|
||||
{
|
||||
_cleanedUp = false;
|
||||
@@ -313,19 +319,7 @@ public class MatchManager : MonoBehaviour
|
||||
Phase = MatchPhase.Lobby;
|
||||
ApplyPhaseLocal(MatchSubPhase.None, 0f, _localMode);
|
||||
_pendingHiders.Clear();
|
||||
if (_net)
|
||||
{
|
||||
_net.OnClientConnectedCallback -= OnClientConnected;
|
||||
_net.OnClientDisconnectCallback -= OnClientDisconnected;
|
||||
if (_net.SceneManager != null) _net.SceneManager.OnSceneEvent -= OnSceneEvent;
|
||||
if (_net.CustomMessagingManager != null)
|
||||
{
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgAuthorityGranted);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgRequestEndMatch);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgPhase);
|
||||
_net.CustomMessagingManager.UnregisterNamedMessageHandler(MsgReportHit);
|
||||
}
|
||||
}
|
||||
if (_net) UnhookSessionCallbacks();
|
||||
|
||||
ReturnToMainOnly();
|
||||
}
|
||||
@@ -463,15 +457,7 @@ public class MatchManager : MonoBehaviour
|
||||
|
||||
private IEnumerator MatchSequence(HashSet<ulong> hunterIds)
|
||||
{
|
||||
var sm = _net.SceneManager;
|
||||
|
||||
// Strictly serialized: NGO allows only one scene op in flight at a time.
|
||||
Scene lobby = SceneManager.GetSceneByName(lobbySceneName);
|
||||
if (lobby.IsValid() && lobby.isLoaded)
|
||||
yield return SceneOp(() => sm.UnloadScene(lobby), SceneEventType.UnloadEventCompleted, lobbySceneName);
|
||||
|
||||
yield return SceneOp(() => sm.LoadScene(matchSceneName, LoadSceneMode.Additive),
|
||||
SceneEventType.LoadEventCompleted, matchSceneName);
|
||||
yield return SwapScenes(lobbySceneName, matchSceneName);
|
||||
|
||||
RespawnAll(id => hunterIds.Contains(id) ? hunterPrefab : hiderPrefab, matchSpawnCenter);
|
||||
|
||||
@@ -500,7 +486,7 @@ public class MatchManager : MonoBehaviour
|
||||
yield return WaitPhase(resolveDuration, null);
|
||||
|
||||
_phaseRoutine = null;
|
||||
EndMatch(); // swaps the map back to the lobby and respawns everyone as the neutral Player
|
||||
EndMatch();
|
||||
}
|
||||
|
||||
// Waits up to 'seconds' of server real time, returning early the moment 'until' (if supplied) is true.
|
||||
@@ -691,15 +677,7 @@ public class MatchManager : MonoBehaviour
|
||||
|
||||
private IEnumerator EndMatchSequence()
|
||||
{
|
||||
var sm = _net.SceneManager;
|
||||
|
||||
// Strictly serialized: NGO allows only one scene op in flight at a time.
|
||||
Scene map = SceneManager.GetSceneByName(matchSceneName);
|
||||
if (map.IsValid() && map.isLoaded)
|
||||
yield return SceneOp(() => sm.UnloadScene(map), SceneEventType.UnloadEventCompleted, matchSceneName);
|
||||
|
||||
yield return SceneOp(() => sm.LoadScene(lobbySceneName, LoadSceneMode.Additive),
|
||||
SceneEventType.LoadEventCompleted, lobbySceneName);
|
||||
yield return SwapScenes(matchSceneName, lobbySceneName);
|
||||
|
||||
RespawnAll(_ => _playerPrefab, lobbySpawnCenter);
|
||||
|
||||
@@ -707,6 +685,20 @@ public class MatchManager : MonoBehaviour
|
||||
Debug.Log("[MatchManager] Back in lobby.", this);
|
||||
}
|
||||
|
||||
// Unloads one gameplay scene (if loaded), then additively loads the next (shared by the match
|
||||
// start/end sequences).
|
||||
private IEnumerator SwapScenes(string unloadSceneName, string loadSceneName)
|
||||
{
|
||||
var sm = _net.SceneManager;
|
||||
|
||||
Scene old = SceneManager.GetSceneByName(unloadSceneName);
|
||||
if (old.IsValid() && old.isLoaded)
|
||||
yield return SceneOp(() => sm.UnloadScene(old), SceneEventType.UnloadEventCompleted, unloadSceneName);
|
||||
|
||||
yield return SceneOp(() => sm.LoadScene(loadSceneName, LoadSceneMode.Additive),
|
||||
SceneEventType.LoadEventCompleted, loadSceneName);
|
||||
}
|
||||
|
||||
// Runs an NGO scene op and waits for its server-side completion event. NGO rejects a new op while one
|
||||
// is in flight, so callers must await this before issuing the next.
|
||||
private IEnumerator SceneOp(System.Func<SceneEventProgressStatus> op, SceneEventType completed, string sceneName)
|
||||
@@ -823,18 +815,22 @@ public class MatchManager : MonoBehaviour
|
||||
public bool IsLocalSceneLobby => SceneManager.GetActiveScene().name == lobbySceneName;
|
||||
public bool IsLocalSceneMap => SceneManager.GetActiveScene().name == matchSceneName;
|
||||
|
||||
// Server -> client: tell the designated client it is the match authority (so it reads Esc locally).
|
||||
private void SendAuthorityGrant(ulong clientId)
|
||||
// Sends a named message whose payload carries no information (a named message still needs a buffer,
|
||||
// so a single dummy byte is written).
|
||||
private void SendEmptyNamedMessage(string messageName, ulong targetClientId)
|
||||
{
|
||||
var cmm = _net != null ? _net.CustomMessagingManager : null;
|
||||
if (cmm == null) return;
|
||||
using (var writer = new FastBufferWriter(sizeof(byte), Allocator.Temp))
|
||||
{
|
||||
writer.WriteByteSafe(1); // payload unused; a named message still needs a buffer
|
||||
cmm.SendNamedMessage(MsgAuthorityGranted, clientId, writer);
|
||||
writer.WriteByteSafe(1);
|
||||
cmm.SendNamedMessage(messageName, targetClientId, writer);
|
||||
}
|
||||
}
|
||||
|
||||
// Server -> client: tell the designated client it is the match authority (so it reads Esc locally).
|
||||
private void SendAuthorityGrant(ulong clientId) => SendEmptyNamedMessage(MsgAuthorityGranted, clientId);
|
||||
|
||||
// Client handler: this machine has been granted match authority.
|
||||
private void OnAuthorityGrantedMessage(ulong senderClientId, FastBufferReader reader)
|
||||
{
|
||||
@@ -844,16 +840,7 @@ public class MatchManager : MonoBehaviour
|
||||
|
||||
// Client -> server: ask the server to end the match. Only honored from the authority client (and only
|
||||
// while a match is running - EndMatch guards the phase).
|
||||
private void RequestEndMatchFromServer()
|
||||
{
|
||||
var cmm = _net != null ? _net.CustomMessagingManager : null;
|
||||
if (cmm == null) return;
|
||||
using (var writer = new FastBufferWriter(sizeof(byte), Allocator.Temp))
|
||||
{
|
||||
writer.WriteByteSafe(1);
|
||||
cmm.SendNamedMessage(MsgRequestEndMatch, NetworkManager.ServerClientId, writer);
|
||||
}
|
||||
}
|
||||
private void RequestEndMatchFromServer() => SendEmptyNamedMessage(MsgRequestEndMatch, NetworkManager.ServerClientId);
|
||||
|
||||
// Server handler: an authority client asked to end the match.
|
||||
private void OnRequestEndMatchMessage(ulong senderClientId, FastBufferReader reader)
|
||||
|
||||
Reference in new issue
Block a user