aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2009-05-15 09:27:39 +0000
committerMax Horn2009-05-15 09:27:39 +0000
commit8f0b776afbe57127ee94c8c33293f241fd7a0d3d (patch)
treef483830c85c389e0eeed1203135046b39a50f525 /engines/sci
parent75c0d719c9d79eb1093c997960b3c6239c5a8a29 (diff)
downloadscummvm-rg350-8f0b776afbe57127ee94c8c33293f241fd7a0d3d.tar.gz
scummvm-rg350-8f0b776afbe57127ee94c8c33293f241fd7a0d3d.tar.bz2
scummvm-rg350-8f0b776afbe57127ee94c8c33293f241fd7a0d3d.zip
SCI: Added SegManager::getScriptIfLoaded() method
svn-id: r40598
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/kscripts.cpp8
-rw-r--r--engines/sci/engine/seg_manager.cpp7
-rw-r--r--engines/sci/engine/seg_manager.h33
-rw-r--r--engines/sci/engine/vm.cpp4
4 files changed, 41 insertions, 11 deletions
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index b66647e390..9464ba92c8 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -265,11 +265,11 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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);
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index b4cbc75d55..ad7b2e8fc1 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -402,6 +402,13 @@ Script *SegManager::getScript(const int id, idFlag flag) {
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
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index 9521d84b7b..549363b9aa 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -75,11 +75,13 @@ public:
// 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,8 +96,29 @@ public:
// 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
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index e1d3b254e8..c425d462fc 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -258,7 +258,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
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 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) {
}
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) {