private long Update(long id) { lock (_locker) { DateTime utcNow = DateTime.UtcNow; try { if ((utcNow - _lastSpawn).TotalSeconds >= 1 && _spawned < AIShipsToSpawn) { _spawned += SpawnsPerInterval; SpawnAIShips(SpawnsPerInterval); _lastSpawn = utcNow; } _gameTime.Update(utcNow); GameHandler.Update(_gameTime); _space.Update(); if (_actualFPS <= _drawFPS || (++_drawCount) % DRAW_AFTER == 0) { Draw(); _drawCount = 0; } } catch (Exception e) { ErrorLog.Instance.Log(e); } return(id); } }
private async Task <long> Update(long id) { await _gameLock.WaitAsync(); try { var utcNow = DateTime.UtcNow; if ((utcNow - _lastSpawn).TotalSeconds >= 1 && _spawned < AIShipsToSpawn) { _spawned += SpawnsPerInterval; SpawnAIShips(SpawnsPerInterval); _lastSpawn = utcNow; } _gameTime.Update(utcNow); await GameHandler.Update(_gameTime); _space.Update(); if (_actualFPS <= _drawFPS || (++_drawCount) % DRAW_AFTER == 0) { await DrawAsync(); _drawCount = 0; } } catch (Exception e) { //ErrorLog.Instance.Log(e); } finally { _gameLock.Release(); } return(id); }