Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not sure if this is the best way to deal with the problem, but I've started to use RenderTarget2D to pre-render chunks of the world into textures. I have to load chunks within a given area around the actual screen bounds at a time, because loading all chunks at once will make it run out of memory.</p> <p>When you get close to the bounds of the current pre-rendered area, it will re-process chunks based on your new position in the world. The processing takes roughly 100 milliseconds, so when loading new areas the player will feel a slight slowdown for this duration. I don't really like that, but at least the FPS is 60 now.</p> <p>Here's my chunk processor:</p> <pre><code> public bool ProcessChunk(int x, int y) { // Create render target using (RenderTarget2D target = new RenderTarget2D(Game.CurrentDevice, 16 * 48, 16 * 48, false, SurfaceFormat.Color, DepthFormat.Depth24)) { // Set render target Game.CurrentDevice.SetRenderTarget(target); // Clear back buffer Game.CurrentDevice.Clear(Color.Black * 0f); // Begin drawing Game.spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend); // Get block coordinates int bx = x * 48, by = y * 48; // Draw blocks int count = 0; foreach (WorldSection section in Sections) { // Continue if section is out of chunk bounds if (section.X &gt;= bx + 48) continue; // Draw all tiles within the screen range for (int ax = 0; ax &lt; 48; ax++) for (int ay = 0; ay &lt; 48; ay++) { // Get the block character char b = section.Blocks[ax + bx - section.X, ay + by]; // Draw the block unless it's an empty block if (b != '0') { Processor.Blocks[b.ToString()].DrawBlock(new Vector2(ax, ay), true); count++; } } } // End drawing Game.spriteBatch.End(); // Clear target target.GraphicsDevice.SetRenderTarget(null); // Set texture if (count &gt; 0) { // Create texture Chunks[x, y] = new Texture2D(Game.CurrentDevice, target.Width, target.Height, true, target.Format); // Set data Color[] data = new Color[target.Width * target.Height]; target.GetData&lt;Color&gt;(data); Chunks[x, y].SetData&lt;Color&gt;(data); // Return true return true; } } // Return false return false; } </code></pre> <p>If there are any suggestions on how this approach can be improved, I won't be sad to hear them!</p> <p>Thanks for the help given here!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload