Dras.biz Just another WordPress site

June 27, 2012

What are VFS Contexts?

Filed under: SaveIt,SaveIT API Reference — mark @ 16:20

VFS stands for Virtual File System. SaveIt provides a VFSLoadContext and a VFSSaveContext who use this technique.

Basically the VFSSaveContext makes it possible to incremental write data to a single file without the need to rewrite the whole file
and without the need to batch all incoming save calls until Flush() needs to be called.

For example you need to use the plain SaveContext like this:

C#:

1
2
3
4
SaveContext context = SaveContext.ToFile("MyFile.dat");
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");
context.Flush();

JS:

1
2
3
4
var context : SaveContext = SaveContext.ToFile("MyFile.dat");
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");
context.Flush();

You always need to call the Flush method, which saves everything into the file named “MyFile.dat”.
The VFS eliminates the need of this:

C#:

1
2
3
VFSSaveContext context = SaveContext.ToUnbufferedFile("MyFile.dat");
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");

JS:

1
2
3
var context : VFSSaveContext = SaveContext.ToUnbufferedFile("MyFile.dat");
context.Save(gameObject.name, "name");
context.Save(42, "magicNumber");

After each Save call, the data is written into the file, without the need to rewrite the whole file. So you are
able to write some data and continue later to write some more data. For example small world changes.

The VFSLoadContext on the other hand is able to read from files created by the VFSSaveContext. The difference to the plain LoadContext
is that it is able to load the data on demand. For example, the LoadContext will read the whole file when created. The VFSLoadContext will only
load the data when a Load call is made and the data has not been loaded previously.

The VFS Context system works best when you save multiple classes or structs.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress