Skip to content

Commit 3632b94

Browse files
committed
fix: no singletons, extra doc
1 parent e78da7d commit 3632b94

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
namespace MLAPI
55
{
6+
// todo: This is a pretty minimal tick system. It will be improved in the future
7+
// It currently relies on Time.unscaledTime and, as such, will start suffering
8+
// numerical precision issues after 2^23 ticks have passed (float have 23 bits mantissa)
9+
// For future releases, we'll need to improve on this, probably by leveraging FixedUpdate
10+
611
public class NetworkTickSystem : INetworkUpdateSystem, IDisposable
712
{
813
private const float k_DefaultTickIntervalSec = 1/60f; // Defaults to 60 ticks second
@@ -16,24 +21,12 @@ public class NetworkTickSystem : INetworkUpdateSystem, IDisposable
1621
// Number of ticks over which the tick number wraps back to 0
1722
public const ushort k_TickPeriod = k_NoTick - 1;
1823

19-
public static NetworkTickSystem Instance
20-
{
21-
get
22-
{
23-
if (m_Instance == null)
24-
{
25-
m_Instance = new NetworkTickSystem();
26-
}
27-
return m_Instance;
28-
}
29-
}
30-
3124
/// <summary>
3225
/// Constructor
3326
/// Defaults to k_DefaultTickIntervalSec if no tick duration is specified
3427
/// </summary>
3528
/// <param name="tickIntervalSec">Duration of a network tick</param>
36-
private NetworkTickSystem(float tickIntervalSec = k_DefaultTickIntervalSec)
29+
public NetworkTickSystem(float tickIntervalSec = k_DefaultTickIntervalSec)
3730
{
3831
this.RegisterNetworkUpdate(NetworkUpdateStage.EarlyUpdate);
3932

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class NetworkingManager : MonoBehaviour, INetworkUpdateSystem
7171
static ProfilerMarker s_InvokeRPC = new ProfilerMarker("InvokeRPC");
7272
#endif
7373
internal RpcQueueContainer rpcQueueContainer { get; private set; }
74+
internal NetworkTickSystem networkTickSystem { get; private set; }
7475

7576
/// <summary>
7677
/// A synchronized time, represents the time in seconds since the server application started. Is replicated across all clients
@@ -383,6 +384,12 @@ private void Init(bool server)
383384
return;
384385
}
385386

387+
//This 'if' should never enter
388+
if (networkTickSystem != null)
389+
{
390+
networkTickSystem.Dispose();
391+
}
392+
networkTickSystem = new NetworkTickSystem();
386393

387394
//This should never happen, but in the event that it does there should be (at a minimum) a unity error logged.
388395
if(rpcQueueContainer != null)
@@ -698,6 +705,12 @@ public void Shutdown()
698705
rpcQueueContainer = null;
699706
}
700707

708+
if (networkTickSystem != null)
709+
{
710+
networkTickSystem.Dispose();
711+
}
712+
networkTickSystem = null;
713+
701714
NetworkProfiler.Stop();
702715
IsListening = false;
703716
IsServer = false;

0 commit comments

Comments
 (0)