Skip to content

Commit 69590ad

Browse files
committed
AnticipatedNetworkVariable corrected
1 parent 94f662c commit 69590ad

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44

55
namespace Unity.Netcode
66
{
7-
7+
/// <summary>
8+
/// Defines how anticipated network variables handle authoritative updates that are older than the current anticipated state
9+
/// </summary>
810
public enum StaleDataHandling
911
{
12+
/// <summary>
13+
/// Ignores authoritative updates that are older than the current anticipated state.
14+
/// The anticipated value will not be replaced until a newer authoritative update is received.
15+
/// </summary>
1016
Ignore,
17+
18+
/// <summary>
19+
/// Applies authoritative updates even if they are older than the current anticipated state.
20+
/// This triggers reanticipation to calculate a new anticipated value based on the authoritative state.
21+
/// </summary>
1122
Reanticipate
1223
}
1324

@@ -85,6 +96,12 @@ public class AnticipatedNetworkVariable<T> : NetworkVariableBase
8596
#pragma warning restore IDE0001
8697
public StaleDataHandling StaleDataHandling;
8798

99+
/// <summary>
100+
/// Delegate for handling changes in the authoritative value
101+
/// </summary>
102+
/// <param name="variable">The network variable that changed</param>
103+
/// <param name="previousValue">The previous value before the change</param>
104+
/// <param name="newValue">The new value after the change</param>
88105
public delegate void OnAuthoritativeValueChangedDelegate(AnticipatedNetworkVariable<T> variable, in T previousValue, in T newValue);
89106

90107
/// <summary>
@@ -121,6 +138,9 @@ public void ResetAnticipation()
121138

122139
private AnticipatedObject m_AnticipatedObject;
123140

141+
/// <summary>
142+
/// Initializes the network variable, setting up initial values and registering with the anticipation system
143+
/// </summary>
124144
public override void OnInitialize()
125145
{
126146
m_AuthoritativeValue.Initialize(m_NetworkBehaviour);
@@ -133,6 +153,10 @@ public override void OnInitialize()
133153
}
134154
}
135155

156+
/// <summary>
157+
/// Checks if the current value has changed enough from its last synchronized value to warrant a new network update
158+
/// </summary>
159+
/// <returns>True if the value should be synchronized, false otherwise</returns>
136160
public override bool ExceedsDirtinessThreshold()
137161
{
138162
return m_AuthoritativeValue.ExceedsDirtinessThreshold();
@@ -227,6 +251,10 @@ public T AuthoritativeValue
227251
/// See <see cref="Mathf.Lerp"/>, <see cref="Vector3.Lerp"/>, <see cref="Vector3.Slerp"/>, and so on
228252
/// for examples.
229253
/// </summary>
254+
/// <param name="authoritativeValue">The authoritative value to interpolate from</param>
255+
/// <param name="anticipatedValue">The anticipated value to interpolate to</param>
256+
/// <param name="amount">The interpolation factor between 0 and 1</param>
257+
/// <returns>The interpolated value</returns>
230258
public delegate T SmoothDelegate(T authoritativeValue, T anticipatedValue, float amount);
231259

232260
private SmoothDelegate m_SmoothDelegate = null;
@@ -242,6 +270,9 @@ public AnticipatedNetworkVariable(T value = default,
242270
};
243271
}
244272

273+
/// <summary>
274+
/// Updates the smooth interpolation state if active
275+
/// </summary>
245276
public void Update()
246277
{
247278
if (m_CurrentSmoothTime < m_SmoothDuration)
@@ -253,6 +284,9 @@ public void Update()
253284
}
254285
}
255286

287+
/// <summary>
288+
/// Releases all resources used by this network variable
289+
/// </summary>
256290
public override void Dispose()
257291
{
258292
if (m_IsDisposed)
@@ -357,33 +391,57 @@ public void Smooth(in T from, in T to, float durationSeconds, SmoothDelegate how
357391
m_HasSmoothValues = true;
358392
}
359393

394+
/// <summary>
395+
/// Checks if the variable has been modified since the last network synchronization
396+
/// </summary>
397+
/// <returns>True if the variable needs to be synchronized, false otherwise</returns>
360398
public override bool IsDirty()
361399
{
362400
return m_AuthoritativeValue.IsDirty();
363401
}
364402

403+
/// <summary>
404+
/// Resets the dirty state after network synchronization
405+
/// </summary>
365406
public override void ResetDirty()
366407
{
367408
m_AuthoritativeValue.ResetDirty();
368409
}
369410

411+
/// <summary>
412+
/// Writes only the changes in the variable's value to the network stream
413+
/// </summary>
414+
/// <param name="writer">Buffer to write the delta to</param>
370415
public override void WriteDelta(FastBufferWriter writer)
371416
{
372417
m_AuthoritativeValue.WriteDelta(writer);
373418
}
374419

420+
/// <summary>
421+
/// Writes the complete state of the variable to the network stream
422+
/// </summary>
423+
/// <param name="writer">Buffer to write the field to</param>
375424
public override void WriteField(FastBufferWriter writer)
376425
{
377426
m_AuthoritativeValue.WriteField(writer);
378427
}
379428

429+
/// <summary>
430+
/// Reads the complete state of the variable from the network stream
431+
/// </summary>
432+
/// <param name="reader">Buffer to read the field from</param>
380433
public override void ReadField(FastBufferReader reader)
381434
{
382435
m_AuthoritativeValue.ReadField(reader);
383436
NetworkVariableSerialization<T>.Duplicate(m_AuthoritativeValue.Value, ref m_AnticipatedValue);
384437
NetworkVariableSerialization<T>.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue);
385438
}
386439

440+
/// <summary>
441+
/// Reads changes in the variable's value from the network stream
442+
/// </summary>
443+
/// <param name="reader">Buffer to read the delta from</param>
444+
/// <param name="keepDirtyDelta">Whether to maintain the dirty state after reading</param>
387445
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
388446
{
389447
m_AuthoritativeValue.ReadDelta(reader, keepDirtyDelta);

pvpExceptions.json

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,7 @@
4545
"Unity.Netcode.CustomMessagingManager.HandleNamedMessageDelegate: missing <param name=\"messagePayload\">",
4646
"Unity.Netcode.GenerateSerializationForGenericParameterAttribute: .ctor(int): undocumented",
4747
"Unity.Netcode.GenerateSerializationForTypeAttribute: .ctor(Type): undocumented",
48-
"Unity.Netcode.StaleDataHandling: undocumented",
49-
"Unity.Netcode.StaleDataHandling: Ignore: undocumented",
50-
"Unity.Netcode.StaleDataHandling: Reanticipate: undocumented",
51-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void OnInitialize(): undocumented",
52-
"Unity.Netcode.AnticipatedNetworkVariable<T>: bool ExceedsDirtinessThreshold(): undocumented",
53-
"Unity.Netcode.AnticipatedNetworkVariable<T>: .ctor(T, StaleDataHandling): undocumented",
54-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void Update(): undocumented",
55-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void Dispose(): undocumented",
56-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void Finalize(): undocumented",
57-
"Unity.Netcode.AnticipatedNetworkVariable<T>: bool IsDirty(): undocumented",
58-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void ResetDirty(): undocumented",
59-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void WriteDelta(FastBufferWriter): undocumented",
60-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void WriteField(FastBufferWriter): undocumented",
61-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void ReadField(FastBufferReader): undocumented",
62-
"Unity.Netcode.AnticipatedNetworkVariable<T>: void ReadDelta(FastBufferReader, bool): undocumented",
63-
"Unity.Netcode.AnticipatedNetworkVariable<T>.OnAuthoritativeValueChangedDelegate: undocumented",
64-
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <param name=\"authoritativeValue\">",
65-
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <param name=\"anticipatedValue\">",
66-
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <param name=\"amount\">",
67-
"Unity.Netcode.AnticipatedNetworkVariable<T>.SmoothDelegate: missing <returns>",
48+
6849
"Unity.Netcode.NetworkList<T>: void Finalize(): undocumented",
6950
"Unity.Netcode.NetworkVariable<T>: CheckExceedsDirtinessThreshold: undocumented",
7051
"Unity.Netcode.NetworkVariable<T>: bool ExceedsDirtinessThreshold(): undocumented",

0 commit comments

Comments
 (0)