aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-10-26 20:38:34 +0000
committerMax Horn2009-10-26 20:38:34 +0000
commit6c1c9eda3a18ed7a545a9fc6725cfa3891ae2ac5 (patch)
tree9560cc4e352ca36887cf84b389fbf1abfee6e82d
parentd2e64a350ae9aa6955b2dd7a3715958cdb5477f5 (diff)
downloadscummvm-rg350-6c1c9eda3a18ed7a545a9fc6725cfa3891ae2ac5.tar.gz
scummvm-rg350-6c1c9eda3a18ed7a545a9fc6725cfa3891ae2ac5.tar.bz2
scummvm-rg350-6c1c9eda3a18ed7a545a9fc6725cfa3891ae2ac5.zip
TINSEL: Make MEM_NODE internal to heapmem.cpp
svn-id: r45418
-rw-r--r--engines/tinsel/handle.cpp31
-rw-r--r--engines/tinsel/heapmem.cpp32
-rw-r--r--engines/tinsel/heapmem.h15
3 files changed, 48 insertions, 30 deletions
diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp
index 038fc831b4..04b4b2fc60 100644
--- a/engines/tinsel/handle.cpp
+++ b/engines/tinsel/handle.cpp
@@ -256,8 +256,7 @@ void LoadExtraGraphData(SCNHANDLE start, SCNHANDLE next) {
OpenCDGraphFile();
- if ((handleTable + cdPlayHandle)->_node->pBaseAddr != NULL)
- MemoryDiscard((handleTable + cdPlayHandle)->_node); // Free it
+ MemoryDiscard((handleTable + cdPlayHandle)->_node); // Free it
// It must always be the same
assert(cdPlayHandle == (start >> SCNHANDLE_SHIFT));
@@ -348,12 +347,6 @@ byte *LockMem(SCNHANDLE offset) {
pH = handleTable + handle;
if (pH->filesize & fPreload) {
-#if 0
- if (TinselV2)
- // update the LRU time (new in this file)
- pH->pNode->lruTime = DwGetCurrentTime();
-#endif
-
// permanent files are already loaded
return pH->_ptr + (offset & OFFSETMASK);
} else if (handle == cdPlayHandle) {
@@ -361,28 +354,22 @@ byte *LockMem(SCNHANDLE offset) {
if (offset < cdBaseHandle || offset >= cdTopHandle)
error("Overlapping (in time) CD-plays");
- if (pH->_node->pBaseAddr == NULL) {
- // must have been discarded - reallocate the memory
- MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle);
- assert(pH->_node->pBaseAddr);
- }
+ // may have been discarded, make sure memory is allocated
+ MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle);
if (!(pH->filesize & fLoaded)) {
LoadCDGraphData(pH);
// update the LRU time (new in this file)
- pH->_node->lruTime = DwGetCurrentTime();
+ MemoryTouch(pH->_node);
}
- return pH->_node->pBaseAddr + ((offset - cdBaseHandle) & OFFSETMASK);
+ return MemoryDeref(pH->_node) + ((offset - cdBaseHandle) & OFFSETMASK);
} else {
- if (pH->_node->pBaseAddr == NULL) {
- // must have been discarded - reallocate the memory
- MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
- assert(pH->_node->pBaseAddr);
- }
+ // may have been discarded, make sure memory is allocated
+ MemoryReAlloc(pH->_node, pH->filesize & FSIZE_MASK);
if (!(pH->filesize & fLoaded)) {
@@ -396,7 +383,7 @@ byte *LockMem(SCNHANDLE offset) {
assert(pH->filesize & fLoaded);
}
- return pH->_node->pBaseAddr + (offset & OFFSETMASK);
+ return MemoryDeref(pH->_node) + (offset & OFFSETMASK);
}
}
@@ -492,7 +479,7 @@ void TouchMem(SCNHANDLE offset) {
// update the LRU time whether its loaded or not!
if (pH->_node)
- pH->_node->lruTime = DwGetCurrentTime();
+ MemoryTouch(pH->_node);
}
}
diff --git a/engines/tinsel/heapmem.cpp b/engines/tinsel/heapmem.cpp
index 6ba5fd5a88..24748a4707 100644
--- a/engines/tinsel/heapmem.cpp
+++ b/engines/tinsel/heapmem.cpp
@@ -41,6 +41,16 @@ namespace Tinsel {
#define DWM_SENTINEL 0x0400 ///< the objects memory block is a sentinel
+struct MEM_NODE {
+ MEM_NODE *pNext; // link to the next node in the list
+ MEM_NODE *pPrev; // link to the previous node in the list
+ uint8 *pBaseAddr; // base address of the memory object
+ long size; // size of the memory object
+ uint32 lruTime; // time when memory object was last accessed
+ int flags; // allocation attributes
+};
+
+
// Specifies the total amount of memory required for DW1 demo, DW1, or DW2 respectively.
// Currently this is set at 5MB for the DW1 demo and DW1 and 10MB for DW2
// This could probably be reduced somewhat
@@ -478,6 +488,8 @@ void MemoryReAlloc(MEM_NODE *pMemNode, long size) {
// free the new node
FreeMemNode(pNew);
}
+
+ assert(pMemNode->pBaseAddr);
}
/**
@@ -498,4 +510,24 @@ void MemoryUnlock(MEM_NODE *pMemNode) {
pMemNode->lruTime = DwGetCurrentTime();
}
+/**
+ * Touch a memory object by updating its LRU time.
+ * @param pMemNode Node of the memory object
+ */
+void MemoryTouch(MEM_NODE *pMemNode) {
+ // validate mnode pointer
+ assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1);
+
+ // update the LRU time
+ pMemNode->lruTime = DwGetCurrentTime();
+}
+
+uint8 *MemoryDeref(MEM_NODE *pMemNode) {
+ // validate mnode pointer
+ assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1);
+
+ return pMemNode->pBaseAddr;
+}
+
+
} // End of namespace Tinsel
diff --git a/engines/tinsel/heapmem.h b/engines/tinsel/heapmem.h
index 9fbee0d61f..86c7c456c0 100644
--- a/engines/tinsel/heapmem.h
+++ b/engines/tinsel/heapmem.h
@@ -31,14 +31,7 @@
namespace Tinsel {
-struct MEM_NODE {
- MEM_NODE *pNext; // link to the next node in the list
- MEM_NODE *pPrev; // link to the previous node in the list
- uint8 *pBaseAddr; // base address of the memory object
- long size; // size of the memory object
- uint32 lruTime; // time when memory object was last accessed
- int flags; // allocation attributes
-};
+struct MEM_NODE;
/*----------------------------------------------------------------------*\
@@ -66,6 +59,12 @@ void MemoryReAlloc( // changes the size or attributes of a specified memory obje
void MemoryUnlock( // unlocks a memory object
MEM_NODE *pMemNode); // node of the memory object
+// 'touch' the memory object, i.e., update its "least recently used" counter.
+void MemoryTouch(MEM_NODE *pMemNode);
+
+// Dereference a given memory node
+uint8 *MemoryDeref(MEM_NODE *pMemNode);
+
bool HeapCompact( // Allocates the specified number of bytes from the specified heap
long size, // number of bytes to free up
bool bDiscard); // when set - will discard blocks to fullfill the request