Re: [AD] Emscripten port: writing persistent files

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On May 17, 2014 10:39 AM, "Max Savenkov" <max.savenkov@xxxxxxxxxx> wrote:
>
> By default, Emscripten provides implementation for various file and
> filesystem-related functions which reads data from memory, using
> embedded or preloaded packed filesystems. This allows programs to read
> data as usual with fopen etc.
>
> However, if you WRITE any files, they are not really stored anywhere
> and will be lost when page is reloaded. To avoid this, Emscripten
> provides API to write to IndexedDB, which allows persistent storage of
> files for web pages.
>
> To allow user to work with both in-memory and with IDB data, I think I
> will need to write a file interface, like one for PhysFS, which will
> user will have to set when he is working with persistent data. So, if
> I want to load a resource, then save and load game state, the
> pseudo-code would look like this:
>
> // Load resource from memory
> load_resource( "res/res1.dat" );
>
> #ifdef EMSCRIPTEN
> // Create and mount directory 'saves' (as per
> https://github.com/kripken/emscripten/blob/master/tests/fs/test_idbfs_sync.c
> example)
> al_ems_mount_idbfs( "saves/" );
>
> // Set IDBFS file interface
> set_file_interface( al_ems_get_file_interface() );
> #endif
>
> // Save file to IDBFS
> write_save( "saves/save1.sav" );
>
> #ifdef EMSCRIPTEN
> // Restore default file interface for further loading of resources etc.
> set_file_interface( al_get_default_file_interface() );
> #endif
>
> This will require programs that used just to write things anywhere to
> be modified with ugly #ifdefs, but I can see no way to do this
> transparently. So, unless anyone has a better idea, I will do it this
> way.
>

Sounds good to me.



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/