开发者

Virtual file systems

Most games come with their resources (models, textures, etc.) packed into special files (like .pk3 files in Quake 3 for example). Apparently, those files somehow get "mounted" and are used as if they were separate file systems.

I'd like to know how this is achieved. The only strategy I came up with so far is placing offset-size information in the file's header, then memory-mapping the file and accessing the resources as if they were independent write-protected chunks of memory.

开发者_如何学编程

I'd like to know if my strategy is viable and if there are better alternatives.

Thanks!


Your strategy is quite reasonable; in fact, it's an exact analogue of what a filesystem driver does with a raw block device. What problems are you having with that implementation?


Your approach sounds reasonable. Basically you'll have an ISAM file with (optional) metadata. You can split the file into sections ("directories") based on criteria (content type, frequency of use, locality of use, etc) and have a separate index/table of contents for each section. If you allow a section as a content type, then you can nest them and handle them in a consistent fashion.

If your requirements are fairly basic, you could consider simply using a zip/tar file as a container. Looking at the code for these would probably be a good place to start, regardless.


I can't say about exact format of Quake3, but there are several approaches to do what you need:

  1. archive files (ZIP, Tar, etc)
  2. compound storage of different kind. On Windows there's Microsoft Structured Storage
  3. embedded single-file database
  4. virtual file system, which implements an actual file system, but stored not on the disk partition, but somewhere else (in resources, in memory etc).

Each of those approaches has it's own strengths and weaknesses.

Our SolFS product is an example of virtual file system mentioned above. It was designed for tasks similar to yours.

Archives and some compound file implementations usually have linear sequential structure - the files are written one by one with some directory at the beginning or at the end of file.

Some compound file implementations, databases and virtual file system have page-based structure ("page" is similar to sector or cluster in FAT or NTFS) where files can be scattered across the storage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