diff options
Diffstat (limited to 'engines/saga/sthread.cpp')
-rw-r--r-- | engines/saga/sthread.cpp | 93 |
1 files changed, 44 insertions, 49 deletions
diff --git a/engines/saga/sthread.cpp b/engines/saga/sthread.cpp index 3dc6bd57d2..70a73038a9 100644 --- a/engines/saga/sthread.cpp +++ b/engines/saga/sthread.cpp @@ -45,10 +45,10 @@ ScriptThread *Script::createThread(uint16 scriptModuleNumber, uint16 scriptEntry error("Script::createThread wrong scriptEntryPointNumber"); } - newThread = _threadList.pushFront().operator->(); + newThread = &(*_threadList.pushFront()); newThread->_flags = kTFlagNone; newThread->_stackSize = DEFAULT_THREAD_STACK_SIZE; - newThread->_stackBuf = (uint16 *)malloc(newThread->_stackSize * sizeof(*newThread->_stackBuf)); + newThread->_stackBuf = (uint16 *)malloc(newThread->_stackSize * sizeof(uint16)); newThread->_stackTopIndex = newThread->_stackSize - 2; newThread->_instructionOffset = _modules[scriptModuleNumber].entryPoints[scriptEntryPointNumber].offset; newThread->_commonBase = _commonBuffer; @@ -67,44 +67,40 @@ ScriptThread *Script::createThread(uint16 scriptModuleNumber, uint16 scriptEntry } void Script::wakeUpActorThread(int waitType, void *threadObj) { - ScriptThread *thread; ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - thread = threadIterator.operator->(); - 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; } } } void Script::wakeUpThreads(int waitType) { - ScriptThread *thread; ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - thread = threadIterator.operator->(); - if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType)) { - thread->_flags &= ~kTFlagWaiting; + ScriptThread &thread = *threadIterator; + if ((thread._flags & kTFlagWaiting) && (thread._waitType == waitType)) { + thread._flags &= ~kTFlagWaiting; } } } void Script::wakeUpThreadsDelayed(int waitType, int sleepTime) { - ScriptThread *thread; ScriptThreadList::iterator threadIterator; for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) { - thread = threadIterator.operator->(); - 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; } } } void Script::executeThreads(uint msec) { - ScriptThread *thread; ScriptThreadList::iterator threadIterator; if (_vm->_interface->_statusTextInput) { @@ -114,15 +110,15 @@ void Script::executeThreads(uint msec) { threadIterator = _threadList.begin(); while (threadIterator != _threadList.end()) { - thread = threadIterator.operator->(); + 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); @@ -130,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; } @@ -173,14 +169,13 @@ void Script::executeThreads(uint msec) { } void Script::abortAllThreads(void) { - ScriptThread *thread; ScriptThreadList::iterator threadIterator; threadIterator = _threadList.begin(); while (threadIterator != _threadList.end()) { - thread = threadIterator.operator->(); - thread->_flags |= kTFlagAborted; + ScriptThread &thread = *threadIterator; + thread._flags |= kTFlagAborted; ++threadIterator; } executeThreads(0); @@ -193,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) |