SCUMM: Turned ResTypeData into a Common::Array<Resource>, subsuming its _resource member
This commit is contained in:
parent
cf513e3ed6
commit
9ec64a66fe
16 changed files with 113 additions and 118 deletions
|
@ -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 >= (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());
|
||||
if (value >= (int)_vm->_res->_types[rtCostume].size())
|
||||
DebugPrintf("Costume not changed as %d exceeds max of %d\n", value, _vm->_res->_types[rtCostume].size());
|
||||
else {
|
||||
a->setActorCostume(value);
|
||||
_vm->_fullRedraw = true;
|
||||
|
|
|
@ -68,7 +68,7 @@ static const MD5Table *findInMD5Table(const char *md5) {
|
|||
}
|
||||
|
||||
Common::String ScummEngine::generateFilename(const int room) const {
|
||||
const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
|
||||
const int diskNumber = (room > 0) ? _res->_types[rtRoom][room]._roomno : 0;
|
||||
char buf[128];
|
||||
|
||||
if (_game.version == 4) {
|
||||
|
@ -110,7 +110,7 @@ Common::String ScummEngine_v60he::generateFilename(const int room) const {
|
|||
if (room < 0) {
|
||||
id = '0' - room;
|
||||
} else {
|
||||
const int diskNumber = (room > 0) ? _res->_types[rtRoom]._resources[room]._roomno : 0;
|
||||
const int diskNumber = (room > 0) ? _res->_types[rtRoom][room]._roomno : 0;
|
||||
id = diskNumber + '0';
|
||||
}
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ void ScummEngine_v70he::readRoomsOffsets() {
|
|||
num = READ_LE_UINT16(_heV7RoomOffsets);
|
||||
ptr = _heV7RoomOffsets + 2;
|
||||
for (i = 0; i < num; i++) {
|
||||
_res->_types[rtRoom]._resources[i]._roomoffs = READ_LE_UINT32(ptr);
|
||||
_res->_types[rtRoom][i]._roomoffs = READ_LE_UINT32(ptr);
|
||||
ptr += 4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -625,7 +625,7 @@ void ScummEngine_v72he::o72_getNumFreeArrays() {
|
|||
int i, num = 0;
|
||||
|
||||
for (i = 1; i < _numArray; i++) {
|
||||
if (!rtd._resources[i]._address)
|
||||
if (!rtd[i]._address)
|
||||
num++;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ IMuseInternal::~IMuseInternal() {
|
|||
byte *IMuseInternal::findStartOfSound(int sound) {
|
||||
int32 size, pos;
|
||||
|
||||
byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
|
||||
byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
|
||||
|
||||
if (ptr == NULL) {
|
||||
debug(1, "IMuseInternal::findStartOfSound(): Sound %d doesn't exist", sound);
|
||||
|
@ -134,7 +134,7 @@ byte *IMuseInternal::findStartOfSound(int sound) {
|
|||
}
|
||||
|
||||
bool IMuseInternal::isMT32(int sound) {
|
||||
byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
|
||||
byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
|
||||
if (ptr == NULL)
|
||||
return false;
|
||||
|
||||
|
@ -176,7 +176,7 @@ bool IMuseInternal::isMT32(int sound) {
|
|||
}
|
||||
|
||||
bool IMuseInternal::isMIDI(int sound) {
|
||||
byte *ptr = g_scumm->_res->_types[rtSound]._resources[sound]._address;
|
||||
byte *ptr = g_scumm->_res->_types[rtSound][sound]._address;
|
||||
if (ptr == NULL)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -193,10 +193,10 @@ void ScummEngine::clearOwnerOf(int obj) {
|
|||
_inventory[i] = _inventory[i+1];
|
||||
_inventory[i+1] = 0;
|
||||
// FIXME FIXME FIXME: This is incomplete, as we do not touch flags, status... BUG
|
||||
_res->_types[rtInventory]._resources[i]._address = _res->_types[rtInventory]._resources[i + 1]._address;
|
||||
_res->_types[rtInventory]._resources[i]._size = _res->_types[rtInventory]._resources[i + 1]._size;
|
||||
_res->_types[rtInventory]._resources[i + 1]._address = NULL;
|
||||
_res->_types[rtInventory]._resources[i + 1]._size = 0;
|
||||
_res->_types[rtInventory][i]._address = _res->_types[rtInventory][i + 1]._address;
|
||||
_res->_types[rtInventory][i]._size = _res->_types[rtInventory][i + 1]._size;
|
||||
_res->_types[rtInventory][i + 1]._address = NULL;
|
||||
_res->_types[rtInventory][i + 1]._size = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1799,7 +1799,7 @@ int ScummEngine::findLocalObjectSlot() {
|
|||
int ScummEngine::findFlObjectSlot() {
|
||||
int i;
|
||||
for (i = 1; i < _numFlObject; i++) {
|
||||
if (_res->_types[rtFlObject]._resources[i]._address == NULL)
|
||||
if (_res->_types[rtFlObject][i]._address == NULL)
|
||||
return i;
|
||||
}
|
||||
error("findFlObjectSlot: Out of FLObject slots");
|
||||
|
|
|
@ -83,8 +83,8 @@ void ScummEngine::openRoom(const int room) {
|
|||
// 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
|
||||
// tables -- hence obviously we mustn't use those when loading room 0.
|
||||
const uint32 diskNumber = room ? _res->_types[rtRoom]._resources[room]._roomno : 0;
|
||||
const uint32 room_offs = room ? _res->_types[rtRoom]._resources[room]._roomoffs : 0;
|
||||
const uint32 diskNumber = room ? _res->_types[rtRoom][room]._roomno : 0;
|
||||
const uint32 room_offs = room ? _res->_types[rtRoom][room]._roomoffs : 0;
|
||||
|
||||
// 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
|
||||
|
@ -94,7 +94,7 @@ void ScummEngine::openRoom(const int room) {
|
|||
while (room_offs != RES_INVALID_OFFSET) {
|
||||
|
||||
if (room_offs != 0 && room != 0 && _game.heversion < 98) {
|
||||
_fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
|
||||
_fileOffset = _res->_types[rtRoom][room]._roomoffs;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ void ScummEngine::openRoom(const int room) {
|
|||
return;
|
||||
deleteRoomOffsets();
|
||||
readRoomsOffsets();
|
||||
_fileOffset = _res->_types[rtRoom]._resources[room]._roomoffs;
|
||||
_fileOffset = _res->_types[rtRoom][room]._roomoffs;
|
||||
|
||||
if (_fileOffset != 8)
|
||||
return;
|
||||
|
@ -157,8 +157,8 @@ void ScummEngine::closeRoom() {
|
|||
/** Delete the currently loaded room offsets. */
|
||||
void ScummEngine::deleteRoomOffsets() {
|
||||
for (int i = 0; i < _numRooms; i++) {
|
||||
if (_res->_types[rtRoom]._resources[i]._roomoffs != RES_INVALID_OFFSET)
|
||||
_res->_types[rtRoom]._resources[i]._roomoffs = 0;
|
||||
if (_res->_types[rtRoom][i]._roomoffs != RES_INVALID_OFFSET)
|
||||
_res->_types[rtRoom][i]._roomoffs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,8 +174,8 @@ void ScummEngine::readRoomsOffsets() {
|
|||
while (num--) {
|
||||
int room = _fileHandle->readByte();
|
||||
int offset = _fileHandle->readUint32LE();
|
||||
if (_res->_types[rtRoom]._resources[room]._roomoffs != RES_INVALID_OFFSET) {
|
||||
_res->_types[rtRoom]._resources[room]._roomoffs = offset;
|
||||
if (_res->_types[rtRoom][room]._roomoffs != RES_INVALID_OFFSET) {
|
||||
_res->_types[rtRoom][room]._roomoffs = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ int ScummEngine::readResTypeList(ResType type) {
|
|||
else
|
||||
num = _fileHandle->readUint16LE();
|
||||
|
||||
if (num != _res->_types[type]._resources.size()) {
|
||||
if (num != _res->_types[type].size()) {
|
||||
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
|
||||
}
|
||||
|
||||
|
@ -499,10 +499,10 @@ int ScummEngine::readResTypeList(ResType type) {
|
|||
|
||||
|
||||
for (idx = 0; idx < num; idx++) {
|
||||
_res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
|
||||
_res->_types[type][idx]._roomno = _fileHandle->readByte();
|
||||
}
|
||||
for (idx = 0; idx < num; idx++) {
|
||||
_res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
|
||||
_res->_types[type][idx]._roomoffs = _fileHandle->readUint32LE();
|
||||
}
|
||||
|
||||
return num;
|
||||
|
@ -516,12 +516,12 @@ int ScummEngine_v70he::readResTypeList(ResType type) {
|
|||
|
||||
if (type == rtRoom)
|
||||
for (idx = 0; idx < num; idx++) {
|
||||
_heV7RoomIntOffsets[idx] = _res->_types[rtRoom]._resources[idx]._roomoffs;
|
||||
_heV7RoomIntOffsets[idx] = _res->_types[rtRoom][idx]._roomoffs;
|
||||
}
|
||||
|
||||
for (idx = 0; idx < num; idx++) {
|
||||
// The globsize is currently not being used
|
||||
/*_res->_types[type]._resources[idx]._globsize =*/ _fileHandle->readUint32LE();
|
||||
/*_res->_types[type][idx]._globsize =*/ _fileHandle->readUint32LE();
|
||||
}
|
||||
|
||||
return num;
|
||||
|
@ -539,8 +539,8 @@ void ResourceManager::allocResTypeData(ResType type, uint32 tag, int num, ResTyp
|
|||
|
||||
// If there was data in there, let's clear it out completely. This is important
|
||||
// in case we are restarting the game.
|
||||
_types[type]._resources.clear();
|
||||
_types[type]._resources.resize(num);
|
||||
_types[type].clear();
|
||||
_types[type].resize(num);
|
||||
|
||||
/*
|
||||
TODO: Use multiple Resource subclasses, one for each res mode; then,
|
||||
|
@ -608,7 +608,7 @@ void ScummEngine::ensureResourceLoaded(ResType type, ResId idx) {
|
|||
if (type != rtCharset && idx == 0)
|
||||
return;
|
||||
|
||||
if (idx <= _res->_types[type]._resources.size() && _res->_types[type]._resources[idx]._address)
|
||||
if (idx <= _res->_types[type].size() && _res->_types[type][idx]._address)
|
||||
return;
|
||||
|
||||
loadResource(type, idx);
|
||||
|
@ -631,8 +631,8 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
|
|||
|
||||
roomNr = getResourceRoomNr(type, idx);
|
||||
|
||||
if (idx >= _res->_types[type]._resources.size())
|
||||
error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type]._resources.size(), roomNr);
|
||||
if (idx >= _res->_types[type].size())
|
||||
error("%s %d undefined %d %d", nameOfResType(type), idx, _res->_types[type].size(), roomNr);
|
||||
|
||||
if (roomNr == 0)
|
||||
roomNr = _roomResource;
|
||||
|
@ -702,27 +702,27 @@ int ScummEngine::loadResource(ResType type, ResId idx) {
|
|||
int ScummEngine::getResourceRoomNr(ResType type, ResId idx) {
|
||||
if (type == rtRoom && _game.heversion < 70)
|
||||
return idx;
|
||||
return _res->_types[type]._resources[idx]._roomno;
|
||||
return _res->_types[type][idx]._roomno;
|
||||
}
|
||||
|
||||
uint32 ScummEngine::getResourceRoomOffset(ResType type, ResId idx) {
|
||||
if (type == rtRoom) {
|
||||
return (_game.version == 8) ? 8 : 0;
|
||||
}
|
||||
return _res->_types[type]._resources[idx]._roomoffs;
|
||||
return _res->_types[type][idx]._roomoffs;
|
||||
}
|
||||
|
||||
uint32 ScummEngine_v70he::getResourceRoomOffset(ResType type, ResId idx) {
|
||||
if (type == rtRoom) {
|
||||
return _heV7RoomIntOffsets[idx];
|
||||
}
|
||||
return _res->_types[type]._resources[idx]._roomoffs;
|
||||
return _res->_types[type][idx]._roomoffs;
|
||||
}
|
||||
|
||||
int ScummEngine::getResourceSize(ResType type, ResId idx) {
|
||||
byte *ptr = getResourceAddress(type, idx);
|
||||
assert(ptr);
|
||||
return _res->_types[type]._resources[idx]._size;
|
||||
return _res->_types[type][idx]._size;
|
||||
}
|
||||
|
||||
byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
|
||||
|
@ -735,11 +735,11 @@ byte *ScummEngine::getResourceAddress(ResType type, ResId idx) {
|
|||
return NULL;
|
||||
|
||||
// If the resource is missing, but loadable from the game data files, try to do so.
|
||||
if (!_res->_types[type]._resources[idx]._address && _res->_types[type]._mode != kDynamicResTypeMode) {
|
||||
if (!_res->_types[type][idx]._address && _res->_types[type]._mode != kDynamicResTypeMode) {
|
||||
ensureResourceLoaded(type, idx);
|
||||
}
|
||||
|
||||
ptr = (byte *)_res->_types[type]._resources[idx]._address;
|
||||
ptr = (byte *)_res->_types[type][idx]._address;
|
||||
if (!ptr) {
|
||||
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == NULL", nameOfResType(type), idx);
|
||||
return NULL;
|
||||
|
@ -777,9 +777,9 @@ void ResourceManager::increaseExpireCounter() {
|
|||
|
||||
void ResourceManager::increaseResourceCounters() {
|
||||
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
|
||||
ResId idx = _types[type]._resources.size();
|
||||
ResId idx = _types[type].size();
|
||||
while (idx-- > 0) {
|
||||
byte counter = _types[type]._resources[idx].getResourceCounter();
|
||||
byte counter = _types[type][idx].getResourceCounter();
|
||||
if (counter && counter < RF_USAGE_MAX) {
|
||||
setResourceCounter(type, idx, counter + 1);
|
||||
}
|
||||
|
@ -788,7 +788,7 @@ void ResourceManager::increaseResourceCounters() {
|
|||
}
|
||||
|
||||
void ResourceManager::setResourceCounter(ResType type, ResId idx, byte counter) {
|
||||
_types[type]._resources[idx].setResourceCounter(counter);
|
||||
_types[type][idx].setResourceCounter(counter);
|
||||
}
|
||||
|
||||
void ResourceManager::Resource::setResourceCounter(byte counter) {
|
||||
|
@ -814,8 +814,8 @@ byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
|
|||
// cases. For instance, Zak tries to reload the intro music
|
||||
// while it's playing. See bug #1253171.
|
||||
|
||||
if (_types[type]._resources[idx]._address && (type == rtSound || type == rtScript || type == rtCostume))
|
||||
return _types[type]._resources[idx]._address;
|
||||
if (_types[type][idx]._address && (type == rtSound || type == rtScript || type == rtCostume))
|
||||
return _types[type][idx]._address;
|
||||
}
|
||||
|
||||
nukeResource(type, idx);
|
||||
|
@ -829,8 +829,8 @@ byte *ResourceManager::createResource(ResType type, ResId idx, uint32 size) {
|
|||
|
||||
_allocatedSize += size;
|
||||
|
||||
_types[type]._resources[idx]._address = ptr;
|
||||
_types[type]._resources[idx]._size = size;
|
||||
_types[type][idx]._address = ptr;
|
||||
_types[type][idx]._size = size;
|
||||
setResourceCounter(type, idx, 1);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -884,7 +884,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]._resources.size()) {
|
||||
if (type < rtFirst || type > rtLast || (uint)idx >= (uint)_types[type].size()) {
|
||||
error("%s Illegal Glob type %s (%d) num %d", str, nameOfResType(type), type, idx);
|
||||
return false;
|
||||
}
|
||||
|
@ -892,11 +892,11 @@ bool ResourceManager::validateResource(const char *str, ResType type, ResId idx)
|
|||
}
|
||||
|
||||
void ResourceManager::nukeResource(ResType type, ResId idx) {
|
||||
byte *ptr = _types[type]._resources[idx]._address;
|
||||
byte *ptr = _types[type][idx]._address;
|
||||
if (ptr != NULL) {
|
||||
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", nameOfResType(type), idx);
|
||||
_allocatedSize -= _types[type]._resources[idx]._size;
|
||||
_types[type]._resources[idx].nuke();
|
||||
_allocatedSize -= _types[type][idx]._size;
|
||||
_types[type][idx].nuke();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -928,19 +928,19 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
|
|||
void ResourceManager::lock(ResType type, ResId idx) {
|
||||
if (!validateResource("Locking", type, idx))
|
||||
return;
|
||||
_types[type]._resources[idx].lock();
|
||||
_types[type][idx].lock();
|
||||
}
|
||||
|
||||
void ResourceManager::unlock(ResType type, ResId idx) {
|
||||
if (!validateResource("Unlocking", type, idx))
|
||||
return;
|
||||
_types[type]._resources[idx].unlock();
|
||||
_types[type][idx].unlock();
|
||||
}
|
||||
|
||||
bool ResourceManager::isLocked(ResType type, ResId idx) const {
|
||||
if (!validateResource("isLocked", type, idx))
|
||||
return false;
|
||||
return _types[type]._resources[idx].isLocked();
|
||||
return _types[type][idx].isLocked();
|
||||
}
|
||||
|
||||
void ResourceManager::Resource::lock() {
|
||||
|
@ -989,13 +989,13 @@ bool ScummEngine::isResourceInUse(ResType type, ResId idx) const {
|
|||
void ResourceManager::setModified(ResType type, ResId idx) {
|
||||
if (!validateResource("Modified", type, idx))
|
||||
return;
|
||||
_types[type]._resources[idx].setModified();
|
||||
_types[type][idx].setModified();
|
||||
}
|
||||
|
||||
bool ResourceManager::isModified(ResType type, ResId idx) const {
|
||||
if (!validateResource("isModified", type, idx))
|
||||
return false;
|
||||
return _types[type]._resources[idx].isModified();
|
||||
return _types[type][idx].isModified();
|
||||
}
|
||||
|
||||
void ResourceManager::Resource::setModified() {
|
||||
|
@ -1030,9 +1030,9 @@ 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]._resources.size();
|
||||
ResId idx = _types[type].size();
|
||||
while (idx-- > 0) {
|
||||
Resource &tmp = _types[type]._resources[idx];
|
||||
Resource &tmp = _types[type][idx];
|
||||
byte counter = tmp.getResourceCounter();
|
||||
if (!tmp.isLocked() && counter >= best_counter && tmp._address && !_vm->isResourceInUse(type, idx)) {
|
||||
best_counter = counter;
|
||||
|
@ -1055,12 +1055,12 @@ void ResourceManager::expireResources(uint32 size) {
|
|||
|
||||
void ResourceManager::freeResources() {
|
||||
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
|
||||
ResId idx = _types[type]._resources.size();
|
||||
ResId idx = _types[type].size();
|
||||
while (idx-- > 0) {
|
||||
if (isResourceLoaded(type, idx))
|
||||
nukeResource(type, idx);
|
||||
}
|
||||
_types[type]._resources.clear();
|
||||
_types[type].clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1090,16 +1090,16 @@ void ScummEngine::loadPtrToResource(ResType type, ResId idx, const byte *source)
|
|||
bool ResourceManager::isResourceLoaded(ResType type, ResId idx) const {
|
||||
if (!validateResource("isResourceLoaded", type, idx))
|
||||
return false;
|
||||
return _types[type]._resources[idx]._address != NULL;
|
||||
return _types[type][idx]._address != NULL;
|
||||
}
|
||||
|
||||
void ResourceManager::resourceStats() {
|
||||
uint32 lockedSize = 0, lockedNum = 0;
|
||||
|
||||
for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1)) {
|
||||
ResId idx = _types[type]._resources.size();
|
||||
ResId idx = _types[type].size();
|
||||
while (idx-- > 0) {
|
||||
Resource &tmp = _types[type]._resources[idx];
|
||||
Resource &tmp = _types[type][idx];
|
||||
if (tmp.isLocked() && tmp._address) {
|
||||
lockedSize += tmp._size;
|
||||
lockedNum++;
|
||||
|
|
|
@ -145,7 +145,7 @@ public:
|
|||
/**
|
||||
* This struct represents a resource type and all resource of that type.
|
||||
*/
|
||||
class ResTypeData {
|
||||
class ResTypeData : public Common::Array<Resource> {
|
||||
friend class ResourceManager;
|
||||
public:
|
||||
/**
|
||||
|
@ -160,11 +160,6 @@ public:
|
|||
*/
|
||||
uint32 _tag;
|
||||
|
||||
/**
|
||||
* Array containing the resources of this type.
|
||||
*/
|
||||
Common::Array<Resource> _resources;
|
||||
|
||||
public:
|
||||
ResTypeData();
|
||||
~ResTypeData();
|
||||
|
@ -188,8 +183,8 @@ public:
|
|||
byte *createResource(ResType type, ResId idx, uint32 size);
|
||||
void nukeResource(ResType type, ResId 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]; }
|
||||
// inline Resource &getRes(ResType type, ResId idx) { return _types[type][idx]; }
|
||||
// inline const Resource &getRes(ResType type, ResId idx) const { return _types[type][idx]; }
|
||||
|
||||
bool isResourceLoaded(ResType type, ResId idx) const;
|
||||
|
||||
|
|
|
@ -84,40 +84,40 @@ void ScummEngine_v2::readClassicIndexFile() {
|
|||
}
|
||||
|
||||
for (i = 0; i < _numRooms; i++) {
|
||||
_res->_types[rtRoom]._resources[i]._roomno = i;
|
||||
_res->_types[rtRoom][i]._roomno = i;
|
||||
}
|
||||
_fileHandle->seek(_numRooms, SEEK_CUR);
|
||||
for (i = 0; i < _numRooms; i++) {
|
||||
_res->_types[rtRoom]._resources[i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtRoom]._resources[i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtRoom]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
_res->_types[rtRoom][i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtRoom][i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtRoom][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
}
|
||||
|
||||
for (i = 0; i < _numCostumes; i++) {
|
||||
_res->_types[rtCostume]._resources[i]._roomno = _fileHandle->readByte();
|
||||
_res->_types[rtCostume][i]._roomno = _fileHandle->readByte();
|
||||
}
|
||||
for (i = 0; i < _numCostumes; i++) {
|
||||
_res->_types[rtCostume]._resources[i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtCostume]._resources[i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtCostume]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
_res->_types[rtCostume][i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtCostume][i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtCostume][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
}
|
||||
|
||||
for (i = 0; i < _numScripts; i++) {
|
||||
_res->_types[rtScript]._resources[i]._roomno = _fileHandle->readByte();
|
||||
_res->_types[rtScript][i]._roomno = _fileHandle->readByte();
|
||||
}
|
||||
for (i = 0; i < _numScripts; i++) {
|
||||
_res->_types[rtScript]._resources[i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtScript]._resources[i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtScript]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
_res->_types[rtScript][i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtScript][i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtScript][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
}
|
||||
|
||||
for (i = 0; i < _numSounds; i++) {
|
||||
_res->_types[rtSound]._resources[i]._roomno = _fileHandle->readByte();
|
||||
_res->_types[rtSound][i]._roomno = _fileHandle->readByte();
|
||||
}
|
||||
for (i = 0; i < _numSounds; i++) {
|
||||
_res->_types[rtSound]._resources[i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtSound]._resources[i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtSound]._resources[i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
_res->_types[rtSound][i]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[rtSound][i]._roomoffs == 0xFFFF)
|
||||
_res->_types[rtSound][i]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,16 +44,16 @@ int ScummEngine_v3old::readResTypeList(ResType type) {
|
|||
|
||||
if (type == rtRoom) {
|
||||
for (idx = 0; idx < num; idx++)
|
||||
_res->_types[type]._resources[idx]._roomno = idx;
|
||||
_res->_types[type][idx]._roomno = idx;
|
||||
_fileHandle->seek(num, SEEK_CUR);
|
||||
} else {
|
||||
for (idx = 0; idx < num; idx++)
|
||||
_res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
|
||||
_res->_types[type][idx]._roomno = _fileHandle->readByte();
|
||||
}
|
||||
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;
|
||||
_res->_types[type][idx]._roomoffs = _fileHandle->readUint16LE();
|
||||
if (_res->_types[type][idx]._roomoffs == 0xFFFF)
|
||||
_res->_types[type][idx]._roomoffs = (uint32)RES_INVALID_OFFSET;
|
||||
}
|
||||
|
||||
return num;
|
||||
|
|
|
@ -37,13 +37,13 @@ int ScummEngine_v4::readResTypeList(ResType type) {
|
|||
|
||||
num = _fileHandle->readUint16LE();
|
||||
|
||||
if (num != _res->_types[type]._resources.size()) {
|
||||
if (num != _res->_types[type].size()) {
|
||||
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
|
||||
}
|
||||
|
||||
for (ResId idx = 0; idx < num; idx++) {
|
||||
_res->_types[type]._resources[idx]._roomno = _fileHandle->readByte();
|
||||
_res->_types[type]._resources[idx]._roomoffs = _fileHandle->readUint32LE();
|
||||
_res->_types[type][idx]._roomno = _fileHandle->readByte();
|
||||
_res->_types[type][idx]._roomoffs = _fileHandle->readUint32LE();
|
||||
}
|
||||
|
||||
return num;
|
||||
|
|
|
@ -525,14 +525,14 @@ void ScummEngine::resetRoomSubBlocks() {
|
|||
//
|
||||
// Load scale data
|
||||
//
|
||||
for (i = 1; i < _res->_types[rtScaleTable]._resources.size(); i++)
|
||||
for (i = 1; i < _res->_types[rtScaleTable].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]._resources.size(); i++, ptr += 16) {
|
||||
for (i = 1; i < _res->_types[rtScaleTable].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]._resources.size(); i++, ptr += 8) {
|
||||
for (i = 1; i < _res->_types[rtScaleTable].size(); i++, ptr += 8) {
|
||||
s1 = READ_LE_UINT16(ptr);
|
||||
y1 = READ_LE_UINT16(ptr + 2);
|
||||
s2 = READ_LE_UINT16(ptr + 4);
|
||||
|
@ -793,7 +793,7 @@ void ScummEngine_v3old::resetRoomSubBlocks() {
|
|||
//
|
||||
// No scale data in old bundle games
|
||||
//
|
||||
for (ResId id = 1; id < _res->_types[rtScaleTable]._resources.size(); id++)
|
||||
for (ResId id = 1; id < _res->_types[rtScaleTable].size(); id++)
|
||||
_res->nukeResource(rtScaleTable, id);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -390,26 +390,26 @@ void ScummEngine::getScriptBaseAddress() {
|
|||
break;
|
||||
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
|
||||
assert(idx < _numInventory);
|
||||
_lastCodePtr = &_res->_types[rtInventory]._resources[idx]._address;
|
||||
_lastCodePtr = &_res->_types[rtInventory][idx]._address;
|
||||
break;
|
||||
|
||||
case WIO_LOCAL:
|
||||
case WIO_ROOM: /* room script */
|
||||
if (_game.version == 8) {
|
||||
_scriptOrgPointer = getResourceAddress(rtRoomScripts, _roomResource);
|
||||
assert(_roomResource < (int)_res->_types[rtRoomScripts]._resources.size());
|
||||
_lastCodePtr = &_res->_types[rtRoomScripts]._resources[_roomResource]._address;
|
||||
assert(_roomResource < (int)_res->_types[rtRoomScripts].size());
|
||||
_lastCodePtr = &_res->_types[rtRoomScripts][_roomResource]._address;
|
||||
} else {
|
||||
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
|
||||
assert(_roomResource < _numRooms);
|
||||
_lastCodePtr = &_res->_types[rtRoom]._resources[_roomResource]._address;
|
||||
_lastCodePtr = &_res->_types[rtRoom][_roomResource]._address;
|
||||
}
|
||||
break;
|
||||
|
||||
case WIO_GLOBAL: /* global script */
|
||||
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
|
||||
assert(ss->number < _numScripts);
|
||||
_lastCodePtr = &_res->_types[rtScript]._resources[ss->number]._address;
|
||||
_lastCodePtr = &_res->_types[rtScript][ss->number]._address;
|
||||
break;
|
||||
|
||||
case WIO_FLOBJECT: /* flobject script */
|
||||
|
@ -418,7 +418,7 @@ void ScummEngine::getScriptBaseAddress() {
|
|||
idx = _objs[idx].fl_object_index;
|
||||
_scriptOrgPointer = getResourceAddress(rtFlObject, idx);
|
||||
assert(idx < _numFlObject);
|
||||
_lastCodePtr = &_res->_types[rtFlObject]._resources[idx]._address;
|
||||
_lastCodePtr = &_res->_types[rtFlObject][idx]._address;
|
||||
break;
|
||||
default:
|
||||
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
|
||||
// the pair 29/104 is used, else the pair 28/103.
|
||||
|
||||
if (_res->_types[rtScript]._resources.size() > 460) {
|
||||
if (_res->_types[rtScript].size() > 460) {
|
||||
if (sentenceScript == 104)
|
||||
sentenceScript = 29;
|
||||
} else {
|
||||
|
|
|
@ -361,7 +361,7 @@ int ScummEngine_v6::findFreeArrayId() {
|
|||
int i;
|
||||
|
||||
for (i = 1; i < _numArray; i++) {
|
||||
if (!rtd._resources[i]._address)
|
||||
if (!rtd[i]._address)
|
||||
return i;
|
||||
}
|
||||
error("Out of array pointers, %d max", _numArray);
|
||||
|
|
|
@ -1224,7 +1224,7 @@ int ScummEngine::readSoundResource(ResId idx) {
|
|||
|
||||
if (!dmuFile.open(buffer)) {
|
||||
error("Can't open music file %s", buffer);
|
||||
_res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
return 0;
|
||||
}
|
||||
dmuFile.seek(4, SEEK_SET);
|
||||
|
@ -1248,7 +1248,7 @@ int ScummEngine::readSoundResource(ResId idx) {
|
|||
}
|
||||
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
|
||||
}
|
||||
_res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2123,7 +2123,7 @@ int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
|
|||
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
|
||||
return 1;
|
||||
}
|
||||
_res->_types[rtSound]._resources[idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue