[Scummvm-cvs-logs] SF.net SVN: scummvm:[53571] scummvm/trunk/engines/scumm

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Oct 18 20:43:15 CEST 2010


Revision: 53571
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53571&view=rev
Author:   fingolfin
Date:     2010-10-18 18:43:13 +0000 (Mon, 18 Oct 2010)

Log Message:
-----------
SCUMM: Move common code from ScummEngine::fetchScript* to new method.

The new method is called refreshScriptPointer(). Also renamed
getScriptEntryPoint() to resetScriptPointer() in an attempt to highlight
both the similarity and difference between the two.

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/script.cpp
    scummvm/trunk/engines/scumm/scumm.h

Modified: scummvm/trunk/engines/scumm/script.cpp
===================================================================
--- scummvm/trunk/engines/scumm/script.cpp	2010-10-18 17:42:24 UTC (rev 53570)
+++ scummvm/trunk/engines/scumm/script.cpp	2010-10-18 18:43:13 UTC (rev 53571)
@@ -339,7 +339,7 @@
 
 	_currentScript = script;
 	getScriptBaseAddress();
-	getScriptEntryPoint();
+	resetScriptPointer();
 	executeScript();
 
 	if (vm.numNestedScripts != 0)
@@ -354,7 +354,7 @@
 				slot->status != ssDead && slot->freezeCount == 0) {
 			_currentScript = nest->slot;
 			getScriptBaseAddress();
-			getScriptEntryPoint();
+			resetScriptPointer();
 			return;
 		}
 	}
@@ -441,12 +441,27 @@
 }
 
 
-void ScummEngine::getScriptEntryPoint() {
+void ScummEngine::resetScriptPointer() {
 	if (_currentScript == 0xFF)
 		return;
 	_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
 }
 
+/**
+ * This method checks whether the resource that contains the active script
+ * moved, and if so, updates the script pointer accordingly.
+ *
+ * The script resource may have moved because it might have been garbage
+ * collected by ResourceManager::expireResources.
+ */
+void ScummEngine::refreshScriptPointer() {
+	if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
+		long oldoffs = _scriptPointer - _scriptOrgPointer;
+		getScriptBaseAddress();
+		_scriptPointer = _scriptOrgPointer + oldoffs;
+	}
+}
+
 /** Execute a script - Read opcode, and execute it from the table */
 void ScummEngine::executeScript() {
 	int c;
@@ -492,20 +507,12 @@
 }
 
 byte ScummEngine::fetchScriptByte() {
-	if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
-		long oldoffs = _scriptPointer - _scriptOrgPointer;
-		getScriptBaseAddress();
-		_scriptPointer = _scriptOrgPointer + oldoffs;
-	}
+	refreshScriptPointer();
 	return *_scriptPointer++;
 }
 
 uint ScummEngine::fetchScriptWord() {
-	if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
-		long oldoffs = _scriptPointer - _scriptOrgPointer;
-		getScriptBaseAddress();
-		_scriptPointer = _scriptOrgPointer + oldoffs;
-	}
+	refreshScriptPointer();
 	uint a = READ_LE_UINT16(_scriptPointer);
 	_scriptPointer += 2;
 	return a;
@@ -516,11 +523,7 @@
 }
 
 uint ScummEngine::fetchScriptDWord() {
-	if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
-		long oldoffs = _scriptPointer - _scriptOrgPointer;
-		getScriptBaseAddress();
-		_scriptPointer = _scriptOrgPointer + oldoffs;
-	}
+	refreshScriptPointer();
 	uint a = READ_LE_UINT32(_scriptPointer);
 	_scriptPointer += 4;
 	return a;
@@ -898,7 +901,7 @@
 			if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
 				_currentScript = (byte)i;
 				getScriptBaseAddress();
-				getScriptEntryPoint();
+				resetScriptPointer();
 				executeScript();
 			}
 		}

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2010-10-18 17:42:24 UTC (rev 53570)
+++ scummvm/trunk/engines/scumm/scumm.h	2010-10-18 18:43:13 UTC (rev 53571)
@@ -753,9 +753,10 @@
 	void stopObjectScript(int script);
 
 	void getScriptBaseAddress();
-	void getScriptEntryPoint();
+	void resetScriptPointer();
 	int getVerbEntrypoint(int obj, int entry);
 
+	void refreshScriptPointer();
 	byte fetchScriptByte();
 	virtual uint fetchScriptWord();
 	virtual int fetchScriptWordSigned();


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