Revert "use NetworkTime.localTime for time sync"

This reverts commit a764cefce12268438aa72d1d685e1a06b75d6015.
This commit is contained in:
JohnCorby 2023-06-09 20:23:09 -07:00
parent a764cefce1
commit ce98cd8f28
2 changed files with 15 additions and 15 deletions

View File

@ -1,9 +1,8 @@
using Mirror;
using OWML.Common;
using QSB.Localization;
using QSB.Localization;
using QSB.Utility;
using QSB.WorldSync;
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
@ -61,13 +60,13 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
{
if (!QSBSceneManager.IsInUniverse)
{
DebugLog.ToConsole("Error - Tried to start time sync UI when not in universe!", MessageType.Error);
DebugLog.ToConsole("Error - Tried to start time sync UI when not in universe!", OWML.Common.MessageType.Error);
return;
}
_currentType = type;
_currentReason = reason;
_startTime = (float)NetworkTime.localTime;
_startTime = Time.timeSinceLevelLoad;
enabled = true;
_canvas.enabled = true;
Canvas.willRenderCanvases += OnWillRenderCanvases;
@ -113,7 +112,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
switch ((FastForwardReason)_currentReason)
{
case FastForwardReason.TooFarBehind:
var totalSeconds = Mathf.Max(TargetTime - (float)NetworkTime.localTime, 0f);
var totalSeconds = Mathf.Max(TargetTime - Time.timeSinceLevelLoad, 0f);
var minutes = Mathf.FloorToInt(totalSeconds / 60f);
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
var milliseconds = totalSeconds % 1 * 1000;
@ -131,7 +130,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
break;
case PauseReason.TooFarAhead:
var totalSeconds = Mathf.Max((float)NetworkTime.localTime - TargetTime, 0f);
var totalSeconds = Mathf.Max(Time.timeSinceLevelLoad - TargetTime, 0f);
var minutes = Mathf.FloorToInt(totalSeconds / 60f);
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
var milliseconds = totalSeconds % 1 * 1000;

View File

@ -8,6 +8,7 @@ using QSB.Messaging;
using QSB.Player;
using QSB.Player.Messages;
using QSB.TimeSync.Messages;
using QSB.TimeSync.Patches;
using QSB.Utility;
using QSB.WorldSync;
using System;
@ -65,7 +66,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
public float GetTimeDifference()
{
var myTime = (float)NetworkTime.localTime;
var myTime = Time.timeSinceLevelLoad;
return myTime - _serverTime;
}
@ -159,7 +160,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
return;
}
var myTime = (float)NetworkTime.localTime;
var myTime = Time.timeSinceLevelLoad;
var diff = myTime - _serverTime;
if (ServerStateManager.Instance.GetServerState() is not (ServerState.InSolarSystem or ServerState.InEye))
@ -193,7 +194,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
return;
}
DebugLog.DebugWrite($"START FASTFORWARD (Target:{_serverTime} Current:{(float)NetworkTime.localTime})", MessageType.Info);
DebugLog.DebugWrite($"START FASTFORWARD (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info);
if (Locator.GetActiveCamera() != null)
{
Locator.GetActiveCamera().enabled = false;
@ -217,7 +218,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
return;
}
DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{(float)NetworkTime.localTime})", MessageType.Info);
DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info);
Locator.GetActiveCamera().enabled = false;
//OWInput.ChangeInputMode(InputMode.None);
@ -271,7 +272,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
private void UpdateServer()
{
_serverTime = (float)NetworkTime.localTime;
_serverTime = Time.timeSinceLevelLoad;
if (ServerStateManager.Instance == null)
{
@ -345,7 +346,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
Locator.GetPlayerCamera().enabled = false;
}
var diff = _serverTime - (float)NetworkTime.localTime;
var diff = _serverTime - Time.timeSinceLevelLoad;
OWTime.SetTimeScale(Mathf.SmoothStep(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff));
TimeSyncUI.TargetTime = _serverTime;
@ -404,7 +405,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead)
{
if ((float)NetworkTime.localTime <= _serverTime)
if (Time.timeSinceLevelLoad <= _serverTime)
{
ResetTimeScale();
}
@ -412,7 +413,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind)
{
if ((float)NetworkTime.localTime >= _serverTime)
if (Time.timeSinceLevelLoad >= _serverTime)
{
ResetTimeScale();
}