Why register assets?

In cg_main.c, CG_RegisterGraphics() and CG_RegisterSounds() are called and provide a list of assets to precache. Why is this necessary? Can’t it be automated, by listing all available assets in the game folder and precaching everything?

In cg_main.c, CG_RegisterGraphics() and CG_RegisterSounds() are called and provide a list of assets to load. Why is this necessary? Can’t it be automated, by listing all available assets in the game folder and load everything?

Assets must be loaded to use them.
Loading assets is not asynchronous so it can cause the game to be non-responsive for a moment.
Loading all files in the game data would load unneeded files which causes longer load times and more memory usage.


CGame loads media that is expected to be used at start up. Having the game freeze (to load media) the first time a chat bubble, gibs, etc are shown would not be good.

For the most part it’s not just precaching, it’s storing a handle in a variable (i.e., cgs.media.balloonShader) to use the media later. This is desired so the game doesn’t waste time re-registering media each frame. Glares at UI_DrawNamedPic. Or have to deal with keeping track if the media has been attempted to be loaded yet, to avoid re-registering media.

CG_RegisterGraphics/Sounds could be better; there are assets that are loaded in cases where they won’t be used. Such as Team Arena prepare team sound being loaded in all gametypes, but it will only be used in CTF, 1Flag, Overload, and Harvester.

When removing a precache, can this result in error? Or it will just be slower?

The engine doesn’t care when you load assets. Assets are loaded at the same speed regardless of when they are loaded, because nothing else is done during that time (i.e., not asynchronous loading). For example; when a client joins after cgame start up, if cg_deferPlayers cvar is 0 (baseq3 default) the player model loading is deferred until scoreboard is shown to avoid interrupting game play.

Choose when the time to load assets is spent

  1. in the middle of the game when trying to make that prefect shot
  2. at start up with a nice loading screen
  3. a time when not doing something gameplay important (i.e. looking at scoreboard)