Fix time as double unity 2019 (#3279)

* NetworkServer - TimeAsDouble compatibility for Unity 2019

* NetworkStatistics - TimeAsDouble compatibility for Unity 2019

* Simplified - rely on defines in NetworkTime
This commit is contained in:
MrGadget 2022-11-27 07:35:05 -05:00 committed by GitHub
parent abd1c1689d
commit a86a115a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -182,16 +182,16 @@ void UpdateServer()
// only sync if client has authenticated on the server // only sync if client has authenticated on the server
if (!serverAuthenticated) return; if (!serverAuthenticated) return;
// double for long running servers // NetworkTime.localTime has defines for 2019 / 2020 compatibility
if (Time.timeAsDouble >= lastSendTime + sendInterval) if (NetworkTime.localTime >= lastSendTime + sendInterval)
{ {
lastSendTime = Time.timeAsDouble; lastSendTime = NetworkTime.localTime;
// target rpc to owner client // target rpc to owner client
TargetRpcSync(new Stats( TargetRpcSync(new Stats(
// general // general
NetworkServer.connections.Count, NetworkServer.connections.Count,
Time.realtimeSinceStartupAsDouble, NetworkTime.time,
NetworkServer.tickRate, NetworkServer.tickRate,
NetworkServer.actualTickRate, NetworkServer.actualTickRate,
@ -209,7 +209,6 @@ void UpdateServer()
)); ));
} }
} }
void UpdateClient() void UpdateClient()
{ {
if (Input.GetKeyDown(hotKey)) if (Input.GetKeyDown(hotKey))

View File

@ -1879,13 +1879,15 @@ internal static void NetworkLateUpdate()
if (active) if (active)
{ {
++actualTickRateCounter; ++actualTickRateCounter;
if (Time.timeAsDouble >= actualTickRateStart + 1)
// NetworkTime.localTime has defines for 2019 / 2020 compatibility
if (NetworkTime.localTime >= actualTickRateStart + 1)
{ {
// calculate avg by exact elapsed time. // calculate avg by exact elapsed time.
// assuming 1s wouldn't be accurate, usually a few more ms passed. // assuming 1s wouldn't be accurate, usually a few more ms passed.
float elapsed = (float)(Time.timeAsDouble - actualTickRateStart); float elapsed = (float)(NetworkTime.localTime - actualTickRateStart);
actualTickRate = Mathf.RoundToInt(actualTickRateCounter / elapsed); actualTickRate = Mathf.RoundToInt(actualTickRateCounter / elapsed);
actualTickRateStart = Time.timeAsDouble; actualTickRateStart = NetworkTime.localTime;
actualTickRateCounter = 0; actualTickRateCounter = 0;
} }