[Scummvm-cvs-logs] SF.net SVN: scummvm:[40598] scummvm/trunk/engines/sci/engine
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Fri May 15 11:27:44 CEST 2009
Revision: 40598
http://scummvm.svn.sourceforge.net/scummvm/?rev=40598&view=rev
Author: fingolfin
Date: 2009-05-15 09:27:39 +0000 (Fri, 15 May 2009)
Log Message:
-----------
SCI: Added SegManager::getScriptIfLoaded() method
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/kscripts.cpp
scummvm/trunk/engines/sci/engine/seg_manager.cpp
scummvm/trunk/engines/sci/engine/seg_manager.h
scummvm/trunk/engines/sci/engine/vm.cpp
Modified: scummvm/trunk/engines/sci/engine/kscripts.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kscripts.cpp 2009-05-15 09:27:07 UTC (rev 40597)
+++ scummvm/trunk/engines/sci/engine/kscripts.cpp 2009-05-15 09:27:39 UTC (rev 40598)
@@ -265,11 +265,11 @@
if (argv[0].segment)
return s->r_acc;
- if (s->seg_manager->scriptIsLoaded(script, SCRIPT_ID)) {
- int id = s->seg_manager->segGet(script);
-
+ int id = s->seg_manager->segGet(script);
+ Script *scr = s->seg_manager->getScriptIfLoaded(id, SEG_ID);
+ if (scr) {
if (s->_executionStack[s->execution_stack_pos].addr.pc.segment != id)
- s->seg_manager->getScript(id, SEG_ID)->setLockers(1);
+ scr->setLockers(1);
}
script_uninstantiate(s, script);
Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp 2009-05-15 09:27:07 UTC (rev 40597)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp 2009-05-15 09:27:39 UTC (rev 40598)
@@ -402,6 +402,13 @@
return (Script *)_heap[seg];
}
+Script *SegManager::getScriptIfLoaded(const int id, idFlag flag) {
+ const int seg = (flag == SCRIPT_ID) ? segGet(id) : id;
+ if (seg < 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT)
+ return 0;
+ return (Script *)_heap[seg];
+}
+
// validate the seg
// return:
// false - invalid seg
Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h 2009-05-15 09:27:07 UTC (rev 40597)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h 2009-05-15 09:27:39 UTC (rev 40598)
@@ -75,11 +75,13 @@
// Returns : (int) 1 on success, 0 on failure
int deallocateScript(int script_nr);
- // Determines whether a script has been loaded yet
- // Parameters: (int) id: number of the script or ID of the script segment to check for
- // (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
- // by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
- // but less convenient.
+ /**
+ * Determines whether a script has been loaded yet.
+ * @param id number of the script or ID of the script segment to check for
+ * @param flag whether to address the script by script number (SCRIPT_ID) or
+ * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
+ * but less convenient.
+ */
int scriptIsLoaded(int id, idFlag flag);
// Validate whether the specified public function is exported by the script in the specified segment
@@ -94,10 +96,31 @@
// Returns : (int) The associated segment ID, or -1 if no matching segment exists
int segGet(int script_nr) const;
+ /**
+ * 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().
+ * @param id number of the script or ID of the script segment to check for
+ * @param flag whether to address the script by script number (SCRIPT_ID) or
+ * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
+ * but less convenient.
+ * @return pointer to the Script object
+ */
Script *getScript(int id, idFlag flag);
+ /**
+ * 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 return NULL.
+ * @param id number of the script or ID of the script segment to check for
+ * @param flag whether to address the script by script number (SCRIPT_ID) or
+ * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
+ * but less convenient.
+ * @return pointer to the Script object, or NULL
+ */
+ Script *getScriptIfLoaded(int id, idFlag flag);
+
+
// 1b. Script Initialisation
// The set of functions below are intended
Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp 2009-05-15 09:27:07 UTC (rev 40597)
+++ scummvm/trunk/engines/sci/engine/vm.cpp 2009-05-15 09:27:39 UTC (rev 40598)
@@ -258,7 +258,7 @@
seg = s->seg_manager->segGet(script);
if (!s->seg_manager->scriptIsLoaded(seg, SEG_ID)) // Script not present yet?
- script_instantiate(s, script);
+ seg = script_instantiate(s, script);
else
s->seg_manager->getScript(seg, SEG_ID)->unmarkDeleted();
@@ -528,7 +528,7 @@
}
static Script *script_locate_by_segment(EngineState *s, SegmentId seg) {
- return (Script *)GET_SEGMENT(*s->seg_manager, seg, MEM_OBJ_SCRIPT);
+ return s->seg_manager->getScriptIfLoaded(seg, SEG_ID);
}
static reg_t pointer_add(EngineState *s, reg_t base, int offset) {
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