private void CheckTimeDifference() { var diff = GetTimeDifference(); if (diff is > PauseOrFastForwardThreshold or < (-PauseOrFastForwardThreshold)) { WakeUpOrSleep(); return; } var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds, true); if (mappedTimescale > 100f) { DebugLog.ToConsole($"Warning - CheckTimeDifference() returned over 100 - should have switched into fast-forward!", MessageType.Warning); mappedTimescale = 0f; } if (mappedTimescale < 0) { DebugLog.ToConsole($"Warning - CheckTimeDifference() returned below 0 - should have switched into pausing!", MessageType.Warning); mappedTimescale = 0f; } OWTime.SetTimeScale(mappedTimescale); }
private void CheckTimeDifference() { var diff = GetTimeDifference(); if (diff > PauseOrFastForwardThreshold || diff < -PauseOrFastForwardThreshold) { WakeUpOrSleep(); } var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds); OWTime.SetTimeScale(mappedTimescale); }
private void StartPausing() { if (_state == State.Pausing) { return; } DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info); Locator.GetActiveCamera().enabled = false; OWTime.SetTimeScale(0f); _state = State.Pausing; SpinnerUI.Show(); TimeSyncUI.Start(TimeSyncType.Pausing); }
public void OnDisconnect() { OWTime.SetTimeScale(1f); OWTime.SetMaxDeltaTime(0.06666667f); OWTime.SetFixedTimestep(0.01666667f); Locator.GetActiveCamera().enabled = true; CurrentState = State.NotLoaded; CurrentReason = null; Physics.SyncTransforms(); SpinnerUI.Hide(); TimeSyncUI.Stop(); QSBInputManager.Instance.SetInputsEnabled(true); }
private void ResetTimeScale() { OWTime.SetTimeScale(1f); OWTime.SetMaxDeltaTime(0.06666667f); OWTime.SetFixedTimestep(0.01666667f); Locator.GetActiveCamera().enabled = true; _state = State.Loaded; DebugLog.DebugWrite($"RESET TIMESCALE", MessageType.Info); _isFirstFastForward = false; QSBCore.HasWokenUp = true; Physics.SyncTransforms(); SpinnerUI.Hide(); TimeSyncUI.Stop(); QSBEventManager.FireEvent(EventNames.QSBPlayerStatesRequest); RespawnOnDeath.Instance.Init(); }
private void StartPausing(PauseReason reason) { if (CurrentState == State.Pausing) { TimeSyncUI.TargetTime = _serverTime; return; } DebugLog.DebugWrite($"START PAUSING (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})", MessageType.Info); Locator.GetActiveCamera().enabled = false; //OWInput.ChangeInputMode(InputMode.None); QSBInputManager.Instance.SetInputsEnabled(false); OWTime.SetTimeScale(0f); CurrentState = State.Pausing; CurrentReason = reason; SpinnerUI.Show(); TimeSyncUI.TargetTime = _serverTime; TimeSyncUI.Start(TimeSyncType.Pausing, reason); }
private void UpdateLocal() { _serverTime += Time.unscaledDeltaTime; if (_state == State.NotLoaded) { return; } if (_state == State.FastForwarding) { if (Locator.GetPlayerCamera() != null && !Locator.GetPlayerCamera().enabled) { Locator.GetPlayerCamera().enabled = false; } var diff = _serverTime - Time.timeSinceLevelLoad; OWTime.SetTimeScale(Mathf.SmoothStep(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff)); if (QSBSceneManager.CurrentScene == OWScene.SolarSystem && _isFirstFastForward) { var spawnPoint = Locator.GetPlayerBody().GetComponent <PlayerSpawner>().GetInitialSpawnPoint().transform; Locator.GetPlayerTransform().position = spawnPoint.position; Locator.GetPlayerTransform().rotation = spawnPoint.rotation; Physics.SyncTransforms(); } } var isDoneFastForwarding = _state == State.FastForwarding && Time.timeSinceLevelLoad >= _serverTime; var isDonePausing = _state == State.Pausing && Time.timeSinceLevelLoad < _serverTime; if (isDoneFastForwarding || isDonePausing) { ResetTimeScale(); } if (_state == State.Loaded) { CheckTimeDifference(); } }
private void ResetTimeScale() { OWTime.SetTimeScale(1f); OWTime.SetMaxDeltaTime(0.06666667f); OWTime.SetFixedTimestep(0.01666667f); Locator.GetActiveCamera().enabled = true; CurrentState = State.Loaded; CurrentReason = null; DebugLog.DebugWrite($"RESET TIMESCALE", MessageType.Info); Physics.SyncTransforms(); SpinnerUI.Hide(); TimeSyncUI.Stop(); new RequestStateResyncMessage().Send(); RespawnOnDeath.Instance.Init(); QSBInputManager.Instance.SetInputsEnabled(true); if (!_hasWokenUp) { WakeUp(); } }
private void UpdateClient() { _serverTime += Time.unscaledDeltaTime; var serverState = ServerStateManager.Instance.GetServerState(); var clientState = QSBPlayerManager.LocalPlayer.State; var currentScene = QSBSceneManager.CurrentScene; // set fastforwarding timescale if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind) { if (Locator.GetPlayerCamera() != null && !Locator.GetPlayerCamera().enabled) { Locator.GetPlayerCamera().enabled = false; } var diff = _serverTime - Time.timeSinceLevelLoad; OWTime.SetTimeScale(Mathf.SmoothStep(MinFastForwardSpeed, MaxFastForwardSpeed, Mathf.Abs(diff) / MaxFastForwardDiff)); TimeSyncUI.TargetTime = _serverTime; } if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead) { TimeSyncUI.TargetTime = _serverTime; } if (CurrentState != State.Loaded && CurrentState != State.NotLoaded && CurrentReason == null) { DebugLog.ToConsole($"Warning - CurrentReason is null.", MessageType.Warning); } // Checks to pause/fastforward if (clientState is ClientState.NotLoaded or ClientState.InTitleScreen) { return; } if (serverState == ServerState.NotLoaded && CurrentState != State.Pausing && QSBSceneManager.IsInUniverse) { StartPausing(PauseReason.ServerNotStarted); } if (serverState == ServerState.WaitingForAllPlayersToReady && CurrentState != State.Pausing && clientState == ClientState.WaitingForOthersToBeReady) { StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } if (serverState == ServerState.WaitingForAllPlayersToDie && clientState == ClientState.WaitingForOthersToBeReady) { StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } // Checks to revert to normal if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.ServerNotStarted) { if (serverState != ServerState.NotLoaded) { ResetTimeScale(); } } if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.WaitingForAllPlayersToBeReady) { if (clientState == ClientState.AliveInSolarSystem && serverState == ServerState.InSolarSystem) { ResetTimeScale(); } } if (CurrentState == State.Pausing && (PauseReason)CurrentReason == PauseReason.TooFarAhead) { if (Time.timeSinceLevelLoad <= _serverTime) { ResetTimeScale(); } } if (CurrentState == State.FastForwarding && (FastForwardReason)CurrentReason == FastForwardReason.TooFarBehind) { if (Time.timeSinceLevelLoad >= _serverTime) { ResetTimeScale(); } } if (CurrentState == State.Loaded) { CheckTimeDifference(); } }