private Game() { Configuration = new GameConfigurationManager(); DRAW_AFTER = Configuration.gameConfig.DRAW_INTERVAL / Configuration.gameConfig.UPDATE_INTERVAL; _drawFPS = 1000 / Configuration.gameConfig.DRAW_INTERVAL; _gameLoop = new HighFrequencyTimer(1000 / Configuration.gameConfig.UPDATE_INTERVAL, id => Update(id), () => { }, () => { }, (fps) => { _actualFPS = fps; }); _leaderboardLoop = new Timer(UpdateLeaderboard, null, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL); _gameTime = new GameTime(); _space = new Map(); GameHandler = new GameHandler(_space); _payloadManager = new PayloadManager(); UserHandler = new UserHandler(GameHandler); Leaderboard = new Leaderboard(UserHandler); ConnectionManager = new ConnectionManager(UserHandler, _locker); RegistrationHandler = new RegistrationHandler(); RuntimeConfiguration = new RuntimeConfiguration(); _gameLoop.Start(); }
private Game() { Configuration = new GameConfigurationManager(); DRAW_AFTER = TimeSpan.FromMilliseconds(Configuration.gameConfig.DRAW_INTERVAL); _gameLoop = new HighFrequencyTimer(1000 / Configuration.gameConfig.UPDATE_INTERVAL, id => Update(id)); _leaderboardLoop = new Timer(UpdateLeaderboard, null, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL); _gameTime = new GameTime(); _space = new Map(); GameHandler = new GameHandler(_space); _payloadManager = new PayloadManager(); UserHandler = new UserHandler(GameHandler); Leaderboard = new Leaderboard(UserHandler); ConnectionManager = new ConnectionManager(UserHandler, _locker); RegistrationHandler = new RegistrationHandler(); RuntimeConfiguration = new RuntimeConfiguration(); _gameLoop.Start(); }
public Game(IHubContext <GameHub> gameHub) { Configuration = new GameConfigurationManager(); _gameLoop = new HighFrequencyTimer(1000 / Configuration.gameConfig.UPDATE_INTERVAL, async id => await Update(id), () => { }, () => { }, (fps) => { _actualFPS = fps; }); _gameHub = gameHub; _leaderboardLoop = new Timer(UpdateLeaderboard, null, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL); DRAW_AFTER = Configuration.gameConfig.DRAW_INTERVAL / Configuration.gameConfig.UPDATE_INTERVAL; _gameTime = new GameTime(); _space = new Map(this, gameHub); GameHandler = new GameHandler(_space, this); _payloadManager = new PayloadManager(); UserHandler = new UserHandler(GameHandler); Leaderboard = new Leaderboard(UserHandler, gameHub); ConnectionManager = new ConnectionManager(UserHandler, _gameLock, gameHub); _gameLoop.Start(); }
/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc) { if (!UserHandler.UserExistsAndReady(connectionId)) { try { lock (_locker) { User user = UserHandler.FindUserByIdentity(rc.Identity); Ship ship; if (user == null) { if (UserHandler.TotalActiveUsers >= RuntimeConfiguration.MaxServerUsers) { return(new { ServerFull = true }); } else { ship = new Ship(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; user = new User(connectionId, ship, rc) { Controller = false }; UserHandler.AddUser(user); } } else { string previousConnectionID = user.ConnectionID; UserHandler.ReassignUser(connectionId, user); ship = user.MyShip; if (user.Connected) // Check if it's a duplicate login { GetContext().Clients.Client(previousConnectionID).controlTransferred(); user.NotificationManager.Notify("Transfering control to this browser. You were already logged in."); } else { ship.Disposed = false; ship.LifeController.HealFull(); user.Connected = true; } user.IdleManager.RecordActivity(); user.IdleManager.Idle = false; } GameHandler.AddShipToGame(ship); } return(new { Configuration = Configuration, ServerFull = false, CompressionContracts = new { PayloadContract = _payloadManager.Compressor.PayloadCompressionContract, CollidableContract = _payloadManager.Compressor.CollidableCompressionContract, ShipContract = _payloadManager.Compressor.ShipCompressionContract, BulletContract = _payloadManager.Compressor.BulletCompressionContract, LeaderboardEntryContract = _payloadManager.Compressor.LeaderboardEntryCompressionContract, PowerupContract = _payloadManager.Compressor.PowerupCompressionContract }, ShipID = UserHandler.GetUserShip(connectionId).ID, ShipName = UserHandler.GetUserShip(connectionId).Name }); } catch (Exception e) { ErrorLog.Instance.Log(e); } } return(null); }
/// <summary> /// Sends down batches of data to the clients in order to update their screens /// </summary> private void Draw() { _space.CheckIncreaseMapSize(UserHandler.TotalActiveUsers); UserHandler.Update(); ConcurrentDictionary <string, object[]> payloads = _payloadManager.GetGamePayloads(UserHandler.GetUsers(), UserHandler.TotalActiveUsers, GameHandler.BulletManager.Bullets.Count, _space); IHubContext context = GetContext(); foreach (string connectionID in payloads.Keys) { UserHandler.GetUser(connectionID).PushToClient(payloads[connectionID], context); } }
public Leaderboard(UserHandler userHandler, IHubContext <GameHub> gameHub) { _userHandler = userHandler; _gameHub = gameHub; }
public ConnectionManager(UserHandler userHandler, object locker) { _userHandler = userHandler; _locker = locker; }
public Leaderboard(UserHandler userHandler) { _userHandler = userHandler; }
/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc, bool isPlayer) { if (!UserHandler.UserExistsAndReady(connectionId)) { _gameLock.Wait(); try { User user = null;//UserHandler.FindUserByIdentity(rc.Identity); Ship ship = null; if (user == null) { if (UserHandler.TotalActiveUsers >= 50 /*RuntimeConfiguration.MaxServerUsers*/) { return(new { ServerFull = true }); } else { // Only create a ship if they are a player if (isPlayer) { ship = new Ship(this, RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; } user = new User(connectionId, ship, rc) { Controller = false, IsPlayer = isPlayer }; UserHandler.AddUser(user); } } if (ship != null) { GameHandler.AddShipToGame(ship); } ship = UserHandler.GetUserShip(connectionId); return(new { Configuration = Configuration, ServerFull = false, CompressionContracts = new { PayloadContract = _payloadManager.Compressor.PayloadCompressionContract, CollidableContract = _payloadManager.Compressor.CollidableCompressionContract, ShipContract = _payloadManager.Compressor.ShipCompressionContract, BulletContract = _payloadManager.Compressor.BulletCompressionContract, LeaderboardEntryContract = _payloadManager.Compressor.LeaderboardEntryCompressionContract, PowerupContract = _payloadManager.Compressor.PowerupCompressionContract }, ShipID = ship?.ID, ShipName = ship?.Name, IsPlayer = isPlayer, }); } catch { } finally { _gameLock.Release(); } } return(null); }
public ConnectionManager(UserHandler userHandler, SemaphoreSlim gameLock, IHubContext <GameHub> gameHub) { _gameLock = gameLock; _userHandler = userHandler; _gameHub = gameHub; }