|
22 | 22 |
|
23 | 23 | namespace MLAPI |
24 | 24 | { |
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 |
29 | 27 | { |
30 | 28 | // todo: this might belong in the tick system, in the end |
31 | 29 | // special value to indicate "No tick information" |
32 | | - private const ushort k_NoTick = 65535; |
| 30 | + public const ushort k_NoTick = 65535; |
33 | 31 | // 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 | + } |
35 | 39 |
|
| 40 | + /// <summary> |
| 41 | + /// The base class to override to write networked code. Inherits MonoBehaviour |
| 42 | + /// </summary> |
| 43 | + public abstract class NetworkedBehaviour : MonoBehaviour |
| 44 | + { |
36 | 45 | [Browsable(false)] |
37 | 46 | [EditorBrowsable(EditorBrowsableState.Never)] |
38 | 47 | #if UNITY_2020_2_OR_NEWER |
@@ -533,7 +542,7 @@ internal void InitializeVars() |
533 | 542 | internal static void NetworkedBehaviourUpdate() |
534 | 543 | { |
535 | 544 | // Don't NetworkedBehaviourUpdate more than once per network tick |
536 | | - ushort tick = GetTick(); |
| 545 | + ushort tick = TickSystem.GetTick(); |
537 | 546 | if (tick == currentTick) |
538 | 547 | { |
539 | 548 | return; |
@@ -631,12 +640,6 @@ internal void VarUpdate(ulong clientId) |
631 | 640 | private readonly List<int> networkedVarIndexesToReset = new List<int>(); |
632 | 641 | private readonly HashSet<int> networkedVarIndexesToResetSet = new HashSet<int>(); |
633 | 642 |
|
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 | | - |
640 | 643 | private void NetworkedVarUpdate(ulong clientId) |
641 | 644 | { |
642 | 645 | if (!CouldHaveDirtyNetworkedVars()) |
@@ -870,7 +873,7 @@ internal static void HandleNetworkedVarUpdate(List<INetworkedVar> networkedVarLi |
870 | 873 |
|
871 | 874 | long readStartPos = stream.Position; |
872 | 875 |
|
873 | | - networkedVarList[i].ReadField(stream, k_NoTick, k_NoTick); |
| 876 | + networkedVarList[i].ReadField(stream, TickSystem.k_NoTick, TickSystem.k_NoTick); |
874 | 877 | ProfilerStatManager.networkVarsRcvd.Record(); |
875 | 878 |
|
876 | 879 | if (NetworkingManager.Singleton.NetworkConfig.EnsureNetworkedVarLengthSafety) |
|
0 commit comments