diff options
author | Lars Skovlund | 2010-12-21 15:36:27 +0000 |
---|---|---|
committer | Lars Skovlund | 2010-12-21 15:36:27 +0000 |
commit | 7b0760f1bc5c28abcede041a6e3930f84ff3d319 (patch) | |
tree | 2b70b164ada19471b6c9baec07958ac78017a3e5 | |
parent | f1cd95e462a8edaacb6e25c119e02b9aa0c657a3 (diff) | |
download | scummvm-rg350-7b0760f1bc5c28abcede041a6e3930f84ff3d319.tar.gz scummvm-rg350-7b0760f1bc5c28abcede041a6e3930f84ff3d319.tar.bz2 scummvm-rg350-7b0760f1bc5c28abcede041a6e3930f84ff3d319.zip |
Make Object::_baseMethod a Common::Array. This is intended to clean up
the Object class, and it also plugs a leak.
svn-id: r54986
-rw-r--r-- | engines/sci/engine/object.cpp | 20 | ||||
-rw-r--r-- | engines/sci/engine/object.h | 13 |
2 files changed, 16 insertions, 17 deletions
diff --git a/engines/sci/engine/object.cpp b/engines/sci/engine/object.cpp index 12b2e36d31..ed78a5fc2d 100644 --- a/engines/sci/engine/object.cpp +++ b/engines/sci/engine/object.cpp @@ -62,13 +62,15 @@ void Object::init(byte *buf, reg_t obj_pos, bool initVariables) { if (getSciVersion() <= SCI_VERSION_1_LATE) { _variables.resize(READ_LE_UINT16(data + kOffsetSelectorCounter)); _baseVars = (const uint16 *)(_baseObj + _variables.size() * 2); - _baseMethod = (const uint16 *)(data + READ_LE_UINT16(data + kOffsetFunctionArea)); - _methodCount = READ_LE_UINT16(_baseMethod - 1); + _methodCount = READ_LE_UINT16(data + READ_LE_UINT16(data + kOffsetFunctionArea) - 2); + _baseMethod = Common::Array<uint16>((const uint16 *)(data + READ_LE_UINT16(data + kOffsetFunctionArea)), + _methodCount*2+2); } else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) { _variables.resize(READ_SCI11ENDIAN_UINT16(data + 2)); _baseVars = (const uint16 *)(buf + READ_SCI11ENDIAN_UINT16(data + 4)); - _baseMethod = (const uint16 *)(buf + READ_SCI11ENDIAN_UINT16(data + 6)); - _methodCount = READ_SCI11ENDIAN_UINT16(_baseMethod); + _methodCount = READ_SCI11ENDIAN_UINT16(buf + READ_SCI11ENDIAN_UINT16(data + 6)); + _baseMethod = Common::Array<uint16>((const uint16 *) (buf + READ_SCI11ENDIAN_UINT16(data + 6)), + _methodCount*2+3); } else if (getSciVersion() == SCI_VERSION_3) { initSelectorsSci3(buf); } @@ -220,9 +222,8 @@ void Object::initSelectorsSci3(const byte *buf) { } _variables.resize(properties); - uint16 *methodIds = (uint16*) malloc(sizeof(uint16)*2*methods); uint16 *propertyIds = (uint16*) malloc(sizeof(uint16)*properties); - uint16 *methodOffsets = (uint16*) malloc(sizeof(uint16)*2*methods); +// uint16 *methodOffsets = (uint16*) malloc(sizeof(uint16)*2*methods); uint16 *propertyOffsets = (uint16*) malloc(sizeof(uint16)*properties); int propertyCounter = 0; int methodCounter = 0; @@ -246,9 +247,9 @@ void Object::initSelectorsSci3(const byte *buf) { propertyOffsets[propertyCounter] = (seeker + bit * 2) - buf; ++propertyCounter; } else if (value != 0xffff) { // Method - methodIds[methodCounter * 2] = groupBaseId + bit; - methodIds[methodCounter * 2 + 1] = value + READ_SCI11ENDIAN_UINT32(buf); - methodOffsets[methodCounter] = (seeker + bit * 2) - buf; + _baseMethod.push_back(groupBaseId + bit); + _baseMethod.push_back(value + READ_SCI11ENDIAN_UINT32(buf)); +// methodOffsets[methodCounter] = (seeker + bit * 2) - buf; ++methodCounter; } else /* Undefined selector */ {}; @@ -260,7 +261,6 @@ void Object::initSelectorsSci3(const byte *buf) { _superClassPosSci3 = make_reg(0, READ_SCI11ENDIAN_UINT16(_baseObj + 8)); _baseVars = propertyIds; - _baseMethod = methodIds; _methodCount = methods; _propertyOffsetsSci3 = propertyOffsets; //_methodOffsetsSci3 = methodOffsets; diff --git a/engines/sci/engine/object.h b/engines/sci/engine/object.h index 842e600b89..f59874bb44 100644 --- a/engines/sci/engine/object.h +++ b/engines/sci/engine/object.h @@ -65,12 +65,11 @@ public: _flags = 0; _baseObj = 0; _baseVars = 0; - _baseMethod = 0; _methodCount = 0; _propertyOffsetsSci3 = 0; } - ~Object() { } + ~Object() { free(_propertyOffsetsSci3); } reg_t getSpeciesSelector() const { if (getSciVersion() <= SCI_VERSION_2_1) @@ -162,14 +161,14 @@ public: uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? _methodCount + 1 + i : i * 2 + 2; if (getSciVersion() == SCI_VERSION_3) offset--; - return make_reg(_pos.segment, READ_SCI11ENDIAN_UINT16(_baseMethod + offset)); + return make_reg(_pos.segment, _baseMethod[offset]); } Selector getFuncSelector(uint16 i) const { uint16 offset = (getSciVersion() < SCI_VERSION_1_1) ? i : i * 2 + 1; if (getSciVersion() == SCI_VERSION_3) offset--; - return READ_SCI11ENDIAN_UINT16(_baseMethod + offset); + return _baseMethod[offset]; } /** @@ -212,7 +211,7 @@ public: void cloneFromObject(const Object *obj) { _baseObj = obj ? obj->_baseObj : NULL; - _baseMethod = obj ? obj->_baseMethod : NULL; + _baseMethod = obj ? obj->_baseMethod : Common::Array<uint16>(); _baseVars = obj ? obj->_baseVars : NULL; } @@ -231,8 +230,8 @@ private: const byte *_baseObj; /**< base + object offset within base */ const uint16 *_baseVars; /**< Pointer to the varselector area for this object */ - const uint16 *_baseMethod; /**< Pointer to the method selector area for this object */ - const uint16 *_propertyOffsetsSci3; + Common::Array<uint16> _baseMethod; /**< Pointer to the method selector area for this object */ + uint16 *_propertyOffsetsSci3; /**< This is used to enable relocation of property valuesa in SCI3 */ Common::Array<reg_t> _variables; uint16 _methodCount; |