public ObservedGameInfo ObserveNextTurn(Observer observer) { lock (_liveLock) { checkRunState(); ObserverQueue q = findObserver(observer.ObserverId); ObservedTurnInfo ot = q.Pop(); if (ot == null && q.IsLive) { Monitor.Wait(_liveLock, Settings.ObserverPollTimeoutMillis); ot = q.Pop(); } ObservedGameInfo gi = new ObservedGameInfo { GameId = GameId, GameState = State, QueuedTurns = (q.IsLive) ? q.Count : -1, TurnInfo = ot }; return(gi); } }
public ObservedGameInfo ObserveNextTurn(Observer observer) { ObserverQueue queue; List <int> lags = new List <int>(); DateTime now = DateTime.Now; lock (_liveLock) { CheckRunState(); queue = FindObserver(observer.ObserverId); for (int i = 0; i < _playerStates.Length; i++) { if (_playerStates[i].TurnCompleted >= _gameTurnStarted) { continue; } double delayMillis = (now - _turnStart).TotalSeconds; if (delayMillis > Settings.SlowTurnIntervalSeconds) { lags.Add(i); } } } int queueLength; ObservedTurnInfo ot = queue.Pop(out queueLength); // This has its own blocking ObservedGameInfo gi = new ObservedGameInfo { GameId = GameId, GameState = State, QueuedTurns = queueLength, TurnInfo = ot, SlowPlayers = lags }; return(gi); }