Started to make the save/load system slightly more object oriented

svn-id: r19224
This commit is contained in:
Max Horn 2005-10-21 23:01:13 +00:00
parent 1185f51388
commit ffc5e1718f
5 changed files with 26 additions and 17 deletions

View file

@ -2134,7 +2134,7 @@ void ScummEngine_v71he::queueAuxEntry(int actorNum, int subIndex) {
#endif
const SaveLoadEntry *Actor::getSaveLoadEntries() {
void Actor::saveLoadWithSerializer(Serializer *ser) {
static const SaveLoadEntry actorEntries[] = {
MKLINE(Actor, _pos.x, sleInt16, VER(8)),
MKLINE(Actor, _pos.y, sleInt16, VER(8)),
@ -2234,7 +2234,14 @@ const SaveLoadEntry *Actor::getSaveLoadEntries() {
MKEND()
};
return actorEntries;
if (ser->isLoading()) {
// Not all actor data is saved; so when loading, we first reset
// the actor, to ensure completely reproducible behaviour (else,
// some not saved value in the actor class can cause odd things)
initActor(-1);
}
ser->saveLoadEntries(this, actorEntries);
}
} // End of namespace Scumm

View file

@ -25,6 +25,7 @@
#define ACTOR_H
#include "common/scummsys.h"
#include "scumm/saveload.h"
#include "scumm/scumm.h"
@ -81,9 +82,7 @@ struct AdjustBoxResult { /* Result type of AdjustBox functions */
byte box;
};
struct SaveLoadEntry;
class Actor {
class Actor : public Serializable {
public:
static byte kInvalidBox;
@ -277,8 +276,8 @@ public:
void setTalkCondition(int slot);
bool isTalkConditionSet(int slot) const;
// Used by the save/load syste:
static const SaveLoadEntry *getSaveLoadEntries();
// Used by the save/load system:
void saveLoadWithSerializer(Serializer *ser);
protected:
bool isInClass(int cls);

View file

@ -1603,7 +1603,7 @@ int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) {
for (i = 0; i < 8; ++i)
ser->saveLoadEntries(0, volumeFaderEntries);
if (!ser->isSaving()) {
if (ser->isLoading()) {
// Load all sounds that we need
fix_players_after_load(scumm);
fix_parts_after_load();

View file

@ -625,7 +625,6 @@ void ScummEngine::saveOrLoad(Serializer *s, uint32 savegameVersion) {
MKEND()
};
const SaveLoadEntry *actorEntries = Actor::getSaveLoadEntries();
const SaveLoadEntry *soundEntries = _sound->getSaveLoadEntries();
const SaveLoadEntry verbEntries[] = {
@ -951,14 +950,8 @@ void ScummEngine::saveOrLoad(Serializer *s, uint32 savegameVersion) {
//
// Save/load actors
//
if (s->isLoading()) {
// Not all actor data is saved; so when loading, we first reset
// all actors, to ensure completely reproducible behaviour (else,
// some not saved value in the actor class can cause odd things)
for (i = 0; i < _numActors; i++)
_actors[i].initActor(-1);
}
s->saveLoadArrayOf(_actors, _numActors, sizeof(_actors[0]), actorEntries);
_actors[i].saveLoadWithSerializer(s);
//

View file

@ -133,6 +133,8 @@ public:
_savegameVersion(savegameVersion)
{ }
// FIXME: Try to get rid of the _save_ref / _load_ref / _ref_me HACK !!!
// This is used by imuse...
SerializerSaveReference *_save_ref;
SerializerLoadReference *_load_ref;
void *_ref_me;
@ -168,6 +170,14 @@ protected:
void loadEntries(void *d, const SaveLoadEntry *sle);
};
// Mixin class / interface. Maybe call it ISerializable or SerializableMixin ?
class Serializable {
public:
virtual ~Serializable() {}
virtual void saveLoadWithSerializer(Serializer *ser) = 0;
};
} // End of namespace Scumm
#endif