/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { //Exit the game when pressing escape if (Input.WasKeyPressed(Keys.Escape)) { Exit(); } _screenManager.Update(gameTime, _isActive); //BEPU Physics if (GameSettings.p_Physics) { _physicsSpace.Update((float)gameTime.ElapsedGameTime.TotalSeconds); } base.Update(gameTime); const string mark = "Update"; GS.StartFrame(); GS.BeginMark(mark, FlatTheme.PeterRiver); //GS.Plot("FPS", (float) GameStats.fps_avg, 100); #if USE_GEARSET if (GS.GearsetComponent.Console.Profiler.DoUpdate() == false) { return; } #endif GS.EndMark(mark); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(new Color(48, 48, 48, 255)); GS.BeginMark("Draw", FlatTheme.Pomegrantate); GS.BeginMark("Draw Background", FlatTheme.Pumpkin); Thread.Sleep(2); //Let's trick the update into taking some time so that we can see some profile info GS.EndMark("Draw Background"); //Test nesting GS.BeginMark("Draw Sprites", FlatTheme.Sunflower); Thread.Sleep(1); //Let's trick the update into taking some time so that we can see some profile info GS.BeginMark("Draw Sprites", FlatTheme.Sunflower); Thread.Sleep(1); //Let's trick the update into taking some time so that we can see some profile info GS.EndMark("Draw Sprites"); GS.EndMark("Draw Sprites"); GS.BeginMark("Draw Particles", FlatTheme.Amethyst); Thread.Sleep(2); //Let's trick the update into taking some time so that we can see some profile info GS.EndMark("Draw Particles"); GS.BeginMark("base.Draw", FlatTheme.Nephritis); base.Draw(gameTime); GS.EndMark("base.Draw"); GS.EndMark("Draw"); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } //We must call StartFrame at the top of Update to indicate to the TimeRuler that a new frame has started. GS.StartFrame(); GS.BeginMark("Update", FlatTheme.PeterRiver); //Some nice plots... //GS.Plot("FPS", _fpsCounter.Fps); //GS.Plot("Total Memory K", _memoryMonitor.TotalMemoryK, 240); //GS.Plot("Tick Memory K", _memoryMonitor.TickMemoryK); #if USE_GEARSET //Test for CPU / GPU bound if (GS.GearsetComponent.Console.Profiler.DoUpdate() == false) { GS.EndMark("Update"); return; } #endif Thread.Sleep(1);//Let's trick the update into taking some time so that we can see some profile info base.Update(gameTime); GS.EndMark("Update"); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { //Don't draw when the game is not running if (!_isActive) { return; } GS.BeginMark("Draw", FlatTheme.Pomegrantate); _screenManager.Draw(gameTime); base.Draw(gameTime); GS.EndMark("Draw"); }
//////////////////////////////////////////////////////////////////////////////////////////////////////// // RENDER FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////// #region MAIN DRAW FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////// // MAIN DRAW FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Main Draw function of the game /// </summary> /// <param name="camera">view point of the renderer</param> /// <param name="meshMaterialLibrary">a class that has stored all our mesh data</param> /// <param name="entities">entities and their properties</param> /// <param name="pointLights"></param> /// <param name="directionalLights"></param> /// <param name="editorData">The data passed from our editor logic</param> /// <param name="gameTime"></param> /// <returns></returns> public void Draw(Camera camera, MeshMaterialLibrary meshMaterialLibrary, List <BasicEntity> entities, List <PointLightSource> pointLights, List <DirectionalLightSource> directionalLights, EditorLogic.EditorSendData editorData, GameTime gameTime) { //Reset the stat counter, so we can count stats/information for this frame only ResetStats(); //Update the mesh data for changes in physics etc. meshMaterialLibrary.FrustumCullingStartFrame(entities); //Check if we changed some drastic stuff for which we need to reload some elements CheckRenderChanges(directionalLights); //Render ShadowMaps //DrawShadowMaps(meshMaterialLibrary, entities, pointLights, directionalLights, camera); //Update our view projection matrices if the camera moved UpdateViewProjection(camera, meshMaterialLibrary, entities); GS.BeginMark("DrawTextureBuffer", Color.Red); //Draw our meshes to the G Buffer DrawTextureBuffer(meshMaterialLibrary); GS.EndMark("DrawTextureBuffer"); FixSeams(); GS.BeginMark("DrawMeshes", Color.Blue); DrawObjects(meshMaterialLibrary); GS.EndMark("DrawMeshes"); //Draw the final rendered image, change the output based on user input to show individual buffers/rendertargets RenderMode(); //Draw (debug) lines LineHelperManager.Draw(_graphicsDevice, _staticViewProjection); //Set up the frustum culling for the next frame meshMaterialLibrary.FrustumCullingFinalizeFrame(entities); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { const string mark = "Update"; try { base.Update(gameTime); //We must call StartFrame at the top of Update to indicate to the Profiler that a new frame has started. GS.StartFrame(); GS.BeginMark(mark, FlatTheme.PeterRiver); _previousKeyboardState = _keyboardState; _keyboardState = Keyboard.GetState(); // Allows the game to exit #if WINDOWS if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); return; } #endif if (_keyboardState.IsKeyUp(Keys.Escape) && _previousKeyboardState.IsKeyDown(Keys.Escape)) { Exit(); return; } #if USE_GEARSET //Test for CPU / GPU bound if (GS.GearsetComponent.Console.Profiler.DoUpdate() == false) { return; } #endif //PLOT test GS.Plot("FPS", _fpsCounter.Fps); // GS.Plot("Tick Memory K", _memoryMonitor.TickMemoryK); var mouseState = Mouse.GetState(); var mousePos2 = new Vector2(mouseState.X, mouseState.Y); var mousePos3 = new Vector3(mousePos2, 0); //Label test GS.ShowLabel("I follow the mouse pointer!", mousePos2); //Line Test //Draw a line but then use the same key to reference it a second time and alter the postion / color // GS.ShowLine("TestLine", new Vector2(mouseState.X, mouseState.Y + 20), new Vector2(mouseState.X + 200, mouseState.Y + 20), Color.Green); // GS.ShowLine("TestLine", new Vector2(mouseState.X, mouseState.Y - 20), new Vector2(mouseState.X + 200, mouseState.Y - 20), Color.Violet); //Other lines... GS.ShowLineOnce(new Vector2(mouseState.X, mouseState.Y + 25), new Vector2(mouseState.X + 200, mouseState.Y + 25), Color.Pink); GS.ShowLineOnce(new Vector2(mouseState.X, mouseState.Y + 35), new Vector2(mouseState.X + 200, mouseState.Y + 35), Color.Red); //ALERT test - press SPACE for an alert message! if (_keyboardState.IsKeyUp(Keys.Space) && _previousKeyboardState.IsKeyDown(Keys.Space)) { GS.Alert("I am an alert message"); } Thread.Sleep(1);//Let's trick the update into taking some time so that we can see some profile info //Update Gearset matrixes for 3d geometry GS.SetMatrices(ref _worldMatrix, ref _viewMatrix, ref _projectionMatrix); //Geometry tests... // GS.ShowSphere("TestSphere", mousePos3, 50, Color.Azure); GS.ShowSphereOnce(mousePos3, 50, Color.Azure); // GS.ShowBox("TestBox", new Vector3(mouseState.X + 50, mouseState.Y + 50, 0), new Vector3(mouseState.X + 100, mouseState.Y + 100, 0), Color.Blue); GS.ShowBoxOnce(new Vector3(mouseState.X + 100, mouseState.Y + 100, 0), new Vector3(mouseState.X + 150, mouseState.Y + 150, 0), Color.Red); } finally { //Must call EndMark GS.EndMark(mark); } }