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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun May 30 01:09:00 CEST 2010


Revision: 49316
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49316&view=rev
Author:   fingolfin
Date:     2010-05-29 23:09:00 +0000 (Sat, 29 May 2010)

Log Message:
-----------
SCI: Merge Script::relocateBlock and Object::relocate

The shared code now resides in a new static function named
relocateBlock, which is invoked by the two methods.

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

Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp	2010-05-29 21:42:42 UTC (rev 49315)
+++ scummvm/trunk/engines/sci/engine/segment.cpp	2010-05-29 23:09:00 UTC (rev 49316)
@@ -225,33 +225,34 @@
 	_objects.erase(obj_pos.toUint16());
 }
 
-int Script::relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location) {
+// This helper function is used by Script::relocateLocal and Object::relocate
+static bool relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location, size_t scriptSize) {
 	int rel = location - block_location;
 
 	if (rel < 0)
-		return 0;
+		return false;
 
 	uint idx = rel >> 1;
 
 	if (idx >= block.size())
-		return 0;
+		return false;
 
 	if (rel & 1) {
 		warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location);
-		return 0;
+		return false;
 	}
 	block[idx].segment = segment; // Perform relocation
 	if (getSciVersion() >= SCI_VERSION_1_1)
-		block[idx].offset += _scriptSize;
+		block[idx].offset += scriptSize;
 
-	return 1;
+	return true;
 }
 
-int Script::relocateLocal(SegmentId segment, int location) {
+bool Script::relocateLocal(SegmentId segment, int location) {
 	if (_localsBlock)
-		return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location);
+		return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location, _scriptSize);
 	else
-		return 0; // No hands, no cookies
+		return false;
 }
 
 void Script::scriptAddCodeBlock(reg_t location) {
@@ -745,25 +746,7 @@
 }
 
 bool Object::relocate(SegmentId segment, int location, size_t scriptSize) {
-	int rel = location - getPos().offset;
-
-	if (rel < 0)
-		return false;
-
-	uint idx = rel >> 1;
-
-	if (idx >= _variables.size())
-		return false;
-
-	if (rel & 1) {
-		warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, getPos().offset);
-		return false;
-	}
-	_variables[idx].segment = segment; // Perform relocation
-	if (getSciVersion() >= SCI_VERSION_1_1)
-		_variables[idx].offset += scriptSize;
-
-	return true;
+	return relocateBlock(_variables, getPos().offset, segment, location, scriptSize);
 }
 
 int Object::propertyOffsetToId(SegManager *segMan, int propertyOffset) const {

Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h	2010-05-29 21:42:42 UTC (rev 49315)
+++ scummvm/trunk/engines/sci/engine/segment.h	2010-05-29 23:09:00 UTC (rev 49316)
@@ -408,8 +408,7 @@
 	void heapRelocate(reg_t block);
 
 private:
-	int relocateLocal(SegmentId segment, int location);
-	int relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location);
+	bool relocateLocal(SegmentId segment, int location);
 
 public:
 	// script lock operations


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