Performance oriented Minecraft Clone


view:  full / summary

MineClone's Current Optimisation Techniques

Posted by evilhamburger on March 8, 2011 at 11:33 AM Comments comments (5)

Just thought I'd write down all the optimisations that MineClone currently employs...

General Optimisations

  • MineClone stores regions in a hashtable, containing up to 262k entries (To minimise rebuild frequency). Whenever a region needs to be found, the bottom 6 bits of it's X, Y and Z components are combined to produce an index in the hashtable. This allows for very fast lookups in O(1) time. Whenever an out-of-bounds region is requested, the hashtable must be rebuilt and regions that no longer fit unloaded.
  • The Texture Atlas which MineClone uses only extends along the U Coordinate (Tiles appear from left to right in a single row). This allows for multiple blocks to share the same primitives. (By letting the texture wrap around the V Coordinate)

Render Optimisations

  • Each region stores a small bounding box, which is checked against the camera frustrum before the region is drawn.
  • A single index buffer is used to render everything. Even the menus.
  • Camera matrices are only rebuilt when the view changes, many games rebuild them every frame.

Loader Optimisations

  • If the loader finds multiple adjacent blocks sharing the same texture, it will combine them (To reduce the number of rendered primitives)
  • Before generating a block face, the loader will check whether or not the face is visible.
  • Because the number of vertices a region will require is difficult to calculate in advance, the loader is required to allocate the maximum size as a tempory buffer before copying to the graphics card. Rather than malloc'ing this buffer each time the loader creates 2 buffers which it uses over the entire execution. (2 are needed as a region rebuild, which is performed whenever a block is editted, can take place on another thread).
  • The File Format which MineClone uses to save is designed so that it can easily be memory mapped, indexed, and used directly. This allows for faster lookup times.