Game Development Reference
In-Depth Information
find that you need to be a bit smarter about the lifetime of the resource and how you
manage loading in content to ensure you do not exceed memory limits.
Commercial engines such as Unreal Engine use streaming technology to load in the
content in the background while the user plays the game, avoiding the need for load-
ing screens whenever new content appears. This also allows for the resources to be
unloaded if the memory is almost full. Other options include controlling the size of
the assets in a single level and unloading the assets when loading a new level; or
keeping the assets that are shared and only unloading what isn't used.
If you bring all of this together you can build a robust, re-usable resource manager
that will really help you with your game development. That is too big for this topic
though, so for our simple game we will just implement a simple std::map in the
renderer that handles caching textures for us based on their filenames.
Culling
Having too much in the game world at once can reduce the frame rate of a game.
We need a way to manage what is displayed to ensure we aren't drawing unneces-
sary objects. By drawing every single sprite, even the sprites and objects outside of
the visible area (above, below, behind, or on either side), we waste a lot of time that
could be spent drawing a new frame and giving a better experience. To resolve this,
renderers often implement a method of culling to only draw what is visible. Essen-
tially this is a glorified search algorithm, designed to search the scene for only the
visible objects, and draw those while ignoring everything else. You could do this by
iterating through a list and checking if each sprite is in the camera's view, but if you're
working with many sprites you will soon waste CPU time going through every sprite
every frame.
To resolve this, acceleration structures were invented that consider the position of
the object and allow for coarse grained culling of entire batches, reducing the load on
the CPU. In 3D one of the best known structures is called a Binary Space Partition
Tree (BSP Tree). Here, the scene is constantly split in half, forming a tree structure
until a threshold is met, usually a maximum number of objects in a node.
Another option is the Quad-Tree , which splits the scene into four sections at a time;
however, unlike the BSP Tree, the Quad-Tree needs to be aligned to a grid (when
splitting in half, you can place the split anywhere). This is great for static objects, and
Search WWH ::




Custom Search