diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/hugo/hugo.cpp | 96 | ||||
-rw-r--r-- | engines/hugo/hugo.h | 8 | ||||
-rw-r--r-- | engines/hugo/object.cpp | 7 | ||||
-rw-r--r-- | engines/hugo/object.h | 5 |
4 files changed, 69 insertions, 47 deletions
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp index 4f9a814da3..3074a3d97d 100644 --- a/engines/hugo/hugo.cpp +++ b/engines/hugo/hugo.cpp @@ -84,30 +84,9 @@ HugoEngine::HugoEngine(OSystem *syst, const HugoGameDescription *gd) : Engine(sy } HugoEngine::~HugoEngine() { - delete _object; - delete _sound; - delete _route; - delete _parser; - delete _inventory; - delete _mouse; - delete _screen; - delete _scheduler; - delete _file; - free(_palette); free(_introX); free(_introY); - -#if 0 - freeTexts(_textData); - freeTexts(_stringtData); - freeTexts(_textEngine); - freeTexts(_textIntro); - freeTexts(_textMouse); - freeTexts(_textParser); - freeTexts(_textSchedule); - freeTexts(_textUtil); -#endif free(_textData); free(_stringtData); free(_screenNames); @@ -118,8 +97,13 @@ HugoEngine::~HugoEngine() { free(_textSchedule); free(_textUtil); - warning("Missing: free _arrayNouns"); - warning("Missing: free _arrayVerbs"); + for (int i = 0; _arrayNouns[i]; i++) + free(_arrayNouns[i]); + free(_arrayNouns); + + for (int i = 0; _arrayVerbs[i]; i++) + free(_arrayVerbs[i]); + free(_arrayVerbs); free(_arrayReqs); free(_hotspots); @@ -127,13 +111,25 @@ HugoEngine::~HugoEngine() { free(_uses); free(_catchallList); - warning("Missing: free _background_objects"); + for (int i = 0; i < _backgroundObjectsSize; i++) + free(_backgroundObjects[i]); + free(_backgroundObjects); free(_points); - warning("Missing: free _cmdList"); - warning("Missing: free _screenActs"); - warning("Missing: free _objects"); + for (int i = 0; i < _cmdListSize; i++) + free(_cmdList[i]); + free(_cmdList); + + for (int i = 0; i < _screenActsSize; i++) + free(_screenActs[i]); + free(_screenActs); + + _object->freeObjectArr(); + + for (int i = 0; i < _actListArrSize; i++) + free(_actListArr[i]); + free(_actListArr); free(_defltTunes); free(_screenStates); @@ -146,6 +142,16 @@ HugoEngine::~HugoEngine() { if (_arrayFont[2]) free(_arrayFont[2]); + + delete _object; + delete _sound; + delete _route; + delete _parser; + delete _inventory; + delete _mouse; + delete _screen; + delete _scheduler; + delete _file; } GameType HugoEngine::getGameType() const { @@ -389,10 +395,10 @@ bool HugoEngine::loadHugoDat() { _stringtData = loadTextsVariante(in, 0); // Read arrayNouns - _arrayNouns = loadTextsArray(in); + _arrayNouns = loadTextsArray(in, &_arrayNounsSize); // Read arrayVerbs - _arrayVerbs = loadTextsArray(in); + _arrayVerbs = loadTextsArray(in, &_arrayVerbsSize); // Read screenNames _screenNames = loadTextsVariante(in, &_numScreens); @@ -546,8 +552,9 @@ bool HugoEngine::loadHugoDat() { for (int varnt = 0; varnt < _numVariant; varnt++) { numElem = in.readUint16BE(); if (varnt == _gameVariant) { - _backgroundObjects = (background_t **)malloc(sizeof(background_t *) * numElem); - for (int i = 0; i < numElem; i++) { + _backgroundObjectsSize = numElem; + _backgroundObjects = (background_t **)malloc(sizeof(background_t *) * _backgroundObjectsSize); + for (int i = 0; i < _backgroundObjectsSize; i++) { numSubElem = in.readUint16BE(); _backgroundObjects[i] = (background_t *)malloc(sizeof(background_t) * numSubElem); for (int j = 0; j < numSubElem; j++) { @@ -594,8 +601,9 @@ bool HugoEngine::loadHugoDat() { for (int varnt = 0; varnt < _numVariant; varnt++) { numElem = in.readUint16BE(); if (varnt == _gameVariant) { - _cmdList = (cmd **)malloc(sizeof(cmd *) * numElem); - for (int i = 0; i < numElem; i++) { + _cmdListSize = numElem; + _cmdList = (cmd **)malloc(sizeof(cmd *) * _cmdListSize); + for (int i = 0; i < _cmdListSize; i++) { numSubElem = in.readUint16BE(); _cmdList[i] = (cmd *)malloc(sizeof(cmd) * numSubElem); for (int j = 0; j < numSubElem; j++) { @@ -631,8 +639,9 @@ bool HugoEngine::loadHugoDat() { for (int varnt = 0; varnt < _numVariant; varnt++) { numElem = in.readUint16BE(); if (varnt == _gameVariant) { - _screenActs = (uint16 **)malloc(sizeof(uint16 *) * numElem); - for (int i = 0; i < numElem; i++) { + _screenActsSize = numElem; + _screenActs = (uint16 **)malloc(sizeof(uint16 *) * _screenActsSize); + for (int i = 0; i < _screenActsSize; i++) { numSubElem = in.readUint16BE(); if (numSubElem == 0) { _screenActs[i] = 0; @@ -651,7 +660,7 @@ bool HugoEngine::loadHugoDat() { } } - _object->loadObject(in); + _object->loadObjectArr(in); //#define HERO 0 _hero = &_object->_objects[HERO]; // This always points to hero _screen_p = &(_object->_objects[HERO].screenIndex); // Current screen is hero's @@ -661,8 +670,9 @@ bool HugoEngine::loadHugoDat() { for (int varnt = 0; varnt < _numVariant; varnt++) { numElem = in.readUint16BE(); if (varnt == _gameVariant) { - _actListArr = (act **)malloc(sizeof(act *) * numElem); - for (int i = 0; i < numElem; i++) { + _actListArrSize = numElem; + _actListArr = (act **)malloc(sizeof(act *) * _actListArrSize); + for (int i = 0; i < _actListArrSize; i++) { numSubElem = in.readUint16BE(); _actListArr[i] = (act *) malloc(sizeof(act) * (numSubElem + 1)); for (int j = 0; j < numSubElem; j++) { @@ -1377,16 +1387,16 @@ uint16 **HugoEngine::loadLongArray(Common::File &in) { return resArray; } -char ***HugoEngine::loadTextsArray(Common::File &in) { +char ***HugoEngine::loadTextsArray(Common::File &in, uint16 *arraySize) { char ***resArray = 0; for (int varnt = 0; varnt < _numVariant; varnt++) { - int numNouns = in.readUint16BE(); + *arraySize = in.readUint16BE(); if (varnt == _gameVariant) { - resArray = (char ** *)malloc(sizeof(char **) * (numNouns + 1)); - resArray[numNouns] = 0; + resArray = (char ***)malloc(sizeof(char **) * (*arraySize + 1)); + resArray[*arraySize] = 0; } - for (int i = 0; i < numNouns; i++) { + for (int i = 0; i < *arraySize; i++) { int numTexts = in.readUint16BE(); int entryLen = in.readUint16BE(); char *pos = (char *)malloc(entryLen); diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h index 2be56e345d..7a73c70622 100644 --- a/engines/hugo/hugo.h +++ b/engines/hugo/hugo.h @@ -139,17 +139,23 @@ public: char **_textSchedule; char **_textUtil; char ***_arrayNouns; + uint16 _arrayNounsSize; char ***_arrayVerbs; + uint16 _arrayVerbsSize; uint16 **_arrayReqs; hotspot_t *_hotspots; int16 *_invent; uses_t *_uses; background_t *_catchallList; background_t **_backgroundObjects; + uint16 _backgroundObjectsSize; point_t *_points; cmd **_cmdList; + uint16 _cmdListSize; uint16 **_screenActs; + uint16 _screenActsSize; act **_actListArr; + uint16 _actListArrSize; int16 *_defltTunes; uint16 _look; uint16 _take; @@ -287,7 +293,7 @@ private: int _maxscore; // Holds maximum score char **loadTextsVariante(Common::File &in, uint16 *arraySize); - char ***loadTextsArray(Common::File &in); + char ***loadTextsArray(Common::File &in, uint16 *arraySize); uint16 **loadLongArray(Common::File &in); char **loadTexts(Common::File &in); void freeTexts(char **ptr); diff --git a/engines/hugo/object.cpp b/engines/hugo/object.cpp index 0ab008415b..77a25ca343 100644 --- a/engines/hugo/object.cpp +++ b/engines/hugo/object.cpp @@ -317,13 +317,18 @@ bool ObjectHandler::findObjectSpace(object_t *obj, int16 *destx, int16 *desty) { return foundFl; } -void ObjectHandler::loadObject(Common::File &in) { +void ObjectHandler::freeObjectArr() { + free(_objects); +} + +void ObjectHandler::loadObjectArr(Common::File &in) { debugC(6, kDebugObject, "loadObject(&in)"); // TODO: For Hugo3, if not in story mode, set _objects[2].state to 3 for (int varnt = 0; varnt < _vm->_numVariant; varnt++) { uint16 numElem = in.readUint16BE(); if (varnt == _vm->_gameVariant) { + _objCount = numElem; _objects = (object_t *)malloc(sizeof(object_t) * numElem); for (int i = 0; i < numElem; i++) { _objects[i].nounIndex = in.readUint16BE(); diff --git a/engines/hugo/object.h b/engines/hugo/object.h index a30a2ed57d..72b13caa8f 100644 --- a/engines/hugo/object.h +++ b/engines/hugo/object.h @@ -55,9 +55,9 @@ public: bool findObjectSpace(object_t *obj, int16 *destx, int16 *desty); int16 findObject(uint16 x, uint16 y); - void freeObjects(); - void loadObject(Common::File &in); + void loadObjectArr(Common::File &in); + void freeObjectArr(); void lookObject(object_t *obj); void restoreSeq(object_t *obj); void saveSeq(object_t *obj); @@ -86,6 +86,7 @@ public: } protected: HugoEngine *_vm; + uint16 _objCount; }; class ObjectHandler_v1d : public ObjectHandler { |