mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-06 00:39:55 +00:00
use NetworkTime.localTime for time sync
This commit is contained in:
parent
05d5116695
commit
a764cefce1
@ -1,8 +1,9 @@
|
||||
using QSB.Localization;
|
||||
using Mirror;
|
||||
using OWML.Common;
|
||||
using QSB.Localization;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -60,13 +61,13 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Tried to start time sync UI when not in universe!", OWML.Common.MessageType.Error);
|
||||
DebugLog.ToConsole("Error - Tried to start time sync UI when not in universe!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_currentType = type;
|
||||
_currentReason = reason;
|
||||
_startTime = Time.timeSinceLevelLoad;
|
||||
_startTime = (float)NetworkTime.localTime;
|
||||
enabled = true;
|
||||
_canvas.enabled = true;
|
||||
Canvas.willRenderCanvases += OnWillRenderCanvases;
|
||||
@ -112,7 +113,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
||||
switch ((FastForwardReason)_currentReason)
|
||||
{
|
||||
case FastForwardReason.TooFarBehind:
|
||||
var totalSeconds = Mathf.Max(TargetTime - Time.timeSinceLevelLoad, 0f);
|
||||
var totalSeconds = Mathf.Max(TargetTime - (float)NetworkTime.localTime, 0f);
|
||||
var minutes = Mathf.FloorToInt(totalSeconds / 60f);
|
||||
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
||||
var milliseconds = totalSeconds % 1 * 1000;
|
||||
@ -130,7 +131,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
||||
break;
|
||||
|
||||
case PauseReason.TooFarAhead:
|
||||
var totalSeconds = Mathf.Max(Time.timeSinceLevelLoad - TargetTime, 0f);
|
||||
var totalSeconds = Mathf.Max((float)NetworkTime.localTime - TargetTime, 0f);
|
||||
var minutes = Mathf.FloorToInt(totalSeconds / 60f);
|
||||
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
||||
var milliseconds = totalSeconds % 1 * 1000;
|
||||
|
@ -8,7 +8,6 @@ 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;
|
||||
@ -66,7 +65,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
public float GetTimeDifference()
|
||||
{
|
||||
var myTime = Time.timeSinceLevelLoad;
|
||||
var myTime = (float)NetworkTime.localTime;
|
||||
return myTime - _serverTime;
|
||||
}
|
||||
|
||||
@ -160,7 +159,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
return;
|
||||
}
|
||||
|
||||
var myTime = Time.timeSinceLevelLoad;
|
||||
var myTime = (float)NetworkTime.localTime;
|
||||
var diff = myTime - _serverTime;
|
||||
|
||||
if (ServerStateManager.Instance.GetServerState() is not (ServerState.InSolarSystem or ServerState.InEye))
|
||||
@ -194,7 +193,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"START FASTFORWARD (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info);
|
||||
DebugLog.DebugWrite($"START FASTFORWARD (Target:{_serverTime} Current:{(float)NetworkTime.localTime})", MessageType.Info);
|
||||
if (Locator.GetActiveCamera() != null)
|
||||
{
|
||||
Locator.GetActiveCamera().enabled = false;
|
||||
@ -218,7 +217,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info);
|
||||
DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{(float)NetworkTime.localTime})", MessageType.Info);
|
||||
Locator.GetActiveCamera().enabled = false;
|
||||
|
||||
//OWInput.ChangeInputMode(InputMode.None);
|
||||
@ -272,7 +271,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
private void UpdateServer()
|
||||
{
|
||||
_serverTime = Time.timeSinceLevelLoad;
|
||||
_serverTime = (float)NetworkTime.localTime;
|
||||
|
||||
if (ServerStateManager.Instance == null)
|
||||
{
|
||||
@ -346,7 +345,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
Locator.GetPlayerCamera().enabled = false;
|
||||
}
|
||||
|
||||
var diff = _serverTime - Time.timeSinceLevelLoad;
|
||||
var diff = _serverTime - (float)NetworkTime.localTime;
|
||||
OWTime.SetTimeScale(Mathf.SmoothStep(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff));
|
||||
|
||||
TimeSyncUI.TargetTime = _serverTime;
|
||||
@ -405,7 +404,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead)
|
||||
{
|
||||
if (Time.timeSinceLevelLoad <= _serverTime)
|
||||
if ((float)NetworkTime.localTime <= _serverTime)
|
||||
{
|
||||
ResetTimeScale();
|
||||
}
|
||||
@ -413,7 +412,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind)
|
||||
{
|
||||
if (Time.timeSinceLevelLoad >= _serverTime)
|
||||
if ((float)NetworkTime.localTime >= _serverTime)
|
||||
{
|
||||
ResetTimeScale();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user