diff options
author | Max Horn | 2005-10-22 23:42:12 +0000 |
---|---|---|
committer | Max Horn | 2005-10-22 23:42:12 +0000 |
commit | 899eb271c6ade38b4fe4ebe82131591124e9f68e (patch) | |
tree | 334c766ca1ee0a62b413ae4bb52c4e56e3689296 /scumm | |
parent | b9b49c3b55a3625f9a56fb47ca0001f069739fed (diff) | |
download | scummvm-rg350-899eb271c6ade38b4fe4ebe82131591124e9f68e.tar.gz scummvm-rg350-899eb271c6ade38b4fe4ebe82131591124e9f68e.tar.bz2 scummvm-rg350-899eb271c6ade38b4fe4ebe82131591124e9f68e.zip |
Got rid of 'ref' code (or rather: hack) in the save/load system
svn-id: r19246
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/imuse.cpp | 60 | ||||
-rw-r--r-- | scumm/imuse_internal.h | 5 | ||||
-rw-r--r-- | scumm/imuse_player.cpp | 15 | ||||
-rw-r--r-- | scumm/saveload.cpp | 10 | ||||
-rw-r--r-- | scumm/saveload.h | 17 |
5 files changed, 33 insertions, 74 deletions
diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp index aedc2ba3b9..08b85be47f 100644 --- a/scumm/imuse.cpp +++ b/scumm/imuse.cpp @@ -323,6 +323,7 @@ void IMuseInternal::init_parts() { for (i = 0, part = _parts; i != ARRAYSIZE(_parts); i++, part++) { part->init(); + part->_se = this; part->_slot = i; } } @@ -1477,35 +1478,6 @@ void IMuseInternal::addDeferredCommand(int time, int a, int b, int c, int d, int // //////////////////////////////////////////////////////////// -enum { - TYPE_PART = 1, - TYPE_PLAYER = 2 -}; - -int IMuseInternal::saveReference(void *me_ref, byte type, void *ref) { - IMuseInternal *me = (IMuseInternal *)me_ref; - switch (type) { - case TYPE_PART: - return (Part *)ref - me->_parts; - case TYPE_PLAYER: - return (Player *)ref - me->_players; - default: - error("saveReference: invalid type"); - } -} - -void *IMuseInternal::loadReference(void *me_ref, byte type, int ref) { - IMuseInternal *me = (IMuseInternal *)me_ref; - switch (type) { - case TYPE_PART: - return &me->_parts[ref]; - case TYPE_PLAYER: - return &me->_players[ref]; - default: - error("loadReference: invalid type"); - } -} - int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) { const SaveLoadEntry mainEntries[] = { MKLINE(IMuseInternal, _queue_end, sleUint8, VER(8)), @@ -1529,7 +1501,7 @@ int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) { // VolumeFader is obsolete. const SaveLoadEntry volumeFaderEntries[] = { - MK_OBSOLETE_REF(VolumeFader, player, TYPE_PLAYER, VER(8), VER(16)), + MK_OBSOLETE(VolumeFader, player, sleUint16, VER(8), VER(16)), MK_OBSOLETE(VolumeFader, active, sleUint8, VER(8), VER(16)), MK_OBSOLETE(VolumeFader, curvol, sleUint8, VER(8), VER(16)), MK_OBSOLETE(VolumeFader, speed_lo_max, sleUint16, VER(8), VER(16)), @@ -1551,10 +1523,6 @@ int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) { int i; - ser->_ref_me = this; - ser->_save_ref = saveReference; - ser->_load_ref = loadReference; - ser->saveLoadEntries(this, mainEntries); ser->saveLoadArrayOf(_cmd_queue, ARRAYSIZE(_cmd_queue), sizeof(_cmd_queue[0]), cmdQueueEntries); ser->saveLoadArrayOf(_snm_triggers, ARRAYSIZE(_snm_triggers), sizeof(_snm_triggers[0]), snmTriggerEntries); @@ -1654,11 +1622,7 @@ Part::Part() { } void Part::saveLoadWithSerializer(Serializer *ser) { - // TODO: Get rid of MKREF usage! const SaveLoadEntry partEntries[] = { - MKREF(Part, _next, TYPE_PART, VER(8)), - MKREF(Part, _prev, TYPE_PART, VER(8)), - MKREF(Part, _player, TYPE_PLAYER, VER(8)), MKLINE(Part, _pitchbend, sleInt16, VER(8)), MKLINE(Part, _pitchbend_factor, sleUint8, VER(8)), MKLINE(Part, _transpose, sleInt8, VER(8)), @@ -1678,6 +1642,26 @@ void Part::saveLoadWithSerializer(Serializer *ser) { MKEND() }; + int num; + if (ser->isSaving()) { + num = (_next ? (_next - _se->_parts + 1) : 0); + ser->saveUint16(num); + + num = (_prev ? (_prev - _se->_parts + 1) : 0); + ser->saveUint16(num); + + num = (_player ? (_player - _se->_players + 1) : 0); + ser->saveUint16(num); + } else { + num = ser->loadUint16(); + _next = (num ? &_se->_parts[num - 1] : 0); + + num = ser->loadUint16(); + _prev = (num ? &_se->_parts[num - 1] : 0); + + num = ser->loadUint16(); + _player = (num ? &_se->_players[num - 1] : 0); + } ser->saveLoadEntries(this, partEntries); } diff --git a/scumm/imuse_internal.h b/scumm/imuse_internal.h index 10f6e5a373..985f376523 100644 --- a/scumm/imuse_internal.h +++ b/scumm/imuse_internal.h @@ -273,6 +273,7 @@ public: }; struct Part : public Serializable { + IMuseInternal *_se; int _slot; Part *_next, *_prev; MidiChannel *_mc; @@ -344,6 +345,7 @@ struct Part : public Serializable { // the public version, only contains a set of methods. class IMuseInternal { friend class Player; + friend class Part; protected: bool _native_mt32; @@ -430,9 +432,6 @@ protected: void fix_parts_after_load(); void fix_players_after_load(ScummEngine *scumm); - static int saveReference(void *me_ref, byte type, void *ref); - static void *loadReference(void *me_ref, byte type, int ref); - static void midiTimerCallback(void *data); public: diff --git a/scumm/imuse_player.cpp b/scumm/imuse_player.cpp index 496c90f480..92447a0a86 100644 --- a/scumm/imuse_player.cpp +++ b/scumm/imuse_player.cpp @@ -1171,15 +1171,8 @@ void Player::metaEvent(byte type, byte *msg, uint16 len) { // //////////////////////////////////////// -enum { - TYPE_PART = 1, - TYPE_PLAYER = 2 -}; - void Player::saveLoadWithSerializer(Serializer *ser) { - // TODO: Get rid of MKREF usage! static const SaveLoadEntry playerEntries[] = { - MKREF(Player, _parts, TYPE_PART, VER(8)), MKLINE(Player, _active, sleByte, VER(8)), MKLINE(Player, _id, sleUint16, VER(8)), MKLINE(Player, _priority, sleByte, VER(8)), @@ -1230,6 +1223,14 @@ void Player::saveLoadWithSerializer(Serializer *ser) { } _music_tick = _parser ? _parser->getTick() : 0; + int num; + if (ser->isSaving()) { + num = (_parts ? (_parts - _se->_parts + 1) : 0); + ser->saveUint16(num); + } else { + num = ser->loadUint16(); + _parts = (num ? &_se->_parts[num - 1] : 0); + } ser->saveLoadEntries(this, playerEntries); ser->saveLoadArrayOf(_parameterFaders, ARRAYSIZE(_parameterFaders), sizeof(ParameterFader), parameterFaderEntries); diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index fac979c1b9..f41576aa26 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -1547,10 +1547,6 @@ void Serializer::saveEntries(void *d, const SaveLoadEntry *sle) { // Skip obsolete entries if (type & 128) sle++; - } else if (size == 0xFF) { - // save reference - void *ptr = *((void **)at); - saveUint16(ptr ? ((*_save_ref) (_ref_me, type, ptr) + 1) : 0); } else { // save entry int columns = 1; @@ -1586,12 +1582,6 @@ void Serializer::loadEntries(void *d, const SaveLoadEntry *sle) { // Skip entries which are not present in this save game version if (type & 128) sle++; - } else if (size == 0xFF) { - // load reference... - int num = loadUint16(); - // ...but only use it if it's still there in CURRENT_VER - if (sle->maxVersion == CURRENT_VER) - *((void **)at) = num ? (*_load_ref) (_ref_me, type, num - 1) : NULL; } else { // load entry int columns = 1; diff --git a/scumm/saveload.h b/scumm/saveload.h index 3c27f8f9c7..e499f501aa 100644 --- a/scumm/saveload.h +++ b/scumm/saveload.h @@ -98,12 +98,6 @@ namespace Scumm { // End marker #define MKEND() {0xFFFF,0xFF,0xFF,0,0} -// A reference -#define MKREF(type,item,refid,minVer) {OFFS(type,item),refid,0xFF,minVer,CURRENT_VER} - -// An obsolete reference. -#define MK_OBSOLETE_REF(type,item,refid,minVer,maxVer) {0,sleUint16,0,minVer,maxVer} - enum { sleByte = 1, @@ -123,22 +117,13 @@ struct SaveLoadEntry { uint8 maxVersion; }; -typedef int SerializerSaveReference(void *me, byte type, void *ref); -typedef void *SerializerLoadReference(void *me, byte type, int ref); - class Serializer { public: Serializer(Common::InSaveFile *in, Common::OutSaveFile *out, uint32 savegameVersion) - : _loadStream(in), _saveStream(out), _save_ref(0), _load_ref(0), _ref_me(0), + : _loadStream(in), _saveStream(out), _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; - void saveLoadArrayOf(void *b, int len, int datasize, byte filetype); void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle); void saveLoadEntries(void *d, const SaveLoadEntry *sle); |