Пример #1
0
        /// <summary>
        /// A Player without network component
        /// </summary>
        /// <param name="model"></param>
        /// <param name="gamePadIndex"></param>
        /// <param name="transformPos"></param>
        /// <param name="cameraPos"></param>
        /// <param name="cameraAspectRatio"></param>
        /// <param name="followPlayer"></param>
        /// <param name="texture"></param>
        /// <returns></returns>
        public static Entity NewLocalPlayer(String model, int gamePadIndex, Vector3 transformPos, Vector3 cameraPos, float cameraAspectRatio, bool followPlayer, Texture2D texture)
        {
            Entity            player                    = NewBasePlayer(model, gamePadIndex, transformPos, texture, LOCAL_PLAYER);
            CameraComponent   cameraComponent           = new CameraComponent(player, cameraPos, cameraAspectRatio, followPlayer);
            KeyboardComponent keyboardComponent         = new KeyboardComponent(player);
            GamePadComponent  gamePadComponent          = new GamePadComponent(player, gamePadIndex);
            FPSComponent      fpsComponent              = new FPSComponent(player);
            UIComponent       spriteFPSCounterComponent = new UIComponent(player)
            {
                Position   = new Vector2(10, 10),
                Text       = fpsComponent.CurrentFramesPerSecond.ToString(),
                Color      = Color.White,
                SpriteFont = AssetManager.Instance.GetContent <SpriteFont>("menu")
            };
            NetworkDiagnosticComponent networkDiagnosticComponent = new NetworkDiagnosticComponent(player);

            ComponentManager.Instance.AddComponentToEntity(player, cameraComponent);
            ComponentManager.Instance.AddComponentToEntity(player, keyboardComponent);
            ComponentManager.Instance.AddComponentToEntity(player, gamePadComponent);
            ComponentManager.Instance.AddComponentToEntity(player, fpsComponent);
            ComponentManager.Instance.AddComponentToEntity(player, networkDiagnosticComponent);
            ComponentManager.Instance.AddComponentToEntity(player, spriteFPSCounterComponent);


            return(player);
        }
Пример #2
0
        private void Diagnostics(NetOutgoingMessage om, GameTime gameTime)
        {
            //do preformance measurement here
            networkDiagnostic = ComponentManager.Instance.GetConcurrentDictionary <NetworkDiagnosticComponent>().Values.First() as NetworkDiagnosticComponent;
            int sentData = 0;

            if (om.Data != null)
            {
                sentData = om.Data.Length;
            }



            networkDiagnostic.TotalDataSent += sentData;
            //networkDiagnostic.DataSentThisSecond = (int)(networkDiagnostic.TotalDataSent / gameTime.ElapsedGameTime.TotalSeconds); //this does not work and is not really important


            Console.WriteLine("sent data  this frame" + sentData.ToString());
            //Console.WriteLine("sent data this second" + networkDiagnostic.DataSentThisSecond);
            Console.WriteLine("total data sent " + networkDiagnostic.TotalDataSent);
        }