Skip to content

Commit bd081fd

Browse files
committed
Make the default local update rate for NetworkedVars the global update rate
Prevent possibility of duplicate sends across the network by only sending when the NetworkedVars value actually changes. Rename SendDelay to SendTickrate. This unifies the naming convention of the local update rate for NetworkedVar with the global update rate.
1 parent c3272ee commit bd081fd

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

MLAPI/Data/NetworkedCollections/NetworkedDictionary.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ public bool CanClientRead(uint clientId)
221221
public bool IsDirty()
222222
{
223223
if (dirtyEvents.Count == 0) return false;
224-
if (Settings.SendOnChange) return true;
225-
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendDelay) return true;
224+
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendTickrate) return true;
226225
return false;
227226
}
228227

MLAPI/Data/NetworkedCollections/NetworkedList.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public void ResetDirty()
5151
public bool IsDirty()
5252
{
5353
if (dirtyEvents.Count == 0) return false;
54-
if (Settings.SendOnChange) return true;
55-
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendDelay) return true;
54+
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendTickrate) return true;
5655
return false;
5756
}
5857

MLAPI/Data/NetworkedVar.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using MLAPI.NetworkingManagerComponents.Binary;
22
using MLAPI.MonoBehaviours.Core;
33
using MLAPI.NetworkingManagerComponents.Core;
4+
using System;
5+
using System.Collections.Generic;
46

57
namespace MLAPI.Data
68
{
@@ -49,8 +51,11 @@ public T Value
4951
}
5052
set
5153
{
52-
isDirty = true;
53-
InternalValue = value;
54+
if (!EqualityComparer<T>.Default.Equals(InternalValue, value))
55+
{
56+
isDirty = true;
57+
InternalValue = value;
58+
}
5459
}
5560
}
5661

@@ -65,8 +70,7 @@ public void ResetDirty()
6570
public bool IsDirty()
6671
{
6772
if (!isDirty) return false;
68-
if (Settings.SendOnChange) return true;
69-
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendDelay) return true;
73+
if (NetworkingManager.singleton.NetworkTime - LastSyncedTime >= Settings.SendTickrate) return true;
7074
return false;
7175
}
7276

MLAPI/Data/NetworkedVarMeta.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MLAPI.Data.Transports;
2+
using MLAPI.MonoBehaviours.Core;
23

34
namespace MLAPI.Data
45
{
@@ -24,13 +25,9 @@ public class NetworkedVarSettings
2425
/// </summary>
2526
public NetworkedVarPermissionsDelegate ReadPermissionCallback = null;
2627
/// <summary>
27-
/// If enabled, sends will be sent the as fast as possible. If disabled, the sendDelay will be used
28-
/// </summary>
29-
public bool SendOnChange = false;
30-
/// <summary>
3128
/// The minimum amount of delay in seconds between sends
3229
/// </summary>
33-
public float SendDelay = 0.1f;
30+
public float SendTickrate = NetworkingManager.singleton.NetworkConfig.SendTickrate;
3431
/// <summary>
3532
/// The name of the channel to use for this variable.
3633
/// Variables with different channels will be split into different packets

0 commit comments

Comments
 (0)