aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorAndrew Kurushin2005-03-29 17:54:53 +0000
committerAndrew Kurushin2005-03-29 17:54:53 +0000
commit1b4b92c0f5d876d9a149a7631383369c11fffcb8 (patch)
tree3e165f98f779345d1d584be87071cd860bbc3da0 /saga
parentba98e11eb1d9b89b607644e32ea102379c312cb4 (diff)
downloadscummvm-rg350-1b4b92c0f5d876d9a149a7631383369c11fffcb8.tar.gz
scummvm-rg350-1b4b92c0f5d876d9a149a7631383369c11fffcb8.tar.bz2
scummvm-rg350-1b4b92c0f5d876d9a149a7631383369c11fffcb8.zip
endScene now aborts all running threads (fixing Okk stuckiness on way out of tent)
svn-id: r17286
Diffstat (limited to 'saga')
-rw-r--r--saga/scene.cpp6
-rw-r--r--saga/script.h4
-rw-r--r--saga/sthread.cpp62
3 files changed, 45 insertions, 27 deletions
diff --git a/saga/scene.cpp b/saga/scene.cpp
index 1033d5c80b..056d10705f 100644
--- a/saga/scene.cpp
+++ b/saga/scene.cpp
@@ -934,9 +934,9 @@ int Scene::endScene() {
_sceneProc(SCENE_END, &scene_info, this);
-/* if (_desc.scriptModuleNumber > 0) {
- _vm->_script->freeScript();
- }*/
+ //
+ _vm->_script->abortAllThreads();
+ _vm->_script->_skipSpeeches = false;
// Free scene background
if (_bg.loaded) {
diff --git a/saga/script.h b/saga/script.h
index 10be3ce886..4cb99f99c0 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -427,6 +427,7 @@ public:
int executeThreads(uint msec);
int SThreadDebugStep();
void completeThread(void);
+ void abortAllThreads(void);
void wakeUpActorThread(int waitType, void *threadObj);
void wakeUpThreads(int waitType);
@@ -436,7 +437,8 @@ private:
void loadModuleBase(ModuleData &module, const byte *resourcePointer, size_t resourceLength);
void loadModuleVoiceLUT(ModuleData &module, const byte *resourcePointer, size_t resourceLength);
- void runThread(ScriptThread *thread, uint instructionLimit);
+ // runThread returns true if we should break running of other threads
+ bool runThread(ScriptThread *thread, uint instructionLimit);
void setThreadEntrypoint(ScriptThread *thread, int entrypointNumber);
public:
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 7653a3c655..1354d2c0b9 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -142,8 +142,11 @@ int Script::executeThreads(uint msec) {
}
}
- if (!(thread->_flags & kTFlagWaiting))
- runThread(thread, STHREAD_TIMESLICE);
+ if (!(thread->_flags & kTFlagWaiting)) {
+ if (runThread(thread, STHREAD_TIMESLICE)) {
+ break;
+ }
+ }
++threadIterator;
}
@@ -151,6 +154,20 @@ int Script::executeThreads(uint msec) {
return SUCCESS;
}
+void Script::abortAllThreads(void) {
+ ScriptThread *thread;
+ ScriptThreadList::iterator threadIterator;
+
+ threadIterator = _threadList.begin();
+
+ while (threadIterator != _threadList.end()) {
+ thread = threadIterator.operator->();
+ thread->_flags |= kTFlagAborted;
+ ++threadIterator;
+ }
+ executeThreads(0);
+}
+
void Script::completeThread(void) {
for (int i = 0; i < 40 && !_threadList.isEmpty() ; i++)
executeThreads(0);
@@ -164,7 +181,7 @@ int Script::SThreadDebugStep() {
return SUCCESS;
}
-void Script::runThread(ScriptThread *thread, uint instructionLimit) {
+bool Script::runThread(ScriptThread *thread, uint instructionLimit) {
const char*operandName;
uint instructionCount;
uint16 savedInstructionOffset;
@@ -191,7 +208,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
instructionLimit = 1;
_dbg_dostep = 0;
} else {
- return;
+ return false;
}
}
@@ -320,9 +337,9 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
scriptFunction = _scriptFunctionsList[functionNumber].scriptFunction;
(this->*scriptFunction)(thread, argumentsCount);
- if (functionNumber == 16) { // SF_gotoScene
- instructionCount = instructionLimit; // break the loop
- break;
+ if (scriptFunction == sfScriptGotoScene) {
+ //if (functionNumber == 16) { // sfScriptGotoScene
+ return true; // cause abortAllThreads called and _this_ thread destroyed
}
if (operandChar == opCcall) {// CALL function
@@ -344,7 +361,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
thread->_frameIndex = thread->pop();
if (thread->pushedSize() == 0) {
thread->_flags |= kTFlagFinished;
- break;
+ return true;
} else {
thread->_instructionOffset = thread->pop();
iparam1 = thread->pop();
@@ -583,7 +600,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
if (_vm->_actor->isSpeaking()) {
thread->wait(kWaitTypeSpeech);
- return;
+ return false;
}
stringsCount = scriptS.readByte();
@@ -625,7 +642,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
CASEOP(opDialogBegin)
if (_conversingThread) {
thread->wait(kWaitTypeDialogBegin);
- return;
+ return false;
}
_conversingThread = thread;
_vm->_interface->converseClear();
@@ -674,23 +691,22 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
if (thread->_flags & (kTFlagFinished | kTFlagAborted)) {
- _vm->_console->DebugPrintf("Script finished\n");
- break;
- } else {
-
- // Set instruction offset only if a previous instruction didn't branch
- if (savedInstructionOffset == thread->_instructionOffset) {
- thread->_instructionOffset = scriptS.pos();
- } else {
- if (thread->_instructionOffset >= scriptS.size()) {
- error("Script::runThread() Out of range script execution");
- }
+ error("Wrong flags in thread");
+
+ }
- scriptS.seek(thread->_instructionOffset);
+ // Set instruction offset only if a previous instruction didn't branch
+ if (savedInstructionOffset == thread->_instructionOffset) {
+ thread->_instructionOffset = scriptS.pos();
+ } else {
+ if (thread->_instructionOffset >= scriptS.size()) {
+ error("Script::runThread() Out of range script execution");
}
- }
+ scriptS.seek(thread->_instructionOffset);
+ }
}
+ return false;
}
} // End of namespace Saga