Skip to content

virtual file system structure

Tim Leonard edited this page Sep 15, 2023 · 1 revision

Virtual File System

Overview

All the IO in the engine passes through a virtual file system rather than directly accessing drives or other storage mediums. The virtual file system provides an abstracted file system with a common interface to access files that are stored in different ways.

The VFS is accessed through the virtual_file_system class in workshop.core, this class is a singleton that will always be available one the engine is initialized.

Paths

All paths used to access the VFS are in the format:

protcol:a/path/myfile.dat

The protocol dictates where the file comes from. Different protocols can be stored in different areas.

For example on console you could have a "save" protocol that reads or writes using propriatory savegame apis rather than access a disk directly.

Handlers

Handlers are classes that derived from virtual_file_system_handler. They implement an interface that allows the VFS to access the data they provide access to.

There are many different types of handlers - ones that access specific folders on disk, ones that access archives, ones that redirect access, and so forth.

Each handler is registered with the virtual file system and associated with a protocol. All attempts to access that protocol will use the registered handler.

Multiple handlers can be registered to the same protocol with different priority levels. When trying to access a file the VFS will go through each handler in priority order until it can find one that can handle the request. This allows folders to be "overlaid" onto each other - for example the "data" protocol points to the engine assets and has the game assets overlaid, allowing unified access to both and allowing games to override engine assets.

The main handlers for the engine are registered in engine::create_filesystem.