[Scummvm-cvs-logs] CVS: scummvm/queen command.cpp,1.76,1.77 command.h,1.21,1.22 grid.cpp,1.5,1.6 grid.h,1.3,1.4 logic.cpp,1.207,1.208 logic.h,1.119,1.120

Gregory Montoir cyx at users.sourceforge.net
Sun Oct 17 12:01:15 CEST 2004


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12221/queen

Modified Files:
	command.cpp command.h grid.cpp grid.h logic.cpp logic.h 
Log Message:
plugged some memory leaks

Index: command.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/command.cpp,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- command.cpp	8 Oct 2004 18:43:23 -0000	1.76
+++ command.cpp	17 Oct 2004 19:00:09 -0000	1.77
@@ -125,6 +125,14 @@
 	: _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();

Index: command.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/command.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- command.h	3 Apr 2004 17:58:58 -0000	1.21
+++ command.h	17 Oct 2004 19:00:09 -0000	1.22
@@ -72,6 +72,7 @@
 public:
 	
 	Command(QueenEngine *vm);
+	~Command();
 	
 	//! initialise command construction
 	void clear(bool clearTexts);

Index: grid.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/grid.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- grid.cpp	23 Mar 2004 20:34:19 -0000	1.5
+++ grid.cpp	17 Oct 2004 19:00:09 -0000	1.6
@@ -33,6 +33,13 @@
 	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;
 

Index: grid.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/grid.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- grid.h	12 Jan 2004 13:40:01 -0000	1.3
+++ grid.h	17 Oct 2004 19:00:09 -0000	1.4
@@ -39,6 +39,7 @@
 public:
 
 	Grid(QueenEngine *vm);
+	~Grid();
 
 	void readDataFrom(uint16 numObjects, uint16 numRooms, byte *&ptr);
 

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.207
retrieving revision 1.208
diff -u -d -r1.207 -r1.208
--- logic.cpp	10 Oct 2004 17:12:50 -0000	1.207
+++ logic.cpp	17 Oct 2004 19:00:09 -0000	1.208
@@ -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() {
 	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 @@
 
 	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();
+	_objName.push_back("");
+	for (i = 1; i <= _numNames; i++) {
+		_objName.push_back(queen2jas->nextLine());
+	}
 
-	_roomName = new char*[_numRooms + 1];
-	_roomName[0] = 0;
-	for (i = 1; i <= _numRooms; i++)
-		_roomName[i] = _queen2jas->nextLine();
+	_roomName.push_back("");
+	for (i = 1; i <= _numRooms; i++) {
+		_roomName.push_back(queen2jas->nextLine());
+	}
 
-	_verbName[0] = 0;
-	for (i = 1; i <= 12; i++)
-		_verbName[i] = _queen2jas->nextLine();
+	_verbName.push_back("");
+	for (i = 1; i <= 12; i++) {
+		_verbName.push_back(queen2jas->nextLine());
+	}
 
-	_joeResponse[0] = 0;
-	for (i = 1; i <= JOE_RESPONSE_MAX; i++)
-		_joeResponse[i] = _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 @@
 		}
 	}
 
-	_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 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 @@
 	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 @@
 
 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 @@
 		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 @@
 	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::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;
 	}

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.h,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -d -r1.119 -r1.120
--- logic.h	8 Oct 2004 18:43:24 -0000	1.119
+++ logic.h	17 Oct 2004 19:00:09 -0000	1.120
@@ -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 @@
 	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 @@
 	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 @@
 
 	virtual bool preChangeRoom() = 0;
 	virtual bool handleSpecialMove(uint16 sm) = 0;
-
-
-	LineReader *_queen2jas;
+	
 
 	uint16 _currentRoom;
 	uint16 _oldRoom;
@@ -300,29 +298,29 @@
 	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 @@
 	//! Inventory items
 	int16 _inventoryItem[4];
 
+	//! Puzzle counter for room T7
 	uint8 _puzzleAttemptCount;
 
-	//! scene counter
+	//! Cutscene counter
 	int _scene;
 
 	Credits *_credits;





More information about the Scummvm-git-logs mailing list