예제 #1
0
        public void ExchangeData()
        {
            var memoryAllocator = new SimpleManagedAllocator();
            var memoryPool      = new SimpleMemoryPool(memoryAllocator);
            var peer1           = new NetworkSocket(memoryPool);
            var peer2           = new NetworkSocket(memoryPool);

            var bindingAddress1 = new IPEndPoint(IPAddress.Any, 50000);
            var bindingAddress2 = new IPEndPoint(IPAddress.Any, 50001);

            var sendingAddress1 = new IPEndPoint(IPAddress.Loopback, 50001);
            var sendingAddress2 = new IPEndPoint(IPAddress.Loopback, 50000);

            var dataToSend1 = new byte[] { 10, 9, 8, 7, 6, 5 };
            var dataToSend2 = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };

            byte[]   arrivedData1     = default(byte[]);
            EndPoint arrivedEndpoint1 = default(EndPoint);
            bool     canProceed1      = false;

            byte[]   arrivedData2     = default(byte[]);
            EndPoint arrivedEndpoint2 = default(EndPoint);
            bool     canProceed2      = false;

            peer1.Bind(bindingAddress1);
            peer2.Bind(bindingAddress2);

            peer1.SendTo(sendingAddress1, dataToSend1);
            peer2.SendTo(sendingAddress2, dataToSend2);

            while (!canProceed1 || !canProceed2)
            {
                if (peer1.Poll(out NetworkArrivedData data1))
                {
                    arrivedData1     = data1.Data;
                    arrivedEndpoint1 = data1.EndPoint;
                    canProceed1      = true;
                }

                if (peer2.Poll(out NetworkArrivedData data2))
                {
                    arrivedData2     = data2.Data;
                    arrivedEndpoint2 = data2.EndPoint;
                    canProceed2      = true;
                }
            }

            Assert.True(arrivedData1.Length == dataToSend2.Length);
            Assert.True(arrivedData2.Length == dataToSend1.Length);

            for (int i = 0; i < arrivedData1.Length; i++)
            {
                Assert.Equal(arrivedData1[i], dataToSend2[i]);

                //_testOutputHelper.WriteLine(arrivedData1[i].ToString() + " == " + dataToSend2[i].ToString());
            }

            for (int i = 0; i < arrivedData2.Length; i++)
            {
                Assert.Equal(arrivedData2[i], dataToSend1[i]);

                //_testOutputHelper.WriteLine(arrivedData2[i].ToString() + " == " + dataToSend1[i].ToString());
            }

            Assert.Equal(arrivedEndpoint1, sendingAddress1);
            Assert.Equal(arrivedEndpoint2, sendingAddress2);

            Assert.True(peer1.Statistics.BytesSent == (ulong)dataToSend1.Length);
            Assert.True(peer2.Statistics.BytesSent == (ulong)dataToSend2.Length);
            Assert.True(peer1.Statistics.BytesReceived == (ulong)dataToSend2.Length);
            Assert.True(peer2.Statistics.BytesReceived == (ulong)dataToSend1.Length);
        }
예제 #2
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            gameFont = content.Load <SpriteFont>("gamefont");

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.

            #region Locals
            spriteBatch  = new SpriteBatch(ScreenManager.GraphicsDevice);
            otherTexture = ScreenManager.Game.Content.Load <Texture2D>("vein256");
            #endregion Locals

            #region Camera Manager

            cameraManager        = new CameraManager(ScreenManager.Game);
            Costam.CameraManager = cameraManager;

            DebugCamera camera = new Core.DebugCamera(ScreenManager.Game, new Vector3(-15, 0, 0),
                                                      Vector3.Zero, Vector3.Up);

            ChaseCamera chaseCamera = new ChaseCamera(ScreenManager.Game);

            cameraManager.AddCamera("DebugCamera", camera);
            cameraManager.AddCamera("ChaseCamera", chaseCamera);

            #endregion CameraManager

            #region Triggers
            triggerManager        = new TriggerManager(ScreenManager.Game);
            Costam.TriggerManager = triggerManager;

            #endregion Triggers

            #region Tunnel Manager
            tunnelManager        = new TunnelManager(ScreenManager.Game);
            Costam.TunnelManager = tunnelManager;
            #endregion TunnelManager

            #region Memory Managment
            objectsProvider = new SimpleMemoryPool();
            Costam.MemoryPoolObjectProvider = objectsProvider;
            #endregion Memory Managment

            #region Player

            playerManager        = new PlayerManager(ScreenManager.Game);
            Costam.PlayerManager = playerManager;

            chaseCamera.ChasedObject = Costam.PlayerManager.players.ElementAt(0).Value;


            #endregion PLayer

            #region HUD

            hud        = new Hud(ScreenManager.Game, spriteBatch);
            Costam.HUD = hud;
            //ScreenManager.Game.Components.Add(hud);

            SpriteFont consoleFont = ScreenManager.Game.Content.Load <SpriteFont>("HudFont");
            DebugTextWindow = new DebugConsole(new Rectangle(10, 10, 100, 50), consoleFont);
            hud.AddComponent(DebugDrawWindowName, DebugTextWindow);

            Vector2 windowDimensions = new Vector2(ScreenManager.Game.GraphicsDevice.Viewport.Width, ScreenManager.Game.GraphicsDevice.Viewport.Height);

            FPSCounter fpsCounter = new FPSCounter(new Rectangle((int)windowDimensions.X - 60, 5, 30, 20), consoleFont);
            hud.AddComponent("FPS", fpsCounter);

            if (playerManager.players.Count < 2)
            {
                PlayerHUD player1HUD = new PlayerHUD(new Rectangle((int)windowDimensions.X / 2, 0, 30, 20), consoleFont, playerManager.players.ElementAt(0).Value);
                hud.AddComponent("player1HUD", player1HUD);
            }
            else
            {
                PlayerHUD player1HUD = new PlayerHUD(new Rectangle(((int)windowDimensions.X / 2) - 70, 0, 30, 20), consoleFont, playerManager.players.ElementAt(0).Value);
                hud.AddComponent("player1HUD", player1HUD);


                PlayerHUD player2HUD = new PlayerHUD(new Rectangle((int)windowDimensions.X / 2, 0, 30, 20), consoleFont, playerManager.players.ElementAt(1).Value);
                hud.AddComponent("player2HUD", player2HUD);
            }



            #endregion HUD

            #region Object Manager
            objectManager        = new ObjectManager(Costam.Game);
            Costam.ObjectManager = objectManager;
            #endregion Object Manager

            #region Colision Manager
            collisionManager       = new CollisionManager(Costam.Game);
            Costam.ColisionManager = collisionManager;
            #endregion Colision Manager

            #region Debug
            debugDraw        = new DebugDraw();
            Costam.DebugDraw = debugDraw;

            Costam.Random = new Random((int)System.DateTime.Now.Ticks);
            #endregion Debug

            AfterLoadContent();


            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }