# Loading content (meshes, textures, sounds) in the background

In my game, I am aiming for a continuous world, that is, a world where you can go anywhere without breaking the immersion through load times and "virtual seams".

My world is broken up into regions, which are nodes in a graph. A region is considered adjacent to another if it can be travelled to or seen from that region. In order to keep this continuous, I want to preload the assets needed in the adjacent regions (such as world meshes, textures, and music) before they are actually used.

As for actually loading the content, I use a manager that keeps at most one copy of each asset in memory at a time, accessible by its filename. When I try to access an asset, it loads it (if necessary) and then returns it. I can then unload any asset that is currently loaded to save memory.

Clearly, I want to do this in the background so there are no hiccups. I assume I have to use threads in some way, but I'm not sure how.

• One of the guys who worked on Dungeon Siege (one of the earliest continuous world games) did a talk at GDC several years ago. His slides and other notes can be found here: scottbilas.com/games/dungeon-siege – Tetrad May 6 '12 at 0:41
• Reading that article brings up an interesting point. How should I store coordinates in a world that huge? I don't think I want to handle transformations in relation to a region center, because that will muddle up for inter-regional interactions. – jmegaffin May 6 '12 at 0:52
• @Boreal huge world coordinates is a totally separate question, you'll want to research and then post if you don't find any answers that match your situation =) – Patrick Hughes May 6 '12 at 1:20
• @boreal could you maybe introduce a Quad-tree, and then if character in section X then load content l-s this way you get the same effect as streaming zones – gardian06 May 6 '12 at 3:07
• Have you taken a look at Background Loading in XNA, just instead of a Loading screen you'll be showing your game world? – Joshua Drake May 7 '12 at 12:37

## 1 Answer

I think I have figured it out. I'll process the content using a job queue and send thread-safe messages to the main thread to tell when an asset has loaded. When the assets are needed, the engine will wait (if necessary) for all the required assets to load and then continue with business as usual.