@@ -11,19 +11,43 @@ public class NetworkBehaviourUpdater
1111 {
1212 private NetworkManager m_NetworkManager ;
1313 private NetworkConnectionManager m_ConnectionManager ;
14+
15+ /// <summary>
16+ /// Contains the current dirty <see cref="NetworkObject"/>s that are proccessed each new network tick.
17+ /// Under most cases, dirty <see cref="NetworkObject"/>s are fully processed on the next network tick.
18+ /// Under certain conditions, like user script invoking <see cref="NetworkVariableBase.SetUpdateTraits(NetworkVariableUpdateTraits)"/>
19+ /// to define <see cref="NetworkVariableUpdateTraits"/>, a <see cref="NetworkObject"/> can remain in the
20+ /// <see cref="m_DirtyNetworkObjects"/> list until the configured traits' conditions have been met.
21+ /// </summary>
1422 private HashSet < NetworkObject > m_DirtyNetworkObjects = new HashSet < NetworkObject > ( ) ;
23+
24+ /// <summary>
25+ /// Contains any dirty <see cref="NetworkObject"/>s that will be added to the <see cref="m_DirtyNetworkObjects"/>
26+ /// list on the next network tick (<see cref="OnNetworkTick"/>).
27+ /// </summary>
1528 private HashSet < NetworkObject > m_PendingDirtyNetworkObjects = new HashSet < NetworkObject > ( ) ;
1629
1730#if DEVELOPMENT_BUILD || UNITY_EDITOR
1831 private ProfilerMarker m_NetworkBehaviourUpdate = new ProfilerMarker ( $ "{ nameof ( NetworkBehaviour ) } .{ nameof ( NetworkBehaviourUpdate ) } ") ;
1932#endif
2033
34+ /// <summary>
35+ /// Adds a <see cref="NetworkObject"/> to the prending dirty list.
36+ /// The <see cref="m_PendingDirtyNetworkObjects"/> list is merged into the <see cref="m_DirtyNetworkObjects"/> list
37+ /// when processed.
38+ /// </summary>
2139 internal void AddForUpdate ( NetworkObject networkObject )
2240 {
2341 // Since this is a HashSet, we don't need to worry about duplicate entries
2442 m_PendingDirtyNetworkObjects . Add ( networkObject ) ;
2543 }
2644
45+ /// <summary>
46+ /// (Client-server network topology only)
47+ /// The server handles processing network variables the same way as a client
48+ /// with the primary difference being that the server sends updates to all
49+ /// observers.
50+ /// </summary>
2751 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2852 internal void ProcessDirtyObjectServer ( NetworkObject dirtyObj , bool forceSend )
2953 {
@@ -41,6 +65,12 @@ internal void ProcessDirtyObjectServer(NetworkObject dirtyObj, bool forceSend)
4165 }
4266 }
4367
68+ /// <summary>
69+ /// Clients handle processing dirty objects relative to the client.
70+ /// The <see cref="NetworkVariableDeltaMessage"/> is client to server.
71+ /// With distributed authority live service sessions, this is sent to
72+ /// the Rust server.
73+ /// </summary>
4474 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4575 internal void ProcessDirtyObjectClient ( NetworkObject dirtyObj , bool forceSend )
4676 {
@@ -50,6 +80,10 @@ internal void ProcessDirtyObjectClient(NetworkObject dirtyObj, bool forceSend)
5080 }
5181 }
5282
83+ /// <summary>
84+ /// Handle house cleaning on the child <see cref="NetworkBehaviour"/>s.
85+ /// This includes some collections specific checks and updates.
86+ /// </summary>
5387 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5488 internal void PostProcessDirtyObject ( NetworkObject dirtyObj )
5589 {
@@ -73,6 +107,11 @@ internal void PostProcessDirtyObject(NetworkObject dirtyObj)
73107 }
74108 }
75109
110+ /// <summary>
111+ /// Invokes <see cref="NetworkBehaviour.PostNetworkVariableWrite(bool)"/> on all child <see cref="NetworkBehaviour"/>s.
112+ /// </summary>
113+ /// <param name="dirtyObj"></param>
114+ /// <param name="forceSend">Refer to the <see cref="ProcessDirtyObject(NetworkObject, bool)"/> definition.</param>
76115 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
77116 internal void ResetDirtyObject ( NetworkObject dirtyObj , bool forceSend )
78117 {
@@ -103,6 +142,18 @@ internal void ForceSendIfDirtyOnNetworkShow(NetworkObject networkObject)
103142 m_DirtyNetworkObjects . Remove ( networkObject ) ;
104143 }
105144
145+ /// <summary>
146+ /// The primary "dirty" <see cref="NetworkObject"/> processor.
147+ /// Invokes:
148+ /// - <see cref="NetworkBehaviour.PreVariableUpdate"/> on all properties that derive from <see cref="NetworkVariableBase"/>.
149+ /// - <see cref="ProcessDirtyObjectServer(NetworkObject, bool)"/> (if the server).
150+ /// - <see cref="ProcessDirtyObjectClient(NetworkObject, bool)"/> (if the client).
151+ /// - <see cref="PostProcessDirtyObject"/> to handle the post processing of network variables.
152+ /// - <see cref="ResetDirtyObject"/> which cleans up and removes the <see cref="NetworkObject"/> from the dirty list.
153+ /// </summary>
154+ /// <param name="networkObject">The <see cref="NetworkObject"/> to process.</param>
155+ /// <param name="forceSend">When enabled, any dirty network variables will be added to a
156+ /// <see cref="NetworkVariableDeltaMessage"/> and added to the outbound queue.</param>
106157 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
107158 internal void ProcessDirtyObject ( NetworkObject networkObject , bool forceSend )
108159 {
@@ -138,7 +189,7 @@ internal void ProcessDirtyObject(NetworkObject networkObject, bool forceSend)
138189 /// <summary>
139190 /// Sends NetworkVariable deltas
140191 /// </summary>
141- /// <param name="forceSend">internal only, when changing ownership we want to send this before the change in ownership message </param>
192+ /// <param name="forceSend"> Refer to the <see cref="ProcessDirtyObject(NetworkObject, bool)"/> definition. </param>
142193 internal void NetworkBehaviourUpdate ( bool forceSend = false )
143194 {
144195#if DEVELOPMENT_BUILD || UNITY_EDITOR
@@ -175,18 +226,20 @@ internal void Initialize(NetworkManager networkManager)
175226 {
176227 m_NetworkManager = networkManager ;
177228 m_ConnectionManager = networkManager . ConnectionManager ;
178- m_NetworkManager . NetworkTickSystem . Tick += NetworkBehaviourUpdater_Tick ;
229+ m_NetworkManager . NetworkTickSystem . Tick += OnNetworkTick ;
179230 }
180231
181232 internal void Shutdown ( )
182233 {
183- m_NetworkManager . NetworkTickSystem . Tick -= NetworkBehaviourUpdater_Tick ;
234+ m_NetworkManager . NetworkTickSystem . Tick -= OnNetworkTick ;
184235 }
185236
186- // Order of operations requires NetworkVariable updates first then showing NetworkObjects
187- private void NetworkBehaviourUpdater_Tick ( )
237+ /// <summary>
238+ /// Process any dirty <see cref="NetworkObject"/>s on each new
239+ /// network tick.
240+ /// </summary>
241+ private void OnNetworkTick ( )
188242 {
189- // Handle showing NetworkObjects on the next network tick, and only if we sent
190243 NetworkBehaviourUpdate ( ) ;
191244 }
192245 }
0 commit comments