[Scummvm-cvs-logs] SF.net SVN: scummvm:[39934] scummvm/trunk/engines/saga

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sat Apr 11 14:46:00 CEST 2009


Revision: 39934
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39934&view=rev
Author:   thebluegr
Date:     2009-04-11 12:46:00 +0000 (Sat, 11 Apr 2009)

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/engines/saga/script.h
    scummvm/trunk/engines/saga/sfuncs.cpp
    scummvm/trunk/engines/saga/sthread.cpp

Modified: scummvm/trunk/engines/saga/script.h
===================================================================
--- scummvm/trunk/engines/saga/script.h	2009-04-11 12:44:27 UTC (rev 39933)
+++ scummvm/trunk/engines/saga/script.h	2009-04-11 12:46:00 UTC (rev 39934)
@@ -267,7 +267,7 @@
 	}
 };
 
-typedef Common::List<ScriptThread> ScriptThreadList;
+typedef Common::List<ScriptThread*> 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 @@
 	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:

Modified: scummvm/trunk/engines/saga/sfuncs.cpp
===================================================================
--- scummvm/trunk/engines/saga/sfuncs.cpp	2009-04-11 12:44:27 UTC (rev 39933)
+++ scummvm/trunk/engines/saga/sfuncs.cpp	2009-04-11 12:46:00 UTC (rev 39934)
@@ -399,7 +399,7 @@
 	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;

Modified: scummvm/trunk/engines/saga/sthread.cpp
===================================================================
--- scummvm/trunk/engines/saga/sthread.cpp	2009-04-11 12:44:27 UTC (rev 39933)
+++ scummvm/trunk/engines/saga/sthread.cpp	2009-04-11 12:46:00 UTC (rev 39934)
@@ -61,18 +61,18 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 			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 @@
 	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 @@
 		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)


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list