public void Update(GameTime gameTime) { var elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; fpsComponent = ComponentManager.Instance.GetConcurrentDictionary <FPSComponent>().Values.First() as FPSComponent; //there shoudl only exist one fps-comp fpsComponent.CurrentFramesPerSecond = 1.0f / elapsedTime; frameBuffer.Enqueue(fpsComponent.CurrentFramesPerSecond); if (frameBuffer.Count > MAXIMUM_SAMPLES) { frameBuffer.Dequeue(); fpsComponent.AverageFramesPerSecond = frameBuffer.Average(i => i); } else { fpsComponent.AverageFramesPerSecond = fpsComponent.CurrentFramesPerSecond; } fpsComponent.TotalFrames++; fpsComponent.TotalSeconds += elapsedTime; UIComponent uIComponent = ComponentManager.Instance.GetConcurrentDictionary <UIComponent>().Values.First() as UIComponent; uIComponent.Text = "FPS: " + fpsComponent.CurrentFramesPerSecond.ToString(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { Tile.TileVisualOffsetX = 0; Tile.TileVisualOffsetY = 48; mapVisualizer = new TileMapManagerExtension(this, @"Textures\TileSets\TileSheet"); mapComponent = new TileMapComponent <InGameObject>(this, mapVisualizer); Components.Add(mapComponent); fpsComponent = new FPSComponent(this); Components.Add(fpsComponent); Window.AllowUserResizing = true; Window.ClientSizeChanged += new EventHandler <EventArgs>(Window_ClientSizeChanged); preferredWindowedWidth = graphics.PreferredBackBufferWidth; preferredWindowedHeight = graphics.PreferredBackBufferHeight; if (hyperDrive) { this.IsFixedTimeStep = false; this.graphics.SynchronizeWithVerticalRetrace = false; this.graphics.ApplyChanges(); } base.Initialize(); }
/// <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); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { mapManager = new TileMapManagerExtension(this); mapComponent = new TileMapComponent(this, mapManager); Components.Add(mapComponent); fpsComponent = new FPSComponent(this, "Fonts/Segoe"); Components.Add(fpsComponent); Window.AllowUserResizing = true; Window.ClientSizeChanged += new EventHandler <EventArgs>(Window_ClientSizeChanged); preferredWindowedWidth = graphics.PreferredBackBufferWidth; preferredWindowedHeight = graphics.PreferredBackBufferHeight; recognizeHyperDrive(); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { mapManager = new TileMapManagerExtension(this); mapComponent = new TileMapComponent(this, mapManager); Components.Add(mapComponent); fpsComponent = new FPSComponent(this, "Fonts/Segoe"); Components.Add(fpsComponent); Window.AllowUserResizing = true; Window.ClientSizeChanged += new EventHandler<EventArgs>(Window_ClientSizeChanged); preferredWindowedWidth = graphics.PreferredBackBufferWidth; preferredWindowedHeight = graphics.PreferredBackBufferHeight; recognizeHyperDrive(); base.Initialize(); }