A Virtual File System (VFS) abstracts the physical storage of your computer. Instead of the engine looking for a specific path like C:/Games/Data/Textures/Grass.png, it looks for a “Virtual Path” like assets://textures/grass.
.pak or .wad file, which is much faster for the OS to read.grass.png in the patch folder, it ignores the base version.A VFS works by managing a list of Mount Points:
C:/Users/Mods/CoolSword/C:/Game/Patches/v1.1/C:/Game/Data/base.pakWhen you call VFS.Open("textures/sword.png"), the system checks each mount point in order. The first one that contains the file wins.
class VirtualFileSystem {
std::vector<IMount*> mounts;
FileHandle Open(string path) {
for (auto* m : mounts) {
if (m->Exists(path)) {
return m->Open(path); // Returns a stream from Disk or PAK
}
}
return nullptr; // 404 Not Found
}
};
In modern open-world games, the VFS is usually Thread-Safe. You request a file, and the VFS returns a “Future” or “Task.” The data is loaded on a background thread and delivered to you when it’s ready, preventing “hitch” during gameplay.