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

View File

@ -1879,13 +1879,15 @@ internal static void NetworkLateUpdate()
if (active)
{
++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.
// assuming 1s wouldn't be accurate, usually a few more ms passed.
float elapsed = (float)(Time.timeAsDouble - actualTickRateStart);
actualTickRate = Mathf.RoundToInt(actualTickRateCounter / elapsed);
actualTickRateStart = Time.timeAsDouble;
float elapsed = (float)(NetworkTime.localTime - actualTickRateStart);
actualTickRate = Mathf.RoundToInt(actualTickRateCounter / elapsed);
actualTickRateStart = NetworkTime.localTime;
actualTickRateCounter = 0;
}