aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/script.cpp
diff options
context:
space:
mode:
authorMax Horn2010-10-18 18:43:13 +0000
committerMax Horn2010-10-18 18:43:13 +0000
commitd69a63c14506a2d7182f4193a922cf6bd06c857b (patch)
treed0a5a1f36dd2a6c8785e75aa77dbb0b6a2b8df6c /engines/scumm/script.cpp
parent5d08ad157d903c61d788edfee97854aa9a162503 (diff)
downloadscummvm-rg350-d69a63c14506a2d7182f4193a922cf6bd06c857b.tar.gz
scummvm-rg350-d69a63c14506a2d7182f4193a922cf6bd06c857b.tar.bz2
scummvm-rg350-d69a63c14506a2d7182f4193a922cf6bd06c857b.zip
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. svn-id: r53571
Diffstat (limited to 'engines/scumm/script.cpp')
-rw-r--r--engines/scumm/script.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/engines/scumm/script.cpp b/engines/scumm/script.cpp
index 223e9822e2..3c5dd9df6f 100644
--- a/engines/scumm/script.cpp
+++ b/engines/scumm/script.cpp
@@ -339,7 +339,7 @@ void ScummEngine::runScriptNested(int script) {
_currentScript = script;
getScriptBaseAddress();
- getScriptEntryPoint();
+ resetScriptPointer();
executeScript();
if (vm.numNestedScripts != 0)
@@ -354,7 +354,7 @@ void ScummEngine::runScriptNested(int script) {
slot->status != ssDead && slot->freezeCount == 0) {
_currentScript = nest->slot;
getScriptBaseAddress();
- getScriptEntryPoint();
+ resetScriptPointer();
return;
}
}
@@ -441,12 +441,27 @@ void ScummEngine::getScriptBaseAddress() {
}
-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 @@ const char *ScummEngine::getOpcodeDesc(byte i) {
}
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 @@ int ScummEngine::fetchScriptWordSigned() {
}
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 @@ void ScummEngine::runAllScripts() {
if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
_currentScript = (byte)i;
getScriptBaseAddress();
- getScriptEntryPoint();
+ resetScriptPointer();
executeScript();
}
}