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.
This commit is contained in:
Max Horn 2011-05-11 16:23:26 +02:00
parent b37463fe59
commit 45e65d7ea0
16 changed files with 157 additions and 152 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()); DebugPrintf("Actor[%d]._elevation = %d\n", actnum, a->getElevation());
_vm->_fullRedraw = true; _vm->_fullRedraw = true;
} else if (!strcmp(argv[2], "costume")) { } else if (!strcmp(argv[2], "costume")) {
if (value >= _vm->_res->num[rtCostume]) if (value >= _vm->_res->_types[rtCostume].num)
DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->num[rtCostume]); DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume].num);
else { else {
a->setActorCostume(value); a->setActorCostume(value);
_vm->_fullRedraw = true; _vm->_fullRedraw = true;

View file

@ -68,7 +68,7 @@ static const MD5Table *findInMD5Table(const char *md5) {
} }
Common::String ScummEngine::generateFilename(const int room) const { Common::String ScummEngine::generateFilename(const int room) const {
const int diskNumber = (room > 0) ? _res->roomno[rtRoom][room] : 0; const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
char buf[128]; char buf[128];
if (_game.version == 4) { if (_game.version == 4) {
@ -110,7 +110,7 @@ Common::String ScummEngine_v60he::generateFilename(const int room) const {
if (room < 0) { if (room < 0) {
id = '0' - room; id = '0' - room;
} else { } else {
const int diskNumber = (room > 0) ? _res->roomno[rtRoom][room] : 0; const int diskNumber = (room > 0) ? _res->_types[rtRoom].roomno[room] : 0;
id = diskNumber + '0'; id = diskNumber + '0';
} }

View file

@ -226,7 +226,7 @@ void ScummEngine_v70he::readRoomsOffsets() {
num = READ_LE_UINT16(_heV7RoomOffsets); num = READ_LE_UINT16(_heV7RoomOffsets);
ptr = _heV7RoomOffsets + 2; ptr = _heV7RoomOffsets + 2;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->roomoffs[rtRoom][i] = READ_LE_UINT32(ptr); _res->_types[rtRoom].roomoffs[i] = READ_LE_UINT32(ptr);
ptr += 4; ptr += 4;
} }
} }

View file

@ -621,7 +621,7 @@ void ScummEngine_v72he::o72_getArrayDimSize() {
} }
void ScummEngine_v72he::o72_getNumFreeArrays() { void ScummEngine_v72he::o72_getNumFreeArrays() {
byte **addr = _res->address[rtString]; byte **addr = _res->_types[rtString].address;
int i, num = 0; int i, num = 0;
for (i = 1; i < _numArray; i++) { for (i = 1; i < _numArray; i++) {

View file

@ -192,8 +192,8 @@ void ScummEngine::clearOwnerOf(int obj) {
if (!_inventory[i] && _inventory[i+1]) { if (!_inventory[i] && _inventory[i+1]) {
_inventory[i] = _inventory[i+1]; _inventory[i] = _inventory[i+1];
_inventory[i+1] = 0; _inventory[i+1] = 0;
_res->address[rtInventory][i] = _res->address[rtInventory][i + 1]; _res->_types[rtInventory].address[i] = _res->_types[rtInventory].address[i + 1];
_res->address[rtInventory][i + 1] = NULL; _res->_types[rtInventory].address[i + 1] = NULL;
} }
} }
break; break;
@ -1796,7 +1796,7 @@ int ScummEngine::findLocalObjectSlot() {
int ScummEngine::findFlObjectSlot() { int ScummEngine::findFlObjectSlot() {
int i; int i;
for (i = 1; i < _numFlObject; i++) { for (i = 1; i < _numFlObject; i++) {
if (_res->address[rtFlObject][i] == NULL) if (_res->_types[rtFlObject].address[i] == NULL)
return i; return i;
} }
error("findFlObjectSlot: Out of FLObject slots"); error("findFlObjectSlot: Out of FLObject slots");

View file

@ -83,8 +83,8 @@ void ScummEngine::openRoom(const int room) {
// Load the disk numer / room offs (special case for room 0 exists because // Load the disk numer / room offs (special case for room 0 exists because
// room 0 contains the data which is used to create the roomno / roomoffs // room 0 contains the data which is used to create the roomno / roomoffs
// tables -- hence obviously we mustn't use those when loading room 0. // tables -- hence obviously we mustn't use those when loading room 0.
const uint32 diskNumber = room ? _res->roomno[rtRoom][room] : 0; const uint32 diskNumber = room ? _res->_types[rtRoom].roomno[room] : 0;
const uint32 room_offs = room ? _res->roomoffs[rtRoom][room] : 0; const uint32 room_offs = room ? _res->_types[rtRoom].roomoffs[room] : 0;
// FIXME: Since room_offs is const, clearly the following loop either // FIXME: Since room_offs is const, clearly the following loop either
// is never entered, or loops forever (if it wasn't for the return/error // is never entered, or loops forever (if it wasn't for the return/error
@ -94,7 +94,7 @@ void ScummEngine::openRoom(const int room) {
while (room_offs != RES_INVALID_OFFSET) { while (room_offs != RES_INVALID_OFFSET) {
if (room_offs != 0 && room != 0 && _game.heversion < 98) { if (room_offs != 0 && room != 0 && _game.heversion < 98) {
_fileOffset = _res->roomoffs[rtRoom][room]; _fileOffset = _res->_types[rtRoom].roomoffs[room];
return; return;
} }
@ -122,7 +122,7 @@ void ScummEngine::openRoom(const int room) {
return; return;
deleteRoomOffsets(); deleteRoomOffsets();
readRoomsOffsets(); readRoomsOffsets();
_fileOffset = _res->roomoffs[rtRoom][room]; _fileOffset = _res->_types[rtRoom].roomoffs[room];
if (_fileOffset != 8) if (_fileOffset != 8)
return; return;
@ -157,8 +157,8 @@ void ScummEngine::closeRoom() {
/** Delete the currently loaded room offsets. */ /** Delete the currently loaded room offsets. */
void ScummEngine::deleteRoomOffsets() { void ScummEngine::deleteRoomOffsets() {
for (int i = 0; i < _numRooms; i++) { for (int i = 0; i < _numRooms; i++) {
if (_res->roomoffs[rtRoom][i] != RES_INVALID_OFFSET) if (_res->_types[rtRoom].roomoffs[i] != RES_INVALID_OFFSET)
_res->roomoffs[rtRoom][i] = 0; _res->_types[rtRoom].roomoffs[i] = 0;
} }
} }
@ -174,8 +174,8 @@ void ScummEngine::readRoomsOffsets() {
while (num--) { while (num--) {
int room = _fileHandle->readByte(); int room = _fileHandle->readByte();
int offset = _fileHandle->readUint32LE(); int offset = _fileHandle->readUint32LE();
if (_res->roomoffs[rtRoom][room] != RES_INVALID_OFFSET) { if (_res->_types[rtRoom].roomoffs[room] != RES_INVALID_OFFSET) {
_res->roomoffs[rtRoom][room] = offset; _res->_types[rtRoom].roomoffs[room] = offset;
} }
} }
} }
@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(int id) {
else else
num = _fileHandle->readUint16LE(); num = _fileHandle->readUint16LE();
if (num != _res->num[id]) { if (num != _res->_types[id].num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num); error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
} }
@ -499,10 +499,10 @@ int ScummEngine::readResTypeList(int id) {
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->roomno[id][i] = _fileHandle->readByte(); _res->_types[id].roomno[i] = _fileHandle->readByte();
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->roomoffs[id][i] = _fileHandle->readUint32LE(); _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
} }
return num; return num;
@ -516,11 +516,11 @@ int ScummEngine_v70he::readResTypeList(int id) {
if (id == rtRoom) if (id == rtRoom)
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_heV7RoomIntOffsets[i] = _res->roomoffs[rtRoom][i]; _heV7RoomIntOffsets[i] = _res->_types[rtRoom].roomoffs[i];
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->globsize[id][i] = _fileHandle->readUint32LE(); _res->_types[id].globsize[i] = _fileHandle->readUint32LE();
} }
return num; return num;
@ -528,26 +528,26 @@ int ScummEngine_v70he::readResTypeList(int id) {
void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) { void ResourceManager::allocResTypeData(int id, uint32 tag, int num_, const char *name_, int mode_) {
debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name_, tag2str(TO_BE_32(tag)), num_, mode_); debug(9, "allocResTypeData(%s/%s,%s,%d,%d)", resTypeFromId(id), name_, tag2str(TO_BE_32(tag)), num_, mode_);
assert(id >= 0 && id < (int)(ARRAYSIZE(this->mode))); assert(id >= 0 && id < (int)(ARRAYSIZE(_types)));
if (num_ >= 8000) if (num_ >= 8000)
error("Too many %ss (%d) in directory", name_, num_); error("Too many %ss (%d) in directory", name_, num_);
mode[id] = mode_; _types[id].mode = mode_;
num[id] = num_; _types[id].num = num_;
tags[id] = tag; _types[id].tags = tag;
name[id] = name_; _types[id].name = name_;
address[id] = (byte **)calloc(num_, sizeof(void *)); _types[id].address = (byte **)calloc(num_, sizeof(void *));
flags[id] = (byte *)calloc(num_, sizeof(byte)); _types[id].flags = (byte *)calloc(num_, sizeof(byte));
status[id] = (byte *)calloc(num_, sizeof(byte)); _types[id].status = (byte *)calloc(num_, sizeof(byte));
if (mode_) { if (mode_) {
roomno[id] = (byte *)calloc(num_, sizeof(byte)); _types[id].roomno = (byte *)calloc(num_, sizeof(byte));
roomoffs[id] = (uint32 *)calloc(num_, sizeof(uint32)); _types[id].roomoffs = (uint32 *)calloc(num_, sizeof(uint32));
} }
if (_vm->_game.heversion >= 70) { if (_vm->_game.heversion >= 70) {
globsize[id] = (uint32 *)calloc(num_, sizeof(uint32)); _types[id].globsize = (uint32 *)calloc(num_, sizeof(uint32));
} }
} }
@ -606,8 +606,8 @@ void ScummEngine::ensureResourceLoaded(int type, int i) {
if (type != rtCharset && i == 0) if (type != rtCharset && i == 0)
return; return;
if (i <= _res->num[type]) if (i <= _res->_types[type].num)
addr = _res->address[type][i]; addr = _res->_types[type].address[i];
if (addr) if (addr)
return; return;
@ -632,8 +632,8 @@ int ScummEngine::loadResource(int type, int idx) {
roomNr = getResourceRoomNr(type, idx); roomNr = getResourceRoomNr(type, idx);
if (idx >= _res->num[type]) if (idx >= _res->_types[type].num)
error("%s %d undefined %d %d", _res->name[type], idx, _res->num[type], roomNr); error("%s %d undefined %d %d", _res->_types[type].name, idx, _res->_types[type].num, roomNr);
if (roomNr == 0) if (roomNr == 0)
roomNr = _roomResource; roomNr = _roomResource;
@ -669,9 +669,9 @@ int ScummEngine::loadResource(int type, int idx) {
tag = _fileHandle->readUint32BE(); tag = _fileHandle->readUint32BE();
if (tag != _res->tags[type] && _game.heversion < 70) { if (tag != _res->_types[type].tags && _game.heversion < 70) {
error("%s %d not in room %d at %d+%d in file %s", error("%s %d not in room %d at %d+%d in file %s",
_res->name[type], idx, roomNr, _res->_types[type].name, idx, roomNr,
_fileOffset, fileOffs, _fileHandle->getName()); _fileOffset, fileOffs, _fileHandle->getName());
} }
@ -695,21 +695,21 @@ int ScummEngine::loadResource(int type, int idx) {
int ScummEngine::getResourceRoomNr(int type, int idx) { int ScummEngine::getResourceRoomNr(int type, int idx) {
if (type == rtRoom && _game.heversion < 70) if (type == rtRoom && _game.heversion < 70)
return idx; return idx;
return _res->roomno[type][idx]; return _res->_types[type].roomno[idx];
} }
uint32 ScummEngine::getResourceRoomOffset(int type, int idx) { uint32 ScummEngine::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) { if (type == rtRoom) {
return (_game.version == 8) ? 8 : 0; return (_game.version == 8) ? 8 : 0;
} }
return _res->roomoffs[type][idx]; return _res->_types[type].roomoffs[idx];
} }
uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) { uint32 ScummEngine_v70he::getResourceRoomOffset(int type, int idx) {
if (type == rtRoom) { if (type == rtRoom) {
return _heV7RoomIntOffsets[idx]; return _heV7RoomIntOffsets[idx];
} }
return _res->roomoffs[type][idx]; return _res->_types[type].roomoffs[idx];
} }
int ScummEngine::getResourceSize(int type, int idx) { int ScummEngine::getResourceSize(int type, int idx) {
@ -729,16 +729,16 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
if (!_res->validateResource("getResourceAddress", type, idx)) if (!_res->validateResource("getResourceAddress", type, idx))
return NULL; return NULL;
if (!_res->address[type]) { if (!_res->_types[type].address) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->address[type] == NULL", resTypeFromId(type), idx); debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d), _res->_types[type].address == NULL", resTypeFromId(type), idx);
return NULL; return NULL;
} }
if (_res->mode[type] && !_res->address[type][idx]) { if (_res->_types[type].mode && !_res->_types[type].address[idx]) {
ensureResourceLoaded(type, idx); ensureResourceLoaded(type, idx);
} }
if (!(ptr = (byte *)_res->address[type][idx])) { if (!(ptr = (byte *)_res->_types[type].address[idx])) {
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx); debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
return NULL; return NULL;
} }
@ -777,8 +777,8 @@ void ResourceManager::increaseResourceCounter() {
byte counter; byte counter;
for (i = rtFirst; i <= rtLast; i++) { for (i = rtFirst; i <= rtLast; i++) {
for (j = num[i]; --j >= 0;) { for (j = _types[i].num; --j >= 0;) {
counter = flags[i][j] & RF_USAGE; counter = _types[i].flags[j] & RF_USAGE;
if (counter && counter < RF_USAGE_MAX) { if (counter && counter < RF_USAGE_MAX) {
setResourceCounter(i, j, counter + 1); setResourceCounter(i, j, counter + 1);
} }
@ -787,8 +787,8 @@ void ResourceManager::increaseResourceCounter() {
} }
void ResourceManager::setResourceCounter(int type, int idx, byte flag) { void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
flags[type][idx] &= ~RF_USAGE; _types[type].flags[idx] &= ~RF_USAGE;
flags[type][idx] |= flag; _types[type].flags[idx] |= flag;
} }
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */ /* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
@ -805,8 +805,8 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
// cases. For instance, Zak tries to reload the intro music // cases. For instance, Zak tries to reload the intro music
// while it's playing. See bug #1253171. // while it's playing. See bug #1253171.
if (address[type][idx] && (type == rtSound || type == rtScript || type == rtCostume)) if (_types[type].address[idx] && (type == rtSound || type == rtScript || type == rtCostume))
return address[type][idx] + sizeof(MemBlkHeader); return _types[type].address[idx] + sizeof(MemBlkHeader);
} }
nukeResource(type, idx); nukeResource(type, idx);
@ -820,7 +820,7 @@ byte *ResourceManager::createResource(int type, int idx, uint32 size) {
_allocatedSize += size; _allocatedSize += size;
address[type][idx] = (byte *)ptr; _types[type].address[idx] = (byte *)ptr;
((MemBlkHeader *)ptr)->size = size; ((MemBlkHeader *)ptr)->size = size;
setResourceCounter(type, idx, 1); setResourceCounter(type, idx, 1);
return (byte *)ptr + sizeof(MemBlkHeader); /* skip header */ return (byte *)ptr + sizeof(MemBlkHeader); /* skip header */
@ -844,7 +844,7 @@ void ResourceManager::setHeapThreshold(int min, int max) {
} }
bool ResourceManager::validateResource(const char *str, int type, int idx) const { bool ResourceManager::validateResource(const char *str, int type, int idx) const {
if (type < rtFirst || type > rtLast || (uint) idx >= (uint)num[type]) { 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); error("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
return false; return false;
} }
@ -854,17 +854,17 @@ bool ResourceManager::validateResource(const char *str, int type, int idx) const
void ResourceManager::nukeResource(int type, int idx) { void ResourceManager::nukeResource(int type, int idx) {
byte *ptr; byte *ptr;
if (!address[type]) if (!_types[type].address)
return; return;
assert(idx >= 0 && idx < num[type]); assert(idx >= 0 && idx < _types[type].num);
ptr = address[type][idx]; ptr = _types[type].address[idx];
if (ptr != NULL) { if (ptr != NULL) {
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx); debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
address[type][idx] = 0; _types[type].address[idx] = 0;
flags[type][idx] = 0; _types[type].flags[idx] = 0;
status[type][idx] &= ~RS_MODIFIED; _types[type].status[idx] &= ~RS_MODIFIED;
_allocatedSize -= ((MemBlkHeader *)ptr)->size; _allocatedSize -= ((MemBlkHeader *)ptr)->size;
free(ptr); free(ptr);
} }
@ -898,19 +898,19 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
void ResourceManager::lock(int type, int i) { void ResourceManager::lock(int type, int i) {
if (!validateResource("Locking", type, i)) if (!validateResource("Locking", type, i))
return; return;
flags[type][i] |= RF_LOCK; _types[type].flags[i] |= RF_LOCK;
} }
void ResourceManager::unlock(int type, int i) { void ResourceManager::unlock(int type, int i) {
if (!validateResource("Unlocking", type, i)) if (!validateResource("Unlocking", type, i))
return; return;
flags[type][i] &= ~RF_LOCK; _types[type].flags[i] &= ~RF_LOCK;
} }
bool ResourceManager::isLocked(int type, int i) const { bool ResourceManager::isLocked(int type, int i) const {
if (!validateResource("isLocked", type, i)) if (!validateResource("isLocked", type, i))
return false; return false;
return (flags[type][i] & RF_LOCK) != 0; return (_types[type].flags[i] & RF_LOCK) != 0;
} }
bool ScummEngine::isResourceInUse(int type, int i) const { bool ScummEngine::isResourceInUse(int type, int i) const {
@ -947,13 +947,13 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
void ResourceManager::setModified(int type, int i) { void ResourceManager::setModified(int type, int i) {
if (!validateResource("Modified", type, i)) if (!validateResource("Modified", type, i))
return; return;
status[type][i] |= RS_MODIFIED; _types[type].status[i] |= RS_MODIFIED;
} }
bool ResourceManager::isModified(int type, int i) const { bool ResourceManager::isModified(int type, int i) const {
if (!validateResource("isModified", type, i)) if (!validateResource("isModified", type, i))
return false; return false;
return (status[type][i] & RS_MODIFIED) != 0; return (_types[type].status[i] & RS_MODIFIED) != 0;
} }
void ResourceManager::expireResources(uint32 size) { void ResourceManager::expireResources(uint32 size) {
@ -978,10 +978,10 @@ void ResourceManager::expireResources(uint32 size) {
best_counter = 2; best_counter = 2;
for (i = rtFirst; i <= rtLast; i++) for (i = rtFirst; i <= rtLast; i++)
if (mode[i]) { if (_types[i].mode) {
for (j = num[i]; --j >= 0;) { for (j = _types[i].num; --j >= 0;) {
flag = flags[i][j]; flag = _types[i].flags[j];
if (!(flag & RF_LOCK) && flag >= best_counter && address[i][j] && !_vm->isResourceInUse(i, j)) { if (!(flag & RF_LOCK) && flag >= best_counter && _types[i].address[j] && !_vm->isResourceInUse(i, j)) {
best_counter = flag; best_counter = flag;
best_type = i; best_type = i;
best_res = j; best_res = j;
@ -1002,17 +1002,17 @@ void ResourceManager::expireResources(uint32 size) {
void ResourceManager::freeResources() { void ResourceManager::freeResources() {
int i, j; int i, j;
for (i = rtFirst; i <= rtLast; i++) { for (i = rtFirst; i <= rtLast; i++) {
for (j = num[i]; --j >= 0;) { for (j = _types[i].num; --j >= 0;) {
if (isResourceLoaded(i, j)) if (isResourceLoaded(i, j))
nukeResource(i, j); nukeResource(i, j);
} }
free(address[i]); free(_types[i].address);
free(flags[i]); free(_types[i].flags);
free(status[i]); free(_types[i].status);
free(roomno[i]); free(_types[i].roomno);
free(roomoffs[i]); free(_types[i].roomoffs);
free(globsize[i]); free(_types[i].globsize);
} }
} }
@ -1043,7 +1043,7 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
bool ResourceManager::isResourceLoaded(int type, int idx) const { bool ResourceManager::isResourceLoaded(int type, int idx) const {
if (!validateResource("isResourceLoaded", type, idx)) if (!validateResource("isResourceLoaded", type, idx))
return false; return false;
return address[type][idx] != NULL; return _types[type].address[idx] != NULL;
} }
void ResourceManager::resourceStats() { void ResourceManager::resourceStats() {
@ -1052,10 +1052,10 @@ void ResourceManager::resourceStats() {
byte flag; byte flag;
for (i = rtFirst; i <= rtLast; i++) for (i = rtFirst; i <= rtLast; i++)
for (j = num[i]; --j >= 0;) { for (j = _types[i].num; --j >= 0;) {
flag = flags[i][j]; flag = _types[i].flags[j];
if (flag & RF_LOCK && address[i][j]) { if (flag & RF_LOCK && _types[i].address[j]) {
lockedSize += ((MemBlkHeader *)address[i][j])->size; lockedSize += ((MemBlkHeader *)_types[i].roomoffs[j])->size;
lockedNum++; lockedNum++;
} }
} }

View file

@ -60,18 +60,23 @@ protected:
ScummEngine *_vm; ScummEngine *_vm;
public: public:
byte mode[rtNumTypes]; class ResTypeData {
uint16 num[rtNumTypes]; friend class ResourceManager;
uint32 tags[rtNumTypes]; public:
const char *name[rtNumTypes]; byte mode;
byte **address[rtNumTypes]; uint16 num;
protected: uint32 tags;
byte *flags[rtNumTypes]; const char *name;
byte *status[rtNumTypes]; byte **address;
public: protected:
byte *roomno[rtNumTypes]; byte *flags;
uint32 *roomoffs[rtNumTypes]; byte *status;
uint32 *globsize[rtNumTypes]; public:
byte *roomno;
uint32 *roomoffs;
uint32 *globsize;
};
ResTypeData _types[rtNumTypes];
protected: protected:
uint32 _allocatedSize; uint32 _allocatedSize;

View file

@ -84,40 +84,40 @@ void ScummEngine_v2::readClassicIndexFile() {
} }
for (i = 0; i < _numRooms; i++) { for (i = 0; i < _numRooms; i++) {
_res->roomno[rtRoom][i] = i; _res->_types[rtRoom].roomno[i] = i;
} }
_fileHandle->seek(_numRooms, SEEK_CUR); _fileHandle->seek(_numRooms, SEEK_CUR);
for (i = 0; i < _numRooms; i++) { for (i = 0; i < _numRooms; i++) {
_res->roomoffs[rtRoom][i] = _fileHandle->readUint16LE(); _res->_types[rtRoom].roomoffs[i] = _fileHandle->readUint16LE();
if (_res->roomoffs[rtRoom][i] == 0xFFFF) if (_res->_types[rtRoom].roomoffs[i] == 0xFFFF)
_res->roomoffs[rtRoom][i] = (uint32)RES_INVALID_OFFSET; _res->_types[rtRoom].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
} }
for (i = 0; i < _numCostumes; i++) { for (i = 0; i < _numCostumes; i++) {
_res->roomno[rtCostume][i] = _fileHandle->readByte(); _res->_types[rtCostume].roomno[i] = _fileHandle->readByte();
} }
for (i = 0; i < _numCostumes; i++) { for (i = 0; i < _numCostumes; i++) {
_res->roomoffs[rtCostume][i] = _fileHandle->readUint16LE(); _res->_types[rtCostume].roomoffs[i] = _fileHandle->readUint16LE();
if (_res->roomoffs[rtCostume][i] == 0xFFFF) if (_res->_types[rtCostume].roomoffs[i] == 0xFFFF)
_res->roomoffs[rtCostume][i] = (uint32)RES_INVALID_OFFSET; _res->_types[rtCostume].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
} }
for (i = 0; i < _numScripts; i++) { for (i = 0; i < _numScripts; i++) {
_res->roomno[rtScript][i] = _fileHandle->readByte(); _res->_types[rtScript].roomno[i] = _fileHandle->readByte();
} }
for (i = 0; i < _numScripts; i++) { for (i = 0; i < _numScripts; i++) {
_res->roomoffs[rtScript][i] = _fileHandle->readUint16LE(); _res->_types[rtScript].roomoffs[i] = _fileHandle->readUint16LE();
if (_res->roomoffs[rtScript][i] == 0xFFFF) if (_res->_types[rtScript].roomoffs[i] == 0xFFFF)
_res->roomoffs[rtScript][i] = (uint32)RES_INVALID_OFFSET; _res->_types[rtScript].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
} }
for (i = 0; i < _numSounds; i++) { for (i = 0; i < _numSounds; i++) {
_res->roomno[rtSound][i] = _fileHandle->readByte(); _res->_types[rtSound].roomno[i] = _fileHandle->readByte();
} }
for (i = 0; i < _numSounds; i++) { for (i = 0; i < _numSounds; i++) {
_res->roomoffs[rtSound][i] = _fileHandle->readUint16LE(); _res->_types[rtSound].roomoffs[i] = _fileHandle->readUint16LE();
if (_res->roomoffs[rtSound][i] == 0xFFFF) if (_res->_types[rtSound].roomoffs[i] == 0xFFFF)
_res->roomoffs[rtSound][i] = (uint32)RES_INVALID_OFFSET; _res->_types[rtSound].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
} }
} }

View file

@ -44,16 +44,16 @@ int ScummEngine_v3old::readResTypeList(int id) {
if (id == rtRoom) { if (id == rtRoom) {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
_res->roomno[id][i] = i; _res->_types[id].roomno[i] = i;
_fileHandle->seek(num, SEEK_CUR); _fileHandle->seek(num, SEEK_CUR);
} else { } else {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
_res->roomno[id][i] = _fileHandle->readByte(); _res->_types[id].roomno[i] = _fileHandle->readByte();
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->roomoffs[id][i] = _fileHandle->readUint16LE(); _res->_types[id].roomoffs[i] = _fileHandle->readUint16LE();
if (_res->roomoffs[id][i] == 0xFFFF) if (_res->_types[id].roomoffs[i] == 0xFFFF)
_res->roomoffs[id][i] = (uint32)RES_INVALID_OFFSET; _res->_types[id].roomoffs[i] = (uint32)RES_INVALID_OFFSET;
} }
return num; return num;

View file

@ -38,13 +38,13 @@ int ScummEngine_v4::readResTypeList(int id) {
num = _fileHandle->readUint16LE(); num = _fileHandle->readUint16LE();
if (num != _res->num[id]) { if (num != _res->_types[id].num) {
error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num); error("Invalid number of %ss (%d) in directory", resTypeFromId(id), num);
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
_res->roomno[id][i] = _fileHandle->readByte(); _res->_types[id].roomno[i] = _fileHandle->readByte();
_res->roomoffs[id][i] = _fileHandle->readUint32LE(); _res->_types[id].roomoffs[i] = _fileHandle->readUint32LE();
} }
return num; return num;

View file

@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
// //
// Load scale data // Load scale data
// //
for (i = 1; i < _res->num[rtScaleTable]; i++) for (i = 1; i < _res->_types[rtScaleTable].num; i++)
_res->nukeResource(rtScaleTable, i); _res->nukeResource(rtScaleTable, i);
ptr = findResourceData(MKTAG('S','C','A','L'), roomptr); ptr = findResourceData(MKTAG('S','C','A','L'), roomptr);
if (ptr) { if (ptr) {
int s1, s2, y1, y2; int s1, s2, y1, y2;
if (_game.version == 8) { if (_game.version == 8) {
for (i = 1; i < _res->num[rtScaleTable]; i++, ptr += 16) { for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 16) {
s1 = READ_LE_UINT32(ptr); s1 = READ_LE_UINT32(ptr);
y1 = READ_LE_UINT32(ptr + 4); y1 = READ_LE_UINT32(ptr + 4);
s2 = READ_LE_UINT32(ptr + 8); s2 = READ_LE_UINT32(ptr + 8);
@ -540,7 +540,7 @@ void ScummEngine::resetRoomSubBlocks() {
setScaleSlot(i, 0, y1, s1, 0, y2, s2); setScaleSlot(i, 0, y1, s1, 0, y2, s2);
} }
} else { } else {
for (i = 1; i < _res->num[rtScaleTable]; i++, ptr += 8) { for (i = 1; i < _res->_types[rtScaleTable].num; i++, ptr += 8) {
s1 = READ_LE_UINT16(ptr); s1 = READ_LE_UINT16(ptr);
y1 = READ_LE_UINT16(ptr + 2); y1 = READ_LE_UINT16(ptr + 2);
s2 = READ_LE_UINT16(ptr + 4); s2 = READ_LE_UINT16(ptr + 4);
@ -794,7 +794,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
// //
// No scale data in old bundle games // No scale data in old bundle games
// //
for (i = 1; i < _res->num[rtScaleTable]; i++) for (i = 1; i < _res->_types[rtScaleTable].num; i++)
_res->nukeResource(rtScaleTable, i); _res->nukeResource(rtScaleTable, i);
} }

View file

@ -428,7 +428,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
// Nuke all resources // Nuke all resources
for (i = rtFirst; i <= rtLast; i++) for (i = rtFirst; i <= rtLast; i++)
if (i != rtTemp && i != rtBuffer && (i != rtSound || _saveSound || !compat)) 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); _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. // loading such an old save game, try to upgrade the old to new format.
if (hdr.ver < VER(22)) { if (hdr.ver < VER(22)) {
// Convert all rtScaleTable resources to matching scale items // 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); convertScaleTableToScaleSlot(i);
} }
} }
@ -1243,11 +1243,11 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// number of script resources, savegames won't break. // number of script resources, savegames won't break.
if (s->isSaving()) { if (s->isSaving()) {
for (type = rtFirst; type <= rtLast; 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) {
s->saveUint16(type); // Save the res type... 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... // 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 s->saveUint16(idx); // Save the index of the resource
saveResource(s, type, idx); saveResource(s, type, idx);
} }
@ -1259,7 +1259,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
} else { } else {
while ((type = s->loadUint16()) != 0xFFFF) { while ((type = s->loadUint16()) != 0xFFFF) {
while ((idx = 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); 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 // with index 0, and breaks whenever we change the limit on a given
// resource type. // resource type.
for (type = rtFirst; type <= rtLast; 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. // For V1-V5 games, there used to be no object name resources.
// At some point this changed. But since old savegames rely on // At some point this changed. But since old savegames rely on
// unchanged resource counts, we have to hard code the following check // unchanged resource counts, we have to hard code the following check
if (_game.version < 6 && type == rtObjectName) if (_game.version < 6 && type == rtObjectName)
continue; continue;
for (idx = 1; idx < _res->num[type]; idx++) for (idx = 1; idx < _res->_types[type].num; idx++)
saveLoadResource(s, type, idx); saveLoadResource(s, type, idx);
} }
} }
@ -1388,7 +1388,7 @@ void ScummEngine::saveOrLoad(Serializer *s) {
// //
if (s->isSaving()) { if (s->isSaving()) {
for (i = rtFirst; i <= rtLast; i++) 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)) { if (_res->isLocked(i, j)) {
s->saveByte(i); s->saveByte(i);
s->saveUint16(j); s->saveUint16(j);
@ -1637,9 +1637,9 @@ void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {
byte *ptr; byte *ptr;
uint32 size; uint32 size;
if (!_res->mode[type]) { if (!_res->_types[type].mode) {
if (ser->isSaving()) { if (ser->isSaving()) {
ptr = _res->address[type][idx]; ptr = _res->_types[type].address[idx];
if (ptr == NULL) { if (ptr == NULL) {
ser->saveUint32(0); ser->saveUint32(0);
return; 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. // Save/load only a list of resource numbers that need to be reloaded.
if (ser->isSaving()) { if (ser->isSaving()) {
ser->saveUint16(_res->address[type][idx] ? 1 : 0); ser->saveUint16(_res->_types[type].address[idx] ? 1 : 0);
} else { } else {
if (ser->loadUint16()) if (ser->loadUint16())
ensureResourceLoaded(type, idx); 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) { 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) { if (_res->_types[type].mode == 0) {
byte *ptr = _res->address[type][idx]; byte *ptr = _res->_types[type].address[idx];
uint32 size = ((MemBlkHeader *)ptr)->size; uint32 size = ((MemBlkHeader *)ptr)->size;
ser->saveUint32(size); ser->saveUint32(size);
@ -1713,7 +1713,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
assert(size); assert(size);
_res->createResource(type, idx, size); _res->createResource(type, idx, size);
ser->loadBytes(getResourceAddress(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(); uint32 size = ser->loadUint32();
assert(size); assert(size);
_res->createResource(type, idx, size); _res->createResource(type, idx, size);
@ -1725,7 +1725,7 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
if (type == rtObjectName) { if (type == rtObjectName) {
_newNames[idx] = ser->loadUint16(); _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 // HE Games use sound resource 1 for speech
if (_game.heversion >= 60 && idx == 1) if (_game.heversion >= 60 && idx == 1)
return; return;

View file

@ -390,26 +390,26 @@ void ScummEngine::getScriptBaseAddress() {
break; break;
_scriptOrgPointer = getResourceAddress(rtInventory, idx); _scriptOrgPointer = getResourceAddress(rtInventory, idx);
assert(idx < _numInventory); assert(idx < _numInventory);
_lastCodePtr = &_res->address[rtInventory][idx]; _lastCodePtr = &_res->_types[rtInventory].address[idx];
break; break;
case WIO_LOCAL: case WIO_LOCAL:
case WIO_ROOM: /* room script */ case WIO_ROOM: /* room script */
if (_game.version == 8) { if (_game.version == 8) {
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource); _scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
assert(_roomResource < _res->num[rtRoomScripts]); assert(_roomResource < _res->_types[rtRoomScripts].num);
_lastCodePtr = &_res->address[rtRoomScripts][_roomResource]; _lastCodePtr = &_res->_types[rtRoomScripts].address[_roomResource];
} else { } else {
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource); _scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
assert(_roomResource < _numRooms); assert(_roomResource < _numRooms);
_lastCodePtr = &_res->address[rtRoom][_roomResource]; _lastCodePtr = &_res->_types[rtRoom].address[_roomResource];
} }
break; break;
case WIO_GLOBAL: /* global script */ case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number); _scriptOrgPointer = getResourceAddress(rtScript, ss->number);
assert(ss->number < _numScripts); assert(ss->number < _numScripts);
_lastCodePtr = &_res->address[rtScript][ss->number]; _lastCodePtr = &_res->_types[rtScript].address[ss->number];
break; break;
case WIO_FLOBJECT: /* flobject script */ case WIO_FLOBJECT: /* flobject script */
@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
idx = _objs[idx].fl_object_index; idx = _objs[idx].fl_object_index;
_scriptOrgPointer = getResourceAddress(rtFlObject, idx); _scriptOrgPointer = getResourceAddress(rtFlObject, idx);
assert(idx < _numFlObject); assert(idx < _numFlObject);
_lastCodePtr = &_res->address[rtFlObject][idx]; _lastCodePtr = &_res->_types[rtFlObject].address[idx];
break; break;
default: default:
error("Bad type while getting base address"); error("Bad type while getting base address");
@ -1099,7 +1099,7 @@ void ScummEngine::checkAndRunSentenceScript() {
// For now we assume that if there are more than 460 scripts, then // For now we assume that if there are more than 460 scripts, then
// the pair 29/104 is used, else the pair 28/103. // the pair 29/104 is used, else the pair 28/103.
if (_res->num[rtScript] > 460) { if (_res->_types[rtScript].num > 460) {
if (sentenceScript == 104) if (sentenceScript == 104)
sentenceScript = 29; sentenceScript = 29;
} else { } else {

View file

@ -357,7 +357,7 @@ void ScummEngine_v6::nukeArray(int a) {
} }
int ScummEngine_v6::findFreeArrayId() { int ScummEngine_v6::findFreeArrayId() {
byte **addr = _res->address[rtString]; byte **addr = _res->_types[rtString].address;
int i; int i;
for (i = 1; i < _numArray; i++) { for (i = 1; i < _numArray; i++) {

View file

@ -1185,7 +1185,7 @@ Common::Error ScummEngine::init() {
resetScummVars(); resetScummVars();
if (_imuse) { if (_imuse) {
_imuse->setBase(_res->address[rtSound]); _imuse->setBase(_res->_types[rtSound].address);
} }
if (_game.version >= 5 && _game.version <= 7) if (_game.version >= 5 && _game.version <= 7)
@ -2462,7 +2462,7 @@ void ScummEngine::restart() {
resetScummVars(); resetScummVars();
if (_imuse) { if (_imuse) {
_imuse->setBase(_res->address[rtSound]); _imuse->setBase(_res->_types[rtSound].address);
} }
// Reinit sound engine // Reinit sound engine

View file

@ -1224,7 +1224,7 @@ int ScummEngine::readSoundResource(int idx) {
if (!dmuFile.open(buffer)) { if (!dmuFile.open(buffer)) {
error("Can't open music file %s", buffer); error("Can't open music file %s", buffer);
_res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET; _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0; return 0;
} }
dmuFile.seek(4, SEEK_SET); dmuFile.seek(4, SEEK_SET);
@ -1248,7 +1248,7 @@ int ScummEngine::readSoundResource(int idx) {
} }
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx); error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
} }
_res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET; _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0; return 0;
} }
@ -2123,7 +2123,7 @@ int ScummEngine::readSoundResourceSmallHeader(int idx) {
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4); _fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
return 1; return 1;
} }
_res->roomoffs[rtSound][idx] = RES_INVALID_OFFSET; _res->_types[rtSound].roomoffs[idx] = RES_INVALID_OFFSET;
return 0; return 0;
} }