Skip to content

Commit 9b76a81

Browse files
committed
Added networktime
1 parent 384dfbd commit 9b76a81

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace MLAPI
1111
{
1212
public class NetworkingManager : MonoBehaviour
1313
{
14+
public static float NetworkTime;
1415
public bool DontDestroy = true;
1516
public bool RunInBackground = true;
1617
public List<GameObject> SpawnablePrefabs;
@@ -73,6 +74,7 @@ private void OnValidate()
7374
private ConnectionConfig Init(NetworkingConfiguration netConfig)
7475
{
7576
NetworkConfig = netConfig;
77+
NetworkTime = 0f;
7678
lastSendTickTime = 0;
7779
lastEventTickTime = 0;
7880
lastReceiveTickTime = 0;
@@ -388,6 +390,7 @@ private void Update()
388390
NetworkedObject.InvokeSyncvarUpdate();
389391
lastEventTickTime = Time.time;
390392
}
393+
NetworkTime += Time.deltaTime;
391394
}
392395
}
393396

@@ -545,6 +548,14 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
545548
{
546549
sceneIndex = messageReader.ReadUInt32();
547550
}
551+
552+
float netTime = messageReader.ReadSingle();
553+
int remoteStamp = messageReader.ReadInt32();
554+
int msDelay = NetworkTransport.GetRemoteDelayTimeMS(hostId, clientId, remoteStamp, out error);
555+
if ((NetworkError)error != NetworkError.Ok)
556+
msDelay = 0;
557+
NetworkTime = netTime + (msDelay / 1000f);
558+
548559
connectedClients.Add(MyClientId, new NetworkedClient() { ClientId = MyClientId });
549560
int clientCount = messageReader.ReadInt32();
550561
for (int i = 0; i < clientCount; i++)
@@ -1124,7 +1135,7 @@ private void HandleApproval(int clientId, bool approved)
11241135
}
11251136

11261137

1127-
int sizeOfStream = 4 + 4 + ((connectedClients.Count - 1) * 4);
1138+
int sizeOfStream = 16 + ((connectedClients.Count - 1) * 4);
11281139
int amountOfObjectsToSend = 0;
11291140
foreach (KeyValuePair<uint, NetworkedObject> pair in SpawnManager.spawnedObjects)
11301141
{
@@ -1136,8 +1147,7 @@ private void HandleApproval(int clientId, bool approved)
11361147
if(NetworkConfig.HandleObjectSpawning)
11371148
{
11381149
sizeOfStream += 4;
1139-
sizeOfStream += 13 * amountOfObjectsToSend;
1140-
sizeOfStream += amountOfObjectsToSend; //Bool isActive
1150+
sizeOfStream += 14 * amountOfObjectsToSend;
11411151
}
11421152
if(NetworkConfig.EnableSceneSwitching)
11431153
{
@@ -1153,6 +1163,8 @@ private void HandleApproval(int clientId, bool approved)
11531163
{
11541164
writer.Write(NetworkSceneManager.CurrentSceneIndex);
11551165
}
1166+
writer.Write(NetworkTime);
1167+
writer.Write(NetworkTransport.GetNetworkTimestamp());
11561168
writer.Write(connectedClients.Count - 1);
11571169
foreach (KeyValuePair<int, NetworkedClient> item in connectedClients)
11581170
{

0 commit comments

Comments
 (0)