[Scummvm-cvs-logs] SF.net SVN: scummvm:[45418] scummvm/trunk/engines/tinsel

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Oct 26 21:38:41 CET 2009


Revision: 45418
          http://scummvm.svn.sourceforge.net/scummvm/?rev=45418&view=rev
Author:   fingolfin
Date:     2009-10-26 20:38:34 +0000 (Mon, 26 Oct 2009)

Log Message:
-----------
TINSEL: Make MEM_NODE internal to heapmem.cpp

Modified Paths:
--------------
    scummvm/trunk/engines/tinsel/handle.cpp
    scummvm/trunk/engines/tinsel/heapmem.cpp
    scummvm/trunk/engines/tinsel/heapmem.h

Modified: scummvm/trunk/engines/tinsel/handle.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/handle.cpp	2009-10-26 20:36:44 UTC (rev 45417)
+++ scummvm/trunk/engines/tinsel/handle.cpp	2009-10-26 20:38:34 UTC (rev 45418)
@@ -256,8 +256,7 @@
 
 	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 @@
 	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 @@
 		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 @@
 			assert(pH->filesize & fLoaded);
 		}
 
-		return pH->_node->pBaseAddr + (offset & OFFSETMASK);
+		return MemoryDeref(pH->_node) + (offset & OFFSETMASK);
 	}
 }
 
@@ -492,7 +479,7 @@
 
 		// update the LRU time whether its loaded or not!
 		if (pH->_node)
-			pH->_node->lruTime = DwGetCurrentTime();
+			MemoryTouch(pH->_node);
 	}
 }
 

Modified: scummvm/trunk/engines/tinsel/heapmem.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/heapmem.cpp	2009-10-26 20:36:44 UTC (rev 45417)
+++ scummvm/trunk/engines/tinsel/heapmem.cpp	2009-10-26 20:38:34 UTC (rev 45418)
@@ -41,6 +41,16 @@
 #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 @@
 		// free the new node
 		FreeMemNode(pNew);
 	}
+
+	assert(pMemNode->pBaseAddr);
 }
 
 /**
@@ -498,4 +510,24 @@
 	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

Modified: scummvm/trunk/engines/tinsel/heapmem.h
===================================================================
--- scummvm/trunk/engines/tinsel/heapmem.h	2009-10-26 20:36:44 UTC (rev 45417)
+++ scummvm/trunk/engines/tinsel/heapmem.h	2009-10-26 20:38:34 UTC (rev 45418)
@@ -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 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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list