protected override void Handle(SpeedPauseRequestCommand command) { // If we are not yet connected don't answer as we're not counted towards // the "number of required consenting clients" until we are done with loading if (!MultiplayerManager.Instance.IsConnected()) { return; } SpeedPauseHelper.PlayPauseRequest(command.SimulationPaused, command.SelectedSimulationSpeed, command.RequestId); }
protected override void Handle(SpeedPauseRequestCommand command) { // If we are a client but not yet connected, don't answer as we're not counted towards // the "number of required consenting clients" until we are done with loading if (MultiplayerManager.Instance.CurrentRole == MultiplayerRole.Client && MultiplayerManager.Instance.CurrentClient.Status != ClientStatus.Connected) { return; } SpeedPauseHelper.PlayPauseRequest(command.SimulationPaused, command.SelectedSimulationSpeed, command.RequestId); }
protected override void Handle(SpeedPauseReachedCommand command) { if (command.RequestId == _currentWaitingId) { _numberOfClients++; if (_numberOfClients == _maxNumberOfClients) { SpeedPauseHelper.StateReached(); _currentWaitingId = -1; } } }
private void ResetData() { // Pause simulation on game load and reset cached speed and pause states SpeedPauseHelper.ResetSpeedAndPauseState(); // Reset waiting id as the last speed/pause request is no longer valid SpeedPauseResponseHandler.ResetWaitingId(); // Don't handle dropped frames from before the map was loaded SlowdownHelper.ClearDropFrames(); SlowdownHelper.ClearLocalDropFrames(); // TODO: Check if we need to reset more caches }
public override void OnBeforeSimulationTick() { base.OnBeforeSimulationTick(); // Normally, the game is paused when the player is in Esc or similar menus. We ignore this setting. if (SimulationManager.instance.ForcedSimulationPaused && MultiplayerManager.Instance.CurrentRole != MultiplayerRole.None) { SimulationManager.instance.ForcedSimulationPaused = false; } // Process changes in the pause state and game speed SpeedPauseHelper.SimulationStep(); // Process events of the network lib MultiplayerManager.Instance.ProcessEvents(); }
protected override void Handle(SpeedPauseResponseCommand command) { int requestId = command.RequestId; // Use highest request id in case of conflicting requests if (requestId < _currentWaitingId) { return; } // If the new id is new, reset all other values if (requestId != _currentWaitingId) { ResetValues(); } _currentWaitingId = requestId; if (command.NumberOfClients != -1) { _maxNumberOfClients = command.NumberOfClients; } if (command.MaxLatency != -1 && command.MaxLatency > _highestLatency) { _highestLatency = command.MaxLatency; } if (command.CurrentTime > _highestTime) { _highestTime = command.CurrentTime; } _numberOfClients++; // Check if all clients have answered if (_numberOfClients == _maxNumberOfClients) { SpeedPauseHelper.SpeedPauseResponseReceived(_highestTime, _highestLatency); // Set waiting target for the SpeedPauseReachedCommand SpeedPauseReachedHandler.SetWaitingFor(_currentWaitingId, _maxNumberOfClients); // Reset waiting id _currentWaitingId = -1; } }
protected override void Handle(SpeedPauseReachedCommand command) { if (command.RequestId == _currentWaitingId) { _numberOfClients++; if (_numberOfClients == _maxNumberOfClients) { SpeedPauseHelper.StateReached(); _currentWaitingId = -1; // Allow the response handler to process new requests // We need to wait until now because responses of conflicting requests // could arrive during the waiting phase, but need to be discarded. SpeedPauseResponseHandler.ResetWaitingId(); } } }
public override void OnBeforeSimulationTick() { base.OnBeforeSimulationTick(); // Make sure the games stays paused when blocked (e.g. when another player is joining) if (_lastSimulationPausedState != SimulationManager.instance.SimulationPaused && MultiplayerManager.Instance.GameBlocked) { SimulationManager.instance.SimulationPaused = true; } // Normally, the game is paused when the player is in Esc or similar menus. We ignore this setting. if (SimulationManager.instance.ForcedSimulationPaused && MultiplayerManager.Instance.CurrentRole != MultiplayerRole.None) { SimulationManager.instance.ForcedSimulationPaused = false; } // First tick in the game, initialize speed and pause state tracking variables if (_lastSelectedSimulationSpeed == -1) { _lastSelectedSimulationSpeed = SimulationManager.instance.SelectedSimulationSpeed; _lastSimulationPausedState = SimulationManager.instance.SimulationPaused; SpeedPauseHelper.Initialize(_lastSimulationPausedState, _lastSelectedSimulationSpeed); } // Check if speed or pause state have changed if (_lastSelectedSimulationSpeed != SimulationManager.instance.SelectedSimulationSpeed || _lastSimulationPausedState != SimulationManager.instance.SimulationPaused) { SpeedPauseHelper.PlayPauseSpeedChanged(SimulationManager.instance.SimulationPaused, SimulationManager.instance.SelectedSimulationSpeed); // Temporarily reset to old value while waiting for a changed state SimulationManager.instance.SimulationPaused = _lastSimulationPausedState; SimulationManager.instance.SelectedSimulationSpeed = _lastSelectedSimulationSpeed; } // Update play/pause state if needed SpeedPauseHelper.ChangePauseStateIfNeeded(); _lastSimulationPausedState = SimulationManager.instance.SimulationPaused; _lastSelectedSimulationSpeed = SimulationManager.instance.SelectedSimulationSpeed; MultiplayerManager.Instance.ProcessEvents(); }
public static void PrepareWorldLoad(Player newPlayer) { newPlayer.Status = ClientStatus.Downloading; MultiplayerManager.Instance.BlockGame(newPlayer.Username); // Inform other clients about the joining client Command.SendToOtherClients(new ClientJoiningCommand { JoiningFinished = false, JoiningUsername = newPlayer.Username }, newPlayer); WorldLoadingPlayer = newPlayer; // If the game is already paused, continue with the load process. // Otherwise we wait until the pause negotiation is done. // Note that a joining (+syncing) player is not considered during this process, but already force paused at this point. // See SpeedPauseHelper::StateReached() if (SimulationManager.instance.SimulationPaused && SpeedPauseHelper.IsStable()) { AllGamesBlocked(); } }
protected override void Handle(SpeedPauseRequestCommand command) { SpeedPauseHelper.PlayPauseRequest(command.SimulationPaused, command.SelectedSimulationSpeed, command.RequestId); }