File I/O


Saving Object Data
Object-based modules typically need to save their state data in the scene file when it gets saved. To do this your module must request notification of the O_LOAD() and O_SAVE() Access Notification messages. When handling each of these AN messages you will use functions from the ARG component to create and retrieve data blocks (called "formats") from the scene file as well as store and retrieve data from those formats.
For example, consider the following handlers that load and store an effect's state information:
//...
        case O_SAVE:
                {
                        FX_Format *f;
                        med = fxObjectGetTypeData(effect, FX_NOFLAG);

                        if (!med) return CONTINUE_ENTRY;

                        f = fxFormatNew(ai, "LagData", FX_NOFLAG);
                                fxArgSaveObj(f, "weight", med->weight_obj);
                                fxArgSaveInt(f, "scan", med->scan);
                }
                break;

        case O_LOAD:
                {
                        FX_Format *f;
                        med = fxObjectGetTypeData(effect, FX_NOFLAG);

                        if (!med) return CONTINUE_ENTRY;

                        EffectDataInit(med); 
                        f = fxFormatGet(ai, "LagData");
                        if(!f) return CONTINUE_ENTRY;
                                fxArgLoadObj(f, "weight", &med->weight_obj);
                                fxArgLoadInt(f, "scan", &med->scan);
                }
                break;

The first thing that happens in each handler is the retrieval of the effect's state data structure. In the O_SAVE() handler we then create a new format in the AccessInfo object passed to our access_func(), we've named the new format "LagData" (remember a format is a block of data in messiah files see ARG for more info). Then we add our state data to that new format using fxArgSave*() functions, giving each a name and setting it's value from our state data structure.
Getting the information back from the file is just as easy, this time instead of creating the format in the AccessInfo variable we retrieve it using fxFormatGet(). Once we've got a valid format pointer we can use the fxArgLoad*() functions to get individual pieces of data from it, accessing them by the name they where stored with. Typically you will want to retrieve this data right to your module's state data structure (after properly initializing it of course).
Saving Module Data
You can also save data to the scene file at the module level. This will typically be the way non-object based modules (e.g. Setup Module) will save their data. The process is exactly the same as above, however you would respond to GEN_SAVE_SCENE() and GEN_LOAD_SCENE(). If you decide you'd like to save data to messiah's config file you could respond to GEN_SAVE_CONFIG() and GEN_LOAD_CONFIG().


© 2003 pmG WorldWide, LLC.


www.projectmessiah.com

groups.yahoo.com/pmGmessiah

Last Updated on Thu Jul 10 04:49:36 2003