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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Apr 11 02:29:12 CEST 2009


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

Log Message:
-----------
SAGA: Stop needlessly using operator*() and operator->() (many of the resulting &* uses can be removed if references are used instead of pointers everywhere, which would be a good idea anyway)

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/events.cpp
    scummvm/trunk/engines/saga/font.h
    scummvm/trunk/engines/saga/scene.cpp
    scummvm/trunk/engines/saga/script.h
    scummvm/trunk/engines/saga/sfuncs.cpp
    scummvm/trunk/engines/saga/sthread.cpp

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2009-04-11 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/actor.cpp	2009-04-11 00:29:12 UTC (rev 39920)
@@ -944,7 +944,7 @@
 	createDrawOrderList();
 
 	for (drawOrderIterator = _drawOrderList.begin(); drawOrderIterator != _drawOrderList.end(); ++drawOrderIterator) {
-		drawObject = drawOrderIterator.operator*();
+		drawObject = *drawOrderIterator;
 		if (skipProtagonist && (drawObject == _protagonist)) {
 			continue;
 		}
@@ -1070,7 +1070,7 @@
 	createDrawOrderList();
 
 	for (drawOrderIterator = _drawOrderList.begin(); drawOrderIterator != _drawOrderList.end(); ++drawOrderIterator) {
-		drawObject = drawOrderIterator.operator*();
+		drawObject = *drawOrderIterator;
 
 		if (!getSpriteParams(drawObject, frameNumber, spriteList)) {
 			continue;

Modified: scummvm/trunk/engines/saga/events.cpp
===================================================================
--- scummvm/trunk/engines/saga/events.cpp	2009-04-11 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/events.cpp	2009-04-11 00:29:12 UTC (rev 39920)
@@ -56,8 +56,6 @@
 // First advances event times, then processes each event with the appropriate
 // handler depending on the type of event.
 int Events::handleEvents(long msec) {
-	Event *event_p;
-
 	long delta_time;
 	int result;
 
@@ -66,7 +64,7 @@
 
 	// Process each event in list
 	for (EventList::iterator eventi = _eventList.begin(); eventi != _eventList.end(); ++eventi) {
-		event_p = (Event *)eventi.operator->();
+		Event *event_p = &*eventi;
 
 		// Call the appropriate event handler for the specific event type
 		switch (event_p->type) {
@@ -582,7 +580,7 @@
 Event *Events::queue(Event *event) {
 	Event *queuedEvent;
 
-	queuedEvent = _eventList.pushBack(*event).operator->();
+	queuedEvent = &*_eventList.pushBack(*event);
 	initializeEvent(queuedEvent);
 
 	return queuedEvent;
@@ -628,25 +626,23 @@
 int Events::clearList(bool playQueuedMusic) {
 	Event *chain_walk;
 	Event *next_chain;
-	Event *event_p;
 
 	// Walk down event list
 	for (EventList::iterator eventi = _eventList.begin(); eventi != _eventList.end(); ++eventi) {
-		event_p = (Event *)eventi.operator->();
 
 		// Only remove events not marked kEvFNoDestory (engine events)
-		if (!(event_p->code & kEvFNoDestory)) {
+		if (!(eventi->code & kEvFNoDestory)) {
 			// Handle queued music change events before deleting them
 			// This can happen in IHNM by music events set by sfQueueMusic()
 			// Fixes bug #2057987 - "IHNM: Music stops in Ellen's chapter"
-			if (playQueuedMusic && ((event_p->code & EVENT_MASK) == kMusicEvent)) {
+			if (playQueuedMusic && ((eventi->code & EVENT_MASK) == kMusicEvent)) {
 				_vm->_music->stop();
-				if (event_p->op == kEventPlay)
-					_vm->_music->play(event_p->param, (MusicFlags)event_p->param2);
+				if (eventi->op == kEventPlay)
+					_vm->_music->play(eventi->param, (MusicFlags)eventi->param2);
 			}
 
 			// Remove any events chained off this one
-			for (chain_walk = event_p->chain; chain_walk != NULL; chain_walk = next_chain) {
+			for (chain_walk = eventi->chain; chain_walk != NULL; chain_walk = next_chain) {
 				next_chain = chain_walk->chain;
 				free(chain_walk);
 			}
@@ -661,19 +657,17 @@
 int Events::freeList() {
 	Event *chain_walk;
 	Event *next_chain;
-	Event *event_p;
 
 	// Walk down event list
 	EventList::iterator eventi = _eventList.begin();
 	while (eventi != _eventList.end()) {
-		event_p = (Event *)eventi.operator->();
 
 		// Remove any events chained off this one */
-		for (chain_walk = event_p->chain; chain_walk != NULL; chain_walk = next_chain) {
+		for (chain_walk = eventi->chain; chain_walk != NULL; chain_walk = next_chain) {
 			next_chain = chain_walk->chain;
 			free(chain_walk);
 		}
-		eventi=_eventList.erase(eventi);
+		eventi = _eventList.erase(eventi);
 	}
 
 	return SUCCESS;
@@ -681,16 +675,13 @@
 
 // Walks down the event list, updating event times by 'msec'.
 int Events::processEventTime(long msec) {
-	Event *event_p;
 	uint16 event_count = 0;
 
 	for (EventList::iterator eventi = _eventList.begin(); eventi != _eventList.end(); ++eventi) {
-		event_p = (Event *)eventi.operator->();
-
-		event_p->time -= msec;
+		eventi->time -= msec;
 		event_count++;
 
-		if (event_p->type == kEvTImmediate)
+		if (eventi->type == kEvTImmediate)
 			break;
 
 		if (event_count > EVENT_WARNINGCOUNT) {

Modified: scummvm/trunk/engines/saga/font.h
===================================================================
--- scummvm/trunk/engines/saga/font.h	2009-04-11 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/font.h	2009-04-11 00:29:12 UTC (rev 39920)
@@ -94,7 +94,7 @@
 public:
 
 	TextListEntry *addEntry(const TextListEntry &entry) {
-		return pushBack(entry).operator->();
+		return &*pushBack(entry);
 	}
 };
 

Modified: scummvm/trunk/engines/saga/scene.cpp
===================================================================
--- scummvm/trunk/engines/saga/scene.cpp	2009-04-11 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/scene.cpp	2009-04-11 00:29:12 UTC (rev 39920)
@@ -252,10 +252,8 @@
 }
 
 void Scene::drawTextList() {
-	TextListEntry *entry;
+	for (TextList::iterator entry = _textList.begin(); entry != _textList.end(); ++entry) {
 
-	for (TextList::iterator textIterator = _textList.begin(); textIterator != _textList.end(); ++textIterator) {
-		entry = (TextListEntry *)textIterator.operator->();
 		if (entry->display) {
 
 			if (entry->useRect) {
@@ -317,7 +315,7 @@
 		return;
 	}
 
-	sceneQueue = queueIterator.operator->();
+	sceneQueue = &*queueIterator;
 
 	loadScene(sceneQueue);
 }
@@ -378,7 +376,7 @@
 	}
 
 	// Load the head in scene queue
-	sceneQueue = queueIterator.operator->();
+	sceneQueue = &*queueIterator;
 
 	loadScene(sceneQueue);
 }
@@ -405,7 +403,7 @@
 
 	++queueIterator;
 	while (queueIterator != _sceneQueue.end()) {
-		sceneQueue = queueIterator.operator->();
+		sceneQueue = &*queueIterator;
 		assert(sceneQueue != NULL);
 
 		if (sceneQueue->sceneSkipTarget) {

Modified: scummvm/trunk/engines/saga/script.h
===================================================================
--- scummvm/trunk/engines/saga/script.h	2009-04-11 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/script.h	2009-04-11 00:29:12 UTC (rev 39920)
@@ -398,7 +398,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 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/sfuncs.cpp	2009-04-11 00:29:12 UTC (rev 39920)
@@ -399,7 +399,7 @@
 	int16 actorId = thread->pop();
 
 	for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) {
-		anotherThread = threadIterator.operator->();
+		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 00:28:49 UTC (rev 39919)
+++ scummvm/trunk/engines/saga/sthread.cpp	2009-04-11 00:29:12 UTC (rev 39920)
@@ -45,10 +45,10 @@
 		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 @@
 }
 
 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 @@
 	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 @@
 			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::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 @@
 		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