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/he/intern_he.h | 11 +- engines/scumm/he/resource_he.cpp | 6 +- engines/scumm/he/script_v100he.cpp | 5 +- engines/scumm/he/script_v72he.cpp | 5 +- engines/scumm/resource.cpp | 240 ++++++++++++++++++------------------- engines/scumm/resource.h | 30 ++--- engines/scumm/resource_v3.cpp | 28 ++--- engines/scumm/resource_v4.cpp | 17 ++- engines/scumm/saveload.cpp | 54 ++++----- engines/scumm/script_v2.cpp | 12 +- engines/scumm/script_v5.cpp | 2 +- engines/scumm/scumm.h | 42 +++---- engines/scumm/scumm_v3.h | 2 +- engines/scumm/scumm_v4.h | 2 +- engines/scumm/scumm_v6.h | 2 +- engines/scumm/sound.cpp | 10 +- 16 files changed, 235 insertions(+), 233 deletions(-) (limited to 'engines/scumm') diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h index e1d7beec82..c49217b650 100644 --- a/engines/scumm/he/intern_he.h +++ b/engines/scumm/he/intern_he.h @@ -129,8 +129,8 @@ public: protected: virtual void allocateArrays(); - virtual int readResTypeList(int id); - virtual uint32 getResourceRoomOffset(int type, int idx); + virtual int readResTypeList(ResType type); + virtual uint32 getResourceRoomOffset(ResType type, ResId idx); virtual void setupOpcodes(); virtual void setupScummVars(); @@ -265,7 +265,7 @@ protected: virtual void resetScummVars(); virtual void readArrayFromIndexFile(); - virtual byte *getStringAddress(int i); + virtual byte *getStringAddress(ResId idx); virtual void readMAXS(int blockSize); virtual void redrawBGAreas(); @@ -289,7 +289,7 @@ protected: void copyScriptString(byte *dst, int dstSize); int findObject(int x, int y, int num, int *args); - int getSoundResourceSize(int id); + int getSoundResourceSize(ResId idx); virtual bool handleNextCharsetCode(Actor *a, int *c); virtual int convertMessageToString(const byte *msg, byte *dst, int dstSize); @@ -554,7 +554,8 @@ protected: class ScummEngine_v100he : public ScummEngine_v99he { protected: - int32 _heResId, _heResType; + ResType _heResType; + int32 _heResId; byte _debugInputBuffer[256]; public: diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp index 70b5543add..1dce01ae5a 100644 --- a/engines/scumm/he/resource_he.cpp +++ b/engines/scumm/he/resource_he.cpp @@ -341,14 +341,14 @@ void ScummEngine_v72he::readMAXS(int blockSize) { ScummEngine_v6::readMAXS(blockSize); } -byte *ScummEngine_v72he::getStringAddress(int i) { - byte *addr = getResourceAddress(rtString, i); +byte *ScummEngine_v72he::getStringAddress(ResId idx) { + byte *addr = getResourceAddress(rtString, idx); if (addr == NULL) return NULL; return ((ScummEngine_v72he::ArrayHeader *)addr)->data; } -int ScummEngine_v72he::getSoundResourceSize(int id) { +int ScummEngine_v72he::getSoundResourceSize(ResId id) { const byte *ptr; int offs, size; diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp index 8ff28a1068..b6f92942a1 100644 --- a/engines/scumm/he/script_v100he.cpp +++ b/engines/scumm/he/script_v100he.cpp @@ -2380,7 +2380,8 @@ void ScummEngine_v100he::o100_isResourceLoaded() { void ScummEngine_v100he::o100_getResourceSize() { const byte *ptr; - int size, type; + int size; + ResType type; int resid = pop(); byte subOp = fetchScriptByte(); @@ -2399,7 +2400,7 @@ void ScummEngine_v100he::o100_getResourceSize() { type = rtScript; break; case 72: - push (getSoundResourceSize(resid)); + push(getSoundResourceSize(resid)); return; default: error("o100_getResourceSize: default type %d", subOp); diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp index dfcfa32df4..0e25fe4849 100644 --- a/engines/scumm/he/script_v72he.cpp +++ b/engines/scumm/he/script_v72he.cpp @@ -1911,7 +1911,8 @@ void ScummEngine_v72he::o72_writeINI() { void ScummEngine_v72he::o72_getResourceSize() { const byte *ptr; - int size, type; + int size; + ResType type; int resid = pop(); if (_game.heversion == 72) { @@ -1923,7 +1924,7 @@ void ScummEngine_v72he::o72_getResourceSize() { switch (subOp) { case 13: - push (getSoundResourceSize(resid)); + push(getSoundResourceSize(resid)); return; case 14: type = rtRoomImage; diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp index 8767e1b315..2eedf5e144 100644 --- a/engines/scumm/resource.cpp +++ b/engines/scumm/resource.cpp @@ -52,7 +52,7 @@ enum { -extern const char *resTypeFromId(int id); +extern const char *resTypeFromId(int type); static uint16 newTag2Old(uint32 newTag); static const byte *findResourceSmall(uint32 tag, const byte *searchin); @@ -482,72 +482,72 @@ void ScummEngine::readArrayFromIndexFile() { error("readArrayFromIndexFile() not supported in pre-V6 games"); } -int ScummEngine::readResTypeList(int id) { - int num; - int i; +int ScummEngine::readResTypeList(ResType type) { + uint num; + ResId idx; if (_game.version == 8) num = _fileHandle->readUint32LE(); else num = _fileHandle->readUint16LE(); - if (num != _res->_types[id]._num) { - error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num); + if (num != _res->_types[type]._num) { + error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num); } - debug(2, " readResTypeList(%s): %d entries", resTypeFromId(id), num); + debug(2, " readResTypeList(%s): %d entries", resTypeFromId(type), num); - for (i = 0; i < num; i++) { - _res->_types[id]._resources[i]._roomno = _fileHandle->readByte(); + for (idx = 0; idx < num; idx++) { + _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte(); } - for (i = 0; i < num; i++) { - _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE(); + for (idx = 0; idx < num; idx++) { + _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE(); } return num; } -int ScummEngine_v70he::readResTypeList(int id) { - int num; - int i; +int ScummEngine_v70he::readResTypeList(ResType type) { + uint num; + ResId idx; - num = ScummEngine::readResTypeList(id); + num = ScummEngine::readResTypeList(type); - if (id == rtRoom) - for (i = 0; i < num; i++) { - _heV7RoomIntOffsets[i] = _res->_types[rtRoom]._resources[i]._roomoffs; + if (type == rtRoom) + for (idx = 0; idx < num; idx++) { + _heV7RoomIntOffsets[idx] = _res->_types[rtRoom]._resources[idx]._roomoffs; } - for (i = 0; i < num; i++) { - _res->_types[id]._resources[i]._globsize = _fileHandle->readUint32LE(); + for (idx = 0; idx < num; idx++) { + _res->_types[type]._resources[idx]._globsize = _fileHandle->readUint32LE(); } return num; } -void ResourceManager::allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode) { - debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(id), tag2str(TO_BE_32(tag)), num, mode); - assert(id >= 0 && id < (int)(ARRAYSIZE(_types))); +void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode) { + debug(2, "allocResTypeData(%s,%s,%d,%d)", resTypeFromId(type), tag2str(TO_BE_32(tag)), num, mode); + assert(type >= 0 && type < (int)(ARRAYSIZE(_types))); if (num >= 8000) - error("Too many %s resources (%d) in directory", resTypeFromId(id), num); + error("Too many %s resources (%d) in directory", resTypeFromId(type), num); - _types[id]._mode = mode; - _types[id]._num = num; - _types[id]._tag = tag; - _types[id]._resources.resize(num); + _types[type]._mode = mode; + _types[type]._num = num; + _types[type]._tag = tag; + _types[type]._resources.resize(num); /* TODO: Use multiple Resource subclasses, one for each res mode; then, given them serializability. if (mode) { - _types[id].roomno = (byte *)calloc(num, sizeof(byte)); - _types[id].roomoffs = (uint32 *)calloc(num, sizeof(uint32)); + _types[type].roomno = (byte *)calloc(num, sizeof(byte)); + _types[type].roomoffs = (uint32 *)calloc(num, sizeof(uint32)); } if (_vm->_game.heversion >= 70) { - _types[id].globsize = (uint32 *)calloc(num, sizeof(uint32)); + _types[type].globsize = (uint32 *)calloc(num, sizeof(uint32)); } */ } @@ -583,14 +583,14 @@ void ScummEngine::nukeCharset(int i) { _res->nukeResource(rtCharset, i); } -void ScummEngine::ensureResourceLoaded(int type, int i) { - debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i); +void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) { + debugC(DEBUG_RESOURCE, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), idx); - if ((type == rtRoom) && i > 0x7F && _game.version < 7 && _game.heversion <= 71) { - i = _resourceMapper[i & 0x7F]; + if ((type == rtRoom) && idx > 0x7F && _game.version < 7 && _game.heversion <= 71) { + idx = _resourceMapper[idx & 0x7F]; } - // FIXME: This check used to be "i==0". However, that causes + // FIXME: This check used to be "idx==0". However, that causes // problems when using this function to ensure charset 0 is loaded. // This is done for many games, e.g. Zak256 or Indy3 (EGA and VGA). // For now we restrict the check to anything which is not a charset. @@ -601,19 +601,19 @@ void ScummEngine::ensureResourceLoaded(int type, int i) { // our code base? After all we also have to add special cases for many // of our script opcodes that check for the (invalid) actor 0... so // maybe both issues are related... - if (type != rtCharset && i == 0) + if (type != rtCharset && idx == 0) return; - if (i <= _res->_types[type]._num && _res->_types[type]._resources[i]._address) + if (idx <= _res->_types[type]._num && _res->_types[type]._resources[idx]._address) return; - loadResource(type, i); + loadResource(type, idx); - if (_game.version == 5 && type == rtRoom && i == _roomResource) + if (_game.version == 5 && type == rtRoom && (int)idx == _roomResource) VAR(VAR_ROOM_FLAG) = 1; } -int ScummEngine::loadResource(int type, int idx) { +int ScummEngine::loadResource(ResType type, ResId idx) { int roomNr; uint32 fileOffs; uint32 size, tag; @@ -687,33 +687,33 @@ int ScummEngine::loadResource(int type, int idx) { return 1; } -int ScummEngine::getResourceRoomNr(int type, int idx) { +int ScummEngine::getResourceRoomNr(ResType type, ResId idx) { if (type == rtRoom && _game.heversion < 70) return idx; return _res->_types[type]._resources[idx]._roomno; } -uint32 ScummEngine::getResourceRoomOffset(int type, int idx) { +uint32 ScummEngine::getResourceRoomOffset(ResType type, ResId idx) { if (type == rtRoom) { return (_game.version == 8) ? 8 : 0; } return _res->_types[type]._resources[idx]._roomoffs; } -uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) { +uint32 ScummEngine_v70he::getResourceRoomOffset(ResType type, ResId idx) { if (type == rtRoom) { return _heV7RoomIntOffsets[idx]; } return _res->_types[type]._resources[idx]._roomoffs; } -int ScummEngine::getResourceSize(int type, int idx) { +int ScummEngine::getResourceSize(ResType type, ResId idx) { byte *ptr = getResourceAddress(type, idx); assert(ptr); return _res->_types[type]._resources[idx]._size; } -byte *ScummEngine::getResourceAddress(int type, int idx) { +byte *ScummEngine::getResourceAddress(ResType type, ResId idx) { byte *ptr; if (_game.heversion >= 80 && type == rtString) @@ -739,13 +739,13 @@ byte *ScummEngine::getResourceAddress(int type, int idx) { return ptr; } -byte *ScummEngine::getStringAddress(int i) { - byte *addr = getResourceAddress(rtString, i); +byte *ScummEngine::getStringAddress(ResId idx) { + byte *addr = getResourceAddress(rtString, idx); return addr; } -byte *ScummEngine_v6::getStringAddress(int i) { - byte *addr = getResourceAddress(rtString, i); +byte *ScummEngine_v6::getStringAddress(ResId idx) { + byte *addr = getResourceAddress(rtString, idx); if (addr == NULL) return NULL; // Skip over the ArrayHeader @@ -764,20 +764,18 @@ void ResourceManager::increaseExpireCounter() { } void ResourceManager::increaseResourceCounters() { - int i, j; - byte counter; - - for (i = rtFirst; i <= rtLast; i++) { - for (j = _types[i]._num; --j >= 0;) { - counter = _types[i]._resources[j].getResourceCounter(); + for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) { + ResId idx = _types[type]._num; + while (idx-- > 0) { + byte counter = _types[type]._resources[idx].getResourceCounter(); if (counter && counter < RF_USAGE_MAX) { - setResourceCounter(i, j, counter + 1); + setResourceCounter(type, idx, counter + 1); } } } } -void ResourceManager::setResourceCounter(int type, int idx, byte counter) { +void ResourceManager::setResourceCounter(ResType type, ResId idx, byte counter) { _types[type]._resources[idx].setResourceCounter(counter); } @@ -793,7 +791,7 @@ byte ResourceManager::Resource::getResourceCounter() const { /* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */ #define SAFETY_AREA 2 -byte *ResourceManager::createResource(int type, int idx, uint32 size) { +byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) { debugC(DEBUG_RESOURCE, "_res->createResource(%s,%d,%d)", resTypeFromId(type), idx, size); if (!validateResource("allocating", type, idx)) @@ -875,15 +873,15 @@ void ResourceManager::setHeapThreshold(int min, int max) { _minHeapThreshold = min; } -bool ResourceManager::validateResource(const char *str, int type, int idx) const { - if (type < rtFirst || type > rtLast || (uint) idx >= (uint)_types[type]._num) { +bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const { + if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._num) { error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx); return false; } return true; } -void ResourceManager::nukeResource(int type, int idx) { +void ResourceManager::nukeResource(ResType type, ResId idx) { byte *ptr = _types[type]._resources[idx]._address; if (ptr != NULL) { debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx); @@ -917,22 +915,22 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const { return READ_BE_UINT32(ptr - 4) - _resourceHeaderSize; } -void ResourceManager::lock(int type, int i) { - if (!validateResource("Locking", type, i)) +void ResourceManager::lock(ResType type, ResId idx) { + if (!validateResource("Locking", type, idx)) return; - _types[type]._resources[i].lock(); + _types[type]._resources[idx].lock(); } -void ResourceManager::unlock(int type, int i) { - if (!validateResource("Unlocking", type, i)) +void ResourceManager::unlock(ResType type, ResId idx) { + if (!validateResource("Unlocking", type, idx)) return; - _types[type]._resources[i].unlock(); + _types[type]._resources[idx].unlock(); } -bool ResourceManager::isLocked(int type, int i) const { - if (!validateResource("isLocked", type, i)) +bool ResourceManager::isLocked(ResType type, ResId idx) const { + if (!validateResource("isLocked", type, idx)) return false; - return _types[type]._resources[i].isLocked(); + return _types[type]._resources[idx].isLocked(); } void ResourceManager::Resource::lock() { @@ -947,47 +945,47 @@ bool ResourceManager::Resource::isLocked() const { return (_flags & RF_LOCK) != 0; } -bool ScummEngine::isResourceInUse(int type, int i) const { - if (!_res->validateResource("isResourceInUse", type, i)) +bool ScummEngine::isResourceInUse(ResType type, ResId idx) const { + if (!_res->validateResource("isResourceInUse", type, idx)) return false; switch (type) { case rtRoom: - return _roomResource == (byte)i; + return _roomResource == (byte)idx; case rtRoomImage: - return _roomResource == (byte)i; + return _roomResource == (byte)idx; case rtRoomScripts: - return _roomResource == (byte)i; + return _roomResource == (byte)idx; case rtScript: - return isScriptInUse(i); + return isScriptInUse(idx); case rtCostume: - return isCostumeInUse(i); + return isCostumeInUse(idx); case rtSound: // Sound resource 1 is used for queued speech - if (_game.heversion >= 60 && i == 1) + if (_game.heversion >= 60 && idx == 1) return true; else - return _sound->isSoundInUse(i); + return _sound->isSoundInUse(idx); case rtCharset: - return _charset->getCurID() == i; + return _charset->getCurID() == (int)idx; case rtImage: - return _res->isModified(type, i) != 0; + return _res->isModified(type, idx) != 0; case rtSpoolBuffer: - return _sound->isSoundRunning(10000 + i) != 0; + return _sound->isSoundRunning(10000 + idx) != 0; default: return false; } } -void ResourceManager::setModified(int type, int i) { - if (!validateResource("Modified", type, i)) +void ResourceManager::setModified(ResType type, ResId idx) { + if (!validateResource("Modified", type, idx)) return; - _types[type]._resources[i].setModified(); + _types[type]._resources[idx].setModified(); } -bool ResourceManager::isModified(int type, int i) const { - if (!validateResource("isModified", type, i)) +bool ResourceManager::isModified(ResType type, ResId idx) const { + if (!validateResource("isModified", type, idx)) return false; - return _types[type]._resources[i].isModified(); + return _types[type]._resources[idx].isModified(); } void ResourceManager::Resource::setModified() { @@ -999,9 +997,9 @@ bool ResourceManager::Resource::isModified() const { } void ResourceManager::expireResources(uint32 size) { - int i, j; byte best_counter; - int best_type, best_res = 0; + ResType best_type; + int best_res = 0; uint32 oldAllocatedSize; if (_expireCounter != 0xFF) { @@ -1015,23 +1013,25 @@ void ResourceManager::expireResources(uint32 size) { oldAllocatedSize = _allocatedSize; do { - best_type = 0; + best_type = rtInvalid; best_counter = 2; - for (i = rtFirst; i <= rtLast; i++) - if (_types[i]._mode != kDynamicResTypeMode) { + for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) { + if (_types[type]._mode != kDynamicResTypeMode) { // Resources of this type can be reloaded from the data files, // so we can potentially unload them to free memory. - for (j = _types[i]._num; --j >= 0;) { - Resource &tmp = _types[i]._resources[j]; + ResId idx = _types[type]._num; + while (idx-- > 0) { + Resource &tmp = _types[type]._resources[idx]; byte counter = tmp.getResourceCounter(); - if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(i, j)) { + if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(type, idx)) { best_counter = counter; - best_type = i; - best_res = j; + best_type = type; + best_res = idx; } } } + } if (!best_type) break; @@ -1044,28 +1044,27 @@ void ResourceManager::expireResources(uint32 size) { } void ResourceManager::freeResources() { - int i, j; - for (i = rtFirst; i <= rtLast; i++) { - for (j = _types[i]._num; --j >= 0;) { - if (isResourceLoaded(i, j)) - nukeResource(i, j); + for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) { + ResId idx = _types[type]._num; + while (idx-- > 0) { + if (isResourceLoaded(type, idx)) + nukeResource(type, idx); } - _types[i]._resources.clear(); + _types[type]._resources.clear(); } } -void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source) { +void ScummEngine::loadPtrToResource(ResType type, ResId idx, const byte *source) { byte *alloced; int len; - _res->nukeResource(type, resindex); + _res->nukeResource(type, idx); len = resStrLen(source) + 1; - if (len <= 0) return; - alloced = _res->createResource(type, resindex, len); + alloced = _res->createResource(type, idx, len); if (!source) { // Need to refresh the script pointer, since createResource may @@ -1078,24 +1077,25 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source) } } -bool ResourceManager::isResourceLoaded(int type, int idx) const { +bool ResourceManager::isResourceLoaded(ResType type, ResId idx) const { if (!validateResource("isResourceLoaded", type, idx)) return false; return _types[type]._resources[idx]._address != NULL; } void ResourceManager::resourceStats() { - int i, j; uint32 lockedSize = 0, lockedNum = 0; - for (i = rtFirst; i <= rtLast; i++) - for (j = _types[i]._num; --j >= 0;) { - Resource &tmp = _types[i]._resources[j]; + for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) { + ResId idx = _types[type]._num; + while (idx-- > 0) { + Resource &tmp = _types[type]._resources[idx]; if (tmp.isLocked() && tmp._address) { lockedSize += tmp._size; lockedNum++; } } + } debug(1, "Total allocated size=%d, locked=%d(%d)", _allocatedSize, lockedSize, lockedNum); } @@ -1340,7 +1340,7 @@ void ScummEngine_v70he::allocateArrays() { } -void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) { +void ScummEngine::dumpResource(const char *tag, int id, const byte *ptr, int length) { char buf[256]; Common::DumpFile out; @@ -1354,7 +1354,7 @@ void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int le else size = READ_BE_UINT32(ptr + 4); - sprintf(buf, "dumps/%s%d.dmp", tag, idx); + sprintf(buf, "dumps/%s%d.dmp", tag, id); out.open(buf); if (out.isOpen() == false) @@ -1523,10 +1523,10 @@ uint16 newTag2Old(uint32 newTag) { } } -const char *resTypeFromId(int id) { +const char *resTypeFromId(int type) { static char buf[100]; - switch (id) { + switch (type) { case rtRoom: return "Room"; case rtScript: @@ -1569,10 +1569,8 @@ const char *resTypeFromId(int id) { return "Talkie"; case rtSpoolBuffer: return "SpoolBuffer"; - case rtNumTypes: - return "NumTypes"; default: - sprintf(buf, "%d", id); + sprintf(buf, "rt%d", type); return buf; } } diff --git a/engines/scumm/resource.h b/engines/scumm/resource.h index 5aae49b7ad..15aed24b36 100644 --- a/engines/scumm/resource.h +++ b/engines/scumm/resource.h @@ -23,7 +23,7 @@ #define SCUMM_RESOURCE_H #include "common/array.h" -#include "scumm/scumm.h" // for rtNumTypes +#include "scumm/scumm.h" // for ResType namespace Scumm { @@ -175,7 +175,7 @@ public: ResTypeData(); ~ResTypeData(); }; - ResTypeData _types[rtNumTypes]; + ResTypeData _types[rtLast + 1]; protected: uint32 _allocatedSize; @@ -188,23 +188,23 @@ public: void setHeapThreshold(int min, int max); - void allocResTypeData(int id, uint32 tag, int num, ResTypeMode mode); + void allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode); void freeResources(); - byte *createResource(int type, int idx, uint32 size); - void nukeResource(int type, int idx); + byte *createResource(ResType type, ResId idx, uint32 size); + void nukeResource(ResType type, ResId idx); - inline Resource &getRes(int type, int idx) { return _types[type]._resources[idx]; } - inline const Resource &getRes(int type, int idx) const { return _types[type]._resources[idx]; } +// inline Resource &getRes(ResType type, ResId idx) { return _types[type]._resources[idx]; } +// inline const Resource &getRes(ResType type, ResId idx) const { return _types[type]._resources[idx]; } - bool isResourceLoaded(int type, int idx) const; + bool isResourceLoaded(ResType type, ResId idx) const; - void lock(int type, int idx); - void unlock(int type, int idx); - bool isLocked(int type, int idx) const; + void lock(ResType type, ResId idx); + void unlock(ResType type, ResId idx); + bool isLocked(ResType type, ResId idx) const; - void setModified(int type, int idx); - bool isModified(int type, int idx) const; + void setModified(ResType type, ResId idx); + bool isModified(ResType type, ResId idx) const; /** * This method increments the _expireCounter, and if it overflows (which happens @@ -216,7 +216,7 @@ public: /** * Update the specified resource's counter. */ - void setResourceCounter(int type, int idx, byte counter); + void setResourceCounter(ResType type, ResId idx, byte counter); /** * Increment the counter of all unlocked loaded resources. @@ -229,7 +229,7 @@ public: void resourceStats(); //protected: - bool validateResource(const char *str, int type, int idx) const; + bool validateResource(const char *str, ResType type, ResId idx) const; protected: void expireResources(uint32 size); }; diff --git a/engines/scumm/resource_v3.cpp b/engines/scumm/resource_v3.cpp index 0f9f97ad16..f422f823b7 100644 --- a/engines/scumm/resource_v3.cpp +++ b/engines/scumm/resource_v3.cpp @@ -30,30 +30,30 @@ namespace Scumm { extern const char *resTypeFromId(int id); -int ScummEngine_v3old::readResTypeList(int id) { - int num; - int i; +int ScummEngine_v3old::readResTypeList(ResType type) { + uint num; + ResId idx; - debug(9, "readResTypeList(%s)", resTypeFromId(id)); + debug(9, "readResTypeList(%s)", resTypeFromId(type)); num = _fileHandle->readByte(); if (num >= 0xFF) { - error("Too many %ss (%d) in directory", resTypeFromId(id), num); + error("Too many %ss (%d) in directory", resTypeFromId(type), num); } - if (id == rtRoom) { - for (i = 0; i < num; i++) - _res->_types[id]._resources[i]._roomno = i; + if (type == rtRoom) { + for (idx = 0; idx < num; idx++) + _res->_types[type]._resources[idx]._roomno = idx; _fileHandle->seek(num, SEEK_CUR); } else { - for (i = 0; i < num; i++) - _res->_types[id]._resources[i]._roomno = _fileHandle->readByte(); + for (idx = 0; idx < num; idx++) + _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte(); } - for (i = 0; i < num; i++) { - _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint16LE(); - if (_res->_types[id]._resources[i]._roomoffs == 0xFFFF) - _res->_types[id]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET; + for (idx = 0; idx < num; idx++) { + _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint16LE(); + if (_res->_types[type]._resources[idx]._roomoffs == 0xFFFF) + _res->_types[type]._resources[idx]._roomoffs = (uint32)RES_INVALID_OFFSET; } return num; diff --git a/engines/scumm/resource_v4.cpp b/engines/scumm/resource_v4.cpp index e7e6d30352..d062fe108e 100644 --- a/engines/scumm/resource_v4.cpp +++ b/engines/scumm/resource_v4.cpp @@ -30,21 +30,20 @@ namespace Scumm { extern const char *resTypeFromId(int id); -int ScummEngine_v4::readResTypeList(int id) { - int num; - int i; +int ScummEngine_v4::readResTypeList(ResType type) { + uint num; - debug(9, "readResTypeList(%s)", resTypeFromId(id)); + debug(9, "readResTypeList(%s)", resTypeFromId(type)); num = _fileHandle->readUint16LE(); - if (num != _res->_types[id]._num) { - error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num); + if (num != _res->_types[type]._num) { + error("Invalid number of %ss (%d) in directory", resTypeFromId(type), num); } - for (i = 0; i < num; i++) { - _res->_types[id]._resources[i]._roomno = _fileHandle->readByte(); - _res->_types[id]._resources[i]._roomoffs = _fileHandle->readUint32LE(); + for (ResId idx = 0; idx < num; idx++) { + _res->_types[type]._resources[idx]._roomno = _fileHandle->readByte(); + _res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE(); } return num; 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(); diff --git a/engines/scumm/script_v2.cpp b/engines/scumm/script_v2.cpp index f7d4e74898..7f02e899b4 100644 --- a/engines/scumm/script_v2.cpp +++ b/engines/scumm/script_v2.cpp @@ -738,23 +738,23 @@ void ScummEngine_v2::o2_drawObject() { } void ScummEngine_v2::o2_resourceRoutines() { - const ResTypes resTypes[] = { - rtNumTypes, // Invalid - rtNumTypes, // Invalid + const ResType resTypes[] = { + rtInvalid, + rtInvalid, rtCostume, rtRoom, - rtNumTypes, // Invalid + rtInvalid, rtScript, rtSound }; int resid = getVarOrDirectByte(PARAM_1); int opcode = fetchScriptByte(); - ResTypes type = rtNumTypes; + ResType type = rtInvalid; if (0 <= (opcode >> 4) && (opcode >> 4) < (int)ARRAYSIZE(resTypes)) type = resTypes[opcode >> 4]; - if ((opcode & 0x0f) == 0 || type == rtNumTypes) + if ((opcode & 0x0f) == 0 || type == rtInvalid) return; // HACK V2 Maniac Mansion tries to load an invalid sound resource in demo script. diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp index 81f28fbbd6..b8f3b4b3b3 100644 --- a/engines/scumm/script_v5.cpp +++ b/engines/scumm/script_v5.cpp @@ -1490,7 +1490,7 @@ void ScummEngine_v5::o5_systemOps() { } void ScummEngine_v5::o5_resourceRoutines() { - const ResTypes resType[4] = { rtScript, rtSound, rtCostume, rtRoom }; + const ResType resType[4] = { rtScript, rtSound, rtCostume, rtRoom }; int resid = 0; int foo, bar; diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index 9d64202ce8..636c909911 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -308,7 +308,8 @@ struct SaveStateMetaInfos { * WARNING: Do not change the order of these, as the savegame format relies * on it; any change made here will break savegame compatibility! */ -enum ResTypes { +enum ResType { + rtInvalid = 0, rtFirst = 1, rtRoom = 1, rtScript = 2, @@ -331,10 +332,11 @@ enum ResTypes { rtImage = 19, rtTalkie = 20, rtSpoolBuffer = 21, - rtLast = 21, - rtNumTypes = 22 + rtLast = 21 }; +typedef uint16 ResId; + class ResourceManager; /** @@ -576,9 +578,9 @@ protected: bool saveState(int slot, bool compat); bool loadState(int slot, bool compat); virtual void saveOrLoad(Serializer *s); - void saveResource(Serializer *ser, int type, int index); - void loadResource(Serializer *ser, int type, int index); - void loadResourceOLD(Serializer *ser, int type, int index); // "Obsolete" + void saveResource(Serializer *ser, ResType type, ResId idx); + void loadResource(Serializer *ser, ResType type, ResId idx); + void loadResourceOLD(Serializer *ser, ResType type, ResId idx); // "Obsolete" Common::String makeSavegameName(int slot, bool temporary) const { return makeSavegameName(_targetName, slot, temporary); @@ -711,26 +713,26 @@ protected: void askForDisk(const char *filename, int disknum); // TODO: Use Common::String bool openResourceFile(const Common::String &filename, byte encByte); // TODO: Use Common::String - void loadPtrToResource(int type, int i, const byte *ptr); - virtual int readResTypeList(int id); -// void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode); + void loadPtrToResource(ResType type, ResId idx, const byte *ptr); + virtual int readResTypeList(ResType type); +// void allocResTypeData(ResType type, uint32 tag, int num, int mode); // byte *createResource(int type, int index, uint32 size); - int loadResource(int type, int i); -// void nukeResource(int type, int i); - int getResourceRoomNr(int type, int idx); - virtual uint32 getResourceRoomOffset(int type, int idx); - int getResourceSize(int type, int idx); + int loadResource(ResType type, ResId idx); +// void nukeResource(ResType type, ResId idx); + int getResourceRoomNr(ResType type, ResId idx); + virtual uint32 getResourceRoomOffset(ResType type, ResId idx); + int getResourceSize(ResType type, ResId idx); public: - byte *getResourceAddress(int type, int i); - virtual byte *getStringAddress(int i); + byte *getResourceAddress(ResType type, ResId idx); + virtual byte *getStringAddress(ResId idx); byte *getStringAddressVar(int i); - void ensureResourceLoaded(int type, int i); + void ensureResourceLoaded(ResType type, ResId idx); protected: - int readSoundResource(int index); - int readSoundResourceSmallHeader(int index); - bool isResourceInUse(int type, int i) const; + int readSoundResource(ResId idx); + int readSoundResourceSmallHeader(ResId idx); + bool isResourceInUse(ResType type, ResId idx) const; virtual void setupRoomSubBlocks(); virtual void resetRoomSubBlocks(); diff --git a/engines/scumm/scumm_v3.h b/engines/scumm/scumm_v3.h index 6367f4ae3f..f11ca16a50 100644 --- a/engines/scumm/scumm_v3.h +++ b/engines/scumm/scumm_v3.h @@ -59,7 +59,7 @@ public: ScummEngine_v3old(OSystem *syst, const DetectorResult &dr); protected: - virtual int readResTypeList(int id); + virtual int readResTypeList(ResType type); virtual void readIndexFile(); virtual void setupRoomSubBlocks(); virtual void resetRoomSubBlocks(); diff --git a/engines/scumm/scumm_v4.h b/engines/scumm/scumm_v4.h index 96fa7f7ace..e21e4b26ae 100644 --- a/engines/scumm/scumm_v4.h +++ b/engines/scumm/scumm_v4.h @@ -56,7 +56,7 @@ protected: virtual void scummLoop_handleSaveLoad(); - virtual int readResTypeList(int id); + virtual int readResTypeList(ResType type); virtual void readIndexFile(); virtual void loadCharset(int no); virtual void resetRoomObjects(); diff --git a/engines/scumm/scumm_v6.h b/engines/scumm/scumm_v6.h index 5b6ad88e76..c42a49a9f5 100644 --- a/engines/scumm/scumm_v6.h +++ b/engines/scumm/scumm_v6.h @@ -107,7 +107,7 @@ protected: virtual void decodeParseString(int a, int b); virtual void readArrayFromIndexFile(); - virtual byte *getStringAddress(int i); + virtual byte *getStringAddress(ResId idx); virtual void readMAXS(int blockSize); virtual void palManipulateInit(int resID, int start, int end, int time); diff --git a/engines/scumm/sound.cpp b/engines/scumm/sound.cpp index 4a136f65d5..40b151b6d9 100644 --- a/engines/scumm/sound.cpp +++ b/engines/scumm/sound.cpp @@ -1064,7 +1064,7 @@ void Sound::saveLoadWithSerializer(Serializer *ser) { #pragma mark --- Sound resource handling --- #pragma mark - -static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, int size); +static void convertMac0Resource(ResourceManager *res, ResId idx, byte *src_ptr, int size); /* @@ -1074,7 +1074,7 @@ static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, in * could stand a thorough cleanup! */ -int ScummEngine::readSoundResource(int idx) { +int ScummEngine::readSoundResource(ResId idx) { uint32 pos, total_size, size, tag, basetag, max_total_size; int pri, best_pri; uint32 best_size = 0, best_offs = 0; @@ -1427,7 +1427,7 @@ static byte Mac0ToGMInstrument(uint32 type, int &transpose) { } } -static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, int size) { +static void convertMac0Resource(ResourceManager *res, ResId idx, byte *src_ptr, int size) { /* From Markus Magnuson (superqult) we got this information: Mac0 @@ -1618,7 +1618,7 @@ static void convertMac0Resource(ResourceManager *res, int idx, byte *src_ptr, in #endif } -static void convertADResource(ResourceManager *res, const GameSettings& game, int idx, byte *src_ptr, int size) { +static void convertADResource(ResourceManager *res, const GameSettings& game, ResId idx, byte *src_ptr, int size) { // We will ignore the PPQN in the original resource, because // it's invalid anyway. We use a constant PPQN of 480. const int ppqn = 480; @@ -2001,7 +2001,7 @@ static void convertADResource(ResourceManager *res, const GameSettings& game, in } -int ScummEngine::readSoundResourceSmallHeader(int idx) { +int ScummEngine::readSoundResourceSmallHeader(ResId idx) { uint32 pos, total_size, size, tag; uint32 ad_size = 0, ad_offs = 0; uint32 ro_size = 0, ro_offs = 0; -- cgit v1.2.3