diff options
author | Gregory Montoir | 2004-10-17 19:00:09 +0000 |
---|---|---|
committer | Gregory Montoir | 2004-10-17 19:00:09 +0000 |
commit | b33f7b4b76495b08532989fe9cde9e49a1d08a95 (patch) | |
tree | 5389d5df8921f10f182d3b1bc50cc617202bcba6 | |
parent | a41b8d22937396c10b913a0e9d58af311bccc5ad (diff) | |
download | scummvm-rg350-b33f7b4b76495b08532989fe9cde9e49a1d08a95.tar.gz scummvm-rg350-b33f7b4b76495b08532989fe9cde9e49a1d08a95.tar.bz2 scummvm-rg350-b33f7b4b76495b08532989fe9cde9e49a1d08a95.zip |
plugged some memory leaks
svn-id: r15591
-rw-r--r-- | queen/command.cpp | 8 | ||||
-rw-r--r-- | queen/command.h | 1 | ||||
-rw-r--r-- | queen/grid.cpp | 7 | ||||
-rw-r--r-- | queen/grid.h | 1 | ||||
-rw-r--r-- | queen/logic.cpp | 159 | ||||
-rw-r--r-- | queen/logic.h | 37 |
6 files changed, 129 insertions, 84 deletions
diff --git a/queen/command.cpp b/queen/command.cpp index df93ab097c..bb9efe4d93 100644 --- a/queen/command.cpp +++ b/queen/command.cpp @@ -125,6 +125,14 @@ Command::Command(QueenEngine *vm) : _cmdText((vm->resource()->getLanguage() == HEBREW), CmdText::COMMAND_Y_POS, vm), _vm(vm) { } +Command::~Command() { + delete[] _cmdList; + delete[] _cmdArea; + delete[] _cmdObject; + delete[] _cmdInventory; + delete[] _cmdGameState; +} + void Command::clear(bool clearTexts) { debug(6, "Command::clear(%d)", clearTexts); _cmdText.clear(); diff --git a/queen/command.h b/queen/command.h index 2d7aff98dc..df9dffcc2b 100644 --- a/queen/command.h +++ b/queen/command.h @@ -72,6 +72,7 @@ class Command { public: Command(QueenEngine *vm); + ~Command(); //! initialise command construction void clear(bool clearTexts); diff --git a/queen/grid.cpp b/queen/grid.cpp index f015589a97..08c78c148e 100644 --- a/queen/grid.cpp +++ b/queen/grid.cpp @@ -33,6 +33,13 @@ Grid::Grid(QueenEngine *vm) memset(_zones, 0, sizeof(_zones)); } +Grid::~Grid() { + delete[] _objMax; + delete[] _areaMax; + delete[] _area; + delete[] _objectBox; +} + void Grid::readDataFrom(uint16 numObjects, uint16 numRooms, byte *&ptr) { uint16 i, j; diff --git a/queen/grid.h b/queen/grid.h index e9a99747b7..b85451d5c7 100644 --- a/queen/grid.h +++ b/queen/grid.h @@ -39,6 +39,7 @@ class Grid { public: Grid(QueenEngine *vm); + ~Grid(); void readDataFrom(uint16 numObjects, uint16 numRooms, byte *&ptr); diff --git a/queen/logic.cpp b/queen/logic.cpp index 711bb596fd..531ce1af62 100644 --- a/queen/logic.cpp +++ b/queen/logic.cpp @@ -43,19 +43,22 @@ namespace Queen { -static char *trim(char *str) { - char *p = str + strlen(str) - 1; - while (p != str && *p == ' ') { - *p-- = '\0'; - } - while (str != p && *str == ' ') { - ++str; - } - return str; +static Common::String trim(const Common::String &s) { + const char *p; + + p = s.c_str(); + while (*p == ' ') ++p; + int start = p - s.c_str(); + + p = s.c_str() + s.size() - 1; + while (p != s.c_str() && *p == ' ') --p; + int end = p - s.c_str(); + + return Common::String(s.c_str() + start, end - start + 1); } Logic::Logic(QueenEngine *vm) - : _queen2jas(NULL), _credits(NULL), _vm(vm) { + : _credits(NULL), _vm(vm) { _joe.x = _joe.y = 0; _joe.scale = 100; _joe.walk = JWM_NORMAL; @@ -69,7 +72,16 @@ Logic::Logic(QueenEngine *vm) Logic::~Logic() { delete _journal; delete _credits; - delete _queen2jas; + delete[] _objectData; + delete[] _roomData; + delete[] _sfxName; + delete[] _itemData; + delete[] _graphicData; + delete[] _walkOffData; + delete[] _objectDescription; + delete[] _furnitureData; + delete[] _actorData; + delete[] _graphicAnim; } void Logic::initialise() { @@ -182,37 +194,37 @@ void Logic::initialise() { uint32 size; char *buf = (char *)_vm->resource()->loadFile("QUEEN2.JAS", 0, &size); - _queen2jas = new LineReader(buf, size); + LineReader *queen2jas = new LineReader(buf, size); - _objDescription = new char*[_numDescriptions + 1]; - _objDescription[0] = 0; - for (i = 1; i <= _numDescriptions; i++) - _objDescription[i] = _queen2jas->nextLine(); + _objDescription.push_back(""); + for (i = 1; i <= _numDescriptions; i++) { + _objDescription.push_back(queen2jas->nextLine()); + } - //Patch for German text bug + // Patch for German text bug if (_vm->resource()->getLanguage() == GERMAN) { - char *txt = new char[48]; - strcpy(txt, "Es bringt nicht viel, das festzubinden."); - _objDescription[296] = txt; + _objDescription[296] = "Es bringt nicht viel, das festzubinden."; } - _objName = new char*[_numNames + 1]; - _objName[0] = 0; - for (i = 1; i <= _numNames; i++) - _objName[i] = _queen2jas->nextLine(); - - _roomName = new char*[_numRooms + 1]; - _roomName[0] = 0; - for (i = 1; i <= _numRooms; i++) - _roomName[i] = _queen2jas->nextLine(); - - _verbName[0] = 0; - for (i = 1; i <= 12; i++) - _verbName[i] = _queen2jas->nextLine(); - - _joeResponse[0] = 0; - for (i = 1; i <= JOE_RESPONSE_MAX; i++) - _joeResponse[i] = _queen2jas->nextLine(); + _objName.push_back(""); + for (i = 1; i <= _numNames; i++) { + _objName.push_back(queen2jas->nextLine()); + } + + _roomName.push_back(""); + for (i = 1; i <= _numRooms; i++) { + _roomName.push_back(queen2jas->nextLine()); + } + + _verbName.push_back(""); + for (i = 1; i <= 12; i++) { + _verbName.push_back(queen2jas->nextLine()); + } + + _joeResponse.push_back(""); + for (i = 1; i <= JOE_RESPONSE_MAX; i++) { + _joeResponse.push_back(queen2jas->nextLine()); + } // FIXME - the spanish version adds some space characters (0x20) at the // beginning and the end of the journal button captions. As we don't need @@ -223,21 +235,22 @@ void Logic::initialise() { } } - _aAnim = new char*[_numAAnim + 1]; - _aAnim[0] = 0; - for (i = 1; i <= _numAAnim; i++) - _aAnim[i] = _queen2jas->nextLine(); + _aAnim.push_back(""); + for (i = 1; i <= _numAAnim; i++) { + _aAnim.push_back(queen2jas->nextLine()); + } - _aName = new char*[_numAName + 1]; - _aName[0] = 0; - for (i = 1; i <= _numAName; i++) - _aName[i] = _queen2jas->nextLine(); + _aName.push_back(""); + for (i = 1; i <= _numAName; i++) { + _aName.push_back(queen2jas->nextLine()); + } - _aFile = new char*[_numAFile + 1]; - _aFile[0] = 0; - for (i = 1; i <= _numAFile; i++) - _aFile[i] = _queen2jas->nextLine(); - + _aFile.push_back(""); + for (i = 1; i <= _numAFile; i++) { + _aFile.push_back(queen2jas->nextLine()); + } + + delete queen2jas; _vm->command()->clear(false); _scene = 0; @@ -264,23 +277,23 @@ uint16 Logic::findBob(uint16 obj) const { uint16 bobnum = 0; int16 img = _objectData[obj].image; - if(img != 0) { - if(img == -3 || img == -4) { + if (img != 0) { + if (img == -3 || img == -4) { // a person object bobnum = findPersonNumber(obj, room); } else { uint16 bobtype = 0; // 1 for animated, 0 for static - if(img <= -10) { + if (img <= -10) { // object has been turned off, but the image order hasn't been updated if(_graphicData[-(img + 10)].lastFrame != 0) { bobtype = 1; } - } else if(img == -2) { + } else if (img == -2) { // -1 static, -2 animated bobtype = 1; - } else if(img > 0) { - if(_graphicData[img].lastFrame != 0) { + } else if (img > 0) { + if (_graphicData[img].lastFrame != 0) { bobtype = 1; } } @@ -335,16 +348,16 @@ uint16 Logic::findFrame(uint16 obj) const { int16 img = _objectData[obj].image; if (img == -3 || img == -4) { uint16 bobnum = findPersonNumber(obj, room); - if(bobnum <= 3) { + if (bobnum <= 3) { framenum = 31 + bobnum; } } else { uint16 idx = 0; - for(uint16 i = _roomData[room] + 1; i < obj; ++i) { + for (uint16 i = _roomData[room] + 1; i < obj; ++i) { img = _objectData[i].image; if (img <= -10) { const GraphicData* pgd = &_graphicData[-(img + 10)]; - if(pgd->lastFrame != 0) { + if (pgd->lastFrame != 0) { // skip all the frames of the animation idx += ABS(pgd->lastFrame) - pgd->firstFrame + 1; } else { @@ -436,7 +449,23 @@ void Logic::gameState(int index, int16 newValue) { const char *Logic::roomName(uint16 roomNum) const { assert(roomNum >= 1 && roomNum <= _numRooms); - return _roomName[roomNum]; + return _roomName[roomNum].c_str(); +} + +const char *Logic::objectName(uint16 objNum) const { + return _objName[objNum].c_str(); +} + +const char *Logic::objectTextualDescription(uint16 objNum) const { + return _objDescription[objNum].c_str(); +} + +const char *Logic::joeResponse(int i) const { + return _joeResponse[i].c_str(); +} + +const char *Logic::verbName(Verb v) const { + return _verbName[v].c_str(); } void Logic::eraseRoom() { @@ -539,7 +568,7 @@ ActorData *Logic::findActor(uint16 noun, const char *name) const { for (uint16 i = 1; i <= _numActors; ++i) { ActorData *pad = &_actorData[i]; if (pad->room == _currentRoom && gameState(pad->gsSlot) == pad->gsValue) { - if (bobNum == pad->bobNum || (name && !strcmp(_aName[pad->name], name))) { + if (bobNum == pad->bobNum || (name && _aName[pad->name] == name)) { return pad; } } @@ -552,14 +581,14 @@ bool Logic::initPerson(uint16 noun, const char *actorName, bool loadBank, Person const ActorData *pad = findActor(noun, actorName); if (pad != NULL) { pp->actor = pad; - pp->name = _aName[pad->name]; + pp->name = _aName[pad->name].c_str(); if (pad->anim != 0) { - pp->anim = _aAnim[pad->anim]; + pp->anim = _aAnim[pad->anim].c_str(); } else { pp->anim = NULL; } if (loadBank && pad->file != 0) { - _vm->bankMan()->load(_aFile[pad->file], pad->bankNum); + _vm->bankMan()->load(_aFile[pad->file].c_str(), pad->bankNum); // if there is no valid actor file (ie pad->file is 0), the person // data is already loaded as it is included in objects room bank (.bbk) } @@ -851,7 +880,7 @@ void Logic::playCutaway(const char *cutFile, char *next) { } void Logic::makeJoeSpeak(uint16 descNum, bool objectType) { - const char *text = objectType ? _objDescription[descNum] : _joeResponse[descNum]; + const char *text = objectType ? _objDescription[descNum].c_str() : _joeResponse[descNum].c_str(); if (objectType) { descNum += JOE_RESPONSE_MAX; } diff --git a/queen/logic.h b/queen/logic.h index e020fd7b87..ea764aa293 100644 --- a/queen/logic.h +++ b/queen/logic.h @@ -22,6 +22,7 @@ #ifndef QUEENLOGIC_H #define QUEENLOGIC_H +#include "common/str.h" #include "common/util.h" #include "queen/defs.h" #include "queen/structs.h" @@ -29,8 +30,8 @@ namespace Queen { enum RoomDisplayMode { - RDM_FADE_NOJOE = 0, // fade in, no Joe - RDM_FADE_JOE = 1, // Joe is to be displayed + RDM_FADE_NOJOE = 0, // fade in, hide Joe + RDM_FADE_JOE = 1, // fade in, display Joe RDM_NOFADE_JOE = 2, // screen does not dissolve into view RDM_FADE_JOE_XY = 3 // display Joe at the current X, Y coords }; @@ -108,9 +109,6 @@ public: void joeScale(uint16 scale) { _joe.scale = scale; } void joeCutFacing(uint16 dir) { _joe.cutFacing = dir; } void joePrevFacing(uint16 dir) { _joe.prevFacing = dir; } - - const char *joeResponse(int i) const { return _joeResponse[i]; } - const char *verbName(Verb v) const { return _verbName[v]; } int16 gameState(int index) const; void gameState(int index, int16 newValue); @@ -118,8 +116,10 @@ public: TalkSelected *talkSelected(int index) { return &_talkSelected[index]; } const char *roomName(uint16 roomNum) const; - const char *objectName(uint16 objNum) const { return _objName[objNum]; } - const char *objectTextualDescription(uint16 objNum) const { return _objDescription[objNum]; } + const char *objectName(uint16 objNum) const; + const char *objectTextualDescription(uint16 objNum) const; + const char *joeResponse(int i) const; + const char *verbName(Verb v) const; void eraseRoom(); void setupRoom(const char *room, int comPanel, bool inCutaway); @@ -250,9 +250,7 @@ protected: virtual bool preChangeRoom() = 0; virtual bool handleSpecialMove(uint16 sm) = 0; - - - LineReader *_queen2jas; + uint16 _currentRoom; uint16 _oldRoom; @@ -300,29 +298,29 @@ protected: int16 _entryObj; //! Object description (Look At) - char **_objDescription; + Common::StringList _objDescription; uint16 _numDescriptions; - char **_objName; + Common::StringList _objName; uint16 _numNames; //! Room name, prefix for data files (PCX, LUM...) - char **_roomName; + Common::StringList _roomName; - char *_verbName[13]; + Common::StringList _verbName; - char *_joeResponse[JOE_RESPONSE_MAX + 1]; + Common::StringList _joeResponse; //! Actor animation string - char **_aAnim; + Common::StringList _aAnim; uint16 _numAAnim; //! Actor name - char **_aName; + Common::StringList _aName; uint16 _numAName; //! Actor filename - char **_aFile; + Common::StringList _aFile; uint16 _numAFile; struct { @@ -339,9 +337,10 @@ protected: //! Inventory items int16 _inventoryItem[4]; + //! Puzzle counter for room T7 uint8 _puzzleAttemptCount; - //! scene counter + //! Cutscene counter int _scene; Credits *_credits; |