From 448a98b8859c222155399462c646c10592ffe2e4 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 11 Apr 2009 12:46:00 +0000 Subject: Changed ScriptThreadList to hold a list of pointers, not a list of instances. This avoids the whole &* mess, as well as the strange references to the list head svn-id: r39934 --- engines/saga/script.h | 4 +-- engines/saga/sfuncs.cpp | 2 +- engines/saga/sthread.cpp | 88 ++++++++++++++++++++++++------------------------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/engines/saga/script.h b/engines/saga/script.h index d252518729..fd4a4df0f3 100644 --- a/engines/saga/script.h +++ b/engines/saga/script.h @@ -267,7 +267,7 @@ public: } }; -typedef Common::List ScriptThreadList; +typedef Common::List ScriptThreadList; #define SCRIPTOP_PARAMS ScriptThread *thread, MemoryReadStream *scriptS, bool &stopParsing, bool &breakOut #define SCRIPTFUNC_PARAMS ScriptThread *thread, int nArgs, bool &disContinue @@ -397,7 +397,7 @@ protected: void loadModuleBase(ModuleData &module, const byte *resourcePointer, size_t resourceLength); // runThread returns true if we should break running of other threads - bool runThread(ScriptThread &thread); + bool runThread(ScriptThread *thread); void setThreadEntrypoint(ScriptThread *thread, int entrypointNumber); public: diff --git a/engines/saga/sfuncs.cpp b/engines/saga/sfuncs.cpp index 8c09934ad2..3010fb696d 100644 --- a/engines/saga/sfuncs.cpp +++ b/engines/saga/sfuncs.cpp @@ -399,7 +399,7 @@ void Script::sfKillActorThreads(SCRIPTFUNC_PARAMS) { int16 actorId = thread->pop(); for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - anotherThread = &*threadIterator; + anotherThread = *threadIterator; if ((anotherThread != thread) && (anotherThread->_threadVars[kThreadVarActor] == actorId)) { anotherThread->_flags &= ~kTFlagWaiting; anotherThread->_flags |= kTFlagAborted; diff --git a/engines/saga/sthread.cpp b/engines/saga/sthread.cpp index 177cabb729..26942d3445 100644 --- a/engines/saga/sthread.cpp +++ b/engines/saga/sthread.cpp @@ -61,18 +61,18 @@ ScriptThread *Script::createThread(uint16 scriptModuleNumber, uint16 scriptEntry else newThread->_voiceLUT = &_modules[scriptModuleNumber].voiceLUT; - _threadList.push_front(*newThread); + _threadList.push_front(newThread); - return &*_threadList.begin(); + return newThread; } void Script::wakeUpActorThread(int waitType, void *threadObj) { ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - ScriptThread &thread = *threadIterator; - if ((thread._flags & kTFlagWaiting) && (thread._waitType == waitType) && (thread._threadObj == threadObj)) { - thread._flags &= ~kTFlagWaiting; + ScriptThread *thread = *threadIterator; + if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType) && (thread->_threadObj == threadObj)) { + thread->_flags &= ~kTFlagWaiting; } } } @@ -81,9 +81,9 @@ void Script::wakeUpThreads(int waitType) { ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - ScriptThread &thread = *threadIterator; - if ((thread._flags & kTFlagWaiting) && (thread._waitType == waitType)) { - thread._flags &= ~kTFlagWaiting; + ScriptThread *thread = *threadIterator; + if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType)) { + thread->_flags &= ~kTFlagWaiting; } } } @@ -92,10 +92,10 @@ void Script::wakeUpThreadsDelayed(int waitType, int sleepTime) { ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - ScriptThread &thread = *threadIterator; - if ((thread._flags & kTFlagWaiting) && (thread._waitType == waitType)) { - thread._waitType = kWaitTypeDelay; - thread._sleepTime = sleepTime; + ScriptThread *thread = *threadIterator; + if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType)) { + thread->_waitType = kWaitTypeDelay; + thread->_sleepTime = sleepTime; } } } @@ -110,15 +110,15 @@ void Script::executeThreads(uint msec) { threadIterator = _threadList.begin(); while (threadIterator != _threadList.end()) { - ScriptThread &thread = *threadIterator; + ScriptThread *thread = *threadIterator; - if (thread._flags & (kTFlagFinished | kTFlagAborted)) { - if (thread._flags & kTFlagFinished) + if (thread->_flags & (kTFlagFinished | kTFlagAborted)) { + if (thread->_flags & kTFlagFinished) setPointerVerb(); if (_vm->getGameId() == GID_IHNM) { - thread._flags &= ~kTFlagFinished; - thread._flags |= kTFlagAborted; + thread->_flags &= ~kTFlagFinished; + thread->_flags |= kTFlagAborted; ++threadIterator; } else { threadIterator = _threadList.erase(threadIterator); @@ -126,38 +126,38 @@ void Script::executeThreads(uint msec) { continue; } - if (thread._flags & kTFlagWaiting) { + if (thread->_flags & kTFlagWaiting) { - switch (thread._waitType) { + switch (thread->_waitType) { case kWaitTypeDelay: - if (thread._sleepTime < msec) { - thread._sleepTime = 0; + if (thread->_sleepTime < msec) { + thread->_sleepTime = 0; } else { - thread._sleepTime -= msec; + thread->_sleepTime -= msec; } - if (thread._sleepTime == 0) - thread._flags &= ~kTFlagWaiting; + if (thread->_sleepTime == 0) + thread->_flags &= ~kTFlagWaiting; break; case kWaitTypeWalk: { ActorData *actor; - actor = (ActorData *)thread._threadObj; + actor = (ActorData *)thread->_threadObj; if (actor->_currentAction == kActionWait) { - thread._flags &= ~kTFlagWaiting; + thread->_flags &= ~kTFlagWaiting; } } break; case kWaitTypeWaitFrames: // IHNM - if (thread._frameWait < _vm->_frameCount) - thread._flags &= ~kTFlagWaiting; + if (thread->_frameWait < _vm->_frameCount) + thread->_flags &= ~kTFlagWaiting; break; } } - if (!(thread._flags & kTFlagWaiting)) { + if (!(thread->_flags & kTFlagWaiting)) { if (runThread(thread)) { break; } @@ -174,8 +174,8 @@ void Script::abortAllThreads(void) { threadIterator = _threadList.begin(); while (threadIterator != _threadList.end()) { - ScriptThread &thread = *threadIterator; - thread._flags |= kTFlagAborted; + ScriptThread *thread = *threadIterator; + thread->_flags |= kTFlagAborted; ++threadIterator; } executeThreads(0); @@ -188,44 +188,44 @@ void Script::completeThread(void) { executeThreads(0); } -bool Script::runThread(ScriptThread &thread) { +bool Script::runThread(ScriptThread *thread) { uint16 savedInstructionOffset; bool stopParsing = false; bool breakOut = false; int operandChar; - MemoryReadStream scriptS(thread._moduleBase, thread._moduleBaseSize); + MemoryReadStream scriptS(thread->_moduleBase, thread->_moduleBaseSize); - scriptS.seek(thread._instructionOffset); + scriptS.seek(thread->_instructionOffset); for (uint instructionCount = 0; instructionCount < STHREAD_TIMESLICE; instructionCount++) { - if (thread._flags & (kTFlagAsleep)) + if (thread->_flags & (kTFlagAsleep)) break; - savedInstructionOffset = thread._instructionOffset; + savedInstructionOffset = thread->_instructionOffset; operandChar = scriptS.readByte(); - debug(8, "Executing thread offset: %u (%x) stack: %d", thread._instructionOffset, operandChar, thread.pushedSize()); + debug(8, "Executing thread offset: %u (%x) stack: %d", thread->_instructionOffset, operandChar, thread->pushedSize()); stopParsing = false; debug(4, "Calling op %s", this->_scriptOpsList[operandChar].scriptOpName); - (this->*_scriptOpsList[operandChar].scriptOp)(&thread, &scriptS, stopParsing, breakOut); + (this->*_scriptOpsList[operandChar].scriptOp)(thread, &scriptS, stopParsing, breakOut); if (stopParsing) return breakOut; - if (thread._flags & (kTFlagFinished | kTFlagAborted)) { - error("Wrong flags %d in thread", thread._flags); + if (thread->_flags & (kTFlagFinished | kTFlagAborted)) { + error("Wrong flags %d in thread", thread->_flags); } // Set instruction offset only if a previous instruction didn't branch - if (savedInstructionOffset == thread._instructionOffset) { - thread._instructionOffset = scriptS.pos(); + if (savedInstructionOffset == thread->_instructionOffset) { + thread->_instructionOffset = scriptS.pos(); } else { - if (thread._instructionOffset >= scriptS.size()) { + if (thread->_instructionOffset >= scriptS.size()) { error("Script::runThread() Out of range script execution"); } - scriptS.seek(thread._instructionOffset); + scriptS.seek(thread->_instructionOffset); } if (breakOut) -- cgit v1.2.3