static int wait = 0; // wait to initialize whatever protected override void Update(GameTime gameTime) { if (RENDER_SECTOR != null && wait > 10) { Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var child in RENDER_SECTOR.GetChildrenAtLevel(8)) { var sectorLoader = new OSMSectorLoader(); var buffer = sectorLoader.GetGraphicsBuffer(GraphicsDevice, child); buffer.Dispose(); } double secs = sw.Elapsed.TotalSeconds; Exit(); } wait++; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape) || Constants.TERMINATE) { Exit(); } if (Keyboard.GetState().WasKeyPressed(Keys.R)) { RECORDING = !RECORDING; } if (Keyboard.GetState().WasKeyPressed(Keys.T)) { DEBUGGING = !DEBUGGING; } if (Keyboard.GetState().WasKeyPressed(Keys.C)) { CameraMatrixManager.MODE = (CameraMatrixManager.MODE + 1) % CameraMatrixManager.MODE_COUNT; } foreach (var component in zComponents) { component.Update(GraphicsDevice, gameTime); } }
protected override void Draw(GameTime gameTime) { RenderContext renderContext = new RenderContext(GraphicsDevice, Matrixd.Identity(), 0, 0, 0, 0, 0, RenderContext.LayerPass.TREE_DENSITY_PASS); foreach (var component in zComponents) { component.InitDraw(renderContext); } GraphicsDevice.SetRenderTargets(TREE_DENSITY_BUFFER); DrawAllComponents(renderContext, gameTime); renderContext.layerPass = RenderContext.LayerPass.GRASS_DENSITY_PASS; GraphicsDevice.SetRenderTargets(GRASS_DENSITY_BUFFER); DrawAllComponents(renderContext, gameTime); GraphicsDevice.BlendState = DEFERRED_RENDERING ? BlendState.Opaque : BlendState.AlphaBlend; renderContext.layerPass = RenderContext.LayerPass.MAIN_PASS; GraphicsDevice.SetRenderTargets(DEFERRED_RENDERING ? G_BUFFER : RENDER_BUFFER); DrawAllComponents(renderContext, gameTime); GraphicsDevice.BlendState = BlendState.AlphaBlend; if (DEFERRED_RENDERING) { GraphicsDevice.SetRenderTargets(RENDER_BUFFER); } DoComposite(); // draw UI directly to backbuffer? renderContext.layerPass = RenderContext.LayerPass.UI_PASS; DrawAllComponents(renderContext, gameTime); if (RECORDING) { OSMSectorLoader.SuperSave((Texture2D)RENDER_BUFFER[0].RenderTarget, Path.Combine(RECORD_PATH, $"frame{recordFrame}.png")); recordFrame++; } }