[Scummvm-cvs-logs] SF.net SVN: scummvm: [26228] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Mar 18 21:18:20 CET 2007


Revision: 26228
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26228&view=rev
Author:   peres001
Date:     2007-03-18 13:18:19 -0700 (Sun, 18 Mar 2007)

Log Message:
-----------
- added constructors for most structs
- structs are now allocated via new instead of malloc's
- respective free's have been replaced with delete

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/animation.cpp
    scummvm/trunk/engines/parallaction/commands.cpp
    scummvm/trunk/engines/parallaction/commands.h
    scummvm/trunk/engines/parallaction/defs.h
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/location.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/walk.cpp
    scummvm/trunk/engines/parallaction/zone.cpp
    scummvm/trunk/engines/parallaction/zone.h

Modified: scummvm/trunk/engines/parallaction/animation.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/animation.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/animation.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -77,8 +77,7 @@
 Animation *Parallaction::parseAnimation(Script& script, Node *list, char *name) {
 //	printf("parseAnimation(%s)\n", name);
 
-	Animation *vD0 = (Animation*)malloc(sizeof(Animation));
-	memset(vD0, 0, sizeof(Animation));
+	Animation *vD0 = new Animation;
 
 	vD0->_zone._label._text = (char*)malloc(strlen(name)+1);
 	strcpy(vD0->_zone._label._text, name);
@@ -158,7 +157,7 @@
 
 	if (!program) return;
 
-	free(program->_locals);
+	delete[] program->_locals;
 	freeNodeList(program);
 
 	return;
@@ -258,13 +257,12 @@
 
 	fillBuffers(*script);
 
-	a->_program = (Program*)malloc(sizeof(Program));
-	memset(a->_program, 0, sizeof(Program));
-	a->_program->_locals = (LocalVariable*)malloc(sizeof(LocalVariable)*10);
+	a->_program = new Program;
+
+	a->_program->_locals = new LocalVariable[10];
 	Node *vD0 = a->_program;
 
-	Instruction *vCC = (Instruction*)malloc(sizeof(Instruction));
-	memset(vCC, 0, sizeof(Instruction));
+	Instruction *vCC = new Instruction;
 
 	while (scumm_stricmp(_tokens[0], "endscript")) {
 
@@ -272,8 +270,7 @@
 		addNode(vD0, vCC);
 		vD0 = vCC;
 
-		vCC = (Instruction*)malloc(sizeof(Instruction));
-		memset(vCC, 0, sizeof(Instruction));
+		vCC = new Instruction;
 		fillBuffers(*script);
 	}
 

Modified: scummvm/trunk/engines/parallaction/commands.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/commands.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/commands.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -56,8 +56,7 @@
 	while (scumm_stricmp(_tokens[0], "ENDCOMMANDS") && scumm_stricmp(_tokens[0], "ENDZONE")) {
 //		printf("token[0] = %s", _tokens[0]);
 
-		Command *cmd = (Command*)malloc(sizeof(Command));
-		memset(cmd, 0, sizeof(Command));
+		Command *cmd = new Command;
 
 		cmd->_id = _vm->searchTable(_tokens[0], commands_names);
 		uint16 _si = 1;
@@ -200,8 +199,8 @@
 	while (cmd) {
 		Command *v4 = (Command*)cmd->_next;
 
-		if (cmd->_id == 6) free(cmd->u._zone);	// open
-		free(cmd);
+		if (cmd->_id == 6) delete cmd->u._zone;	// open
+		delete cmd;
 
 		cmd = v4;
 	}
@@ -350,3 +349,4 @@
 
 } // namespace Parallaction
 
+

Modified: scummvm/trunk/engines/parallaction/commands.h
===================================================================
--- scummvm/trunk/engines/parallaction/commands.h	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/commands.h	2007-03-18 20:18:19 UTC (rev 26228)
@@ -34,6 +34,7 @@
 	kFlagsGlobal		= 0x40000000
 };
 
+// TODO: turn this into a struct
 union CommandData {
 	uint32			_flags;
 	Animation * 	_animation;
@@ -45,6 +46,10 @@
 		int16		 _x;
 		int16		_y;
 	} _move;
+
+	CommandData() {
+		_flags = 0;
+	}
 };
 
 struct Command : public Node {
@@ -53,6 +58,11 @@
 	uint32			_flagsOn;
 	uint32			_flagsOff;
 
+	Command() {
+		_id = 0;
+		_flagsOn = 0;
+		_flagsOff = 0;
+	}
 };
 
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/defs.h
===================================================================
--- scummvm/trunk/engines/parallaction/defs.h	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/defs.h	2007-03-18 20:18:19 UTC (rev 26228)
@@ -74,6 +74,11 @@
 	uint16	_height;	//
 	byte*	_data0; 	// bitmap
 	byte*	_data1; 	// unused
