Metric Panda Games

One pixel at a time.

More About Game PAK files

Rival Fortress Update #26

Last week I talked about the new binary asset file format used by Rival Fortress. This week I’ll talk more about PAK files in general, as in the previous post I didn’t explain why I chose the “PAK” approach for game assets.

The naive approach

A common approach to game asset deployment is to keep all files in a plain directory structure in their original file format (i.e. images as JPG/PNG/TGA, sounds as WAV/OGG, meshes as FBX/OBJ). Many games do this because assets become easy to manage and patch, and become discoverable and editable by modders.

The disadvantage is that the game has to do more work at runtime. Some of the issues are:

  • having to pay the I/O overhead of having to open hundreds/thousands of file handles on each run
  • having to convert compressed image/sound formats to something the GPU/sound card can handle
  • having to build texture atlases or bitmap fonts
  • having to build vertex/index buffers from meshes

The better, but more laborious approach

The approach I like involves using some sort of PAK file. PAKs are resource bundles that are usually game dependent and can range from a simple uncompressed tarball-like blobs, to more complex containers with support for compression and streaming.

PAK files are, in my opinion, superior to the naive approach as they allow games to pre-process each asset into a format that is better suited for runtime use.

For example, the MPAK file format that I described in the previous post apply the following optimizations:

  • images are converted to raw bitmaps or DXTC compressed bitmaps that are GPU friendly
  • meshes are converted to vertex/index buffers
  • texture groups are combined into texture atlases
  • bitmap fonts are generated with drop-shadow and outlines baked into separate channels
  • material parameters are parsed and validated
  • shaders are validated and minified
  • sounds are converted to WAV

The obvious disadvantage of PAKs is the required preprocessing pipeline, that has various degrees of complexity based on how much the source assets are optimized into game-friendly formats.

Patching game PAK files

Applying asset updates to games that use PAK files can be tricky.

The approach I chose is to allow newer PAKs to override assets specified in other PAK files. Each asset in a PAK has unique ID (calculated as the hash of the asset name), and when two assets have conflicting IDs, the one contained in the most recent PAK is chosen.