andersch.dev

<2023-04-10 Mon>

Game Package Formats

Package file formats in game development (and other software fields) are used to bundle up resources such as game assets into one file. The most common goal is to avoid the overhead of interacting with the filesystem when reading in assets.

Example API in C++ (WIP)

#define PKG_MAGIC_NUMBER "PACK"
u32 PKG_FILE_VERSION = 0;
u32 PKG_FLAGS        = 0;

struct pkg_creator_t
{
    u8* data;
    pkg_entry_t entries[];
};

void pkg_creator_init(pkg_creator_t* pkg);
void pkg_creator_deinit(pkg_creator_t* pkg);
void pkg_creator_add(pkg_creator_t* pkg, const char* entry_name, u8* data);
// void pkg_creator_remove(...);
// bool pkg_creator_load_...
// ...

bool pkg_creator_write_file(pkg_creator_t* pkg, const char* filename)
{
    // write header:
    // 1. write out magic nr
    // 2. write out file version
    // 3. write out flags
    // 4. write out offset into toc
    //
    // write out data
    //
    // write out toc
}

struct pkg_package_t
{
    // ...
};

Resources