+
+	StaticCnv() {
+		_width = _height = 0;
+		_data0 = _data1 = NULL;
+	}
 };
 
 
@@ -85,6 +90,11 @@
 	byte**	_array; 	// frames data
 
 public:
+	Cnv() {
+		_width = _height = _count = 0;
+		_array = NULL;
+	}
+
 	byte* getFramePtr(uint16 index) {
 		if (index >= _count)
 			error("frame %i does not exist", index);
@@ -125,3 +135,4 @@
 #endif
 
 
+

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -76,9 +76,8 @@
 	while (scumm_stricmp(_tokens[0], "enddialogue")) {
 		if (scumm_stricmp(_tokens[0], "Question")) continue;
 
-		_questions[num_questions] = (Dialogue*)malloc(sizeof(Dialogue));
+		_questions[num_questions] = new Dialogue;
 		Dialogue *vB4 = _questions[num_questions];
-		memset(_questions[num_questions], 0, sizeof(Dialogue));
 
 		_questions_names[num_questions] = (char*)malloc(strlen(_tokens[1])+1);
 		strcpy(_questions_names[num_questions], _tokens[1]);
@@ -202,18 +201,18 @@
 	if (!d) return;
 
 	uint16 _si;
-	for (_si = 0; _si < 5; _si++) {
+	for (_si = 0; _si < NUM_ANSWERS; _si++) {
 		if (d->_answer_moods[_si] & 0x10)
 			freeDialogue(d->_following._questions[_si]);
 	}
 
-	for (_si = 0; _si < 5; _si++) {
+	for (_si = 0; _si < NUM_ANSWERS; _si++) {
 		freeCommands(d->_commands[_si]);
 		free(d->_answers[_si]);
 	}
 
 	free(d->_text);
-	free(d);
+	delete d;
 
 	return;
 }
@@ -305,7 +304,7 @@
 
 	uint16 i = 0;
 
-	while (i < 5 && q->_answers[i]) {
+	while (i < NUM_ANSWERS && q->_answers[i]) {
 		if (displayAnswer(q, i)) {
 			displayed = true;
 		} else {
@@ -514,7 +513,7 @@
 	int16 top = 1000;
 	int16 bottom = 1000;
 
-	for (int16 _si = 0; _si < 5; _si++) {
+	for (int16 _si = 0; _si < NUM_ANSWERS; _si++) {
 		if (q->_answers[_si] == NULL) break;
 
 		if (_answerBalloonY[_si] != SKIPPED_ANSWER) {

Modified: scummvm/trunk/engines/parallaction/location.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/location.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/location.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -38,7 +38,7 @@
 
 
 void Parallaction::parseLocation(const char *filename) {
-//	printf("parseLocation(%s)", filename);
+	printf("parseLocation(%s)", filename);
     debugC(1, kDebugLocation, "parseLocation('%s')", filename);
 
 	uint16 _si = 1;
@@ -49,7 +49,7 @@
 
 	fillBuffers(*_locationScript, true);
 	while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
-//		printf("token[0] = %s", _tokens[0]);
+		printf("token[0] = %s", _tokens[0]);
 
 		if (!scumm_stricmp(_tokens[0], "LOCATION")) {
 			// The parameter for location is 'location.mask'.

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -876,7 +876,7 @@
 
 Job *Parallaction::addJob(JobFn fn, void *parm, uint16 tag) {
 
-	Job *v8 = (Job*)malloc(sizeof(Job));
+	Job *v8 = new Job;
 
 	v8->_parm = parm;
 	v8->_fn = fn;
@@ -897,7 +897,7 @@
 void Parallaction::removeJob(Job *j) {
 
 	removeNode(j);
-	free(j);
+	delete j;
 	return;
 }
 

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -464,3 +464,4 @@
 
 } // namespace Parallaction
 
+

Modified: scummvm/trunk/engines/parallaction/zone.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/zone.cpp	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/zone.cpp	2007-03-18 20:18:19 UTC (rev 26228)
@@ -59,8 +59,7 @@
 		return;
 	}
 
-	Zone *z = (Zone*)malloc(sizeof(Zone));
-	memset(z, 0, sizeof(Zone));
+	Zone *z = new Zone;
 
 	z->_label._text = (char*)malloc(strlen(name)+1);
 	strcpy(z->_label._text, name);
@@ -147,33 +146,33 @@
 		case kZoneExamine:
 			free(z->u.examine->_filename);
 			free(z->u.examine->_description);
-			free(z->u.examine);
+			delete z->u.examine;
 			break;
 
 		case kZoneDoor:
 			free(z->u.door->_location);
 			free(z->u.door->_background);
 			_vm->_gfx->freeCnv(&z->u.door->_cnv);
-			free(z->u.door);
+			delete  z->u.door;
 			break;
 
 		case kZoneSpeak:
 			freeDialogue(z->u.speak->_dialogue);
-			free(z->u.speak);
+			delete z->u.speak;
 			break;
 
 		case kZoneGet:
 			free(z->u.get->_backup);
 			_vm->_gfx->freeStaticCnv(&z->u.get->_cnv);
-			free(z->u.get);
+			delete z->u.get;
 			break;
 
 		case kZoneHear:
-			free(z->u.hear);
+			delete z->u.hear;
 			break;
 
 		case kZoneMerge:
-			free(z->u.merge);
+			delete z->u.merge;
 			break;
 
 		default:
@@ -185,6 +184,8 @@
 		_vm->_gfx->freeStaticCnv(&z->_label._cnv);
 		freeCommands(z->_commands);
 
+		// TODO: delete Zone
+
 		z=(Zone*)z->_next;
 
 	}
@@ -207,33 +208,27 @@
 
 	switch (z->_type & 0xFFFF) {
 	case kZoneExamine:	// examine Zone alloc
-		u->examine = (ExamineData*)malloc(sizeof(ExamineData));
-		memset(u->examine, 0, sizeof(ExamineData));
+		u->examine = new ExamineData;
 		break;
 
 	case kZoneDoor: // door Zone alloc
-		u->door = (DoorData*)malloc(sizeof(DoorData));
-		memset(u->door, 0, sizeof(DoorData));
+		u->door = new DoorData;
 		break;
 
 	case kZoneGet:	// get Zone alloc
-		u->get = (GetData*)malloc(sizeof(GetData));
-		memset(u->get, 0, sizeof(GetData));
+		u->get = new GetData;
 		break;
 
 	case kZoneMerge:	// merge Zone alloc
-		u->merge = (MergeData*)malloc(sizeof(MergeData));
-		memset(u->merge, 0, sizeof(MergeData));
+		u->merge = new MergeData;
 		break;
 
 	case kZoneHear: // hear Zone alloc
-		u->hear = (HearData*)malloc(sizeof(HearData));
-		memset(u->hear, 0, sizeof(HearData));
+		u->hear = new HearData;
 		break;
 
 	case kZoneSpeak:	// speak Zone alloc
-		u->speak = (SpeakData*)malloc(sizeof(SpeakData));
-		memset(u->speak, 0, sizeof(SpeakData));
+		u->speak = new SpeakData;
 		break;
 
 	}

Modified: scummvm/trunk/engines/parallaction/zone.h
===================================================================
--- scummvm/trunk/engines/parallaction/zone.h	2007-03-18 19:59:56 UTC (rev 26227)
+++ scummvm/trunk/engines/parallaction/zone.h	2007-03-18 20:18:19 UTC (rev 26228)
@@ -59,20 +59,34 @@
 };
 
 
+#define NUM_ANSWERS		 5
 
-
 struct Question {
 	char*		_text;
-	char*		_answers[5];
+	char*		_answers[NUM_ANSWERS];
 	uint16		_mood;
-	uint16		_answer_moods[5];
+	uint16		_answer_moods[NUM_ANSWERS];
 	union {
-		Question*	_questions[5];
-		char*		_names[5];
+		Question*	_questions[NUM_ANSWERS];
+		char*		_names[NUM_ANSWERS];
 	} _following;
-	Command*	_commands[5];
-	uint32		_noFlags[5];
-	uint32		_yesFlags[5];
+	Command*	_commands[NUM_ANSWERS];
+	uint32		_noFlags[NUM_ANSWERS];
+	uint32		_yesFlags[NUM_ANSWERS];
+
+	Question() {
+		_text = NULL;
+		_mood = 0;
+
+		for (uint32 i = 0; i < NUM_ANSWERS; i++) {
+			_answers[i] = NULL;
+			_answer_moods[i] = 0;
+			_following._questions[i] =  NULL;
+			_commands[i] = NULL;
+			_noFlags[i] = 0;
+			_yesFlags[i] = 0;
+		}
+	}
 };
 
 struct GetData {	// size = 24
@@ -81,10 +95,20 @@
 	byte		   *_backup;
 	uint16			field_14;		// unused
 	uint16			field_16;		// unused
+
+	GetData() {
+		_icon = 0;
+		_backup = NULL;
+	}
 };
 struct SpeakData {	// size = 36
 	char		_name[32];
 	Dialogue	*_dialogue;
+
+	SpeakData() {
+		_name[0] = '\0';
+		_dialogue = NULL;
+	}
 };
 struct ExamineData {	// size = 28
 	StaticCnv	_cnv;
@@ -92,6 +116,12 @@
 	uint16		field_12;			// unused
 	char*		_description;
 	char*		_filename;
+
+	ExamineData() {
+		_opBase = 0;
+		_description = NULL;
+		_filename = NULL;
+	}
 };
 struct DoorData {	// size = 28
 	char*	_location;
@@ -99,14 +129,28 @@
 	byte*	_background;
 	Common::Point	_startPos;
 	uint16	_startFrame;
+
+	DoorData() {
+		_location = NULL;
+		_background = NULL;
+		_startFrame = 0;
+	}
 };
 struct HearData {	// size = 20
 	char		_name[20];
+
+	HearData() {
+		_name[0] = '\0';
+	}
 };
 struct MergeData {	// size = 12
 	uint32	_obj1;
 	uint32	_obj2;
 	uint32	_obj3;
+
+	MergeData() {
+		_obj1 = _obj2 = _obj3 = 0;
+	}
 };
 
 struct TypeData {
@@ -116,11 +160,24 @@
 	DoorData	*door;
 	HearData	*hear;
 	MergeData	*merge;
+
+	TypeData() {
+		get = NULL;
+		speak = NULL;
+		examine = NULL;
+		door = NULL;
+		hear = NULL;
+		merge = NULL;
+	}
 };
 
 struct Label {
 	char*			_text;
 	StaticCnv		_cnv;
+
+	Label() {
+		_text = NULL;
+	}
 };
 
 struct Zone : public Node {
@@ -141,6 +198,15 @@
 	Command 		*_commands;
 	Common::Point	_moveTo;
 
+	Zone() {
+		_left = _top = _right = _bottom = 0;
+		_oldLeft = _oldTop = 0;
+
+		_type = 0;
+		_flags = 0;
+		_commands = NULL;
+	}
+
 	void getRect(Common::Rect& r) const {
 		r.left = _left;
 		r.right = _right;
@@ -168,12 +234,22 @@
 	int16		_value;
 	int16		_min;
 	int16		_max;
+
+	LocalVariable() {
+		_value = 0;
+		_min = -10000;
+		_max = 10000;
+	}
 };
 
 union LValue {
 	int16			_value;
 	int16*			_pvalue;
 	LocalVariable*	_local;
+
+	LValue() {
+		_local = NULL;
+	}
 };
 
 enum InstructionFlags {
@@ -186,7 +262,7 @@
 struct Instruction : public Node {
 	uint32	_index;
 	uint32	_flags;
-	union {
+	struct {
 		Animation	*_a;
 		Zone		*_z;
 		uint32		_index;
@@ -194,6 +270,12 @@
 	} _opBase;
 	LValue	_opA;
 	LValue	_opB;
+
+	Instruction() {
+		_index = 0;
+		_flags = 0;
+		_opBase._a = NULL;
+	}
 };
 
 
@@ -202,6 +284,13 @@
 	uint16			_loopCounter;
 	Instruction 	*_ip;
 	Instruction 	*_loopStart;
+
+	Program() {
+		_locals = NULL;
+		_loopCounter = 0;
+		_ip = NULL;
+		_loopStart = NULL;
+	}
 };
 
 
@@ -220,6 +309,24 @@
 	uint16		field_5C;		// unused
 	uint16		field_5E;		// unused
 
+	Animation() {
+
+		// FIXME: temporary hack until Animation become a subclass of Zone
+		_zone._left = _zone._top = _zone._right = _zone._bottom = 0;
+		_zone._oldLeft = _zone._oldTop = 0;
+
+		_zone._type = 0;
+		_zone._flags = 0;
+		_zone._commands = NULL;
+
+
+
+
+		_program = NULL;
+		_frame = 0;
+		_z = 0;
+	}
+
 	uint16 width() const {
 		return _cnv._width;
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list