Skip to content

Commit

Permalink
moving Time back to Server/Client
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 25, 2021
1 parent a4260fc commit ba048f5
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions Assets/Mirage/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg)
identity.NetId = msg.netId;
identity.Client = Client;
identity.ClientObjectManager = this;
identity.World = Client.World;

if (msg.isLocalPlayer)
InternalAddPlayer(identity);
Expand Down
2 changes: 2 additions & 0 deletions Assets/Mirage/Runtime/INetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public interface INetworkServer
/// </summary>
bool Active { get; }

NetworkTime Time { get; }

NetworkWorld World { get; }

IReadOnlyCollection<INetworkPlayer> Players { get; }
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public abstract class NetworkBehaviour : MonoBehaviour
public INetworkPlayer ConnectionToClient => NetIdentity.ConnectionToClient;


public NetworkWorld NetworkWorld => NetIdentity.NetworkWorld;
public NetworkWorld World => NetIdentity.World;

/// <summary>
/// Returns the appropriate NetworkTime instance based on if this NetworkBehaviour is running as a Server or Client.
/// </summary>
public NetworkTime NetworkTime => NetworkWorld.Time;
public NetworkTime NetworkTime => IsClient ? Client.Time : Server.Time;

protected internal ulong SyncVarDirtyBits { get; private set; }
ulong syncVarHookGuard;
Expand Down
5 changes: 3 additions & 2 deletions Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class NetworkClient : MonoBehaviour, INetworkClient
/// <summary>
/// Time kept in this client
/// </summary>
public NetworkTime Time => World.Time;
public NetworkTime Time { get; } = new NetworkTime();

public NetworkWorld World { get; private set; }

Expand Down Expand Up @@ -156,9 +156,10 @@ public async UniTask ConnectAsync(Uri uri)
Time.UpdateClient(this);
OnConnected().Forget();
}
finally
catch (Exception e)
{
connectState = ConnectState.Disconnected;
throw;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public sealed class NetworkIdentity : MonoBehaviour
/// <summary>
/// The world this object exists in
/// </summary>
public NetworkWorld NetworkWorld;
public NetworkWorld World { get; internal set; }

/// <summary>
/// The ServerObjectManager is present only for server/host instances.
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class NetworkServer : MonoBehaviour, INetworkServer
/// <summary>
/// Time kept in this server
/// </summary>
public NetworkTime Time => World.Time;
public NetworkTime Time { get; } = new NetworkTime();

public NetworkWorld World { get; private set; }

Expand Down
2 changes: 0 additions & 2 deletions Assets/Mirage/Runtime/NetworkWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ internal void ClearSpawnedObjects()
}

public NetworkPlayer LocalPlayer { get; private set; }
public NetworkTime Time { get; }

public INetworkServer Server { get; }
public INetworkClient Client { get; }

public NetworkWorld(INetworkServer server, INetworkClient client)
{
Time = new NetworkTime();
Server = server;
Client = client;
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Mirage/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ internal void SpawnObject(GameObject obj, INetworkPlayer ownerPlayer)
identity.ConnectionToClient = ownerPlayer;
identity.Server = Server;
identity.ServerObjectManager = this;
identity.World = Server.World;
identity.Client = Server.LocalClient;

// special case to make sure hasAuthority is set
Expand Down

0 comments on commit ba048f5

Please sign in to comment.