mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-14 06:40:41 +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.Utility;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@ -60,13 +61,13 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
|||||||
{
|
{
|
||||||
if (!QSBSceneManager.IsInUniverse)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentType = type;
|
_currentType = type;
|
||||||
_currentReason = reason;
|
_currentReason = reason;
|
||||||
_startTime = Time.timeSinceLevelLoad;
|
_startTime = (float)NetworkTime.localTime;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
_canvas.enabled = true;
|
_canvas.enabled = true;
|
||||||
Canvas.willRenderCanvases += OnWillRenderCanvases;
|
Canvas.willRenderCanvases += OnWillRenderCanvases;
|
||||||
@ -112,7 +113,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
|||||||
switch ((FastForwardReason)_currentReason)
|
switch ((FastForwardReason)_currentReason)
|
||||||
{
|
{
|
||||||
case FastForwardReason.TooFarBehind:
|
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 minutes = Mathf.FloorToInt(totalSeconds / 60f);
|
||||||
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
||||||
var milliseconds = totalSeconds % 1 * 1000;
|
var milliseconds = totalSeconds % 1 * 1000;
|
||||||
@ -130,7 +131,7 @@ internal class TimeSyncUI : MonoBehaviour, IAddComponentOnStart
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PauseReason.TooFarAhead:
|
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 minutes = Mathf.FloorToInt(totalSeconds / 60f);
|
||||||
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
var seconds = Mathf.FloorToInt(totalSeconds) % 60;
|
||||||
var milliseconds = totalSeconds % 1 * 1000;
|
var milliseconds = totalSeconds % 1 * 1000;
|
||||||
|
@ -8,7 +8,6 @@ using QSB.Messaging;
|
|||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.Player.Messages;
|
using QSB.Player.Messages;
|
||||||
using QSB.TimeSync.Messages;
|
using QSB.TimeSync.Messages;
|
||||||
using QSB.TimeSync.Patches;
|
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
using System;
|
using System;
|
||||||
@ -66,7 +65,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
|
|
||||||
public float GetTimeDifference()
|
public float GetTimeDifference()
|
||||||
{
|
{
|
||||||
var myTime = Time.timeSinceLevelLoad;
|
var myTime = (float)NetworkTime.localTime;
|
||||||
return myTime - _serverTime;
|
return myTime - _serverTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +159,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var myTime = Time.timeSinceLevelLoad;
|
var myTime = (float)NetworkTime.localTime;
|
||||||
var diff = myTime - _serverTime;
|
var diff = myTime - _serverTime;
|
||||||
|
|
||||||
if (ServerStateManager.Instance.GetServerState() is not (ServerState.InSolarSystem or ServerState.InEye))
|
if (ServerStateManager.Instance.GetServerState() is not (ServerState.InSolarSystem or ServerState.InEye))
|
||||||
@ -194,7 +193,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
return;
|
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)
|
if (Locator.GetActiveCamera() != null)
|
||||||
{
|
{
|
||||||
Locator.GetActiveCamera().enabled = false;
|
Locator.GetActiveCamera().enabled = false;
|
||||||
@ -218,7 +217,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
return;
|
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;
|
Locator.GetActiveCamera().enabled = false;
|
||||||
|
|
||||||
//OWInput.ChangeInputMode(InputMode.None);
|
//OWInput.ChangeInputMode(InputMode.None);
|
||||||
@ -272,7 +271,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
|
|
||||||
private void UpdateServer()
|
private void UpdateServer()
|
||||||
{
|
{
|
||||||
_serverTime = Time.timeSinceLevelLoad;
|
_serverTime = (float)NetworkTime.localTime;
|
||||||
|
|
||||||
if (ServerStateManager.Instance == null)
|
if (ServerStateManager.Instance == null)
|
||||||
{
|
{
|
||||||
@ -346,7 +345,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
Locator.GetPlayerCamera().enabled = false;
|
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));
|
OWTime.SetTimeScale(Mathf.SmoothStep(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff));
|
||||||
|
|
||||||
TimeSyncUI.TargetTime = _serverTime;
|
TimeSyncUI.TargetTime = _serverTime;
|
||||||
@ -405,7 +404,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
|
|
||||||
if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead)
|
if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead)
|
||||||
{
|
{
|
||||||
if (Time.timeSinceLevelLoad <= _serverTime)
|
if ((float)NetworkTime.localTime <= _serverTime)
|
||||||
{
|
{
|
||||||
ResetTimeScale();
|
ResetTimeScale();
|
||||||
}
|
}
|
||||||
@ -413,7 +412,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart
|
|||||||
|
|
||||||
if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind)
|
if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind)
|
||||||
{
|
{
|
||||||
if (Time.timeSinceLevelLoad >= _serverTime)
|
if ((float)NetworkTime.localTime >= _serverTime)
|
||||||
{
|
{
|
||||||
ResetTimeScale();
|
ResetTimeScale();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user