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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Sep 6 14:58:17 CEST 2009


Revision: 43981
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43981&view=rev
Author:   fingolfin
Date:     2009-09-06 12:58:16 +0000 (Sun, 06 Sep 2009)

Log Message:
-----------
SCI: Cleanup for some SegManager internals

- rename segGet and getSegment to getScriptSegment; the two can be
  distinguished by the parameter count.
- rename type SCRIPT_GET to ScriptLoadType to conform with our code
  formatting conventions
- rename get_class_address to getClassAddress
- some cleanup

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kscripts.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/engine/memobj.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.h
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/engine/vm.h

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/console.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -2844,7 +2844,7 @@
 		if (*endptr)
 			return 1;
 
-		dest->segment = s->segMan->segGet(script_nr);
+		dest->segment = s->segMan->getScriptSegment(script_nr);
 
 		if (!dest->segment) {
 			return 1;

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -326,7 +326,7 @@
 	s->segMan = new SegManager(s->resMan);
 	s->gc_countdown = GC_INTERVAL - 1;
 
-	SegmentId script_000_segment = s->segMan->getSegment(0, SCRIPT_GET_LOCK);
+	SegmentId script_000_segment = s->segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
 
 	if (script_000_segment <= 0) {
 		debug(2, "Failed to instantiate script.000");

Modified: scummvm/trunk/engines/sci/engine/kscripts.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kscripts.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/kscripts.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -268,7 +268,7 @@
 	if (argv[0].segment)
 		return argv[0];
 
-	SegmentId scriptSeg = s->segMan->getSegment(script, SCRIPT_GET_LOAD);
+	SegmentId scriptSeg = s->segMan->getScriptSegment(script, SCRIPT_GET_LOAD);
 	Script *scr;
 
 	if (!scriptSeg)
@@ -297,7 +297,7 @@
 	if (argv[0].segment)
 		return s->r_acc;
 
-	int id = s->segMan->segGet(script);
+	int id = s->segMan->getScriptSegment(script);
 	Script *scr = s->segMan->getScriptIfLoaded(id);
 	if (scr) {
 		if (s->_executionStack.back().addr.pc.segment != id)

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -146,7 +146,7 @@
 		int synonyms_nr = 0;
 
 		script = GET_SEL32V(objpos, number);
-		seg = s->segMan->segGet(script);
+		seg = s->segMan->getScriptSegment(script);
 
 		if (seg >= 0)
 			synonyms_nr = s->segMan->getScript(seg)->getSynonymsNr();

Modified: scummvm/trunk/engines/sci/engine/memobj.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/memobj.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/memobj.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -319,9 +319,9 @@
 //-------------------- locals --------------------
 reg_t LocalVariables::findCanonicAddress(SegManager *segMan, reg_t addr) {
 	// Reference the owning script
-	SegmentId owner_seg = segMan->segGet(script_id);
+	SegmentId owner_seg = segMan->getScriptSegment(script_id);
 
-	assert(owner_seg >= 0);
+	assert(owner_seg > 0);
 
 	return make_reg(owner_seg, 0);
 }

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -714,7 +714,7 @@
 	reconstruct_scripts(retval, retval->segMan);
 	retval->segMan->reconstructClones();
 	retval->game_obj = s->game_obj;
-	retval->script_000 = retval->segMan->getScript(retval->segMan->getSegment(0, SCRIPT_GET_DONT_LOAD));
+	retval->script_000 = retval->segMan->getScript(retval->segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
 	retval->gc_countdown = GC_INTERVAL - 1;
 	retval->sys_strings_segment = retval->segMan->findSegmentByType(MEM_OBJ_SYS_STRINGS);
 	retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segMan, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS);

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -235,7 +235,7 @@
 
 
 int SegManager::deallocateScript(int script_nr) {
-	SegmentId seg = segGet(script_nr);
+	SegmentId seg = getScriptSegment(script_nr);
 
 	deallocate(seg, true);
 
@@ -262,13 +262,12 @@
 }
 
 // return the seg if script_id is valid and in the map, else -1
-SegmentId SegManager::segGet(int script_id) const {
+SegmentId SegManager::getScriptSegment(int script_id) const {
 	return id_seg_map->lookupKey(script_id);
 }
 
 Script *SegManager::getScript(const SegmentId seg) {
-	// FIXME: We accept segment 0, but that is actually an invalid segment...
-	if (seg < 0 || (uint)seg >= _heap.size()) {
+	if (seg <= 0 || (uint)seg >= _heap.size()) {
 		error("SegManager::getScript(): seg id %x out of bounds", seg);
 	}
 	if (!_heap[seg]) {
@@ -282,7 +281,7 @@
 
 Script *SegManager::getScriptIfLoaded(const SegmentId seg) {
 	// FIXME: We accept segment 0, but that is actually an invalid segment...
-	if (seg < 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT)
+	if (seg <= 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT)
 		return 0;
 	return (Script *)_heap[seg];
 }
@@ -299,8 +298,7 @@
 //	false - invalid seg
 //	true  - valid seg
 bool SegManager::check(SegmentId seg) {
-	// FIXME: We accept segment 0, but that is actually an invalid segment...
-	if (seg < 0 || (uint)seg >= _heap.size()) {
+	if (seg <= 0 || (uint)seg >= _heap.size()) {
 		return false;
 	}
 	if (!_heap[seg]) {
@@ -443,13 +441,13 @@
 	}
 }
 
-SegmentId SegManager::getSegment(int script_nr, SCRIPT_GET load) {
+SegmentId SegManager::getScriptSegment(int script_nr, ScriptLoadType load) {
 	SegmentId segment;
 
 	if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD)
 		script_instantiate(_resMan, this, script_nr);
 
-	segment = segGet(script_nr);
+	segment = getScriptSegment(script_nr);
 
 	if (segment > 0) {
 		if ((load & SCRIPT_GET_LOCK) == SCRIPT_GET_LOCK)
@@ -457,19 +455,19 @@
 
 		return segment;
 	} else
-		return 0;
+		return -1;
 }
 
-#define INST_LOOKUP_CLASS(id) ((id == 0xffff) ? NULL_REG : get_class_address(id, SCRIPT_GET_LOCK, NULL_REG))
+#define INST_LOOKUP_CLASS(id) ((id == 0xffff) ? NULL_REG : getClassAddress(id, SCRIPT_GET_LOCK, NULL_REG))
 
-reg_t SegManager::get_class_address(int classnr, SCRIPT_GET lock, reg_t caller) {
+reg_t SegManager::getClassAddress(int classnr, ScriptLoadType lock, reg_t caller) {
 	if (classnr < 0 || (int)_classtable.size() <= classnr || _classtable[classnr].script < 0) {
 		error("[VM] Attempt to dereference class %x, which doesn't exist (max %x)", classnr, _classtable.size());
 		return NULL_REG;
 	} else {
 		Class *the_class = &_classtable[classnr];
 		if (!the_class->reg.segment) {
-			getSegment(the_class->script, lock);
+			getScriptSegment(the_class->script, lock);
 
 			if (!the_class->reg.segment) {
 				error("[VM] Trying to instantiate class %x by instantiating script 0x%x (%03d) failed;"

Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h	2009-09-06 12:58:16 UTC (rev 43981)
@@ -44,24 +44,24 @@
 		: NULL): NULL)
 
 /**
- * Parameters for getSegment()
+ * Parameters for getScriptSegment().
  */
-typedef enum {
+enum ScriptLoadType {
 	SCRIPT_GET_DONT_LOAD = 0, /**< Fail if not loaded */
 	SCRIPT_GET_LOAD = 1, /**< Load, if neccessary */
 	SCRIPT_GET_LOCK = 3 /**< Load, if neccessary, and lock */
-} SCRIPT_GET;
+};
 
 
 class SegManager : public Common::Serializable {
 public:
 	/**
-	 * Initialize the segment manager
+	 * Initialize the segment manager.
 	 */
 	SegManager(ResourceManager *resMan);
 
 	/**
-	 * Deallocate all memory associated with the segment manager
+	 * Deallocate all memory associated with the segment manager.
 	 */
 	~SegManager();
 
@@ -70,7 +70,7 @@
 	// 1. Scripts
 
 	/**
-	 * Allocate a script into the segment manager
+	 * Allocate a script into the segment manager.
 	 * @param script_nr		The number of the script to load
 	 * @param seg_id		The segment ID of the newly allocated segment,
 	 * 						on success
@@ -81,7 +81,7 @@
 	// The script must then be initialised; see section (1b.), below.
 
 	/**
-	 * Forcefully deallocate a previously allocated script
+	 * Forcefully deallocate a previously allocated script.
 	 * @param script_nr		number of the script to deallocate
 	 * @return				1 on success, 0 on failure
 	 */
@@ -95,7 +95,7 @@
 
 	/**
 	 * Validate whether the specified public function is exported by 
-	 * the script in the specified segment
+	 * the script in the specified segment.
 	 * @param pubfunct		Index of the function to validate
 	 * @param seg			Segment ID of the script the check is to 
 	 * 						be performed for
@@ -105,14 +105,25 @@
 	uint16 validateExportFunc(int pubfunct, SegmentId seg);
 
 	/**
-	 * Get the segment ID associated with a script number
+	 * Determines the segment occupied by a certain script, if any.
 	 * @param script_nr		Number of the script to look up
-	 * @return				The associated segment ID, or -1 if no 
-	 * 						matching segment exists
+	 * @return				The script's segment ID, or -1 on failure
 	 */
-	SegmentId segGet(int script_nr) const;
+	SegmentId getScriptSegment(int script_nr) const;
 
 	/**
+	 * Determines the segment occupied by a certain script. Optionally
+	 * load it, or load & lock it.
+	 * @param[in] script_nr	Number of the script to look up
+	 * @param[in] load		flag determining whether to load/lock the script
+	 * @return				The script's segment ID, or -1 on failure
+	 */
+	SegmentId getScriptSegment(int script_nr, ScriptLoadType load);
+
+	// TODO: document this
+	reg_t getClassAddress(int classnr, ScriptLoadType lock, reg_t caller);
+
+	/**
 	 * Return a pointer to the specified script.
 	 * If the id is invalid, does not refer to a script or the script is 
 	 * not loaded, this will invoke error().
@@ -335,16 +346,7 @@
 	 */
 	byte *dereference(reg_t reg, int *size);
 
-	/**
-	 * Determines the segment occupied by a certain script
-	 * @param[in] script_id	The script in question
-	 * @param[in] load		One of SCRIPT_GET_*
-	 * @return				The script's segment, or 0 on failure
-	 */
-	SegmentId getSegment(int script_nr, SCRIPT_GET load);
-	reg_t get_class_address(int classnr, SCRIPT_GET lock, reg_t caller);
 
-
 	void heapRelocate(reg_t block);
 	void scriptRelocateExportsSci11(SegmentId seg);
 	void scriptInitialiseObjectsSci11(SegmentId seg);

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-09-06 12:58:16 UTC (rev 43981)
@@ -204,7 +204,7 @@
 #define GET_OP_SIGNED_FLEX() ((opcode & 1)? GET_OP_SIGNED_BYTE() : GET_OP_SIGNED_WORD())
 
 ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) {
-	int seg = s->segMan->segGet(script);
+	int seg = s->segMan->getScriptSegment(script);
 	Script *scr = s->segMan->getScriptIfLoaded(seg);
 
 	if (!scr)  // Script not present yet?
@@ -212,7 +212,7 @@
 	else
 		scr->unmarkDeleted();
 
-	int temp = s->segMan->validateExportFunc(pubfunct, seg);
+	const int temp = s->segMan->validateExportFunc(pubfunct, seg);
 	if (!temp) {
 		error("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script);
 		return NULL;
@@ -1042,7 +1042,7 @@
 			break;
 
 		case 0x28: // class
-			s->r_acc = s->segMan->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK,
+			s->r_acc = s->segMan->getClassAddress((unsigned)opparams[0], SCRIPT_GET_LOCK,
 											scriptState.xs->addr.pc);
 			break;
 
@@ -1062,7 +1062,7 @@
 			break;
 
 		case 0x2b: // super
-			r_temp = s->segMan->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc);
+			r_temp = s->segMan->getClassAddress(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc);
 
 			if (!r_temp.segment)
 				error("[VM]: Invalid superclass in object");
@@ -1506,11 +1506,11 @@
 }
 
 reg_t script_lookup_export(SegManager *segMan, int script_nr, int export_index) {
-	SegmentId seg = segMan->getSegment(script_nr, SCRIPT_GET_DONT_LOAD);
+	SegmentId seg = segMan->getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD);
 	return make_reg(seg, segMan->validateExportFunc(export_index, seg));
 }
 
-#define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segMan->get_class_address(id, SCRIPT_GET_LOCK, reg))
+#define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segMan->getClassAddress(id, SCRIPT_GET_LOCK, reg))
 
 int script_instantiate_common(ResourceManager *resMan, SegManager *segMan, int script_nr, Resource **script, Resource **heap, int *was_new) {
 	int seg_id;
@@ -1533,7 +1533,7 @@
 		return 0;
 	}
 
-	seg_id = segMan->segGet(script_nr);
+	seg_id = segMan->getScriptSegment(script_nr);
 	Script *scr = segMan->getScriptIfLoaded(seg_id);
 	if (scr) {
 		if (!scr->isMarkedAsDeleted()) {
@@ -1821,7 +1821,7 @@
 }
 
 void script_uninstantiate(SegManager *segMan, int script_nr) {
-	SegmentId segment = segMan->segGet(script_nr);
+	SegmentId segment = segMan->getScriptSegment(script_nr);
 	Script *scr = segMan->getScriptIfLoaded(segment);
 
 	if (!scr) {   // Is it already loaded?

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2009-09-06 12:57:42 UTC (rev 43980)
+++ scummvm/trunk/engines/sci/engine/vm.h	2009-09-06 12:58:16 UTC (rev 43981)
@@ -344,7 +344,7 @@
 	StackPtr sp, int framesize, StackPtr argp);
 
 
-#define SCI_XS_CALLEE_LOCALS -1
+#define SCI_XS_CALLEE_LOCALS ((SegmentId)-1)
 
 /**
  * Adds an entry to the top of the execution stack.


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