[Scummvm-cvs-logs] SF.net SVN: scummvm:[50548] scummvm/trunk/engines/sci/engine/seg_manager. cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jul 1 18:04:04 CEST 2010


Revision: 50548
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50548&view=rev
Author:   fingolfin
Date:     2010-07-01 16:04:04 +0000 (Thu, 01 Jul 2010)

Log Message:
-----------
SCI: Simplify SegManager::findObjectByName

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/seg_manager.cpp

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-07-01 14:59:58 UTC (rev 50547)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-07-01 16:04:04 UTC (rev 50548)
@@ -263,78 +263,58 @@
 }
 
 reg_t SegManager::findObjectByName(const Common::String &name, int index) {
-	reg_t retVal = NULL_REG;
+	Common::Array<reg_t> result;
+	uint i;
 
 	// Now all values are available; iterate over all objects.
-	int timesFound = 0;
-	for (uint i = 0; i < _heap.size(); i++) {
-		SegmentObj *mobj = _heap[i];
-		int idx = 0;
-		int max_index = 0;
-		ObjMap::iterator it;
-		Script *scr = 0;
-		CloneTable *ct = 0;
+	for (i = 0; i < _heap.size(); i++) {
+		const SegmentObj *mobj = _heap[i];
 
-		if (mobj) {
-			if (mobj->getType() == SEG_TYPE_SCRIPT) {
-				scr = (Script *)mobj;
-				max_index = scr->_objects.size();
-				it = scr->_objects.begin();
-			} else if (mobj->getType() == SEG_TYPE_CLONES) {
-				ct = (CloneTable *)mobj;
-				max_index = ct->_table.size();
-			}
-		}
+		if (!mobj)
+			continue;
 
-		// It's a script or a clone table, scan all objects in it
-		for (; idx < max_index; ++idx) {
-			const Object *obj = NULL;
-			reg_t objpos;
-			objpos.offset = 0;
-			objpos.segment = i;
+		reg_t objpos = make_reg(i, 0);
 
-			if (mobj->getType() == SEG_TYPE_SCRIPT) {
-				obj = &(it->_value);
-				objpos.offset = obj->getPos().offset;
-				++it;
-			} else if (mobj->getType() == SEG_TYPE_CLONES) {
+		if (mobj->getType() == SEG_TYPE_SCRIPT) {
+			// It's a script, scan all objects in it
+			const Script *scr = (const Script *)mobj;
+			for (ObjMap::const_iterator it = scr->_objects.begin(); it != scr->_objects.end(); ++it) {
+				objpos.offset = it->_value.getPos().offset;
+				if (name == getObjectName(objpos))
+					result.push_back(objpos);
+			}
+		} else  if (mobj->getType() == SEG_TYPE_CLONES) {
+			// It's clone table, scan all objects in it
+			const CloneTable *ct = (const CloneTable *)mobj;
+			for (uint idx = 0; idx < ct->_table.size(); ++idx) {
 				if (!ct->isValidEntry(idx))
 					continue;
-				obj = &(ct->_table[idx]);
+
 				objpos.offset = idx;
+				if (name == getObjectName(objpos))
+					result.push_back(objpos);
 			}
-
-			const char *objname = getObjectName(objpos);
-			if (name == objname) {
-				// Found a match!
-				if ((index < 0) && (timesFound > 0)) {
-					if (timesFound == 1) {
-						// First time we realized the ambiguity
-						printf("Ambiguous:\n");
-						printf("  %3x: [%04x:%04x] %s\n", 0, PRINT_REG(retVal), name.c_str());
-					}
-					printf("  %3x: [%04x:%04x] %s\n", timesFound, PRINT_REG(objpos), name.c_str());
-				}
-				if (index < 0 || timesFound == index)
-					retVal = objpos;
-				++timesFound;
-			}
 		}
-
 	}
 
-	if (!timesFound)
+	if (result.empty())
 		return NULL_REG;
 
-	if (timesFound > 1 && index < 0) {
-		printf("Ambiguous: Aborting.\n");
-		return NULL_REG; // Ambiguous
+	if (result.size() > 1) {
+		printf("Ambiguous:\n");
+		for (i = 0; i < result.size(); i++)
+			printf("  %3x: [%04x:%04x] %s\n", i, PRINT_REG(result[i]), name.c_str());
+		if (index < 0) {
+			printf("Ambiguous: Aborting.\n");
+			return NULL_REG; // Ambiguous
+		}
 	}
 
-	if (timesFound <= index)
+	if (index < 0)
+		return result[0];
+	else if (result.size() <= (uint)index)
 		return NULL_REG; // Not found
-
-	return retVal;
+	return result[index];
 }
 
 // validate the seg


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