Monday, December 6, 2021

Resource Management and Asynchronous Loading

Video games typically utilize a multitude of artistic assets, or resources, including audio clips and images. When a game first begins to execute, these resources are typically stored externally on a system hard drive or a server across the network. For this reason, these resources are sometimes referred to as external resources. External resources must be explicitly loaded into a game. Since there can be a large number of required resources to support an entire game, storing them with the running game can potentially be memory intensive.

A game should load and unload resources dynamically based on necessity. However, loading external resources may involve input/output device operations or network packet latencies and thus can be time intensive and potentially affect real-time interactivity. For these reasons, only a portion of resources are kept in memory, with loading operations strategically executed to avoid interrupting the game. In most cases, resources required in each level are kept in memory to support real-time interaction during the game play of that level.

With this approach, external resource loading can be implemented during level transitions where players are expecting a new game environment and slight delays for loadings can be tolerated. Once loaded, a resource must be readily accessible to support interactivity. The efficient and effective management of resources is essential to any game engine. Take note of the clear differentiation between resource managements, the responsibility of a game engine, and the actual ownerships of the resources.

For example, a game engine must support the efficient loading and playing of the background music for a game, and it is the game (or client of the game engine) that actually owns and supplies the audio file for the background music. When implementing support for external resources management, it is important to remember that the actual resources are not part of the game engine. At this point, the game engine you have been building handles only one type of resource—the GLSL shader files. Recall that the SimpleShader object loads and compiles the SimpleVS.glsl and SimpleFS.glsl files in its constructor. So far, the shader file loading has been accomplished via synchronous XMLHttpRequest.open().

Finally

This synchronous loading is an example of inefficient resource management because no operations can occur while the browser attempts to open and load the shader file. An efficient alternative would be to issue an asynchronous load command and allow additional operations to continue while the file is being opened and loaded. This section builds an infrastructure to support asynchronous loading and efficient accessing of the loaded resources. Based on this infrastructure, over the next few projects, the game engine will be expanded to support batch resource loading during scene transitions.

Related Articles

Latest Articles

All Category