From 69b1485a22dc2b8a2cfe0bd10edcbaad0da0cf6e Mon Sep 17 00:00:00 2001 From: strangerke Date: Thu, 12 May 2011 01:13:57 +0200 Subject: GIT: Clean up: Suppress SVN tags, now useless --- engines/scumm/saveload.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 3bfe51a77b..be90ba2f39 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -18,9 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ #include "common/config-manager.h" -- cgit v1.2.3 From 45e65d7ea04b10cf7bb5282bd66b8df609700a63 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 11 May 2011 16:23:26 +0200 Subject: SCUMM: Refactor how resource (types) are srepresented Previously, we had a couple of arrays of size N (where N = number of resource types), one for each attribute of a resource type (such as as the number of resources of that type. Now, we have one array of size N, whose elements are a record aggregating all the attributes of each resource type. --- engines/scumm/saveload.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index be90ba2f39..424e0005f4 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -428,7 +428,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // Nuke all resources for (i = rtFirst; i <= rtLast; i++) if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat)) - for (j = 0; j < _res->num[i]; j++) { + for (j = 0; j < _res->_types[i].num; j++) { _res->nukeResource(i, j); } @@ -517,7 +517,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // loading such an old save game, try to upgrade the old to new format. if (hdr.ver < VER(22)) { // Convert all rtScaleTable resources to matching scale items - for (i = 1; i < _res->num[rtScaleTable]; i++) { + for (i = 1; i < _res->_types[rtScaleTable].num; i++) { convertScaleTableToScaleSlot(i); } } @@ -1243,11 +1243,11 @@ void ScummEngine::saveOrLoad(Serializer *s) { // number of script resources, savegames won't break. if (s->isSaving()) { for (type = rtFirst; type <= rtLast; type++) { - if (_res->mode[type] != 1 && type != rtTemp && type != rtBuffer) { + if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... - for (idx = 0; idx < _res->num[type]; idx++) { + for (idx = 0; idx < _res->_types[type].num; idx++) { // Only save resources which actually exist... - if (_res->address[type][idx]) { + if (_res->_types[type].address[idx]) { s->saveUint16(idx); // Save the index of the resource saveResource(s, type, idx); } @@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { } else { while ((type = s->loadUint16()) != 0xFFFF) { while ((idx = s->loadUint16()) != 0xFFFF) { - assert(0 <= idx && idx < _res->num[type]); + assert(0 <= idx && idx < _res->_types[type].num); loadResource(s, type, idx); } } @@ -1269,13 +1269,13 @@ void ScummEngine::saveOrLoad(Serializer *s) { // with index 0, and breaks whenever we change the limit on a given // resource type. for (type = rtFirst; type <= rtLast; type++) - if (_res->mode[type] != 1 && type != rtTemp && type != rtBuffer) { + if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) { // For V1-V5 games, there used to be no object name resources. // At some point this changed. But since old savegames rely on // unchanged resource counts, we have to hard code the following check if (_game.version < 6 && type == rtObjectName) continue; - for (idx = 1; idx < _res->num[type]; idx++) + for (idx = 1; idx < _res->_types[type].num; idx++) saveLoadResource(s, type, idx); } } @@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // if (s->isSaving()) { for (i = rtFirst; i <= rtLast; i++) - for (j = 1; j < _res->num[i]; j++) { + for (j = 1; j < _res->_types[i].num; j++) { if (_res->isLocked(i, j)) { s->saveByte(i); s->saveUint16(j); @@ -1637,9 +1637,9 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { byte *ptr; uint32 size; - if (!_res->mode[type]) { + if (!_res->_types[type].mode) { if (ser->isSaving()) { - ptr = _res->address[type][idx]; + ptr = _res->_types[type].address[idx]; if (ptr == NULL) { ser->saveUint32(0); return; @@ -1676,10 +1676,10 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { } } } - } else if (_res->mode[type] == 2 && ser->getVersion() >= VER(23)) { + } else if (_res->_types[type].mode == 2 && ser->getVersion() >= VER(23)) { // Save/load only a list of resource numbers that need to be reloaded. if (ser->isSaving()) { - ser->saveUint16(_res->address[type][idx] ? 1 : 0); + ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0); } else { if (ser->loadUint16()) ensureResourceLoaded(type, idx); @@ -1688,10 +1688,10 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { } void ScummEngine::saveResource(Serializer *ser, int type, int idx) { - assert(_res->address[type][idx]); + assert(_res->_types[type].address[idx]); - if (_res->mode[type] == 0) { - byte *ptr = _res->address[type][idx]; + if (_res->_types[type].mode == 0) { + byte *ptr = _res->_types[type].address[idx]; uint32 size = ((MemBlkHeader *)ptr)->size; ser->saveUint32(size); @@ -1713,7 +1713,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { assert(size); _res->createResource(type, idx, size); ser->loadBytes(getResourceAddress(type, idx), size); - } else if (_res->mode[type] == 0) { + } else if (_res->_types[type].mode == 0) { uint32 size = ser->loadUint32(); assert(size); _res->createResource(type, idx, size); @@ -1725,7 +1725,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { if (type == rtObjectName) { _newNames[idx] = ser->loadUint16(); } - } else if (_res->mode[type] == 2) { + } else if (_res->_types[type].mode == 2) { // HE Games use sound resource 1 for speech if (_game.heversion >= 60 && idx == 1) return; -- cgit v1.2.3 From 26efa39d2caa0b6bb7da8414382eb5643c108261 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 11 May 2011 17:07:31 +0200 Subject: SCUMM: Document and cleanup resource type mode --- engines/scumm/saveload.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 424e0005f4..40dc70af4b 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1243,7 +1243,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // number of script resources, savegames won't break. if (s->isSaving()) { for (type = rtFirst; type <= rtLast; type++) { - if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) { + if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... for (idx = 0; idx < _res->_types[type].num; idx++) { // Only save resources which actually exist... @@ -1269,7 +1269,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // with index 0, and breaks whenever we change the limit on a given // resource type. for (type = rtFirst; type <= rtLast; type++) - if (_res->_types[type].mode != 1 && type != rtTemp && type != rtBuffer) { + if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { // For V1-V5 games, there used to be no object name resources. // At some point this changed. But since old savegames rely on // unchanged resource counts, we have to hard code the following check @@ -1637,7 +1637,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { byte *ptr; uint32 size; - if (!_res->_types[type].mode) { + if (_res->_types[type]._mode == kDynamicResTypeMode) { if (ser->isSaving()) { ptr = _res->_types[type].address[idx]; if (ptr == NULL) { @@ -1676,7 +1676,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { } } } - } else if (_res->_types[type].mode == 2 && ser->getVersion() >= VER(23)) { + } else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) { // Save/load only a list of resource numbers that need to be reloaded. if (ser->isSaving()) { ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0); @@ -1690,7 +1690,7 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { void ScummEngine::saveResource(Serializer *ser, int type, int idx) { assert(_res->_types[type].address[idx]); - if (_res->_types[type].mode == 0) { + if (_res->_types[type]._mode == kDynamicResTypeMode) { byte *ptr = _res->_types[type].address[idx]; uint32 size = ((MemBlkHeader *)ptr)->size; @@ -1713,7 +1713,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { assert(size); _res->createResource(type, idx, size); ser->loadBytes(getResourceAddress(type, idx), size); - } else if (_res->_types[type].mode == 0) { + } else if (_res->_types[type]._mode == kDynamicResTypeMode) { uint32 size = ser->loadUint32(); assert(size); _res->createResource(type, idx, size); @@ -1725,7 +1725,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { if (type == rtObjectName) { _newNames[idx] = ser->loadUint16(); } - } else if (_res->_types[type].mode == 2) { + } else if (_res->_types[type]._mode == kSoundResTypeMode) { // HE Games use sound resource 1 for speech if (_game.heversion >= 60 && idx == 1) return; -- cgit v1.2.3 From 7be0305da9998568c9ac2538ab8c0ab4ca507bf1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 11 May 2011 17:10:59 +0200 Subject: SCUMM: Rename saveLoadResource to loadResourceOLD, remove unused save code in it --- engines/scumm/saveload.cpp | 59 +++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 40dc70af4b..cd48feee54 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1276,7 +1276,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { if (_game.version < 6 && type == rtObjectName) continue; for (idx = 1; idx < _res->_types[type].num; idx++) - saveLoadResource(s, type, idx); + loadResourceOLD(s, type, idx); } } @@ -1633,57 +1633,32 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) { } #endif -void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) { - byte *ptr; +void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { uint32 size; if (_res->_types[type]._mode == kDynamicResTypeMode) { - if (ser->isSaving()) { - ptr = _res->_types[type].address[idx]; - if (ptr == NULL) { - ser->saveUint32(0); - return; - } - - size = ((MemBlkHeader *)ptr)->size; - - ser->saveUint32(size); - ser->saveBytes(ptr + sizeof(MemBlkHeader), size); - + size = ser->loadUint32(); + if (size) { + _res->createResource(type, idx, size); + ser->loadBytes(getResourceAddress(type, idx), size); if (type == rtInventory) { - ser->saveUint16(_inventory[idx]); + _inventory[idx] = ser->loadUint16(); } if (type == rtObjectName && ser->getVersion() >= VER(25)) { - ser->saveUint16(_newNames[idx]); - } - } else { - size = ser->loadUint32(); - if (size) { - _res->createResource(type, idx, size); - ser->loadBytes(getResourceAddress(type, idx), size); - if (type == rtInventory) { - _inventory[idx] = ser->loadUint16(); - } - if (type == rtObjectName && ser->getVersion() >= VER(25)) { - // Paranoia: We increased the possible number of new names - // to fix bugs #933610 and #936323. The savegame format - // didn't change, but at least during the transition - // period there is a slight chance that we try to load - // more names than we have allocated space for. If so, - // discard them. - if (idx < _numNewNames) - _newNames[idx] = ser->loadUint16(); - } + // Paranoia: We increased the possible number of new names + // to fix bugs #933610 and #936323. The savegame format + // didn't change, but at least during the transition + // period there is a slight chance that we try to load + // more names than we have allocated space for. If so, + // discard them. + if (idx < _numNewNames) + _newNames[idx] = ser->loadUint16(); } } } else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) { // Save/load only a list of resource numbers that need to be reloaded. - if (ser->isSaving()) { - ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0); - } else { - if (ser->loadUint16()) - ensureResourceLoaded(type, idx); - } + if (ser->loadUint16()) + ensureResourceLoaded(type, idx); } } -- cgit v1.2.3 From 75b9deb1856bae8355403faa5f55857f3929adb6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 11 May 2011 18:06:30 +0200 Subject: SCUMM: Get rid of the MemBlkHeader hack This uncovered at least one potentially serious bug in the inventory code, which still needs to be investigated and fixed. --- engines/scumm/saveload.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index cd48feee54..0ca16482ce 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1247,7 +1247,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { s->saveUint16(type); // Save the res type... for (idx = 0; idx < _res->_types[type].num; idx++) { // Only save resources which actually exist... - if (_res->_types[type].address[idx]) { + if (_res->_types[type]._address[idx]) { s->saveUint16(idx); // Save the index of the resource saveResource(s, type, idx); } @@ -1663,14 +1663,14 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { } void ScummEngine::saveResource(Serializer *ser, int type, int idx) { - assert(_res->_types[type].address[idx]); + assert(_res->_types[type]._address[idx]); if (_res->_types[type]._mode == kDynamicResTypeMode) { - byte *ptr = _res->_types[type].address[idx]; - uint32 size = ((MemBlkHeader *)ptr)->size; + byte *ptr = _res->_types[type]._address[idx]; + uint32 size = _res->_types[type]._size[idx]; ser->saveUint32(size); - ser->saveBytes(ptr + sizeof(MemBlkHeader), size); + ser->saveBytes(ptr, size); if (type == rtInventory) { ser->saveUint16(_inventory[idx]); -- cgit v1.2.3 From 0342ab3f1b2d67de6fa0112311b973b55d509f1c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 11 May 2011 18:11:37 +0200 Subject: SCUMM: Rename ResTypeData::num to _num --- engines/scumm/saveload.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 0ca16482ce..376351c19a 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -428,7 +428,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // Nuke all resources for (i = rtFirst; i <= rtLast; i++) if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat)) - for (j = 0; j < _res->_types[i].num; j++) { + for (j = 0; j < _res->_types[i]._num; j++) { _res->nukeResource(i, j); } @@ -517,7 +517,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // loading such an old save game, try to upgrade the old to new format. if (hdr.ver < VER(22)) { // Convert all rtScaleTable resources to matching scale items - for (i = 1; i < _res->_types[rtScaleTable].num; i++) { + for (i = 1; i < _res->_types[rtScaleTable]._num; i++) { convertScaleTableToScaleSlot(i); } } @@ -1245,7 +1245,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { for (type = rtFirst; type <= rtLast; type++) { if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... - for (idx = 0; idx < _res->_types[type].num; idx++) { + for (idx = 0; idx < _res->_types[type]._num; idx++) { // Only save resources which actually exist... if (_res->_types[type]._address[idx]) { s->saveUint16(idx); // Save the index of the resource @@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { } else { while ((type = s->loadUint16()) != 0xFFFF) { while ((idx = s->loadUint16()) != 0xFFFF) { - assert(0 <= idx && idx < _res->_types[type].num); + assert(0 <= idx && idx < _res->_types[type]._num); loadResource(s, type, idx); } } @@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // unchanged resource counts, we have to hard code the following check if (_game.version < 6 && type == rtObjectName) continue; - for (idx = 1; idx < _res->_types[type].num; idx++) + for (idx = 1; idx < _res->_types[type]._num; idx++) loadResourceOLD(s, type, idx); } } @@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // if (s->isSaving()) { for (i = rtFirst; i <= rtLast; i++) - for (j = 1; j < _res->_types[i].num; j++) { + for (j = 1; j < _res->_types[i]._num; j++) { if (_res->isLocked(i, j)) { s->saveByte(i); s->saveUint16(j); -- cgit v1.2.3 From abaaf0cad9a63c1a6f1946a8a90facd1535e762d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 13 May 2011 11:39:51 +0200 Subject: SCUMM: Tweak sound res syncing --- engines/scumm/saveload.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 376351c19a..d81095a37b 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1636,7 +1636,11 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) { void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { uint32 size; - if (_res->_types[type]._mode == kDynamicResTypeMode) { + if (type == rtSound && ser->getVersion() >= VER(23)) { + // Save/load only a list of resource numbers that need to be reloaded. + if (ser->loadUint16()) + ensureResourceLoaded(rtSound, idx); + } else if (_res->_types[type]._mode == kDynamicResTypeMode) { size = ser->loadUint32(); if (size) { _res->createResource(type, idx, size); @@ -1655,10 +1659,6 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { _newNames[idx] = ser->loadUint16(); } } - } else if (_res->_types[type]._mode == kSoundResTypeMode && ser->getVersion() >= VER(23)) { - // Save/load only a list of resource numbers that need to be reloaded. - if (ser->loadUint16()) - ensureResourceLoaded(type, idx); } } @@ -1688,11 +1688,17 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { assert(size); _res->createResource(type, idx, size); ser->loadBytes(getResourceAddress(type, idx), size); + } else if (type == rtSound) { + // HE Games use sound resource 1 for speech + if (_game.heversion >= 60 && idx == 1) + return; + + ensureResourceLoaded(rtSound, idx); } else if (_res->_types[type]._mode == kDynamicResTypeMode) { uint32 size = ser->loadUint32(); assert(size); - _res->createResource(type, idx, size); - ser->loadBytes(getResourceAddress(type, idx), size); + byte *ptr = _res->createResource(type, idx, size); + ser->loadBytes(ptr, size); if (type == rtInventory) { _inventory[idx] = ser->loadUint16(); @@ -1700,12 +1706,6 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) { if (type == rtObjectName) { _newNames[idx] = ser->loadUint16(); } - } else if (_res->_types[type]._mode == kSoundResTypeMode) { - // HE Games use sound resource 1 for speech - if (_game.heversion >= 60 && idx == 1) - return; - - ensureResourceLoaded(type, idx); } } -- cgit v1.2.3 From c02420df43bec4ec523c18d8e6fdb381af29c1b5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 13 May 2011 11:45:42 +0200 Subject: SCUMM: Add a Resource class, refactor res code around it --- engines/scumm/saveload.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index d81095a37b..996e8685bb 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -1247,7 +1247,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { s->saveUint16(type); // Save the res type... for (idx = 0; idx < _res->_types[type]._num; idx++) { // Only save resources which actually exist... - if (_res->_types[type]._address[idx]) { + if (_res->_types[type]._resources[idx]._address) { s->saveUint16(idx); // Save the index of the resource saveResource(s, type, idx); } @@ -1663,11 +1663,11 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { } void ScummEngine::saveResource(Serializer *ser, int type, int idx) { - assert(_res->_types[type]._address[idx]); + assert(_res->_types[type]._resources[idx]._address); if (_res->_types[type]._mode == kDynamicResTypeMode) { - byte *ptr = _res->_types[type]._address[idx]; - uint32 size = _res->_types[type]._size[idx]; + byte *ptr = _res->_types[type]._resources[idx]._address; + uint32 size = _res->_types[type]._resources[idx]._size; ser->saveUint32(size); ser->saveBytes(ptr, size); -- cgit v1.2.3 From 649f8e0a84804a9d1272ba16b146ea2b9da501fe Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 13 May 2011 14:02:53 +0200 Subject: SCUMM: Rename ResTypes->ResType, introduce ResId typedef, change code to use both --- engines/scumm/saveload.cpp | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 996e8685bb..f37ca36c6f 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -311,7 +311,6 @@ static bool loadSaveGameHeader(Common::SeekableReadStream *in, SaveGameHeader &h bool ScummEngine::loadState(int slot, bool compat) { Common::String filename; Common::SeekableReadStream *in; - int i, j; SaveGameHeader hdr; int sb, sh; @@ -426,10 +425,10 @@ bool ScummEngine::loadState(int slot, bool compat) { memset(gfxUsageBits, 0, sizeof(gfxUsageBits)); // Nuke all resources - for (i = rtFirst; i <= rtLast; i++) - if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat)) - for (j = 0; j < _res->_types[i]._num; j++) { - _res->nukeResource(i, j); + for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) + if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat)) + for (ResId idx = 0; idx < _res->_types[type]._num; idx++) { + _res->nukeResource(type, idx); } resetScummVars(); @@ -517,8 +516,8 @@ bool ScummEngine::loadState(int slot, bool compat) { // loading such an old save game, try to upgrade the old to new format. if (hdr.ver < VER(22)) { // Convert all rtScaleTable resources to matching scale items - for (i = 1; i < _res->_types[rtScaleTable]._num; i++) { - convertScaleTableToScaleSlot(i); + for (ResId idx = 1; idx < _res->_types[rtScaleTable]._num; idx++) { + convertScaleTableToScaleSlot(idx); } } @@ -1116,7 +1115,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { MKEND() }; - int i, j; + int i; int var120Backup; int var98Backup; uint8 md5Backup[16]; @@ -1134,9 +1133,9 @@ void ScummEngine::saveOrLoad(Serializer *s) { // MD5 Operations: Backup on load, compare, and reset. if (s->isLoading()) { char md5str1[32+1], md5str2[32+1]; - for (j = 0; j < 16; j++) { - sprintf(md5str1 + j*2, "%02x", (int)_gameMD5[j]); - sprintf(md5str2 + j*2, "%02x", (int)md5Backup[j]); + for (i = 0; i < 16; i++) { + sprintf(md5str1 + i*2, "%02x", (int)_gameMD5[i]); + sprintf(md5str2 + i*2, "%02x", (int)md5Backup[i]); } debug(2, "Save version: %d", s->getVersion()); @@ -1236,13 +1235,14 @@ void ScummEngine::saveOrLoad(Serializer *s) { // // Save/load resources // - int type, idx; + ResType type; + ResId idx; if (s->getVersion() >= VER(26)) { // New, more robust resource save/load system. This stores the type // and index of each resource. Thus if we increase e.g. the maximum // number of script resources, savegames won't break. if (s->isSaving()) { - for (type = rtFirst; type <= rtLast; type++) { + for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) { if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... for (idx = 0; idx < _res->_types[type]._num; idx++) { @@ -1257,9 +1257,9 @@ void ScummEngine::saveOrLoad(Serializer *s) { } s->saveUint16(0xFFFF); // End marker } else { - while ((type = s->loadUint16()) != 0xFFFF) { + while ((type = (ResType)s->loadUint16()) != 0xFFFF) { while ((idx = s->loadUint16()) != 0xFFFF) { - assert(0 <= idx && idx < _res->_types[type]._num); + assert(idx < _res->_types[type]._num); loadResource(s, type, idx); } } @@ -1268,7 +1268,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // Old, fragile resource save/load system. Doesn't save resources // with index 0, and breaks whenever we change the limit on a given // resource type. - for (type = rtFirst; type <= rtLast; type++) + for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { // For V1-V5 games, there used to be no object name resources. // At some point this changed. But since old savegames rely on @@ -1387,18 +1387,18 @@ void ScummEngine::saveOrLoad(Serializer *s) { // Save/load a list of the locked objects // if (s->isSaving()) { - for (i = rtFirst; i <= rtLast; i++) - for (j = 1; j < _res->_types[i]._num; j++) { - if (_res->isLocked(i, j)) { - s->saveByte(i); - s->saveUint16(j); + for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) + for (idx = 1; idx < _res->_types[type]._num; idx++) { + if (_res->isLocked(type, idx)) { + s->saveByte(type); + s->saveUint16(idx); } } s->saveByte(0xFF); } else { - while ((i = s->loadByte()) != 0xFF) { - j = s->loadUint16(); - _res->lock(i, j); + while ((type = (ResType)s->loadByte()) != 0xFF) { + idx = s->loadUint16(); + _res->lock(type, idx); } } @@ -1633,7 +1633,7 @@ void ScummEngine_v100he::saveOrLoad(Serializer *s) { } #endif -void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { +void ScummEngine::loadResourceOLD(Serializer *ser, ResType type, ResId idx) { uint32 size; if (type == rtSound && ser->getVersion() >= VER(23)) { @@ -1662,7 +1662,7 @@ void ScummEngine::loadResourceOLD(Serializer *ser, int type, int idx) { } } -void ScummEngine::saveResource(Serializer *ser, int type, int idx) { +void ScummEngine::saveResource(Serializer *ser, ResType type, ResId idx) { assert(_res->_types[type]._resources[idx]._address); if (_res->_types[type]._mode == kDynamicResTypeMode) { @@ -1681,7 +1681,7 @@ void ScummEngine::saveResource(Serializer *ser, int type, int idx) { } } -void ScummEngine::loadResource(Serializer *ser, int type, int idx) { +void ScummEngine::loadResource(Serializer *ser, ResType type, ResId idx) { if (_game.heversion >= 60 && ser->getVersion() <= VER(65) && ((type == rtSound && idx == 1) || (type == rtSpoolBuffer))) { uint32 size = ser->loadUint32(); -- cgit v1.2.3 From 45207a52d480cdd70f6bf08bbad76ec3d23a5688 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 13 May 2011 14:12:00 +0200 Subject: SCUMM: Remove ResTypeData::_num --- engines/scumm/saveload.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index f37ca36c6f..b823e3c8f5 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -427,7 +427,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // Nuke all resources for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat)) - for (ResId idx = 0; idx < _res->_types[type]._num; idx++) { + for (ResId idx = 0; idx < _res->_types[type]._resources.size(); idx++) { _res->nukeResource(type, idx); } @@ -516,7 +516,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // loading such an old save game, try to upgrade the old to new format. if (hdr.ver < VER(22)) { // Convert all rtScaleTable resources to matching scale items - for (ResId idx = 1; idx < _res->_types[rtScaleTable]._num; idx++) { + for (ResId idx = 1; idx < _res->_types[rtScaleTable]._resources.size(); idx++) { convertScaleTableToScaleSlot(idx); } } @@ -1245,7 +1245,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) { if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... - for (idx = 0; idx < _res->_types[type]._num; idx++) { + for (idx = 0; idx < _res->_types[type]._resources.size(); idx++) { // Only save resources which actually exist... if (_res->_types[type]._resources[idx]._address) { s->saveUint16(idx); // Save the index of the resource @@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { } else { while ((type = (ResType)s->loadUint16()) != 0xFFFF) { while ((idx = s->loadUint16()) != 0xFFFF) { - assert(idx < _res->_types[type]._num); + assert(idx < _res->_types[type]._resources.size()); loadResource(s, type, idx); } } @@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // unchanged resource counts, we have to hard code the following check if (_game.version < 6 && type == rtObjectName) continue; - for (idx = 1; idx < _res->_types[type]._num; idx++) + for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) loadResourceOLD(s, type, idx); } } @@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // if (s->isSaving()) { for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) - for (idx = 1; idx < _res->_types[type]._num; idx++) { + for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) { if (_res->isLocked(type, idx)) { s->saveByte(type); s->saveUint16(idx); -- cgit v1.2.3 From 9ec64a66fe2f20eb1be0811b5f733332efff1b93 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 13 May 2011 14:48:01 +0200 Subject: SCUMM: Turned ResTypeData into a Common::Array, subsuming its _resource member --- engines/scumm/saveload.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'engines/scumm/saveload.cpp') diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index b823e3c8f5..f5d219c721 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -427,7 +427,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // Nuke all resources for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat)) - for (ResId idx = 0; idx < _res->_types[type]._resources.size(); idx++) { + for (ResId idx = 0; idx < _res->_types[type].size(); idx++) { _res->nukeResource(type, idx); } @@ -516,7 +516,7 @@ bool ScummEngine::loadState(int slot, bool compat) { // loading such an old save game, try to upgrade the old to new format. if (hdr.ver < VER(22)) { // Convert all rtScaleTable resources to matching scale items - for (ResId idx = 1; idx < _res->_types[rtScaleTable]._resources.size(); idx++) { + for (ResId idx = 1; idx < _res->_types[rtScaleTable].size(); idx++) { convertScaleTableToScaleSlot(idx); } } @@ -1245,9 +1245,9 @@ void ScummEngine::saveOrLoad(Serializer *s) { for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) { if (_res->_types[type]._mode != kStaticResTypeMode && type != rtTemp && type != rtBuffer) { s->saveUint16(type); // Save the res type... - for (idx = 0; idx < _res->_types[type]._resources.size(); idx++) { + for (idx = 0; idx < _res->_types[type].size(); idx++) { // Only save resources which actually exist... - if (_res->_types[type]._resources[idx]._address) { + if (_res->_types[type][idx]._address) { s->saveUint16(idx); // Save the index of the resource saveResource(s, type, idx); } @@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { } else { while ((type = (ResType)s->loadUint16()) != 0xFFFF) { while ((idx = s->loadUint16()) != 0xFFFF) { - assert(idx < _res->_types[type]._resources.size()); + assert(idx < _res->_types[type].size()); loadResource(s, type, idx); } } @@ -1275,7 +1275,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // unchanged resource counts, we have to hard code the following check if (_game.version < 6 && type == rtObjectName) continue; - for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) + for (idx = 1; idx < _res->_types[type].size(); idx++) loadResourceOLD(s, type, idx); } } @@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) { // if (s->isSaving()) { for (type = rtFirst; type <= rtLast; type = ResType(type + 1)) - for (idx = 1; idx < _res->_types[type]._resources.size(); idx++) { + for (idx = 1; idx < _res->_types[type].size(); idx++) { if (_res->isLocked(type, idx)) { s->saveByte(type); s->saveUint16(idx); @@ -1663,11 +1663,11 @@ void ScummEngine::loadResourceOLD(Serializer *ser, ResType type, ResId idx) { } void ScummEngine::saveResource(Serializer *ser, ResType type, ResId idx) { - assert(_res->_types[type]._resources[idx]._address); + assert(_res->_types[type][idx]._address); if (_res->_types[type]._mode == kDynamicResTypeMode) { - byte *ptr = _res->_types[type]._resources[idx]._address; - uint32 size = _res->_types[type]._resources[idx]._size; + byte *ptr = _res->_types[type][idx]._address; + uint32 size = _res->_types[type][idx]._size; ser->saveUint32(size); ser->saveBytes(ptr, size); -- cgit v1.2.3