diff options
author | Filippos Karapetis | 2010-06-27 21:18:19 +0000 |
---|---|---|
committer | Filippos Karapetis | 2010-06-27 21:18:19 +0000 |
commit | 4a60ff409050e8f3da6065f2a44d78d31c4f34b9 (patch) | |
tree | 391de4517007053a52451d116d862a3fca23b8e4 /engines/sci/engine/script.cpp | |
parent | 456265f8fac8c5020e30fa99e0be1c1ff1a02aa8 (diff) | |
download | scummvm-rg350-4a60ff409050e8f3da6065f2a44d78d31c4f34b9.tar.gz scummvm-rg350-4a60ff409050e8f3da6065f2a44d78d31c4f34b9.tar.bz2 scummvm-rg350-4a60ff409050e8f3da6065f2a44d78d31c4f34b9.zip |
Made the script initialization/uninitialization methods part of the segment manager
svn-id: r50402
Diffstat (limited to 'engines/sci/engine/script.cpp')
-rw-r--r-- | engines/sci/engine/script.cpp | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index 18244c7906..2bb405372a 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -519,109 +519,4 @@ void Script::initialiseObjectsSci11(SegManager *segMan) { } } -int script_instantiate(ResourceManager *resMan, SegManager *segMan, int scriptNum) { - SegmentId segmentId = segMan->getScriptSegment(scriptNum); - Script *scr = segMan->getScriptIfLoaded(segmentId); - if (scr) { - if (!scr->isMarkedAsDeleted()) { - scr->incrementLockers(); - return segmentId; - } else { - scr->freeScript(); - } - } else { - scr = segMan->allocateScript(scriptNum, &segmentId); - } - - scr->init(scriptNum, resMan); - scr->load(resMan); - scr->initialiseLocals(segMan); - scr->initialiseClasses(segMan); - - if (getSciVersion() >= SCI_VERSION_1_1) { - scr->initialiseObjectsSci11(segMan); - scr->relocate(make_reg(segmentId, READ_SCI11ENDIAN_UINT16(scr->_heapStart))); - } else { - scr->initialiseObjectsSci0(segMan); - byte *relocationBlock = scr->findBlock(SCI_OBJ_POINTERS); - if (relocationBlock) - scr->relocate(make_reg(segmentId, relocationBlock - scr->_buf + 4)); - } - - return segmentId; -} - -void script_uninstantiate_sci0(SegManager *segMan, int script_nr, SegmentId seg) { - bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY); - reg_t reg = make_reg(seg, oldScriptHeader ? 2 : 0); - int objType, objLength = 0; - Script *scr = segMan->getScript(seg); - - // Make a pass over the object in order uninstantiate all superclasses - - do { - reg.offset += objLength; // Step over the last checked object - - objType = READ_SCI11ENDIAN_UINT16(scr->_buf + reg.offset); - if (!objType) - break; - objLength = READ_SCI11ENDIAN_UINT16(scr->_buf + reg.offset + 2); - - reg.offset += 4; // Step over header - - if ((objType == SCI_OBJ_OBJECT) || (objType == SCI_OBJ_CLASS)) { // object or class? - reg.offset += 8; // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET) - int16 superclass = READ_SCI11ENDIAN_UINT16(scr->_buf + reg.offset + 2); - - if (superclass >= 0) { - int superclass_script = segMan->getClass(superclass).script; - - if (superclass_script == script_nr) { - if (scr->getLockers()) - scr->decrementLockers(); // Decrease lockers if this is us ourselves - } else - script_uninstantiate(segMan, superclass_script); - // Recurse to assure that the superclass lockers number gets decreased - } - - reg.offset += SCRIPT_OBJECT_MAGIC_OFFSET; - } // if object or class - - reg.offset -= 4; // Step back on header - - } while (objType != 0); -} - -void script_uninstantiate(SegManager *segMan, int script_nr) { - SegmentId segment = segMan->getScriptSegment(script_nr); - Script *scr = segMan->getScriptIfLoaded(segment); - - if (!scr) { // Is it already loaded? - //warning("unloading script 0x%x requested although not loaded", script_nr); - // This is perfectly valid SCI behaviour - return; - } - - scr->decrementLockers(); // One less locker - - if (scr->getLockers() > 0) - return; - - // Free all classtable references to this script - for (uint i = 0; i < segMan->classTableSize(); i++) - if (segMan->getClass(i).reg.segment == segment) - segMan->setClassOffset(i, NULL_REG); - - if (getSciVersion() < SCI_VERSION_1_1) - script_uninstantiate_sci0(segMan, script_nr, segment); - // FIXME: Add proper script uninstantiation for SCI 1.1 - - if (!scr->getLockers()) { - // The actual script deletion seems to be done by SCI scripts themselves - scr->markDeleted(); - debugC(kDebugLevelScripts, "Unloaded script 0x%x.", script_nr); - } -} - - } // End of namespace Sci |