diff options
author | Filippos Karapetis | 2009-10-11 13:46:58 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-11 13:46:58 +0000 |
commit | 6d030126d7d75f498692d8e2772d58728c6197bd (patch) | |
tree | bb8138787b82997f3d9c0e0ddfba0c790b321ec0 /engines/sci/engine | |
parent | bd6de4f642ed81f6fa32565b1324003857f4bf45 (diff) | |
download | scummvm-rg350-6d030126d7d75f498692d8e2772d58728c6197bd.tar.gz scummvm-rg350-6d030126d7d75f498692d8e2772d58728c6197bd.tar.bz2 scummvm-rg350-6d030126d7d75f498692d8e2772d58728c6197bd.zip |
More work on the Object class
svn-id: r44921
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 20 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 23 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 49 | ||||
-rw-r--r-- | engines/sci/engine/selector.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 7 |
6 files changed, 50 insertions, 59 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 4e161fabaf..619bbfb009 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -613,7 +613,7 @@ void SegManager::reconstructScripts(EngineState *s) { const ObjMap::iterator end = scr->_objects.end(); for (it = scr->_objects.begin(); it != end; ++it) { byte *data = scr->_buf + it->_value.getPos().offset; - it->_value.base_obj = data; + it->_value._baseObj = data; } } @@ -634,24 +634,24 @@ void SegManager::reconstructScripts(EngineState *s) { uint16 *funct_area = (uint16 *)(scr->_buf + READ_LE_UINT16( data + 6 )); uint16 *prop_area = (uint16 *)(scr->_buf + READ_LE_UINT16( data + 4 )); - it->_value.base_method = funct_area; - it->_value.base_vars = prop_area; + it->_value._baseMethod = funct_area; + it->_value._baseVars = prop_area; } else { int funct_area = READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET); - Object *base_obj; + Object *_baseObj; - base_obj = s->_segMan->getObject(it->_value.getSpeciesSelector()); + _baseObj = s->_segMan->getObject(it->_value.getSpeciesSelector()); - if (!base_obj) { + if (!_baseObj) { warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", scr->_nr, i, PRINT_REG(it->_value.getSpeciesSelector())); continue; } - it->_value.setVarCount(base_obj->getVarCount()); - it->_value.base_obj = base_obj->base_obj; + it->_value.setVarCount(_baseObj->getVarCount()); + it->_value._baseObj = _baseObj->_baseObj; - it->_value.base_method = (uint16 *)(data + funct_area); - it->_value.base_vars = (uint16 *)(data + it->_value.getVarCount() * 2 + SCRIPT_SELECTOR_OFFSET); + it->_value._baseMethod = (uint16 *)(data + funct_area); + it->_value._baseVars = (uint16 *)(data + it->_value.getVarCount() * 2 + SCRIPT_SELECTOR_OFFSET); } } } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 5da75638e3..350c1184c9 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -78,13 +78,13 @@ int propertyOffsetToId(SegManager *segMan, int prop_ofs, reg_t objp) { selectors = obj->getVarCount(); if (getSciVersion() < SCI_VERSION_1_1) - selectoroffset = ((byte *)(obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2; + selectoroffset = ((byte *)(obj->_baseObj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2; else { if (!(obj->getInfoSelector().offset & SCRIPT_INFO_CLASS)) { obj = segMan->getObject(obj->getSuperClassSelector()); - selectoroffset = (byte *)obj->base_vars; + selectoroffset = (byte *)obj->_baseVars; } else - selectoroffset = (byte *)obj->base_vars; + selectoroffset = (byte *)obj->_baseVars; } if (prop_ofs < 0 || (prop_ofs >> 1) >= selectors) { diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 50a0d094af..5c9eb9141c 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -242,6 +242,8 @@ Object *SegManager::getObject(reg_t pos) { CloneTable *ct = (CloneTable *)mobj; if (ct->isValidEntry(pos.offset)) obj = &(ct->_table[pos.offset]); + else + warning("getObject(): Trying to get an invalid object"); } else if (mobj->getType() == SEG_TYPE_SCRIPT) { Script *scr = (Script *)mobj; if (pos.offset <= scr->_bufSize && pos.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET @@ -658,9 +660,9 @@ void SegManager::scriptInitialiseObjectsSci11(SegmentId seg) { #if 0 if (obj->_variables[5].offset != 0xffff) { obj->_variables[5] = INST_LOOKUP_CLASS(obj->_variables[5].offset); - base_obj = getObject(obj->_variables[5]); - obj->variable_names_nr = base_obj->variables_nr; - obj->base_obj = base_obj->base_obj; + _baseObj = getObject(obj->_variables[5]); + obj->variable_names_nr = _baseObj->variables_nr; + obj->_baseObj = _baseObj->_baseObj; } #endif @@ -769,8 +771,6 @@ void SegManager::reconstructClones() { CloneTable *ct = (CloneTable *)mobj; for (uint j = 0; j < ct->_table.size(); j++) { - Object *base_obj; - // Check if the clone entry is used uint entryNum = (uint)ct->first_free; bool isUsed = true; @@ -786,17 +786,10 @@ void SegManager::reconstructClones() { continue; CloneTable::Entry &seeker = ct->_table[j]; - base_obj = getObject(seeker.getSpeciesSelector()); - if (!base_obj) { + Object *_baseObj = getObject(seeker.getSpeciesSelector()); + seeker.cloneFromObject(_baseObj); + if (!_baseObj) warning("Clone entry without a base class: %d", j); - seeker.base_obj = NULL; - seeker.base_vars = NULL; - seeker.base_method = NULL; - } else { - seeker.base_obj = base_obj->base_obj; - seeker.base_vars = base_obj->base_vars; - seeker.base_method = base_obj->base_method; - } } // end for } // end if } // end if diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index 38f1895fdd..7266dc3b38 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -217,16 +217,16 @@ public: reg_t getClassScriptSelector() { return _variables[4]; } void setClassScriptSelector(reg_t value) { _variables[4] = value; } - Selector getVarSelector(uint16 i) { - if (getSciVersion() < SCI_VERSION_1_1) - return READ_LE_UINT16(base_obj + _variables.size() * 2 + i * 2); - else - return *(base_vars + i); + Selector getVarSelector(uint16 i) { return *(_baseVars + i); } + + reg_t getFunction(uint16 i) { + uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? _methodCount + 1 + i : i * 2 + 2; + return make_reg(_pos.segment, READ_LE_UINT16((byte *) (_baseMethod + offset))); } Selector getFuncSelector(uint16 i) { uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? i : i * 2 + 1; - return READ_LE_UINT16((byte *) (base_method + offset)); + return READ_LE_UINT16((byte *) (_baseMethod + offset)); } /** @@ -243,11 +243,6 @@ public: return -1; } - reg_t getFunction(uint16 i) { - uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? _methodCount + 1 + i : i * 2 + 2; - return make_reg(_pos.segment, READ_LE_UINT16((byte *) (base_method + offset))); - } - bool isClass() { return (getInfoSelector().offset & SCRIPT_INFO_CLASS); } void markAsFreed() { _flags |= OBJECT_FLAG_FREED; } @@ -258,19 +253,19 @@ public: void init(byte *buf, reg_t obj_pos) { byte *data = (byte *)(buf + obj_pos.offset); - base_obj = data; + _baseObj = data; _pos = obj_pos; if (getSciVersion() < SCI_VERSION_1_1) { - setVarCount(READ_LE_UINT16(data + SCRIPT_SELECTORCTR_OFFSET)); - base_vars = 0; - base_method = (uint16 *)(data + READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET)); - _methodCount = READ_LE_UINT16(base_method - 1); + _variables.resize(READ_LE_UINT16(data + SCRIPT_SELECTORCTR_OFFSET)); + _baseVars = (uint16 *)(_baseObj + _variables.size() * 2); + _baseMethod = (uint16 *)(data + READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET)); + _methodCount = READ_LE_UINT16(_baseMethod - 1); } else { - setVarCount(READ_LE_UINT16(data + 2)); - base_vars = (uint16 *)(buf + READ_LE_UINT16(data + 4)); - base_method = (uint16 *)(buf + READ_LE_UINT16(data + 6)); - _methodCount = READ_LE_UINT16(base_method); + _variables.resize(READ_LE_UINT16(data + 2)); + _baseVars = (uint16 *)(buf + READ_LE_UINT16(data + 4)); + _baseMethod = (uint16 *)(buf + READ_LE_UINT16(data + 6)); + _methodCount = READ_LE_UINT16(_baseMethod); } for (uint i = 0; i < _variables.size(); i++) @@ -284,13 +279,17 @@ public: void saveLoadWithSerializer(Common::Serializer &ser); - // TODO: make private. Used by validate_property(), ObjVarRef::getPointer and Script::relocateObject - Common::Array<reg_t> _variables; + void cloneFromObject(Object *obj) { + _baseObj = obj ? obj->_baseObj : NULL; + _baseMethod = obj ? obj->_baseMethod : NULL; + _baseVars = obj ? obj->_baseVars : NULL; + } // TODO: make private - byte *base_obj; /**< base + object offset within base */ - uint16 *base_method; /**< Pointer to the method selector area for this object */ - uint16 *base_vars; /**< Pointer to the varselector area for this object */ + Common::Array<reg_t> _variables; + byte *_baseObj; /**< base + object offset within base */ + uint16 *_baseVars; /**< Pointer to the varselector area for this object */ + uint16 *_baseMethod; /**< Pointer to the method selector area for this object */ private: uint16 _methodCount; diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp index aa9545d724..f0cf03bb79 100644 --- a/engines/sci/engine/selector.cpp +++ b/engines/sci/engine/selector.cpp @@ -106,12 +106,12 @@ static int _obj_locate_varselector(SegManager *segMan, Object *obj, Selector slc if (getSciVersion() < SCI_VERSION_1_1) { varnum = obj->getVarCount(); int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET; - buf = obj->base_obj + selector_name_offset; + buf = obj->_baseObj + selector_name_offset; } else { if (!(obj->getInfoSelector().offset & SCRIPT_INFO_CLASS)) obj = segMan->getObject(obj->getSuperClassSelector()); - buf = (byte *)obj->base_vars; + buf = (byte *)obj->_baseVars; varnum = obj->getVariable(1).toUint16(); } diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 1b6a5e090a..e6a5dd72d3 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1592,14 +1592,13 @@ int script_instantiate_sci0(ResourceManager *resMan, SegManager *segMan, int scr case SCI_OBJ_OBJECT: case SCI_OBJ_CLASS: { // object or class? Object *obj = scr->scriptObjInit(addr); - Object *base_obj; // Instantiate the superclass, if neccessary obj->setSpeciesSelector(INST_LOOKUP_CLASS(obj->getSpeciesSelector().offset)); - base_obj = segMan->getObject(obj->getSpeciesSelector()); - obj->setVarCount(base_obj->getVarCount()); - obj->base_obj = base_obj->base_obj; + Object *_baseObj = segMan->getObject(obj->getSpeciesSelector()); + obj->setVarCount(_baseObj->getVarCount()); + obj->_baseObj = _baseObj->_baseObj; // Copy base from species class, as we need its selector IDs obj->setSuperClassSelector(INST_LOOKUP_CLASS(obj->getSuperClassSelector().offset)); |