コード例 #1
0
ファイル: Game.cs プロジェクト: EugeneWang/ShootR
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: AbhiLegend/ShootR
        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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: SnoBoarder/CS651-Websites
        /// <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);
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: SnoBoarder/CS651-Websites
        /// <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);
            }
        }
コード例 #7
0
ファイル: Leaderboard.cs プロジェクト: olegaya/ShootR
 public Leaderboard(UserHandler userHandler, IHubContext <GameHub> gameHub)
 {
     _userHandler = userHandler;
     _gameHub     = gameHub;
 }
コード例 #8
0
ファイル: ConnectionManager.cs プロジェクト: JTtheGeek/ShootR
 public ConnectionManager(UserHandler userHandler, object locker)
 {
     _userHandler = userHandler;
     _locker = locker;
 }
コード例 #9
0
ファイル: Leaderboard.cs プロジェクト: JTtheGeek/ShootR
 public Leaderboard(UserHandler userHandler)
 {
     _userHandler = userHandler;
 }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
 public ConnectionManager(UserHandler userHandler, SemaphoreSlim gameLock, IHubContext <GameHub> gameHub)
 {
     _gameLock    = gameLock;
     _userHandler = userHandler;
     _gameHub     = gameHub;
 }
コード例 #12
0
 public Leaderboard(UserHandler userHandler)
 {
     _userHandler = userHandler;
 }
コード例 #13
0
 public ConnectionManager(UserHandler userHandler, object locker)
 {
     _userHandler = userHandler;
     _locker      = locker;
 }