Virtual FileSystem
It's time for me now to open some files. Indeed, a game engine without input data is pretty useless ^^.My needs are not very complicated:
- Simple interface: I would like to have a C like interface to make it easy to use i.e. something like:
namespace VFS
{
FileHandle OpenFile (char const * const pFilePath, usigned int Flags);
void CloseFile (FileHandle pHdl);
size_t Write (FileHandle pHdl, void * pBuffer, size_t BufferSize);
/* etc. */
}
- Possibility to have multiple Virtual File Systems at the same time: e.g. I would like have the following instanciated VFS at the same time:
* VFS in charge of storing game updates,
* VFS in charge of storing game saves,
* VFS in charge of managing temporary files,
* etc.
- The above mentioned need implies that I will have to implement different types of VFS (in memory, standard OS access, zip, etc.),
- Ability to group and order VFS: For example if I have 2 VFS
* 1 VFS for game updates
* 1 VFS for standard game assets
and both contain data X, I want to transparently open data X from game's update VFS since it contains the latest version (last update).
- Group VFS: It could be interesting to put some VFS in groups. I will call these groups Drives e.g.
* Game: drive which will contain released game data,
- Zip VFS
- Standard VFS
* Patch: drive which will contain patched data,
- v1.2 Standard VFS
- v1.3 Standard VFS
- etc.
* etc.
e.g. If I want to open a file from Patch drive I will write the following code:
VFS::OpenFile("Patch:\Test\Test.txt", e_Read);
- Manage compression transparently: I will use a design very similar to the one discribed here : http://www.flipcode.com/archives/Programming_a_Virtual_File_System-Part_I.shtml
- Centralize API calls: For VFS which will access OS File System, I will use a central entry point (COSFileSystemDriver). The goal is to make API calls bottleneck easier to identify/debug (like with memory allocations).
- Thread safe: Since files can be opened from many threads at the same time, it is important to make this unique entry point (COSFileSystemDriver) thread safe. To acheive that I will use a well known design pattern: Producer/Consumer. To implement it, I will use a thread safe queue.
Let's code !!

Commentaires