Skip to content

Commit f791225

Browse files
committed
fix: moving the placeholder TickSystem more clearly out
1 parent 2328a4f commit f791225

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

com.unity.multiplayer.mlapi/Runtime/Core/NetworkedBehaviour.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@
2222

2323
namespace MLAPI
2424
{
25-
/// <summary>
26-
/// The base class to override to write networked code. Inherits MonoBehaviour
27-
/// </summary>
28-
public abstract class NetworkedBehaviour : MonoBehaviour
25+
// todo: This is temporary, to be replaced by the tick system
26+
static class TickSystem
2927
{
3028
// todo: this might belong in the tick system, in the end
3129
// special value to indicate "No tick information"
32-
private const ushort k_NoTick = 65535;
30+
public const ushort k_NoTick = 65535;
3331
// Number of ticks over which the tick number wraps back to 0
34-
private const ushort k_TickPeriod = 65000;
32+
public const ushort k_TickPeriod = 65000;
33+
34+
public static ushort GetTick()
35+
{
36+
return (ushort)(((long)(Time.time / 0.050)) % k_TickPeriod);
37+
}
38+
}
3539

40+
/// <summary>
41+
/// The base class to override to write networked code. Inherits MonoBehaviour
42+
/// </summary>
43+
public abstract class NetworkedBehaviour : MonoBehaviour
44+
{
3645
[Browsable(false)]
3746
[EditorBrowsable(EditorBrowsableState.Never)]
3847
#if UNITY_2020_2_OR_NEWER
@@ -533,7 +542,7 @@ internal void InitializeVars()
533542
internal static void NetworkedBehaviourUpdate()
534543
{
535544
// Don't NetworkedBehaviourUpdate more than once per network tick
536-
ushort tick = GetTick();
545+
ushort tick = TickSystem.GetTick();
537546
if (tick == currentTick)
538547
{
539548
return;
@@ -631,12 +640,6 @@ internal void VarUpdate(ulong clientId)
631640
private readonly List<int> networkedVarIndexesToReset = new List<int>();
632641
private readonly HashSet<int> networkedVarIndexesToResetSet = new HashSet<int>();
633642

634-
// todo: This is temporary, to be replaced by the tick system
635-
private static ushort GetTick()
636-
{
637-
return (ushort)(((long)(Time.time / 0.050)) % k_TickPeriod);
638-
}
639-
640643
private void NetworkedVarUpdate(ulong clientId)
641644
{
642645
if (!CouldHaveDirtyNetworkedVars())
@@ -870,7 +873,7 @@ internal static void HandleNetworkedVarUpdate(List<INetworkedVar> networkedVarLi
870873

871874
long readStartPos = stream.Position;
872875

873-
networkedVarList[i].ReadField(stream, k_NoTick, k_NoTick);
876+
networkedVarList[i].ReadField(stream, TickSystem.k_NoTick, TickSystem.k_NoTick);
874877
ProfilerStatManager.networkVarsRcvd.Record();
875878

876879
if (NetworkingManager.Singleton.NetworkConfig.EnsureNetworkedVarLengthSafety)

0 commit comments

Comments
 (0)