aboutsummaryrefslogtreecommitdiff
path: root/scumm/resource.cpp
diff options
context:
space:
mode:
authorMax Horn2005-04-06 17:31:35 +0000
committerMax Horn2005-04-06 17:31:35 +0000
commit3d5b5f2ad83a5d4b463e9e78f204b132e36f770c (patch)
tree4d494a39724db4906bcb4add6522f35e2143ee10 /scumm/resource.cpp
parent26e0ec1d240c71f5fdc34b912ee8ddf0368ab6dc (diff)
downloadscummvm-rg350-3d5b5f2ad83a5d4b463e9e78f204b132e36f770c.tar.gz
scummvm-rg350-3d5b5f2ad83a5d4b463e9e78f204b132e36f770c.tar.bz2
scummvm-rg350-3d5b5f2ad83a5d4b463e9e78f204b132e36f770c.zip
Moved createResource, resourceStats, expireResources to ResourceManager
svn-id: r17420
Diffstat (limited to 'scumm/resource.cpp')
-rw-r--r--scumm/resource.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/scumm/resource.cpp b/scumm/resource.cpp
index 82adc89f91..a31676e536 100644
--- a/scumm/resource.cpp
+++ b/scumm/resource.cpp
@@ -648,7 +648,7 @@ int ScummEngine::loadResource(int type, int idx) {
size = _fileHandle->readUint32BE();
_fileHandle->seek(-8, SEEK_CUR);
}
- _fileHandle->read(createResource(type, idx, size), size);
+ _fileHandle->read(res.createResource(type, idx, size), size);
// dump the resource if requested
if (_dumpScripts && type == rtScript) {
@@ -743,15 +743,15 @@ void ResourceManager::setResourceCounter(int type, int idx, byte flag) {
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
#define SAFETY_AREA 2
-byte *ScummEngine::createResource(int type, int idx, uint32 size) {
+byte *ResourceManager::createResource(int type, int idx, uint32 size) {
byte *ptr;
CHECK_HEAP
- debugC(DEBUG_RESOURCE, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
+ debugC(DEBUG_RESOURCE, "res.createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
- if (!res.validateResource("allocating", type, idx))
+ if (!validateResource("allocating", type, idx))
return NULL;
- res.nukeResource(type, idx);
+ nukeResource(type, idx);
expireResources(size);
@@ -761,11 +761,11 @@ byte *ScummEngine::createResource(int type, int idx, uint32 size) {
error("Out of memory while allocating %d", size);
}
- res._allocatedSize += size;
+ _allocatedSize += size;
- res.address[type][idx] = ptr;
+ address[type][idx] = ptr;
((MemBlkHeader *)ptr)->size = size;
- res.setResourceCounter(type, idx, 1);
+ setResourceCounter(type, idx, 1);
return ptr + sizeof(MemBlkHeader); /* skip header */
}
@@ -857,32 +857,32 @@ bool ScummEngine::isResourceInUse(int type, int i) const {
}
}
-void ScummEngine::expireResources(uint32 size) {
+void ResourceManager::expireResources(uint32 size) {
int i, j;
byte flag;
byte best_counter;
int best_type, best_res = 0;
uint32 oldAllocatedSize;
- if (res._expireCounter != 0xFF) {
- res._expireCounter = 0xFF;
- res.increaseResourceCounter();
+ if (_expireCounter != 0xFF) {
+ _expireCounter = 0xFF;
+ increaseResourceCounter();
}
- if (size + res._allocatedSize < res._maxHeapThreshold)
+ if (size + _allocatedSize < _maxHeapThreshold)
return;
- oldAllocatedSize = res._allocatedSize;
+ oldAllocatedSize = _allocatedSize;
do {
best_type = 0;
best_counter = 2;
for (i = rtFirst; i <= rtLast; i++)
- if (res.mode[i]) {
- for (j = res.num[i]; --j >= 0;) {
- flag = res.flags[i][j];
- if (!(flag & RF_LOCK) && flag >= best_counter && res.address[i][j] && !isResourceInUse(i, j)) {
+ if (mode[i]) {
+ for (j = num[i]; --j >= 0;) {
+ flag = flags[i][j];
+ if (!(flag & RF_LOCK) && flag >= best_counter && address[i][j] && !_vm->isResourceInUse(i, j)) {
best_counter = flag;
best_type = i;
best_res = j;
@@ -892,12 +892,12 @@ void ScummEngine::expireResources(uint32 size) {
if (!best_type)
break;
- res.nukeResource(best_type, best_res);
- } while (size + res._allocatedSize > res._minHeapThreshold);
+ nukeResource(best_type, best_res);
+ } while (size + _allocatedSize > _minHeapThreshold);
- res.increaseResourceCounter();
+ increaseResourceCounter();
- debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, res._allocatedSize);
+ debugC(DEBUG_RESOURCE, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
}
void ResourceManager::freeResources() {
@@ -927,7 +927,7 @@ void ScummEngine::loadPtrToResource(int type, int resindex, const byte *source)
if (len <= 0)
return;
- alloced = createResource(type, resindex, len);
+ alloced = res.createResource(type, resindex, len);
if (!source) {
alloced[0] = fetchScriptByte();
@@ -945,21 +945,21 @@ bool ResourceManager::isResourceLoaded(int type, int idx) const {
return address[type][idx] != NULL;
}
-void ScummEngine::resourceStats() {
+void ResourceManager::resourceStats() {
int i, j;
uint32 lockedSize = 0, lockedNum = 0;
byte flag;
for (i = rtFirst; i <= rtLast; i++)
- for (j = res.num[i]; --j >= 0;) {
- flag = res.flags[i][j];
- if (flag & RF_LOCK && res.address[i][j]) {
- lockedSize += ((MemBlkHeader *)res.address[i][j])->size;
+ for (j = num[i]; --j >= 0;) {
+ flag = flags[i][j];
+ if (flag & RF_LOCK && address[i][j]) {
+ lockedSize += ((MemBlkHeader *)address[i][j])->size;
lockedNum++;
}
}
- debug(1, "Total allocated size=%d, locked=%d(%d)", res._allocatedSize, lockedSize, lockedNum);
+ debug(1, "Total allocated size=%d, locked=%d(%d)", _allocatedSize, lockedSize, lockedNum);
}
void ScummEngine::readMAXS(int blockSize) {