SCUMM: Remove ResTypeData::_num

This commit is contained in:
Max Horn 2011-05-13 14:12:00 +02:00
parent dfd6112403
commit 45207a52d4
7 changed files with 28 additions and 36 deletions

View File

@ -374,8 +374,8 @@ bool ScummDebugger::Cmd_Actor(int argc, const char **argv) {
DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) {
if (value >= _vm->_res->_types[rtCostume]._num)
DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._num);
if (value >= (int)_vm->_res->_types[rtCostume]._resources.size())
DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume]._resources.size());
else {
a->setActorCostume(value);
_vm->_fullRedraw = true;

View File

@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(ResType type) {
else
num = _fileHandle->readUint16LE();
if (num != _res->_types[type]._num) {
if (num != _res->_types[type]._resources.size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}
@ -534,7 +534,6 @@ void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTyp
error("Too many %s resources (%d) in directory", nameOfResType(type), num);
_types[type]._mode = mode;
_types[type]._num = num;
_types[type]._tag = tag;
_types[type]._resources.resize(num);
@ -604,7 +603,7 @@ void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
if (type != rtCharset && idx == 0)
return;
if (idx <= _res->_types[type]._num && _res->_types[type]._resources[idx]._address)
if (idx <= _res->_types[type]._resources.size() && _res->_types[type]._resources[idx]._address)
return;
loadResource(type, idx);
@ -627,8 +626,8 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
roomNr = getResourceRoomNr(type, idx);
if (idx >= _res->_types[type]._num)
error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._num, roomNr);
if (idx >= _res->_types[type]._resources.size())
error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._resources.size(), roomNr);
if (roomNr == 0)
roomNr = _roomResource;
@ -765,7 +764,7 @@ void ResourceManager::increaseExpireCounter() {
void ResourceManager::increaseResourceCounters() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
ResId idx = _types[type]._num;
ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
byte counter = _types[type]._resources[idx].getResourceCounter();
if (counter && counter < RF_USAGE_MAX) {
@ -848,7 +847,6 @@ void ResourceManager::Resource::nuke() {
ResourceManager::ResTypeData::ResTypeData() {
_mode = kDynamicResTypeMode;
_num = 0;
_tag = 0;
}
@ -874,7 +872,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
}
bool ResourceManager::validateResource(const char *str, ResType type, ResId idx) const {
if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._num) {
if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type]._resources.size()) {
error("%s Illegal Glob type %s (%d) num %d", str, nameOfResType(type), type, idx);
return false;
}
@ -1020,7 +1018,7 @@ void ResourceManager::expireResources(uint32 size) {
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.
ResId idx = _types[type]._num;
ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
Resource &tmp = _types[type]._resources[idx];
byte counter = tmp.getResourceCounter();
@ -1045,7 +1043,7 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() {
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
ResId idx = _types[type]._num;
ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
if (isResourceLoaded(type, idx))
nukeResource(type, idx);
@ -1087,7 +1085,7 @@ void ResourceManager::resourceStats() {
uint32 lockedSize = 0, lockedNum = 0;
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
ResId idx = _types[type]._num;
ResId idx = _types[type]._resources.size();
while (idx-- > 0) {
Resource &tmp = _types[type]._resources[idx];
if (tmp.isLocked() && tmp._address) {

View File

@ -154,11 +154,6 @@ public:
friend class ResourceManager;
public:
ResTypeMode _mode;
/**
* The maximal number of resource of this type. Determines the size
* of various arrays.
*/
uint16 _num;
/**
* The 4-byte tag or chunk type associated to this resource type, if any.
@ -167,7 +162,7 @@ public:
uint32 _tag;
/**
* Array of size _num containing pointers to each resource of this type.
* Array containing the resources of this type.
*/
Common::Array<Resource> _resources;

View File

@ -37,7 +37,7 @@ int ScummEngine_v4::readResTypeList(ResType type) {
num = _fileHandle->readUint16LE();
if (num != _res->_types[type]._num) {
if (num != _res->_types[type]._resources.size()) {
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
}

View File

@ -465,7 +465,7 @@ void ScummEngine::setupRoomSubBlocks() {
* So it is not appropriate to call it after loading a savegame.
*/
void ScummEngine::resetRoomSubBlocks() {
int i;
ResId i;
const byte *ptr;
byte *roomptr;
@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
//
// Load scale data
//
for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++)
_res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) {
int s1, s2, y1, y2;
if (_game.version == 8) {
for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 16) {
for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8);
@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2);
}
} else {
for (i = 1; i < _res->_types[rtScaleTable]._num; i++, ptr += 8) {
for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4);
@ -712,7 +712,6 @@ void ScummEngine_v3old::setupRoomSubBlocks() {
}
void ScummEngine_v3old::resetRoomSubBlocks() {
int i;
const byte *ptr;
byte *roomptr;
@ -769,7 +768,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
size = 0;
// Compute matrix size
for (i = 0; i < numOfBoxes; i++) {
for (int i = 0; i < numOfBoxes; i++) {
while (*tmp != 0xFF) {
size++;
tmp++;
@ -794,8 +793,8 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
//
// No scale data in old bundle games
//
for (i = 1; i < _res->_types[rtScaleTable]._num; i++)
_res->nukeResource(rtScaleTable, i);
for (ResId id = 1; id < _res->_types[rtScaleTable]._resources.size(); id++)
_res->nukeResource(rtScaleTable, id);
}

View File

@ -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);

View File

@ -397,7 +397,7 @@ void ScummEngine::getScriptBaseAddress() {
case WIO_ROOM: /* room script */
if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
assert(_roomResource < _res->_types[rtRoomScripts]._num);
assert(_roomResource < (int)_res->_types[rtRoomScripts]._resources.size());
_lastCodePtr = &_res->_types[rtRoomScripts]._resources[_roomResource]._address;
} else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103.
if (_res->_types[rtScript]._num > 460) {
if (_res->_types[rtScript]._resources.size() > 460) {
if (sentenceScript == 104)
sentenceScript = 29;
} else {