Started to move some resource related code into a new class ResourceManager (hypothetic goal for the future: use ResourceManager in ScummEx)
svn-id: r17311
This commit is contained in:
parent
59331fe535
commit
ac247c9b94
20 changed files with 211 additions and 193 deletions
|
@ -739,7 +739,7 @@ byte AkosRenderer::codec1(int xmoveCur, int ymoveCur) {
|
||||||
|
|
||||||
/* implement custom scale table */
|
/* implement custom scale table */
|
||||||
v1.scaletable = (_vm->_features & GF_HUMONGOUS) ? oldScaleTable : defaultScaleTable;
|
v1.scaletable = (_vm->_features & GF_HUMONGOUS) ? oldScaleTable : defaultScaleTable;
|
||||||
if (_vm->VAR_CUSTOMSCALETABLE != 0xFF && _vm->isResourceLoaded(rtString, _vm->VAR(_vm->VAR_CUSTOMSCALETABLE))) {
|
if (_vm->VAR_CUSTOMSCALETABLE != 0xFF && _vm->res.isResourceLoaded(rtString, _vm->VAR(_vm->VAR_CUSTOMSCALETABLE))) {
|
||||||
v1.scaletable = _vm->getStringAddressVar(_vm->VAR_CUSTOMSCALETABLE);
|
v1.scaletable = _vm->getStringAddressVar(_vm->VAR_CUSTOMSCALETABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,8 +254,8 @@ void ScummEngine::initScreens(int b, int h) {
|
||||||
int adj = 0;
|
int adj = 0;
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
nukeResource(rtBuffer, i + 1);
|
res.nukeResource(rtBuffer, i + 1);
|
||||||
nukeResource(rtBuffer, i + 5);
|
res.nukeResource(rtBuffer, i + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getResourceAddress(rtBuffer, 4)) {
|
if (!getResourceAddress(rtBuffer, 4)) {
|
||||||
|
|
|
@ -342,7 +342,7 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
|
||||||
assert(soundName[0] == 0); // Paranoia check
|
assert(soundName[0] == 0); // Paranoia check
|
||||||
|
|
||||||
_vm->ensureResourceLoaded(rtSound, soundId);
|
_vm->ensureResourceLoaded(rtSound, soundId);
|
||||||
_vm->lock(rtSound, soundId);
|
_vm->res.lock(rtSound, soundId);
|
||||||
ptr = _vm->getResourceAddress(rtSound, soundId);
|
ptr = _vm->getResourceAddress(rtSound, soundId);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
closeSound(sound);
|
closeSound(sound);
|
||||||
|
@ -413,7 +413,7 @@ void ImuseDigiSndMgr::closeSound(soundStruct *soundHandle) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
_vm->unlock(rtSound, soundHandle->soundId);
|
_vm->res.unlock(rtSound, soundHandle->soundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soundHandle->compressedStream)
|
if (soundHandle->compressedStream)
|
||||||
|
|
|
@ -1119,7 +1119,7 @@ int Insane::smlayer_loadSound(int id, int flag, int phase) {
|
||||||
if (phase == 2)
|
if (phase == 2)
|
||||||
_vm->ensureResourceLoaded(rtSound, resid);
|
_vm->ensureResourceLoaded(rtSound, resid);
|
||||||
|
|
||||||
_vm->setResourceCounter(rtSound, resid, 1);
|
_vm->res.setResourceCounter(rtSound, resid, 1);
|
||||||
|
|
||||||
if (phase == 1) {
|
if (phase == 1) {
|
||||||
_objArray2Idx2++;
|
_objArray2Idx2++;
|
||||||
|
@ -1141,7 +1141,7 @@ int Insane::smlayer_loadCostume(int id, int phase) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_vm->ensureResourceLoaded(rtCostume, resid);
|
_vm->ensureResourceLoaded(rtCostume, resid);
|
||||||
_vm->setResourceCounter(rtCostume, resid, 1);
|
_vm->res.setResourceCounter(rtCostume, resid, 1);
|
||||||
|
|
||||||
// smlayer_lock(rtCostume, resid); // FIXME
|
// smlayer_lock(rtCostume, resid); // FIXME
|
||||||
|
|
||||||
|
|
|
@ -521,7 +521,7 @@ void ScummEngine::clearRoomObjects() {
|
||||||
} else {
|
} else {
|
||||||
// Nuke all unlocked flObjects
|
// Nuke all unlocked flObjects
|
||||||
if (!(res.flags[rtFlObject][_objs[i].fl_object_index] & RF_LOCK)) {
|
if (!(res.flags[rtFlObject][_objs[i].fl_object_index] & RF_LOCK)) {
|
||||||
nukeResource(rtFlObject, _objs[i].fl_object_index);
|
res.nukeResource(rtFlObject, _objs[i].fl_object_index);
|
||||||
_objs[i].obj_nr = 0;
|
_objs[i].obj_nr = 0;
|
||||||
_objs[i].fl_object_index = 0;
|
_objs[i].fl_object_index = 0;
|
||||||
}
|
}
|
||||||
|
@ -896,7 +896,7 @@ void ScummEngine::clearOwnerOf(int obj) {
|
||||||
if (_objs[i].obj_nr == obj) {
|
if (_objs[i].obj_nr == obj) {
|
||||||
if (!_objs[i].fl_object_index)
|
if (!_objs[i].fl_object_index)
|
||||||
return;
|
return;
|
||||||
nukeResource(rtFlObject, _objs[i].fl_object_index);
|
res.nukeResource(rtFlObject, _objs[i].fl_object_index);
|
||||||
_objs[i].obj_nr = 0;
|
_objs[i].obj_nr = 0;
|
||||||
_objs[i].fl_object_index = 0;
|
_objs[i].fl_object_index = 0;
|
||||||
}
|
}
|
||||||
|
@ -908,7 +908,7 @@ void ScummEngine::clearOwnerOf(int obj) {
|
||||||
if (_inventory[i] == obj) {
|
if (_inventory[i] == obj) {
|
||||||
j = whereIsObject(obj);
|
j = whereIsObject(obj);
|
||||||
if (j == WIO_INVENTORY) {
|
if (j == WIO_INVENTORY) {
|
||||||
nukeResource(rtInventory, i);
|
res.nukeResource(rtInventory, i);
|
||||||
_inventory[i] = 0;
|
_inventory[i] = 0;
|
||||||
}
|
}
|
||||||
a = _inventory;
|
a = _inventory;
|
||||||
|
@ -990,7 +990,7 @@ void ScummEngine::setObjectName(int obj) {
|
||||||
|
|
||||||
for (i = 0; i < _numNewNames; i++) {
|
for (i = 0; i < _numNewNames; i++) {
|
||||||
if (_newNames[i] == obj) {
|
if (_newNames[i] == obj) {
|
||||||
nukeResource(rtObjectName, i);
|
res.nukeResource(rtObjectName, i);
|
||||||
_newNames[i] = 0;
|
_newNames[i] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1420,7 +1420,7 @@ void ScummEngine::nukeFlObjects(int min, int max) {
|
||||||
|
|
||||||
for (i = (_numLocalObjects-1), od = _objs; --i >= 0; od++)
|
for (i = (_numLocalObjects-1), od = _objs; --i >= 0; od++)
|
||||||
if (od->fl_object_index && od->obj_nr >= min && od->obj_nr <= max) {
|
if (od->fl_object_index && od->obj_nr >= min && od->obj_nr <= max) {
|
||||||
nukeResource(rtFlObject, od->fl_object_index);
|
res.nukeResource(rtFlObject, od->fl_object_index);
|
||||||
od->obj_nr = 0;
|
od->obj_nr = 0;
|
||||||
od->fl_object_index = 0;
|
od->fl_object_index = 0;
|
||||||
}
|
}
|
||||||
|
@ -1638,9 +1638,9 @@ void ScummEngine::loadFlObject(uint object, uint room) {
|
||||||
isRoomLocked = ((res.flags[rtRoom][room] & RF_LOCK) != 0);
|
isRoomLocked = ((res.flags[rtRoom][room] & RF_LOCK) != 0);
|
||||||
isRoomScriptsLocked = ((res.flags[rtRoomScripts][room] & RF_LOCK) != 0);
|
isRoomScriptsLocked = ((res.flags[rtRoomScripts][room] & RF_LOCK) != 0);
|
||||||
if (!isRoomLocked)
|
if (!isRoomLocked)
|
||||||
lock(rtRoom, room);
|
res.lock(rtRoom, room);
|
||||||
if (_version == 8 && !isRoomScriptsLocked)
|
if (_version == 8 && !isRoomScriptsLocked)
|
||||||
lock(rtRoomScripts, room);
|
res.lock(rtRoomScripts, room);
|
||||||
|
|
||||||
// Allocate slot & memory for floating object
|
// Allocate slot & memory for floating object
|
||||||
slot = findFlObjectSlot();
|
slot = findFlObjectSlot();
|
||||||
|
@ -1656,9 +1656,9 @@ void ScummEngine::loadFlObject(uint object, uint room) {
|
||||||
|
|
||||||
// Unlock room/roomScripts
|
// Unlock room/roomScripts
|
||||||
if (!isRoomLocked)
|
if (!isRoomLocked)
|
||||||
unlock(rtRoom, room);
|
res.unlock(rtRoom, room);
|
||||||
if (_version == 8 && !isRoomScriptsLocked)
|
if (_version == 8 && !isRoomScriptsLocked)
|
||||||
unlock(rtRoomScripts, room);
|
res.unlock(rtRoomScripts, room);
|
||||||
|
|
||||||
// Setup local object flags
|
// Setup local object flags
|
||||||
setupRoomObject(od, flob, flob);
|
setupRoomObject(od, flob, flob);
|
||||||
|
|
|
@ -631,7 +631,7 @@ void ScummEngine::loadCharset(int no) {
|
||||||
|
|
||||||
void ScummEngine::nukeCharset(int i) {
|
void ScummEngine::nukeCharset(int i) {
|
||||||
checkRange(_numCharsets - 1, 1, i, "Nuking illegal charset %d");
|
checkRange(_numCharsets - 1, 1, i, "Nuking illegal charset %d");
|
||||||
nukeResource(rtCharset, i);
|
res.nukeResource(rtCharset, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::ensureResourceLoaded(int type, int i) {
|
void ScummEngine::ensureResourceLoaded(int type, int i) {
|
||||||
|
@ -749,7 +749,7 @@ int ScummEngine::loadResource(int type, int idx) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nukeResource(type, idx);
|
res.nukeResource(type, idx);
|
||||||
|
|
||||||
error("Cannot read resource");
|
error("Cannot read resource");
|
||||||
}
|
}
|
||||||
|
@ -771,7 +771,7 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
|
||||||
byte *ptr;
|
byte *ptr;
|
||||||
|
|
||||||
CHECK_HEAP
|
CHECK_HEAP
|
||||||
if (!validateResource("getResourceAddress", type, idx))
|
if (!res.validateResource("getResourceAddress", type, idx))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!res.address[type]) {
|
if (!res.address[type]) {
|
||||||
|
@ -788,7 +788,7 @@ byte *ScummEngine::getResourceAddress(int type, int idx) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
setResourceCounter(type, idx, 1);
|
res.setResourceCounter(type, idx, 1);
|
||||||
|
|
||||||
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
|
debugC(DEBUG_RESOURCE, "getResourceAddress(%s,%d) == %p", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
|
||||||
return ptr + sizeof(MemBlkHeader);
|
return ptr + sizeof(MemBlkHeader);
|
||||||
|
@ -811,9 +811,23 @@ byte *ScummEngine::getStringAddressVar(int i) {
|
||||||
return getStringAddress(_scummVars[i]);
|
return getStringAddress(_scummVars[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::setResourceCounter(int type, int idx, byte flag) {
|
void ResourceManager::increaseResourceCounter() {
|
||||||
res.flags[type][idx] &= ~RF_USAGE;
|
int i, j;
|
||||||
res.flags[type][idx] |= flag;
|
byte counter;
|
||||||
|
|
||||||
|
for (i = rtFirst; i <= rtLast; i++) {
|
||||||
|
for (j = num[i]; --j >= 0;) {
|
||||||
|
counter = flags[i][j] & RF_USAGE;
|
||||||
|
if (counter && counter < RF_USAGE_MAX) {
|
||||||
|
setResourceCounter(i, j, counter + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
|
||||||
|
flags[type][idx] &= ~RF_USAGE;
|
||||||
|
flags[type][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 */
|
||||||
|
@ -825,9 +839,9 @@ byte *ScummEngine::createResource(int type, int idx, uint32 size) {
|
||||||
CHECK_HEAP
|
CHECK_HEAP
|
||||||
debugC(DEBUG_RESOURCE, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
|
debugC(DEBUG_RESOURCE, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
|
||||||
|
|
||||||
if (!validateResource("allocating", type, idx))
|
if (!res.validateResource("allocating", type, idx))
|
||||||
return NULL;
|
return NULL;
|
||||||
nukeResource(type, idx);
|
res.nukeResource(type, idx);
|
||||||
|
|
||||||
expireResources(size);
|
expireResources(size);
|
||||||
|
|
||||||
|
@ -837,35 +851,41 @@ byte *ScummEngine::createResource(int type, int idx, uint32 size) {
|
||||||
error("Out of memory while allocating %d", size);
|
error("Out of memory while allocating %d", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
_allocatedSize += size;
|
res._allocatedSize += size;
|
||||||
|
|
||||||
res.address[type][idx] = ptr;
|
res.address[type][idx] = ptr;
|
||||||
((MemBlkHeader *)ptr)->size = size;
|
((MemBlkHeader *)ptr)->size = size;
|
||||||
setResourceCounter(type, idx, 1);
|
res.setResourceCounter(type, idx, 1);
|
||||||
return ptr + sizeof(MemBlkHeader); /* skip header */
|
return ptr + sizeof(MemBlkHeader); /* skip header */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummEngine::validateResource(const char *str, int type, int idx) const {
|
ResourceManager::ResourceManager(ScummEngine *vm) {
|
||||||
if (type < rtFirst || type > rtLast || (uint) idx >= (uint) res.num[type]) {
|
memset(this, 0, sizeof(ResourceManager));
|
||||||
|
_vm = vm;
|
||||||
|
// _allocatedSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ResourceManager::validateResource(const char *str, int type, int idx) const {
|
||||||
|
if (type < rtFirst || type > rtLast || (uint) idx >= (uint)num[type]) {
|
||||||
warning("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
|
warning("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::nukeResource(int type, int idx) {
|
void ResourceManager::nukeResource(int type, int idx) {
|
||||||
byte *ptr;
|
byte *ptr;
|
||||||
|
|
||||||
CHECK_HEAP
|
CHECK_HEAP
|
||||||
if (!res.address[type])
|
if (!address[type])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(idx >= 0 && idx < res.num[type]);
|
assert(idx >= 0 && idx < num[type]);
|
||||||
|
|
||||||
if ((ptr = res.address[type][idx]) != NULL) {
|
if ((ptr = address[type][idx]) != NULL) {
|
||||||
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
|
debugC(DEBUG_RESOURCE, "nukeResource(%s,%d)", resTypeFromId(type), idx);
|
||||||
res.address[type][idx] = 0;
|
address[type][idx] = 0;
|
||||||
res.flags[type][idx] = 0;
|
flags[type][idx] = 0;
|
||||||
_allocatedSize -= ((MemBlkHeader *)ptr)->size;
|
_allocatedSize -= ((MemBlkHeader *)ptr)->size;
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
@ -896,20 +916,20 @@ int ScummEngine::getResourceDataSize(const byte *ptr) const {
|
||||||
return READ_BE_UINT32(ptr - 4) - 8;
|
return READ_BE_UINT32(ptr - 4) - 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::lock(int type, int i) {
|
void ResourceManager::lock(int type, int i) {
|
||||||
if (!validateResource("Locking", type, i))
|
if (!validateResource("Locking", type, i))
|
||||||
return;
|
return;
|
||||||
res.flags[type][i] |= RF_LOCK;
|
flags[type][i] |= RF_LOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::unlock(int type, int i) {
|
void ResourceManager::unlock(int type, int i) {
|
||||||
if (!validateResource("Unlocking", type, i))
|
if (!validateResource("Unlocking", type, i))
|
||||||
return;
|
return;
|
||||||
res.flags[type][i] &= ~RF_LOCK;
|
flags[type][i] &= ~RF_LOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummEngine::isResourceInUse(int type, int i) const {
|
bool ScummEngine::isResourceInUse(int type, int i) const {
|
||||||
if (!validateResource("isResourceInUse", type, i))
|
if (!res.validateResource("isResourceInUse", type, i))
|
||||||
return false;
|
return false;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case rtRoom:
|
case rtRoom:
|
||||||
|
@ -927,20 +947,6 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::increaseResourceCounter() {
|
|
||||||
int i, j;
|
|
||||||
byte counter;
|
|
||||||
|
|
||||||
for (i = rtFirst; i <= rtLast; i++) {
|
|
||||||
for (j = res.num[i]; --j >= 0;) {
|
|
||||||
counter = res.flags[i][j] & RF_USAGE;
|
|
||||||
if (counter && counter < RF_USAGE_MAX) {
|
|
||||||
setResourceCounter(i, j, counter + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScummEngine::expireResources(uint32 size) {
|
void ScummEngine::expireResources(uint32 size) {
|
||||||
int i, j;
|
int i, j;
|
||||||
byte flag;
|
byte flag;
|
||||||
|
@ -948,15 +954,15 @@ void ScummEngine::expireResources(uint32 size) {
|
||||||
int best_type, best_res = 0;
|
int best_type, best_res = 0;
|
||||||
uint32 oldAllocatedSize;
|
uint32 oldAllocatedSize;
|
||||||
|
|
||||||
if (_expire_counter != 0xFF) {
|
if (res._expireCounter != 0xFF) {
|
||||||
_expire_counter = 0xFF;
|
res._expireCounter = 0xFF;
|
||||||
increaseResourceCounter();
|
res.increaseResourceCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size + _allocatedSize < _maxHeapThreshold)
|
if (size + res._allocatedSize < res._maxHeapThreshold)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
oldAllocatedSize = _allocatedSize;
|
oldAllocatedSize = res._allocatedSize;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
best_type = 0;
|
best_type = 0;
|
||||||
|
@ -976,32 +982,27 @@ void ScummEngine::expireResources(uint32 size) {
|
||||||
|
|
||||||
if (!best_type)
|
if (!best_type)
|
||||||
break;
|
break;
|
||||||
nukeResource(best_type, best_res);
|
res.nukeResource(best_type, best_res);
|
||||||
} while (size + _allocatedSize > _minHeapThreshold);
|
} while (size + res._allocatedSize > res._minHeapThreshold);
|
||||||
|
|
||||||
increaseResourceCounter();
|
res.increaseResourceCounter();
|
||||||
|
|
||||||
debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
|
debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, res._allocatedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::freeResources() {
|
void ResourceManager::freeResources() {
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = rtFirst; i <= rtLast; i++) {
|
for (i = rtFirst; i <= rtLast; i++) {
|
||||||
for (j = res.num[i]; --j >= 0;) {
|
for (j = num[i]; --j >= 0;) {
|
||||||
if (isResourceLoaded(i, j))
|
if (isResourceLoaded(i, j))
|
||||||
nukeResource(i, j);
|
nukeResource(i, j);
|
||||||
}
|
}
|
||||||
free(res.address[i]);
|
free(address[i]);
|
||||||
free(res.flags[i]);
|
free(flags[i]);
|
||||||
free(res.roomno[i]);
|
free(roomno[i]);
|
||||||
free(res.roomoffs[i]);
|
free(roomoffs[i]);
|
||||||
|
|
||||||
if (_heversion >= 70)
|
free(globsize[i]);
|
||||||
free(res.globsize[i]);
|
|
||||||
}
|
|
||||||
if (_heversion >= 70) {
|
|
||||||
free(_heV7RoomIntOffsets);
|
|
||||||
free(_heV7RoomOffsets);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,7 +1010,7 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
|
||||||
byte *alloced;
|
byte *alloced;
|
||||||
int i, len;
|
int i, len;
|
||||||
|
|
||||||
nukeResource(type, resindex);
|
res.nukeResource(type, resindex);
|
||||||
|
|
||||||
len = resStrLen(source) + 1;
|
len = resStrLen(source) + 1;
|
||||||
|
|
||||||
|
@ -1028,10 +1029,10 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScummEngine::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 res.address[type][idx] != NULL;
|
return address[type][idx] != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::resourceStats() {
|
void ScummEngine::resourceStats() {
|
||||||
|
@ -1048,7 +1049,7 @@ void ScummEngine::resourceStats() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(1, "Total allocated size=%d, locked=%d(%d)", _allocatedSize, lockedSize, lockedNum);
|
debug(1, "Total allocated size=%d, locked=%d(%d)", res._allocatedSize, lockedSize, lockedNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine::readMAXS(int blockSize) {
|
void ScummEngine::readMAXS(int blockSize) {
|
||||||
|
|
|
@ -167,7 +167,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
|
||||||
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.num[i]; j++) {
|
||||||
nukeResource(i, j);
|
res.nukeResource(i, j);
|
||||||
res.flags[i][j] = 0;
|
res.flags[i][j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,7 +364,7 @@ void ScummEngine::nukeArrays(byte script) {
|
||||||
|
|
||||||
for (i = 1; i < _numArray; i++) {
|
for (i = 1; i < _numArray; i++) {
|
||||||
if (_arraySlot[i] == script) {
|
if (_arraySlot[i] == script) {
|
||||||
nukeResource(rtString, i);
|
res.nukeResource(rtString, i);
|
||||||
_arraySlot[i] = 0;
|
_arraySlot[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -897,7 +897,7 @@ void ScummEngine::killScriptsAndResources() {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_newNames[i] = 0;
|
_newNames[i] = 0;
|
||||||
nukeResource(rtObjectName, i);
|
res.nukeResource(rtObjectName, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1128,16 +1128,16 @@ void ScummEngine_v100he::o100_resourceRoutines() {
|
||||||
if (_heResType == rtFlObject) {
|
if (_heResType == rtFlObject) {
|
||||||
objidx = getObjectIndex(_heResId);
|
objidx = getObjectIndex(_heResId);
|
||||||
//assert(objidx != -1);
|
//assert(objidx != -1);
|
||||||
//lock(_heResType, objidx);
|
//res.lock(_heResType, objidx);
|
||||||
} else {
|
} else {
|
||||||
lock(_heResType, _heResId);
|
res.lock(_heResType, _heResId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 133:
|
case 133:
|
||||||
if (_heResType == rtCharset)
|
if (_heResType == rtCharset)
|
||||||
nukeCharset(_heResId);
|
nukeCharset(_heResId);
|
||||||
else
|
else
|
||||||
nukeResource(_heResType, _heResId);
|
res.nukeResource(_heResType, _heResId);
|
||||||
break;
|
break;
|
||||||
case 134:
|
case 134:
|
||||||
case 135:
|
case 135:
|
||||||
|
@ -1153,9 +1153,9 @@ void ScummEngine_v100he::o100_resourceRoutines() {
|
||||||
if (_heResType == rtFlObject) {
|
if (_heResType == rtFlObject) {
|
||||||
objidx = getObjectIndex(_heResId);
|
objidx = getObjectIndex(_heResId);
|
||||||
//assert(objidx != -1);
|
//assert(objidx != -1);
|
||||||
//unlock(_heResType, objidx);
|
//res.unlock(_heResType, objidx);
|
||||||
} else {
|
} else {
|
||||||
unlock(_heResType, _heResId);
|
res.unlock(_heResType, _heResId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -782,9 +782,9 @@ void ScummEngine_v2::o2_resourceRoutines() {
|
||||||
ensureResourceLoaded(type, resid);
|
ensureResourceLoaded(type, resid);
|
||||||
} else {
|
} else {
|
||||||
if (opcode & 1)
|
if (opcode & 1)
|
||||||
lock(type, resid);
|
res.lock(type, resid);
|
||||||
else
|
else
|
||||||
unlock(type, resid);
|
res.unlock(type, resid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1732,40 +1732,40 @@ void ScummEngine_v5::o5_resourceRoutines() {
|
||||||
if (_gameId == GID_ZAK256)
|
if (_gameId == GID_ZAK256)
|
||||||
warning("o5_resourceRoutines %d should not occur in Zak256", op);
|
warning("o5_resourceRoutines %d should not occur in Zak256", op);
|
||||||
else
|
else
|
||||||
setResourceCounter(resType[op-5], resid, 0x7F);
|
res.setResourceCounter(resType[op-5], resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 9: // SO_LOCK_SCRIPT
|
case 9: // SO_LOCK_SCRIPT
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
lock(rtScript, resid);
|
res.lock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 10: // SO_LOCK_SOUND
|
case 10: // SO_LOCK_SOUND
|
||||||
lock(rtSound, resid);
|
res.lock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 11: // SO_LOCK_COSTUME
|
case 11: // SO_LOCK_COSTUME
|
||||||
lock(rtCostume, resid);
|
res.lock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 12: // SO_LOCK_ROOM
|
case 12: // SO_LOCK_ROOM
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
lock(rtRoom, resid);
|
res.lock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 13: // SO_UNLOCK_SCRIPT
|
case 13: // SO_UNLOCK_SCRIPT
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
unlock(rtScript, resid);
|
res.unlock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 14: // SO_UNLOCK_SOUND
|
case 14: // SO_UNLOCK_SOUND
|
||||||
unlock(rtSound, resid);
|
res.unlock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 15: // SO_UNLOCK_COSTUME
|
case 15: // SO_UNLOCK_COSTUME
|
||||||
unlock(rtCostume, resid);
|
res.unlock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 16: // SO_UNLOCK_ROOM
|
case 16: // SO_UNLOCK_ROOM
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
unlock(rtRoom, resid);
|
res.unlock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 17: // SO_CLEAR_HEAP
|
case 17: // SO_CLEAR_HEAP
|
||||||
|
@ -2256,7 +2256,7 @@ void ScummEngine_v5::o5_stringOps() {
|
||||||
case 2: /* copystring */
|
case 2: /* copystring */
|
||||||
a = getVarOrDirectByte(PARAM_1);
|
a = getVarOrDirectByte(PARAM_1);
|
||||||
b = getVarOrDirectByte(PARAM_2);
|
b = getVarOrDirectByte(PARAM_2);
|
||||||
nukeResource(rtString, a);
|
res.nukeResource(rtString, a);
|
||||||
ptr = getResourceAddress(rtString, b);
|
ptr = getResourceAddress(rtString, b);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
loadPtrToResource(rtString, a, ptr);
|
loadPtrToResource(rtString, a, ptr);
|
||||||
|
@ -2287,7 +2287,7 @@ void ScummEngine_v5::o5_stringOps() {
|
||||||
case 5: /* create empty string */
|
case 5: /* create empty string */
|
||||||
a = getVarOrDirectByte(PARAM_1);
|
a = getVarOrDirectByte(PARAM_1);
|
||||||
b = getVarOrDirectByte(PARAM_2);
|
b = getVarOrDirectByte(PARAM_2);
|
||||||
nukeResource(rtString, a);
|
res.nukeResource(rtString, a);
|
||||||
if (b) {
|
if (b) {
|
||||||
ptr = createResource(rtString, a, b);
|
ptr = createResource(rtString, a, b);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
|
@ -2332,7 +2332,7 @@ void ScummEngine_v5::o5_verbOps() {
|
||||||
case 2: // SO_VERB_NAME
|
case 2: // SO_VERB_NAME
|
||||||
loadPtrToResource(rtVerb, slot, NULL);
|
loadPtrToResource(rtVerb, slot, NULL);
|
||||||
if (slot == 0)
|
if (slot == 0)
|
||||||
nukeResource(rtVerb, slot);
|
res.nukeResource(rtVerb, slot);
|
||||||
vs->type = kTextVerbType;
|
vs->type = kTextVerbType;
|
||||||
vs->imgindex = 0;
|
vs->imgindex = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -2446,12 +2446,12 @@ void ScummEngine_v5::o5_verbOps() {
|
||||||
case 20: // SO_VERB_NAME_STR
|
case 20: // SO_VERB_NAME_STR
|
||||||
ptr = getResourceAddress(rtString, getVarOrDirectWord(PARAM_1));
|
ptr = getResourceAddress(rtString, getVarOrDirectWord(PARAM_1));
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
nukeResource(rtVerb, slot);
|
res.nukeResource(rtVerb, slot);
|
||||||
else {
|
else {
|
||||||
loadPtrToResource(rtVerb, slot, ptr);
|
loadPtrToResource(rtVerb, slot, ptr);
|
||||||
}
|
}
|
||||||
if (slot == 0)
|
if (slot == 0)
|
||||||
nukeResource(rtVerb, slot);
|
res.nukeResource(rtVerb, slot);
|
||||||
vs->type = kTextVerbType;
|
vs->type = kTextVerbType;
|
||||||
vs->imgindex = 0;
|
vs->imgindex = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -466,7 +466,7 @@ void ScummEngine_v6::nukeArray(int a) {
|
||||||
data = readVar(a);
|
data = readVar(a);
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
nukeResource(rtString, data);
|
res.nukeResource(rtString, data);
|
||||||
if (_features & GF_HUMONGOUS)
|
if (_features & GF_HUMONGOUS)
|
||||||
_arraySlot[data] = 0;
|
_arraySlot[data] = 0;
|
||||||
|
|
||||||
|
@ -1559,59 +1559,59 @@ void ScummEngine_v6::o6_resourceRoutines() {
|
||||||
if (_version >= 7)
|
if (_version >= 7)
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
setResourceCounter(rtScript, resid, 0x7F);
|
res.setResourceCounter(rtScript, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 105: // SO_NUKE_SOUND
|
case 105: // SO_NUKE_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtSound, resid, 0x7F);
|
res.setResourceCounter(rtSound, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 106: // SO_NUKE_COSTUME
|
case 106: // SO_NUKE_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtCostume, resid, 0x7F);
|
res.setResourceCounter(rtCostume, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 107: // SO_NUKE_ROOM
|
case 107: // SO_NUKE_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtRoom, resid, 0x7F);
|
res.setResourceCounter(rtRoom, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 108: // SO_LOCK_SCRIPT
|
case 108: // SO_LOCK_SCRIPT
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
lock(rtScript, resid);
|
res.lock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 109: // SO_LOCK_SOUND
|
case 109: // SO_LOCK_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
lock(rtSound, resid);
|
res.lock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 110: // SO_LOCK_COSTUME
|
case 110: // SO_LOCK_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
lock(rtCostume, resid);
|
res.lock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 111: // SO_LOCK_ROOM
|
case 111: // SO_LOCK_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
lock(rtRoom, resid);
|
res.lock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 112: // SO_UNLOCK_SCRIPT
|
case 112: // SO_UNLOCK_SCRIPT
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
unlock(rtScript, resid);
|
res.unlock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 113: // SO_UNLOCK_SOUND
|
case 113: // SO_UNLOCK_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
unlock(rtSound, resid);
|
res.unlock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 114: // SO_UNLOCK_COSTUME
|
case 114: // SO_UNLOCK_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
unlock(rtCostume, resid);
|
res.unlock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 115: // SO_UNLOCK_ROOM
|
case 115: // SO_UNLOCK_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
unlock(rtRoom, resid);
|
res.unlock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 116: // SO_CLEAR_HEAP
|
case 116: // SO_CLEAR_HEAP
|
||||||
/* this is actually a scumm message */
|
/* this is actually a scumm message */
|
||||||
|
|
|
@ -532,59 +532,59 @@ void ScummEngine_v70he::o70_resourceRoutines() {
|
||||||
break;
|
break;
|
||||||
case 104: // SO_NUKE_SCRIPT
|
case 104: // SO_NUKE_SCRIPT
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtScript, resid, 0x7F);
|
res.setResourceCounter(rtScript, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 105: // SO_NUKE_SOUND
|
case 105: // SO_NUKE_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtSound, resid, 0x7F);
|
res.setResourceCounter(rtSound, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 106: // SO_NUKE_COSTUME
|
case 106: // SO_NUKE_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtCostume, resid, 0x7F);
|
res.setResourceCounter(rtCostume, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 107: // SO_NUKE_ROOM
|
case 107: // SO_NUKE_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
setResourceCounter(rtRoom, resid, 0x7F);
|
res.setResourceCounter(rtRoom, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 108: // SO_LOCK_SCRIPT
|
case 108: // SO_LOCK_SCRIPT
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
lock(rtScript, resid);
|
res.lock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 109: // SO_LOCK_SOUND
|
case 109: // SO_LOCK_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
lock(rtSound, resid);
|
res.lock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 110: // SO_LOCK_COSTUME
|
case 110: // SO_LOCK_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
lock(rtCostume, resid);
|
res.lock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 111: // SO_LOCK_ROOM
|
case 111: // SO_LOCK_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
lock(rtRoom, resid);
|
res.lock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 112: // SO_UNLOCK_SCRIPT
|
case 112: // SO_UNLOCK_SCRIPT
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid >= _numGlobalScripts)
|
if (resid >= _numGlobalScripts)
|
||||||
break;
|
break;
|
||||||
unlock(rtScript, resid);
|
res.unlock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 113: // SO_UNLOCK_SOUND
|
case 113: // SO_UNLOCK_SOUND
|
||||||
resid = pop();
|
resid = pop();
|
||||||
unlock(rtSound, resid);
|
res.unlock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 114: // SO_UNLOCK_COSTUME
|
case 114: // SO_UNLOCK_COSTUME
|
||||||
resid = pop();
|
resid = pop();
|
||||||
unlock(rtCostume, resid);
|
res.unlock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 115: // SO_UNLOCK_ROOM
|
case 115: // SO_UNLOCK_ROOM
|
||||||
resid = pop();
|
resid = pop();
|
||||||
if (resid > 0x7F)
|
if (resid > 0x7F)
|
||||||
resid = _resourceMapper[resid & 0x7F];
|
resid = _resourceMapper[resid & 0x7F];
|
||||||
unlock(rtRoom, resid);
|
res.unlock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 116:
|
case 116:
|
||||||
break;
|
break;
|
||||||
|
@ -611,11 +611,11 @@ void ScummEngine_v70he::o70_resourceRoutines() {
|
||||||
break;
|
break;
|
||||||
case 159:
|
case 159:
|
||||||
resid = pop();
|
resid = pop();
|
||||||
unlock(rtImage, resid);
|
res.unlock(rtImage, resid);
|
||||||
break;
|
break;
|
||||||
case 192:
|
case 192:
|
||||||
resid = pop();
|
resid = pop();
|
||||||
nukeResource(rtImage, resid);
|
res.nukeResource(rtImage, resid);
|
||||||
break;
|
break;
|
||||||
case 201:
|
case 201:
|
||||||
resid = pop();
|
resid = pop();
|
||||||
|
@ -623,7 +623,7 @@ void ScummEngine_v70he::o70_resourceRoutines() {
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
resid = pop();
|
resid = pop();
|
||||||
lock(rtImage, resid);
|
res.lock(rtImage, resid);
|
||||||
break;
|
break;
|
||||||
case 233:
|
case 233:
|
||||||
resid = pop();
|
resid = pop();
|
||||||
|
|
|
@ -779,40 +779,40 @@ void ScummEngine_v8::o8_resourceRoutines() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x42: // SO_HEAP_LOCK_COSTUME Lock costume in heap
|
case 0x42: // SO_HEAP_LOCK_COSTUME Lock costume in heap
|
||||||
lock(rtCostume, resid);
|
res.lock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 0x43: // SO_HEAP_LOCK_ROOM Lock room in heap
|
case 0x43: // SO_HEAP_LOCK_ROOM Lock room in heap
|
||||||
lock(rtRoom, resid);
|
res.lock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 0x44: // SO_HEAP_LOCK_SCRIPT Lock script in heap
|
case 0x44: // SO_HEAP_LOCK_SCRIPT Lock script in heap
|
||||||
lock(rtScript, resid);
|
res.lock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 0x45: // SO_HEAP_LOCK_SOUND Lock sound in heap
|
case 0x45: // SO_HEAP_LOCK_SOUND Lock sound in heap
|
||||||
lock(rtSound, resid);
|
res.lock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 0x46: // SO_HEAP_UNLOCK_COSTUME Unlock costume
|
case 0x46: // SO_HEAP_UNLOCK_COSTUME Unlock costume
|
||||||
unlock(rtCostume, resid);
|
res.unlock(rtCostume, resid);
|
||||||
break;
|
break;
|
||||||
case 0x47: // SO_HEAP_UNLOCK_ROOM Unlock room
|
case 0x47: // SO_HEAP_UNLOCK_ROOM Unlock room
|
||||||
unlock(rtRoom, resid);
|
res.unlock(rtRoom, resid);
|
||||||
break;
|
break;
|
||||||
case 0x48: // SO_HEAP_UNLOCK_SCRIPT Unlock script
|
case 0x48: // SO_HEAP_UNLOCK_SCRIPT Unlock script
|
||||||
unlock(rtScript, resid);
|
res.unlock(rtScript, resid);
|
||||||
break;
|
break;
|
||||||
case 0x49: // SO_HEAP_UNLOCK_SOUND Unlock sound
|
case 0x49: // SO_HEAP_UNLOCK_SOUND Unlock sound
|
||||||
unlock(rtSound, resid);
|
res.unlock(rtSound, resid);
|
||||||
break;
|
break;
|
||||||
case 0x4A: // SO_HEAP_NUKE_COSTUME Remove costume from heap
|
case 0x4A: // SO_HEAP_NUKE_COSTUME Remove costume from heap
|
||||||
setResourceCounter(rtCostume, resid, 0x7F);
|
res.setResourceCounter(rtCostume, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 0x4B: // SO_HEAP_NUKE_ROOM Remove room from heap
|
case 0x4B: // SO_HEAP_NUKE_ROOM Remove room from heap
|
||||||
setResourceCounter(rtRoom, resid, 0x7F);
|
res.setResourceCounter(rtRoom, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 0x4C: // SO_HEAP_NUKE_SCRIPT Remove script from heap
|
case 0x4C: // SO_HEAP_NUKE_SCRIPT Remove script from heap
|
||||||
setResourceCounter(rtScript, resid, 0x7F);
|
res.setResourceCounter(rtScript, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
case 0x4D: // SO_HEAP_NUKE_SOUND Remove sound from heap
|
case 0x4D: // SO_HEAP_NUKE_SOUND Remove sound from heap
|
||||||
setResourceCounter(rtSound, resid, 0x7F);
|
res.setResourceCounter(rtSound, resid, 0x7F);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("o8_resourceRoutines: default case 0x%x", subOp);
|
error("o8_resourceRoutines: default case 0x%x", subOp);
|
||||||
|
@ -1214,13 +1214,13 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
|
||||||
case 11: { // lockObject
|
case 11: { // lockObject
|
||||||
int objidx = getObjectIndex(args[1]);
|
int objidx = getObjectIndex(args[1]);
|
||||||
assert(objidx != -1);
|
assert(objidx != -1);
|
||||||
lock(rtFlObject, objidx);
|
res.lock(rtFlObject, objidx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 12: { // unlockObject
|
case 12: { // unlockObject
|
||||||
int objidx = getObjectIndex(args[1]);
|
int objidx = getObjectIndex(args[1]);
|
||||||
assert(objidx != -1);
|
assert(objidx != -1);
|
||||||
unlock(rtFlObject, objidx);
|
res.unlock(rtFlObject, objidx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 13: // remapCostume
|
case 13: // remapCostume
|
||||||
|
|
|
@ -594,7 +594,9 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameS
|
||||||
_heversion(gs.heversion),
|
_heversion(gs.heversion),
|
||||||
_numActors(gs.numActors),
|
_numActors(gs.numActors),
|
||||||
_features(gs.features),
|
_features(gs.features),
|
||||||
gdi(this), _pauseDialog(0), _mainMenuDialog(0), _versionDialog(0),
|
gdi(this),
|
||||||
|
res(this),
|
||||||
|
_pauseDialog(0), _mainMenuDialog(0), _versionDialog(0),
|
||||||
_targetName(detector->_targetName) {
|
_targetName(detector->_targetName) {
|
||||||
|
|
||||||
// Copy MD5 checksum
|
// Copy MD5 checksum
|
||||||
|
@ -758,8 +760,6 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameS
|
||||||
_lastSaveTime = 0;
|
_lastSaveTime = 0;
|
||||||
_saveTemporaryState = false;
|
_saveTemporaryState = false;
|
||||||
memset(_saveLoadName, 0, sizeof(_saveLoadName));
|
memset(_saveLoadName, 0, sizeof(_saveLoadName));
|
||||||
_maxHeapThreshold = 0;
|
|
||||||
_minHeapThreshold = 0;
|
|
||||||
memset(_localScriptOffsets, 0, sizeof(_localScriptOffsets));
|
memset(_localScriptOffsets, 0, sizeof(_localScriptOffsets));
|
||||||
_scriptPointer = NULL;
|
_scriptPointer = NULL;
|
||||||
_scriptOrgPointer = NULL;
|
_scriptOrgPointer = NULL;
|
||||||
|
@ -776,8 +776,6 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameS
|
||||||
_fileOffset = 0;
|
_fileOffset = 0;
|
||||||
_dynamicRoomOffsets = false;
|
_dynamicRoomOffsets = false;
|
||||||
memset(_resourceMapper, 0, sizeof(_resourceMapper));
|
memset(_resourceMapper, 0, sizeof(_resourceMapper));
|
||||||
_allocatedSize = 0;
|
|
||||||
_expire_counter = 0;
|
|
||||||
_lastLoadedRoom = 0;
|
_lastLoadedRoom = 0;
|
||||||
_roomResource = 0;
|
_roomResource = 0;
|
||||||
_substResFileNameIndex = 0;
|
_substResFileNameIndex = 0;
|
||||||
|
@ -1173,7 +1171,11 @@ ScummEngine::~ScummEngine() {
|
||||||
|
|
||||||
free(_shadowPalette);
|
free(_shadowPalette);
|
||||||
|
|
||||||
freeResources();
|
res.freeResources();
|
||||||
|
if (_heversion >= 70) {
|
||||||
|
free(_heV7RoomIntOffsets);
|
||||||
|
free(_heV7RoomOffsets);
|
||||||
|
}
|
||||||
|
|
||||||
free(_objectStateTable);
|
free(_objectStateTable);
|
||||||
free(_objectRoomTable);
|
free(_objectRoomTable);
|
||||||
|
@ -1309,18 +1311,18 @@ int ScummEngine::init(GameDetector &detector) {
|
||||||
|
|
||||||
#ifdef __PALM_OS__
|
#ifdef __PALM_OS__
|
||||||
if (_features & GF_NEW_COSTUMES)
|
if (_features & GF_NEW_COSTUMES)
|
||||||
_maxHeapThreshold = gVars->memory[kMemScummNewCostGames];
|
res._maxHeapThreshold = gVars->memory[kMemScummNewCostGames];
|
||||||
else
|
else
|
||||||
_maxHeapThreshold = gVars->memory[kMemScummOldCostGames];
|
res._maxHeapThreshold = gVars->memory[kMemScummOldCostGames];
|
||||||
#else
|
#else
|
||||||
// Since the new costumes are very big, we increase the heap limit, to avoid having
|
// Since the new costumes are very big, we increase the heap limit, to avoid having
|
||||||
// to constantly reload stuff from the data files.
|
// to constantly reload stuff from the data files.
|
||||||
if (_features & GF_NEW_COSTUMES)
|
if (_features & GF_NEW_COSTUMES)
|
||||||
_maxHeapThreshold = 2500000;
|
res._maxHeapThreshold = 2500000;
|
||||||
else
|
else
|
||||||
_maxHeapThreshold = 550000;
|
res._maxHeapThreshold = 550000;
|
||||||
#endif
|
#endif
|
||||||
_minHeapThreshold = 400000;
|
res._minHeapThreshold = 400000;
|
||||||
|
|
||||||
allocResTypeData(rtBuffer, MKID('NONE'), 10, "buffer", 0);
|
allocResTypeData(rtBuffer, MKID('NONE'), 10, "buffer", 0);
|
||||||
|
|
||||||
|
@ -2074,8 +2076,8 @@ load_game:
|
||||||
|
|
||||||
camera._last = camera._cur;
|
camera._last = camera._cur;
|
||||||
|
|
||||||
if (!(++_expire_counter)) {
|
if (!(++res._expireCounter)) {
|
||||||
increaseResourceCounter();
|
res.increaseResourceCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
animateCursor();
|
animateCursor();
|
||||||
|
@ -2174,7 +2176,7 @@ void ScummEngine::startScene(int room, Actor *a, int objectNr) {
|
||||||
VAR(VAR_ROOM) = room;
|
VAR(VAR_ROOM) = room;
|
||||||
_fullRedraw = true;
|
_fullRedraw = true;
|
||||||
|
|
||||||
increaseResourceCounter();
|
res.increaseResourceCounter();
|
||||||
|
|
||||||
_currentRoom = room;
|
_currentRoom = room;
|
||||||
VAR(VAR_ROOM) = room;
|
VAR(VAR_ROOM) = room;
|
||||||
|
@ -2391,8 +2393,8 @@ void ScummEngine::initRoomSubBlocks() {
|
||||||
//
|
//
|
||||||
// Load box data
|
// Load box data
|
||||||
//
|
//
|
||||||
nukeResource(rtMatrix, 1);
|
res.nukeResource(rtMatrix, 1);
|
||||||
nukeResource(rtMatrix, 2);
|
res.nukeResource(rtMatrix, 2);
|
||||||
if (_features & GF_SMALL_HEADER) {
|
if (_features & GF_SMALL_HEADER) {
|
||||||
if (_version <= 2)
|
if (_version <= 2)
|
||||||
ptr = roomptr + *(roomptr + 0x15);
|
ptr = roomptr + *(roomptr + 0x15);
|
||||||
|
@ -2451,7 +2453,7 @@ void ScummEngine::initRoomSubBlocks() {
|
||||||
// Load scale data
|
// Load scale data
|
||||||
//
|
//
|
||||||
for (i = 1; i < res.num[rtScaleTable]; i++)
|
for (i = 1; i < res.num[rtScaleTable]; i++)
|
||||||
nukeResource(rtScaleTable, i);
|
res.nukeResource(rtScaleTable, i);
|
||||||
|
|
||||||
if (_features & GF_OLD_BUNDLE)
|
if (_features & GF_OLD_BUNDLE)
|
||||||
ptr = 0;
|
ptr = 0;
|
||||||
|
|
|
@ -291,6 +291,44 @@ struct AuxEntry {
|
||||||
int subIndex;
|
int subIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ResourceManager {
|
||||||
|
friend class ScummDebugger;
|
||||||
|
friend class ScummEngine;
|
||||||
|
protected:
|
||||||
|
ScummEngine *_vm;
|
||||||
|
|
||||||
|
public:
|
||||||
|
byte mode[rtNumTypes];
|
||||||
|
uint16 num[rtNumTypes];
|
||||||
|
uint32 tags[rtNumTypes];
|
||||||
|
const char *name[rtNumTypes];
|
||||||
|
byte **address[rtNumTypes];
|
||||||
|
byte *flags[rtNumTypes];
|
||||||
|
byte *roomno[rtNumTypes];
|
||||||
|
uint32 *roomoffs[rtNumTypes];
|
||||||
|
uint32 *globsize[rtNumTypes];
|
||||||
|
|
||||||
|
uint32 _allocatedSize;
|
||||||
|
uint32 _maxHeapThreshold, _minHeapThreshold;
|
||||||
|
byte _expireCounter;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ResourceManager(ScummEngine *vm);
|
||||||
|
|
||||||
|
void nukeResource(int type, int i);
|
||||||
|
|
||||||
|
void freeResources();
|
||||||
|
|
||||||
|
bool validateResource(const char *str, int type, int index) const;
|
||||||
|
bool isResourceLoaded(int type, int index) const;
|
||||||
|
|
||||||
|
void lock(int type, int i);
|
||||||
|
void unlock(int type, int i);
|
||||||
|
|
||||||
|
void setResourceCounter(int type, int index, byte flag);
|
||||||
|
void increaseResourceCounter();
|
||||||
|
};
|
||||||
|
|
||||||
class ScummEngine : public Engine {
|
class ScummEngine : public Engine {
|
||||||
friend class ScummDebugger;
|
friend class ScummDebugger;
|
||||||
friend class SmushPlayer;
|
friend class SmushPlayer;
|
||||||
|
@ -325,20 +363,10 @@ public:
|
||||||
/** Graphics manager */
|
/** Graphics manager */
|
||||||
Gdi gdi;
|
Gdi gdi;
|
||||||
|
|
||||||
protected:
|
|
||||||
/** Central resource data. */
|
/** Central resource data. */
|
||||||
struct {
|
ResourceManager res;
|
||||||
byte mode[rtNumTypes];
|
|
||||||
uint16 num[rtNumTypes];
|
|
||||||
uint32 tags[rtNumTypes];
|
|
||||||
const char *name[rtNumTypes];
|
|
||||||
byte **address[rtNumTypes];
|
|
||||||
byte *flags[rtNumTypes];
|
|
||||||
byte *roomno[rtNumTypes];
|
|
||||||
uint32 *roomoffs[rtNumTypes];
|
|
||||||
uint32 *globsize[rtNumTypes];
|
|
||||||
} res;
|
|
||||||
|
|
||||||
|
protected:
|
||||||
VirtualMachineState vm;
|
VirtualMachineState vm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -534,13 +562,7 @@ public:
|
||||||
void requestSave(int slot, const char *name, bool temporary = false);
|
void requestSave(int slot, const char *name, bool temporary = false);
|
||||||
void requestLoad(int slot);
|
void requestLoad(int slot);
|
||||||
|
|
||||||
void lock(int type, int i);
|
|
||||||
void unlock(int type, int i);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Heap and memory management */
|
|
||||||
uint32 _maxHeapThreshold, _minHeapThreshold;
|
|
||||||
|
|
||||||
/* Script VM - should be in Script class */
|
/* Script VM - should be in Script class */
|
||||||
uint32 _localScriptOffsets[256];
|
uint32 _localScriptOffsets[256];
|
||||||
const byte *_scriptPointer, *_scriptOrgPointer;
|
const byte *_scriptPointer, *_scriptOrgPointer;
|
||||||
|
@ -631,8 +653,6 @@ protected:
|
||||||
Common::String _targetName; // This is the game the user calls it, so use for saving
|
Common::String _targetName; // This is the game the user calls it, so use for saving
|
||||||
bool _dynamicRoomOffsets;
|
bool _dynamicRoomOffsets;
|
||||||
byte _resourceMapper[128];
|
byte _resourceMapper[128];
|
||||||
uint32 _allocatedSize;
|
|
||||||
byte _expire_counter;
|
|
||||||
byte *_heV7DiskOffsets;
|
byte *_heV7DiskOffsets;
|
||||||
byte *_heV7RoomOffsets;
|
byte *_heV7RoomOffsets;
|
||||||
uint32 *_heV7RoomIntOffsets;
|
uint32 *_heV7RoomIntOffsets;
|
||||||
|
@ -652,11 +672,10 @@ protected:
|
||||||
void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
|
void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
|
||||||
byte *createResource(int type, int index, uint32 size);
|
byte *createResource(int type, int index, uint32 size);
|
||||||
int loadResource(int type, int i);
|
int loadResource(int type, int i);
|
||||||
void nukeResource(int type, int i);
|
// void nukeResource(int type, int i);
|
||||||
int getResourceSize(int type, int idx);
|
int getResourceSize(int type, int idx);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool isResourceLoaded(int type, int index) const;
|
|
||||||
byte *getResourceAddress(int type, int i);
|
byte *getResourceAddress(int type, int i);
|
||||||
byte *getStringAddress(int i);
|
byte *getStringAddress(int i);
|
||||||
byte *getStringAddressVar(int i);
|
byte *getStringAddressVar(int i);
|
||||||
|
@ -669,9 +688,6 @@ protected:
|
||||||
void convertMac0Resource(int type, int index, byte *ptr, int size);
|
void convertMac0Resource(int type, int index, byte *ptr, int size);
|
||||||
void convertADResource(int type, int index, byte *ptr, int size);
|
void convertADResource(int type, int index, byte *ptr, int size);
|
||||||
int readSoundResourceSmallHeader(int type, int index);
|
int readSoundResourceSmallHeader(int type, int index);
|
||||||
void setResourceCounter(int type, int index, byte flag);
|
|
||||||
bool validateResource(const char *str, int type, int index) const;
|
|
||||||
void increaseResourceCounter();
|
|
||||||
bool isResourceInUse(int type, int i) const;
|
bool isResourceInUse(int type, int i) const;
|
||||||
void initRoomSubBlocks();
|
void initRoomSubBlocks();
|
||||||
void clearRoomObjects();
|
void clearRoomObjects();
|
||||||
|
@ -695,7 +711,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void resourceStats();
|
void resourceStats();
|
||||||
void expireResources(uint32 size);
|
void expireResources(uint32 size);
|
||||||
void freeResources();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Should be in Object class */
|
/* Should be in Object class */
|
||||||
|
|
|
@ -841,7 +841,7 @@ int Sound::isSoundRunning(int sound) const {
|
||||||
if (isSoundInQueue(sound))
|
if (isSoundInQueue(sound))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (sound > _vm->_numSounds || !_vm->isResourceLoaded(rtSound, sound))
|
if (sound > _vm->_numSounds || !_vm->res.isResourceLoaded(rtSound, sound))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (_vm->_musicEngine)
|
if (_vm->_musicEngine)
|
||||||
|
@ -872,7 +872,7 @@ bool Sound::isSoundInUse(int sound) const {
|
||||||
if (isSoundInQueue(sound))
|
if (isSoundInQueue(sound))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!_vm->isResourceLoaded(rtSound, sound))
|
if (!_vm->res.isResourceLoaded(rtSound, sound))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_vm->_imuse)
|
if (_vm->_imuse)
|
||||||
|
|
|
@ -720,7 +720,7 @@ void ScummEngine::initCharset(int charsetno) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (_gameId == GID_FT) {
|
if (_gameId == GID_FT) {
|
||||||
if (!isResourceLoaded(rtCharset, charsetno))
|
if (!res.isResourceLoaded(rtCharset, charsetno))
|
||||||
loadCharset(charsetno);
|
loadCharset(charsetno);
|
||||||
} else {
|
} else {
|
||||||
if (!getResourceAddress(rtCharset, charsetno))
|
if (!getResourceAddress(rtCharset, charsetno))
|
||||||
|
|
|
@ -613,7 +613,7 @@ void ScummEngine::killVerb(int slot) {
|
||||||
vs->verbid = 0;
|
vs->verbid = 0;
|
||||||
vs->curmode = 0;
|
vs->curmode = 0;
|
||||||
|
|
||||||
nukeResource(rtVerb, slot);
|
res.nukeResource(rtVerb, slot);
|
||||||
|
|
||||||
if (_version <= 6 && vs->saveid == 0) {
|
if (_version <= 6 && vs->saveid == 0) {
|
||||||
drawVerb(slot, 0);
|
drawVerb(slot, 0);
|
||||||
|
|
|
@ -1424,7 +1424,7 @@ void ScummEngine_v90he::processWizImage(const WizParameters *params) {
|
||||||
f.seek(0, SEEK_SET);
|
f.seek(0, SEEK_SET);
|
||||||
byte *p = createResource(rtImage, params->img.resNum, size);
|
byte *p = createResource(rtImage, params->img.resNum, size);
|
||||||
if (f.read(p, size) != size) {
|
if (f.read(p, size) != size) {
|
||||||
nukeResource(rtImage, params->img.resNum);
|
res.nukeResource(rtImage, params->img.resNum);
|
||||||
warning("i/o error when reading '%s'", params->filename);
|
warning("i/o error when reading '%s'", params->filename);
|
||||||
VAR(VAR_GAME_LOADED) = -2;
|
VAR(VAR_GAME_LOADED) = -2;
|
||||||
VAR(119) = -2;
|
VAR(119) = -2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue