-
Notifications
You must be signed in to change notification settings - Fork 462
chore: simplify accessors network object #3831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
noellie-velez
wants to merge
11
commits into
develop-2.0.0
Choose a base branch
from
chore/simplify-accessors-network-object
base: develop-2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−68
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a1fac91
chore: optimization
noellie-velez b1b85ac
chore: optimize NetworkManager accessors
noellie-velez 0a28480
Merge branch 'develop-2.0.0' into chore/simplify-accessors-network-ob…
noellie-velez 606c9f7
Using m_CachedNetworkObject instead of NetworkObject
noellie-velez 18a1805
Using m_CachedNetworkManager instead of NetworkManager
noellie-velez 7a49a9a
Convert "==" to explicit Unity engine object lifetime check
noellie-velez 7d9ffd5
Fix wording
noellie-velez b255749
Use m_CachedParent and Scene
noellie-velez 0ebab51
Changed parentObject scope
noellie-velez a166482
Removing comments (added in PR)
noellie-velez f817796
Revert null check removal for Log
noellie-velez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3554,7 +3554,7 @@ protected internal override void InternalOnNetworkPostSpawn() | |
| } | ||
|
|
||
| // Standard non-authority synchronization is handled here | ||
| if (!CanCommitToTransform && NetworkManager.IsConnectedClient && SynchronizeState.IsSynchronizing) | ||
| if (!CanCommitToTransform && m_CachedNetworkManager.IsConnectedClient && SynchronizeState.IsSynchronizing) | ||
| { | ||
| NonAuthorityFinalizeSynchronization(); | ||
| } | ||
|
|
@@ -3625,9 +3625,9 @@ private void CleanUpOnDestroyOrDespawn() | |
| #else | ||
| var forUpdate = true; | ||
| #endif | ||
| if (m_CachedNetworkObject != null) | ||
| if (m_CachedNetworkObject) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rider suggested converting "==" to explicit Unity engine object lifetime check. Should we keep or revert those changes? |
||
| { | ||
| NetworkManager?.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false); | ||
| m_CachedNetworkManager?.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false); | ||
| } | ||
|
|
||
| DeregisterForTickUpdate(this); | ||
|
|
@@ -3673,7 +3673,7 @@ protected virtual void OnInitialize(ref NetworkVariable<NetworkTransformState> r | |
| /// </summary> | ||
| private void ResetInterpolatedStateToCurrentAuthoritativeState() | ||
| { | ||
| var serverTime = NetworkManager.ServerTime.Time; | ||
| var serverTime = m_CachedNetworkManager.ServerTime.Time; | ||
| #if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D | ||
| var position = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal.GetPosition() : GetSpaceRelativePosition(); | ||
| var rotation = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal.GetRotation() : GetSpaceRelativeRotation(); | ||
|
|
@@ -3695,7 +3695,7 @@ private void ResetInterpolatedStateToCurrentAuthoritativeState() | |
| } | ||
| private NetworkObject m_CachedNetworkObject; | ||
| /// <summary> | ||
| /// The internal initialzation method to allow for internal API adjustments | ||
| /// The internal initialization method to allow for internal API adjustments | ||
| /// </summary> | ||
| /// <param name="isOwnershipChange"></param> | ||
| private void InternalInitialization(bool isOwnershipChange = false) | ||
|
|
@@ -3707,7 +3707,7 @@ private void InternalInitialization(bool isOwnershipChange = false) | |
| m_CachedNetworkObject = NetworkObject; | ||
|
|
||
| // Determine if this is the first NetworkTransform in the associated NetworkObject's list | ||
| m_IsFirstNetworkTransform = NetworkObject.NetworkTransforms[0] == this; | ||
| m_IsFirstNetworkTransform = m_CachedNetworkObject.NetworkTransforms[0] == this; | ||
|
|
||
| if (m_CachedNetworkManager && m_CachedNetworkManager.DistributedAuthorityMode) | ||
| { | ||
|
|
@@ -3719,7 +3719,7 @@ private void InternalInitialization(bool isOwnershipChange = false) | |
| { | ||
| if (CanCommitToTransform) | ||
| { | ||
| if (NetworkObject.HasParentNetworkObject(transform)) | ||
| if (m_CachedNetworkObject.HasParentNetworkObject(transform)) | ||
| { | ||
| InLocalSpace = true; | ||
| } | ||
|
|
@@ -3763,7 +3763,7 @@ private void InternalInitialization(bool isOwnershipChange = false) | |
| if (CanCommitToTransform) | ||
| { | ||
| // Make sure authority doesn't get added to updates (no need to do this on the authority side) | ||
| m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, false); | ||
| m_CachedNetworkManager.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false); | ||
| if (UseHalfFloatPrecision) | ||
| { | ||
| m_HalfPositionState = new NetworkDeltaPosition(currentPosition, m_CachedNetworkManager.ServerTime.Tick, math.bool3(SyncPositionX, SyncPositionY, SyncPositionZ)); | ||
|
|
@@ -3792,7 +3792,7 @@ private void InternalInitialization(bool isOwnershipChange = false) | |
| m_PreviousScaleLerpSmoothing = ScaleLerpSmoothing; | ||
|
|
||
| // Non-authority needs to be added to updates for interpolation and applying state purposes | ||
| m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, true); | ||
| m_CachedNetworkManager.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, true); | ||
| // Remove this instance from the tick update | ||
| DeregisterForTickUpdate(this); | ||
| ResetInterpolatedStateToCurrentAuthoritativeState(); | ||
|
|
@@ -3890,7 +3890,7 @@ private void DefaultParentChanged() | |
| m_RotationInterpolator.Clear(); | ||
|
|
||
| // Always use NetworkManager here as this can be invoked prior to spawning | ||
| var tempTime = new NetworkTime(NetworkManager.NetworkConfig.TickRate, NetworkManager.ServerTime.Tick).Time; | ||
| var tempTime = new NetworkTime(NetworkManager.NetworkConfig.TickRate, m_CachedNetworkManager.ServerTime.Tick).Time; | ||
| UpdatePositionInterpolator(m_InternalCurrentPosition, tempTime, true); | ||
| m_ScaleInterpolator.ResetTo(m_InternalCurrentScale, tempTime); | ||
| m_RotationInterpolator.ResetTo(m_InternalCurrentRotation, tempTime); | ||
|
|
@@ -3922,7 +3922,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent | |
| if (LastTickSync == m_LocalAuthoritativeNetworkState.GetNetworkTick()) | ||
| { | ||
| m_InternalCurrentPosition = m_LastStateTargetPosition = GetSpaceRelativePosition(); | ||
| m_PositionInterpolator.ResetTo(m_PositionInterpolator.Parent, m_InternalCurrentPosition, NetworkManager.ServerTime.Time); | ||
| m_PositionInterpolator.ResetTo(m_PositionInterpolator.Parent, m_InternalCurrentPosition, m_CachedNetworkManager.ServerTime.Time); | ||
| if (InLocalSpace) | ||
| { | ||
| transform.localPosition = m_InternalCurrentPosition; | ||
|
|
@@ -3954,7 +3954,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent | |
| { | ||
| m_InternalCurrentRotation = GetSpaceRelativeRotation(); | ||
| m_TargetRotation = m_InternalCurrentRotation.eulerAngles; | ||
| m_RotationInterpolator.ResetTo(m_RotationInterpolator.Parent, m_InternalCurrentRotation, NetworkManager.ServerTime.Time); | ||
| m_RotationInterpolator.ResetTo(m_RotationInterpolator.Parent, m_InternalCurrentRotation, m_CachedNetworkManager.ServerTime.Time); | ||
| if (InLocalSpace) | ||
| { | ||
| transform.localRotation = m_InternalCurrentRotation; | ||
|
|
@@ -4638,13 +4638,13 @@ private void UpdateTransformState() | |
| { | ||
| continue; | ||
| } | ||
| NetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, clientId); | ||
| m_CachedNetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, clientId); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // Clients (owner authoritative) send messages to the server-host | ||
| NetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, NetworkManager.ServerClientId); | ||
| m_CachedNetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, NetworkManager.ServerClientId); | ||
| } | ||
| m_LocalAuthoritativeNetworkState.LastSerializedSize = m_OutboundMessage.BytesWritten; | ||
| } | ||
|
|
@@ -4783,7 +4783,7 @@ public NetworkTransformTickRegistration(NetworkManager networkManager) | |
| internal void RegisterForTickSynchronization() | ||
| { | ||
| s_TickSynchPosition++; | ||
| m_NextTickSync = NetworkManager.ServerTime.Tick + (s_TickSynchPosition % (int)NetworkManager.NetworkConfig.TickRate); | ||
| m_NextTickSync = m_CachedNetworkManager.ServerTime.Tick + (s_TickSynchPosition % (int)NetworkManager.NetworkConfig.TickRate); | ||
| } | ||
|
|
||
| private static void RegisterNetworkManagerForTickUpdate(NetworkManager networkManager) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change useful on an optimization point of view?