I'm trying to save some allegro images directly in my save game data file.
I have Deserialiser/Serialiser class that works as stream and is basically wrapped FILE* f, so I thought this won't be hard.
I used the custom data pointer to store pointer to the the (De)serliaser and mapped all the methods of the FILE_INTERFACE.
this->fileInterface = new ALLEGRO_FILE_INTERFACE;
this->fileInterface->fi_fopen = &AllegroFileToDeserialiserConnection::fi_fopen;
this->fileInterface->fi_fclose = &AllegroFileToDeserialiserConnection::fi_fclose;
this->fileInterface->fi_fread = &AllegroFileToDeserialiserConnection::fi_fread;
this->fileInterface->fi_fwrite = NULL;
this->fileInterface->fi_fflush = &AllegroFileToDeserialiserConnection::fi_fflush;
this->fileInterface->fi_ftell = &AllegroFileToDeserialiserConnection::fi_ftell;
this->fileInterface->fi_fseek = &AllegroFileToDeserialiserConnection::fi_fseek;
this->fileInterface->fi_feof = &AllegroFileToDeserialiserConnection::fi_feof;
this->fileInterface->fi_ferror = &AllegroFileToDeserialiserConnection::fi_ferror;
this->fileInterface->fi_fclearerr = &AllegroFileToDeserialiserConnection::fi_fclearerr;
this->fileInterface->fi_fungetc = NULL;
this->fileInterface->fi_fsize = &AllegroFileToDeserialiserConnection::fi_fsize;
this->file = al_fopen_interface(this->fileInterface, (const char*)(&serialiser), "rb");
On the last line I use trick, I use the file name parameter to actually pass the pointer to the serialiser that will be used.
Saving of the bitmap worked fine, and it was saved in nice single call of fi_fwrite (with length of 50kb).
When I tried to load the bitmap, it just didn't work, I observed several calls of ftell (I just return 0, as it calls in the beginning), then reads and fseeks.
After that the result bitmap has 0 width 0 height (and it was saved as 2048X2048 bitmap), and not only that, the stream it reads from is left in some inconsistent state (It doesn't read exactly the same as it wrote to the stream).
Can this work at all? Am I not using some obsolete method that is not working anymore?
Thanks for any pointers.
In the worst case, I can save those bitmaps as separate files, but I would really like to avoid that, it would be messy.