public void Halt() { _logger.LogInformation($"Halting Timer"); _autoEvent.WaitOne(); if (!CanHaltTimer()) { _logger.LogInformation($"Failed to halt timer: {Enum.GetName(typeof(MatchTimerState), Status.State)}"); _autoEvent.Set(); return; } Status.State = MatchTimerState.Halting; _timer.Change(Timeout.Infinite, 1000); _isRunning = false; _secondsRemaining = Status.ForceZeroRemaining(); _secondsElapsed = Status.ForceMaxElapsed(); Status.State = MatchTimerState.Stopped; var message = new MatchTimerTickMessage(Status); // TODO: use both to make MatchTimer razor component self-contained? //OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); _messageService.BroadcastMatchTimerTickMessage(message); // TODO: broadcast a "MatchStateChange" of event of type "Round Ended" here _logger.LogInformation($"Timer Halted"); _autoEvent.Set(); }
public async Task ResetRound() { if (_currentRound == 0) { return; } _timer.Reset(); _wsMonitor.DisableScoring(); await _teamsManager.RollBackAllTeamStats(_currentRound); await _matchDataService.RemoveMatchRoundConfiguration(_currentRound); _currentRound -= 1; if (_currentRound == 0) { _matchState = MatchState.Uninitialized; _latestTimerTickMessage = null; } _matchDataService.CurrentMatchRound = _currentRound; SendMatchStateUpdateMessage(); _messageService.DisableLogging(); }
public async Task ClearMatch() { if (_isRunning) { await EndRound(); } _wsMonitor.DisableScoring(); _wsMonitor.RemoveAllCharacterSubscriptions(); _messageService.DisableLogging(); MatchConfiguration = new MatchConfiguration(); _roundSecondsMax = MatchConfiguration.RoundSecondsTotal; _matchState = MatchState.Uninitialized; _currentRound = 0; _matchDataService.CurrentMatchRound = _currentRound; _matchDataService.CurrentMatchId = string.Empty; _latestTimerTickMessage = null; _teamsManager.ClearAllTeams(); SendMatchStateUpdateMessage(); SendMatchConfigurationUpdateMessage(); }
public void Resume() { _logger.LogInformation($"Resuming Timer"); _autoEvent.WaitOne(); if (Status.State != MatchTimerState.Paused) { _logger.LogInformation($"Failed to resume timer: timer not paused"); _autoEvent.Set(); return; } Status.State = MatchTimerState.Resuming; _timer.Change(_resumeDelayMs, 1000); _isRunning = true; Status.State = MatchTimerState.Running; var message = new MatchTimerTickMessage(Status); // TODO: use both to make MatchTimer razor component self-contained? //OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); _messageService.BroadcastMatchTimerTickMessage(message); // TODO: broadcast a "MatchStateChange" of event of type "Resumed" here // Signal the waiting thread _autoEvent.Set(); }
public void Pause() { _logger.LogInformation($"Pausing Timer"); _autoEvent.WaitOne(); if (Status.State != MatchTimerState.Running) { _logger.LogInformation($"Failed to pause timer: timer not running"); _autoEvent.Set(); return; } var now = DateTime.UtcNow; _resumeDelayMs = (int)(now - _prevTickTime).TotalMilliseconds; _timer.Change(Timeout.Infinite, 1000); _isRunning = false; Status.State = MatchTimerState.Paused; var message = new MatchTimerTickMessage(Status); // TODO: use both to make MatchTimer razor component self-contained? //OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); _messageService.BroadcastMatchTimerTickMessage(message); // TODO: broadcast a "MatchStateChange" of event of type "Round Ended" here _logger.LogInformation($"Timer Paused"); _autoEvent.Set(); }
public void Stop() { _logger.LogInformation($"Stopping Timer"); _autoEvent.WaitOne(); if (Status.State != MatchTimerState.Stopping) { _logger.LogInformation($"Failed to stop timer: timer not running"); _autoEvent.Set(); return; } // TODO: should we Dispose of the timer instead of putting it on hold indefinitely? _timer.Change(Timeout.Infinite, 1000); _isRunning = false; Status.State = MatchTimerState.Stopped; var message = new MatchTimerTickMessage(Status); // TODO: use both to make MatchTimer razor component self-contained? //OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); _messageService.BroadcastMatchTimerTickMessage(message); // TODO: broadcast a "MatchStateChange" of event of type "Round Ended" here _logger.LogInformation($"Timer Stopped"); _autoEvent.Set(); }
public async Task ClearMatch(bool isRematch) { if (_isRunning) { await EndRound(); } _wsMonitor.DisableScoring(); if (!isRematch) { _wsMonitor.RemoveAllCharacterSubscriptions(); } _messageService.DisableLogging(); var previousWorldId = MatchConfiguration.WorldIdString; var previousIsManualWorldId = MatchConfiguration.IsManualWorldId; var previousEndRoundOnFacilityCapture = MatchConfiguration.EndRoundOnFacilityCapture; var previousIsManualEndRoundOnFacilityCapture = MatchConfiguration.EndRoundOnFacilityCapture; MatchConfiguration = new MatchConfiguration(); if (isRematch) { MatchConfiguration.TrySetWorldId(previousWorldId, previousIsManualWorldId); MatchConfiguration.TrySetEndRoundOnFacilityCapture(previousEndRoundOnFacilityCapture, previousIsManualEndRoundOnFacilityCapture); } else { var activeRuleset = await _rulesetManager.GetActiveRulesetAsync(); MatchConfiguration.TrySetEndRoundOnFacilityCapture(activeRuleset.DefaultEndRoundOnFacilityCapture, false); } _roundSecondsMax = MatchConfiguration.RoundSecondsTotal; _matchState = MatchState.Uninitialized; _currentRound = 0; _matchDataService.CurrentMatchRound = _currentRound; _matchDataService.CurrentMatchId = string.Empty; _latestTimerTickMessage = null; if (isRematch) { _teamsManager.UpdateAllTeamsMatchSeriesResults(CurrentSeriesMatch); _teamsManager.ResetAllTeamsMatchData(); } else { CurrentSeriesMatch = 0; _teamsManager.ClearAllTeams(); } SendMatchStateUpdateMessage(); SendMatchConfigurationUpdateMessage(); }
private void HandleTick(object stateInfo) { _logger.LogDebug($"Handling timer tick"); _autoEvent.WaitOne(); if (ShouldProcessTick()) { _prevTickTime = DateTime.UtcNow; _secondsRemaining = Status.DecrementRemaining(); _secondsElapsed = Status.IncrementElapsed(); //Interlocked.Decrement(ref _secondsRemaining); //Status.SecondsRemaining = _secondsRemaining; //Interlocked.Increment(ref _secondsElapsed); //Status.SecondsElapsed = _secondsElapsed; var message = new MatchTimerTickMessage(Status); if (_secondsRemaining == 0) { Status.State = MatchTimerState.Stopping; // Signal the waiting thread. Only a thread waiting in Stop() should be able to do anything due to _status.State _autoEvent.Set(); Stop(); return; } // TODO: use both to make MatchTimer razor component self-contained? //OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); _messageService.BroadcastMatchTimerTickMessage(message); // Signal the waiting thread _autoEvent.Set(); } }
private void SetLatestTimerTickMessage(MatchTimerTickMessage value) { _latestTimerTickMessage = value; }
public void BroadcastMatchTimerTickMessage(MatchTimerTickMessage message) { OnRaiseMatchTimerTickEvent(new ScrimMessageEventArgs <MatchTimerTickMessage>(message)); }
public void BroadcastMatchTimerTickMessage(MatchTimerTickMessage message) { OnRaiseMatchTimerTickEvent(new MatchTimerTickEventArgs(message)); }