aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel/handle.cpp
diff options
context:
space:
mode:
authorMax Horn2009-10-26 16:01:34 +0000
committerMax Horn2009-10-26 16:01:34 +0000
commit6591010f66a05538ddc29b3404d64a27dfc29b3f (patch)
tree7dbf0e90ebea0a229d12346693ca6d55b8ab6fe6 /engines/tinsel/handle.cpp
parentb9534216edd6d95ec94ac342c8a612e7a59f9289 (diff)
downloadscummvm-rg350-6591010f66a05538ddc29b3404d64a27dfc29b3f.tar.gz
scummvm-rg350-6591010f66a05538ddc29b3404d64a27dfc29b3f.tar.bz2
scummvm-rg350-6591010f66a05538ddc29b3404d64a27dfc29b3f.zip
TINSEL: Further untangle memory managment.
* Add new function MemoryNoAlloc * Make MemoryAlloc private * Get rid of params to various memory related functions svn-id: r45409
Diffstat (limited to 'engines/tinsel/handle.cpp')
-rw-r--r--engines/tinsel/handle.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp
index 5ea273379c..cbfd782942 100644
--- a/engines/tinsel/handle.cpp
+++ b/engines/tinsel/handle.cpp
@@ -170,7 +170,7 @@ void SetupHandleTable(void) {
#endif
else {
// allocate a discarded memory node for other files
- pH->_node = MemoryAlloc(DWM_DISCARDABLE | DWM_NOALLOC, pH->filesize & FSIZE_MASK);
+ pH->_node = MemoryNoAlloc();
pH->_ptr = NULL;
// make sure memory allocated
@@ -306,17 +306,6 @@ void LoadFile(MEMHANDLE *pH, bool bWarn) {
// discardable - lock the memory
addr = (uint8 *)MemoryLock(pH->_node);
}
-#ifdef DEBUG
- if (addr == NULL) {
- if (pH->filesize & fPreload)
- // preload - no need to lock the memory
- addr = pH->_ptr;
- else {
- // discardable - lock the memory
- addr = (uint8 *)MemoryLock(pH->_node);
- }
- }
-#endif
// make sure address is valid
assert(addr);
@@ -381,7 +370,7 @@ byte *LockMem(SCNHANDLE offset) {
if (pH->_node->pBaseAddr == NULL)
// must have been discarded - reallocate the memory
- MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle, DWM_DISCARDABLE);
+ MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle);
if (pH->_node->pBaseAddr == NULL)
error("Out of memory");
@@ -403,7 +392,7 @@ byte *LockMem(SCNHANDLE offset) {
if (pH->_node->pBaseAddr == NULL)
// must have been discarded - reallocate the memory
- MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_DISCARDABLE);
+ MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
if (pH->_node->pBaseAddr == NULL)
error("Out of memory");
@@ -422,7 +411,7 @@ byte *LockMem(SCNHANDLE offset) {
}
/**
- * Called to make the current scene non-discardable.
+ * Called to lock the current scene and make it non-discardable.
* @param offset Handle and offset to data
*/
void LockScene(SCNHANDLE offset) {
@@ -443,11 +432,12 @@ void LockScene(SCNHANDLE offset) {
HeapCompact(MAX_INT, false);
if ((pH->filesize & fPreload) == 0) {
- // change the flags for the node
- // WORKAROUND: The original didn't include the DWM_LOCKED flag. It's being
- // included because the method is 'LockScene' so it's presumed that the
- // point of this was that the scene's memory block be locked
- MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_LOCKED);
+ // Ensure the scene handle is allocated.
+ MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
+
+ // Now lock it to make sure it stays allocated and in a fixed position.
+ MemoryLock(pH->_node);
+
#ifdef DEBUG
bLockedScene = true;
#endif
@@ -469,8 +459,9 @@ void UnlockScene(SCNHANDLE offset) {
pH = handleTable + handle;
if ((pH->filesize & fPreload) == 0) {
- // change the flags for the node
- MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK, DWM_DISCARDABLE);
+ // unlock the scene data
+ MemoryUnlock(pH->_node);
+
#ifdef DEBUG
bLockedScene = false;
#endif