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
This commit is contained in:
parent
5d08ad157d
commit
d69a63c145
2 changed files with 24 additions and 20 deletions
|
@ -339,7 +339,7 @@ void ScummEngine::runScriptNested(int script) {
|
||||||
|
|
||||||
_currentScript = script;
|
_currentScript = script;
|
||||||
getScriptBaseAddress();
|
getScriptBaseAddress();
|
||||||
getScriptEntryPoint();
|
resetScriptPointer();
|
||||||
executeScript();
|
executeScript();
|
||||||
|
|
||||||
if (vm.numNestedScripts != 0)
|
if (vm.numNestedScripts != 0)
|
||||||
|
@ -354,7 +354,7 @@ void ScummEngine::runScriptNested(int script) {
|
||||||
slot->status != ssDead && slot->freezeCount == 0) {
|
slot->status != ssDead && slot->freezeCount == 0) {
|
||||||
_currentScript = nest->slot;
|
_currentScript = nest->slot;
|
||||||
getScriptBaseAddress();
|
getScriptBaseAddress();
|
||||||
getScriptEntryPoint();
|
resetScriptPointer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,12 +441,27 @@ void ScummEngine::getScriptBaseAddress() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScummEngine::getScriptEntryPoint() {
|
void ScummEngine::resetScriptPointer() {
|
||||||
if (_currentScript == 0xFF)
|
if (_currentScript == 0xFF)
|
||||||
return;
|
return;
|
||||||
_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
|
_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 */
|
/** Execute a script - Read opcode, and execute it from the table */
|
||||||
void ScummEngine::executeScript() {
|
void ScummEngine::executeScript() {
|
||||||
int c;
|
int c;
|
||||||
|
@ -492,20 +507,12 @@ const char *ScummEngine::getOpcodeDesc(byte i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte ScummEngine::fetchScriptByte() {
|
byte ScummEngine::fetchScriptByte() {
|
||||||
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
|
refreshScriptPointer();
|
||||||
long oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
||||||
getScriptBaseAddress();
|
|
||||||
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
||||||
}
|
|
||||||
return *_scriptPointer++;
|
return *_scriptPointer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint ScummEngine::fetchScriptWord() {
|
uint ScummEngine::fetchScriptWord() {
|
||||||
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
|
refreshScriptPointer();
|
||||||
long oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
||||||
getScriptBaseAddress();
|
|
||||||
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
||||||
}
|
|
||||||
uint a = READ_LE_UINT16(_scriptPointer);
|
uint a = READ_LE_UINT16(_scriptPointer);
|
||||||
_scriptPointer += 2;
|
_scriptPointer += 2;
|
||||||
return a;
|
return a;
|
||||||
|
@ -516,11 +523,7 @@ int ScummEngine::fetchScriptWordSigned() {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint ScummEngine::fetchScriptDWord() {
|
uint ScummEngine::fetchScriptDWord() {
|
||||||
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
|
refreshScriptPointer();
|
||||||
long oldoffs = _scriptPointer - _scriptOrgPointer;
|
|
||||||
getScriptBaseAddress();
|
|
||||||
_scriptPointer = _scriptOrgPointer + oldoffs;
|
|
||||||
}
|
|
||||||
uint a = READ_LE_UINT32(_scriptPointer);
|
uint a = READ_LE_UINT32(_scriptPointer);
|
||||||
_scriptPointer += 4;
|
_scriptPointer += 4;
|
||||||
return a;
|
return a;
|
||||||
|
@ -898,7 +901,7 @@ void ScummEngine::runAllScripts() {
|
||||||
if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
|
if (vm.slot[i].cycle == cycle && vm.slot[i].status == ssRunning && !vm.slot[i].didexec) {
|
||||||
_currentScript = (byte)i;
|
_currentScript = (byte)i;
|
||||||
getScriptBaseAddress();
|
getScriptBaseAddress();
|
||||||
getScriptEntryPoint();
|
resetScriptPointer();
|
||||||
executeScript();
|
executeScript();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -753,9 +753,10 @@ protected:
|
||||||
void stopObjectScript(int script);
|
void stopObjectScript(int script);
|
||||||
|
|
||||||
void getScriptBaseAddress();
|
void getScriptBaseAddress();
|
||||||
void getScriptEntryPoint();
|
void resetScriptPointer();
|
||||||
int getVerbEntrypoint(int obj, int entry);
|
int getVerbEntrypoint(int obj, int entry);
|
||||||
|
|
||||||
|
void refreshScriptPointer();
|
||||||
byte fetchScriptByte();
|
byte fetchScriptByte();
|
||||||
virtual uint fetchScriptWord();
|
virtual uint fetchScriptWord();
|
||||||
virtual int fetchScriptWordSigned();
|
virtual int fetchScriptWordSigned();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue