The constructor of class SavefileCallback can be used to add a callback which is called before a game is saved and after it's restored. This is useful to move data in and out of you.props, or after a restore if there's data not stored in the savefile which can be easily regenerated.
NOTE: I experienced some weirdness with C++ global constructors, and since global constructors probably differ with compiler and system, until this has been tested on all compiler/system combinations, any code which uses the callbacks should fail gracefully if the callbacks aren't called.
L37LE3WIRSYEOR5VQG3M5OEXUXZ4PZEDVXOOSLMYCNNNRQCM63PAC OMSSJON5IE4LBXJ7CZE52IZRZS7ZICS23SKP4AGLHH3QNCRMEFVAC JJULXW764V5C2HJKZNWQAEWB6QM5YZADD7ZCE35LYTBFEM6PMYCAC K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC KR655YT3I3U5DMN5NS3FPUGMDNT4BI56K3SFF2FNJ77C45NFKL5AC QYDFLJPRJ3GKULPAMHDSTR4JFASE5T45FPQYXJ25PWVN77KFKPGAC AM7QPHDAWNXHLUEVUHVRHG2RO2DOIEFFU4GV3DCIROW6O5HW7H4AC 5B5DP5S6A6LQMKZYVLQAEMHQZWFWYDHPCKQGRNSCNNYIBQYZ6BIQC RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC TR4NPGNO5QNNRJNVMNSUEO5QLT37HCXXDOBKXCB5XWXRQNAJ5SHAC NCDWWDJQLAU5ORSAQGZKJJ5E22VTDGGPJMVVBWQFHQ2B3U3UFHDQC 7AMQN7MITMXBNVDAK5VOXTQ4TZIAOD6ZLOFJG7GQMBTY23Y2BKSAC /////////////////////////////////////////////////////////////////////////////// SavefileCallback//// Callbacks which are called before a save and after a restore. Can be used// to move stuff in and out of you.props, or on a restore to recalculate data// which isn't stored in the savefile. Declare a SavefileCallback variable// using a C++ global constructor to register the callback.//// XXX: Due to some weirdness with C++ global constructors (see below) I'm// not sure if this will work for all compiler/system combos, so make any// code which uses this fail gracefully if the callbacks aren't called.SavefileCallback::SavefileCallback(callback func){ASSERT(func != NULL);// XXX: For some reason (at least with GCC 4.3.2 on Linux) if the// callback list is made with a global contructor then it gets emptied// out by the time that pre_save() or post_restore() is called,// probably having something to do with the fact that global// contructors are also used to add the callbacks. Thus we have to do// it this way.if (_callback_list == NULL)_callback_list = new std::vector<SavefileCallback::callback>();_callback_list->push_back(func);}void SavefileCallback::pre_save(){ASSERT(crawl_state.saving_game);if (_callback_list == NULL)return;for (unsigned int i = 0; i < _callback_list->size(); i++){callback func = (*_callback_list)[i];(*func)(true);}}void SavefileCallback::post_restore(){ASSERT(!crawl_state.saving_game);if (_callback_list == NULL)return;for (unsigned int i = 0; i < _callback_list->size(); i++){callback func = (*_callback_list)[i];(*func)(false);}}