diff options
author | Max Horn | 2005-10-21 23:01:13 +0000 |
---|---|---|
committer | Max Horn | 2005-10-21 23:01:13 +0000 |
commit | ffc5e1718f69954d08802ee3a134861b859f76a5 (patch) | |
tree | 654a9d7997839aeaf3a5f72335da99ac4e107167 | |
parent | 1185f51388ba146e300429516093d77f06b6ecdf (diff) | |
download | scummvm-rg350-ffc5e1718f69954d08802ee3a134861b859f76a5.tar.gz scummvm-rg350-ffc5e1718f69954d08802ee3a134861b859f76a5.tar.bz2 scummvm-rg350-ffc5e1718f69954d08802ee3a134861b859f76a5.zip |
Started to make the save/load system slightly more object oriented
svn-id: r19224
-rw-r--r-- | scumm/actor.cpp | 11 | ||||
-rw-r--r-- | scumm/actor.h | 9 | ||||
-rw-r--r-- | scumm/imuse.cpp | 2 | ||||
-rw-r--r-- | scumm/saveload.cpp | 11 | ||||
-rw-r--r-- | scumm/saveload.h | 10 |
5 files changed, 26 insertions, 17 deletions
diff --git a/scumm/actor.cpp b/scumm/actor.cpp index 05f81b0a0b..4ed79ae795 100644 --- a/scumm/actor.cpp +++ b/scumm/actor.cpp @@ -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 diff --git a/scumm/actor.h b/scumm/actor.h index 9c921de6fb..9d7da4e82b 100644 --- a/scumm/actor.h +++ b/scumm/actor.h @@ -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); diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp index bd38329486..322b3230e0 100644 --- a/scumm/imuse.cpp +++ b/scumm/imuse.cpp @@ -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(); diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index c5737939d5..fd94c22b71 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -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); + for (i = 0; i < _numActors; i++) + _actors[i].saveLoadWithSerializer(s); // diff --git a/scumm/saveload.h b/scumm/saveload.h index e413f1288c..dcaab584f5 100644 --- a/scumm/saveload.h +++ b/scumm/saveload.h @@ -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 |