Actually, that was the first time I heard about OBB

, I want my game to be available to cheaper phones in the market (with Android 2.0+) so I haven't done any research on 2.3. But OBB also fits into the system that I'm describing.
First, we have a VFSManager. Hmm, there's no code box in this forum.
A more readable version of the code can be found here:
https://gist.github.com/1062847
class VFSManager
{
//Add a filesystem to a stack of managed filesystem
void mountFilesystem(IFileSystem* fs, const char* name);
//Remove a filesystem
void unmountFilesystem(const char* name);
void getMountedFilesystems(IStringIterator* it) const;
//Similar to dir/ls
void listFiles(const char* path, IStringIterator* it) const;
bool fileExists(const char* path) const;
//return null if file can't be found
IInputStream* openFile(const char* path) const;
//Other stuffs
};
VFSManager serves as a container for other subsystems. listFiles, fileExists, openFile will iterate through the filesystem stack, calling the desired method on each filesystem either until it gets the desired result: non-null return or until it reaches the end of the stack.
IFilesystem is specified as:
class IFilesystem
{
void listFiles(const char* path, IStringIterator* it) const = 0;
bool fileExists(const char* path) const = 0;
//return null if file can't be found
IInputStream* openFile(const char* path) const = 0;
};
And IInputStream:
class IInputStream
{
int getSize() const = 0;
bool eof() const = 0;
//return number of bytes read
int read(MoaiDataBuffer* buff, int numBytesToRead) = 0;
void seek(int offsetType, int value) = 0;
};
We can implement different filesystem based on this interface. Here are some that I can think of right now:
- NativeFilesystem: just wraps C's file functions. Not really useful on Android
- ZipFilesystem: mount a zip file
- AndroidAssetsFilesystem: inherits ZipFilesystem, mount the apk but treat all paths as relative to the assets folder
- OBBFilesystem: use JNI to provide C++ access to OBBs.
- NetworkFilesystem: grab data from an asset server to let designer experiment with their assets without having to rebuild. Removed in release build.
Since filesystem are added to a stack, the last added filesystem will have a higher priority. Thus, things like theme/expansion pack can be easily implemented. Just mount the active pack as the last filesystem. It will override bundled assets. Needless to say, all current file IO(texture, font, audio loading) need to wrapped through VFSManager.
Yep, it looks a lot like PhysFS, but I dislike PhysFS since it is not really open to plugins and does not support password-locked archive, which is important if you want to protect your assets for some reasons (eg: hide source code to prevent hacking of online/competitive games)
I'll be happy to contribute if given some guideline on coding conventions, library structures, etc… so that it fits into the current framework.
About the plugin framework, I believe Moai is still too young for that. But if you have time, you can take a look at how Appcelerator, Unity and Airplay do it.