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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sat Apr 7 11:31:26 CEST 2007


Revision: 26399
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26399&view=rev
Author:   peres001
Date:     2007-04-07 02:31:24 -0700 (Sat, 07 Apr 2007)

Log Message:
-----------
Turned free___() routines into proper destructors for Zone, Animation and Program, and added memo comments for porting the engine to Common::List<>.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/animation.cpp
    scummvm/trunk/engines/parallaction/callables.cpp
    scummvm/trunk/engines/parallaction/location.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/saveload.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-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/animation.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -151,27 +151,12 @@
 }
 
 
-
-void  Parallaction::freeScript(Program *program) {
-
-	if (!program) return;
-
-	delete[] program->_locals;
-	freeNodeList(&program->_start);
-
-	return;
-}
-
-
-
 void Parallaction::freeAnimations() {
 	Animation *v4 = (Animation*)_animations._next;
 	while (v4) {
-		freeScript(v4->_program);
-		if (v4->_cnv) delete v4->_cnv;
-		v4 = (Animation*)v4->_next;
-
-		// TODO: delete Animation
+		Animation *v = (Animation*)v4->_next;
+		delete v4;
+		v4 = (Animation*)v;
 	}
 
 	return;
@@ -683,5 +668,53 @@
 	return;
 }
 
+Animation::Animation() {
+	_cnv = NULL;
+	_program = NULL;
+	_frame = 0;
+	_z = 0;
+}
 
+Animation::~Animation() {
+	if (_program)
+		delete _program;
+
+	if (_cnv)
+		delete _cnv;
+}
+
+uint16 Animation::width() const {
+	if (!_cnv) return 0;
+	return _cnv->_width;
+}
+
+uint16 Animation::height() const {
+	if (!_cnv) return 0;
+	return _cnv->_height;
+}
+
+uint16 Animation::getFrameNum() const {
+	if (!_cnv) return 0;
+	return _cnv->_count;
+}
+
+byte* Animation::getFrameData(uint32 index) const {
+	if (!_cnv) return NULL;
+	return _cnv->getFramePtr(index);
+}
+
+
+Program::Program() {
+	_locals = NULL;
+	_loopCounter = 0;
+	_ip = NULL;
+	_loopStart = NULL;
+}
+
+Program::~Program() {
+	delete[] _locals;
+	freeNodeList(&_start);
+}
+
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/callables.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/callables.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -398,23 +398,29 @@
 		_vm->_menu->selectCharacter();
 	}
 
+	// this code saves main character animation from being removed from the following code
 	removeNode(&_vm->_char._ani);
 	_vm->_locationNames[0][0] = '\0';
 	_vm->_numLocations = 0;
 	_commandFlags = 0;
 
+	// this flag tells freeZones to unconditionally remove *all* Zones
 	_engineFlags |= kEngineQuit;
 
+	// TODO (LIST): this sequence should be just _zones.clear()
 	_vm->freeZones(_vm->_zones._next);
 	freeNodeList(_vm->_zones._next);
 	_vm->_zones._next = NULL;
 
+	// TODO (LIST): this sequence should be just _animations.clear()
 	_vm->freeZones(_vm->_animations._next);
 	freeNodeList(_vm->_animations._next);
 	_vm->_animations._next = NULL;
 
+	// this dangerous flag can now be cleared
 	_engineFlags &= ~kEngineQuit;
 
+	// main character animation is restored
 	addNode(&_vm->_animations, &_vm->_char._ani);
 	_score = 0;
 

Modified: scummvm/trunk/engines/parallaction/location.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/location.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/location.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -185,10 +185,14 @@
 
 	debugC(7, kDebugLocation, "freeLocation: localflags names freed");
 
+	// TODO (LIST): this should be replaced by a call to _location._walkNodes.clear()
 	freeNodeList(_vm->_location._walkNodes._next);
 	_vm->_location._walkNodes._next = NULL;
 	debugC(7, kDebugLocation, "freeLocation: walk nodes freed");
 
+	// TODO (LIST): helperNode should be rendered useless by the use of a Common::List<>
+	// to store Zones and Animations. Right now, it holds a list of Zones to be preserved
+	// but that'll pretty meaningless with a single list approach.
 	helperNode._prev = helperNode._next = NULL;
 	_vm->freeZones(_zones._next);
 	freeNodeList(_zones._next);
@@ -197,6 +201,9 @@
 //	memcpy(&_zones, &helperNode, sizeof(Node));
 	debugC(7, kDebugLocation, "freeLocation: zones freed");
 
+	// TODO (LIST): helperNode should be rendered useless by the use of a Common::List<>
+	// to store Zones and Animations. Right now, it holds a list of Zones to be preserved
+	// but that'll pretty meaningless with a single list approach.
 	helperNode._prev = helperNode._next = NULL;
 	_vm->freeZones(_animations._next);
 	_vm->freeAnimations();
@@ -212,6 +219,7 @@
 	_vm->_location._comment = NULL;
 	debugC(7, kDebugLocation, "freeLocation: comments freed");
 
+	// TODO (LIST): this should be _location._commands.clear();
 	if (_vm->_location._commands) {
 		freeNodeList(_vm->_location._commands);
 	}

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -811,6 +811,8 @@
 	return;
 }
 
+// TODO (LIST): this rouinte basically performs List<>::clear()
+// so it will become useless
 void freeNodeList(Node *list) {
 
 	while (list) {
@@ -822,7 +824,7 @@
 	return;
 }
 
-
+// TODO (LIST): this routine will be removed
 void addNode(Node *list, Node *n) {
 
 	Node *v4 = list->_next;
@@ -838,6 +840,7 @@
 	return;
 }
 
+// TODO (LIST): this routine will be removed
 void removeNode(Node *n) {
 
 	Node *v4 = n->_next;
@@ -863,11 +866,13 @@
 
 	Job *v4 = &_jobs;
 
+	// TODO (LIST): the loop will be useless once we have an ordered
+	// list _jobs. So this code will just be: _jobs.insert(v8)
 	while (v4->_next && ((Job*)(v4->_next))->_tag > tag) {
 		v4 = (Job*)v4->_next;
 	}
+	addNode(v4, v8);
 
-	addNode(v4, v8);
 	return v8;
 }
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-04-07 09:31:24 UTC (rev 26399)
@@ -293,6 +293,7 @@
 //	static void initTable(const char *path, char **table);
 //	static void freeTable(char** table);
 //	static int16 searchTable(const char *s, const char **table);
+	void 		freeCommands(Command*);
 
 	void parseLocation(const char *filename);
 	void changeCursor(int32 index);
@@ -430,12 +431,10 @@
 	void 		pickMusic(const char *location);
 	void		selectCharacterMusic(const char *name);
 
-	void 		freeScript(Program*);
-
 	Command 	*parseCommands(Script &script);
-	void 		freeCommands(Command*);
 	void 		freeCharacter();
 
+
 	void 		initResources();
 
 };

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -81,10 +81,14 @@
 
 	f->readLine(s, 15);
 
+	// TODO (LIST): the very same code can be found in _c_finito().
+	// Why aren't we clearing Animations too, anyway?
 	_engineFlags |= kEngineQuit;
+
 	freeZones(_zones._next);
 	freeNodeList(_zones._next);
 	_zones._next = NULL;
+
 	_engineFlags &= ~kEngineQuit;
 
 	_numLocations = atoi(s);

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -188,6 +188,7 @@
 	uint32 v34 = buildSubPath(pos, stop, v48);
 	if (v38 != 0 && v34 > v38) {
 		// no alternative path (gap?)
+		// TODO (LIST): tempPath.clear()
 		freeNodeList(dummy._next);
 		return v44;
 	}
@@ -370,6 +371,7 @@
 	if (pos == _vm->_char._ani._oldPos) {
 		j->_finished = 1;
 		checkDoor();
+		//TODO (LIST): this should become path.clear()
 		freeNodeList(node);
 	} else {
 		_vm->_char._ani._frame = v16 + walkData2 + 1;

Modified: scummvm/trunk/engines/parallaction/zone.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/zone.cpp	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/zone.cpp	2007-04-07 09:31:24 UTC (rev 26399)
@@ -133,62 +133,15 @@
 			debugC(1, kDebugLocation, "freeZones preserving zone '%s'", z->_label._text);
 
 			v8 = (Zone*)z->_next;
-			removeNode(z);
-			addNode(&helperNode, z);
+			removeNode(z);					// HelperNode holds a list of zones to be preserved. There's code in freeLocation to deal with this too.
+			addNode(&helperNode, z);		// Can't we simply delete the other zones in the list and keep the good ones?
 			z = v8;
 			continue;
 		}
 
-
-		switch (z->_type & 0xFFFF) {
-		case kZoneExamine:
-			free(z->u.examine->_filename);
-			free(z->u.examine->_description);
-			delete z->u.examine;
-			break;
-
-		case kZoneDoor:
-			free(z->u.door->_location);
-			free(z->u.door->_background);
-			if (z->u.door->_cnv)
-				delete z->u.door->_cnv;
-			delete  z->u.door;
-			break;
-
-		case kZoneSpeak:
-			freeDialogue(z->u.speak->_dialogue);
-			delete z->u.speak;
-			break;
-
-		case kZoneGet:
-			free(z->u.get->_backup);
-			_vm->_gfx->freeStaticCnv(z->u.get->_cnv);
-			if (z->u.get->_cnv)
-				delete z->u.get->_cnv;
-			delete z->u.get;
-			break;
-
-		case kZoneHear:
-			delete z->u.hear;
-			break;
-
-		case kZoneMerge:
-			delete z->u.merge;
-			break;
-
-		default:
-			break;
-		}
-
-		free(z->_label._text);
-		z->_label._text = NULL;
-		_vm->_gfx->freeStaticCnv(&z->_label._cnv);
-		freeCommands(z->_commands);
-
-		// TODO: delete Zone
-
-		z=(Zone*)z->_next;
-
+		Zone *z2 = (Zone*)z->_next;
+		delete z;
+		z = z2;
 	}
 
 	return;
@@ -642,7 +595,87 @@
 	}
 
 	return NULL;
+}
 
+
+Zone::Zone() {
+	_left = _top = _right = _bottom = 0;
+
+	_type = 0;
+	_flags = 0;
+	_commands = NULL;
 }
 
+Zone::~Zone() {
+
+	switch (_type & 0xFFFF) {
+	case kZoneExamine:
+		free(u.examine->_filename);
+		free(u.examine->_description);
+		delete u.examine;
+		break;
+
+	case kZoneDoor:
+		free(u.door->_location);
+		free(u.door->_background);
+		if (u.door->_cnv)
+			delete u.door->_cnv;
+		delete u.door;
+		break;
+
+	case kZoneSpeak:
+		_vm->freeDialogue(u.speak->_dialogue);
+		delete u.speak;
+		break;
+
+	case kZoneGet:
+		free(u.get->_backup);
+		_vm->_gfx->freeStaticCnv(u.get->_cnv);
+		if (u.get->_cnv)
+			delete u.get->_cnv;
+		delete u.get;
+		break;
+
+	case kZoneHear:
+		delete u.hear;
+		break;
+
+	case kZoneMerge:
+		delete u.merge;
+		break;
+
+	default:
+		break;
+	}
+
+	free(_label._text);
+	_label._text = NULL;
+	_vm->_gfx->freeStaticCnv(&_label._cnv);
+	_vm->freeCommands(_commands);
+
+}
+
+void Zone::getRect(Common::Rect& r) const {
+	r.left = _left;
+	r.right = _right;
+	r.top = _top;
+	r.bottom = _bottom;
+}
+
+void Zone::translate(int16 x, int16 y) {
+	_left += x;
+	_right += x;
+	_top += y;
+	_bottom += y;
+}
+
+uint16 Zone::width() const {
+	return _right - _left;
+}
+
+uint16 Zone::height() const {
+	return _bottom - _top;
+}
+
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/zone.h
===================================================================
--- scummvm/trunk/engines/parallaction/zone.h	2007-04-07 09:20:48 UTC (rev 26398)
+++ scummvm/trunk/engines/parallaction/zone.h	2007-04-07 09:31:24 UTC (rev 26399)
@@ -184,50 +184,26 @@
 };
 
 struct Zone : public Node {
-	int16 		_left;
-	int16		_top;
-	int16		_right;
-	int16		_bottom;
+	int16 			_left;
+	int16			_top;
+	int16			_right;
+	int16			_bottom;
 	uint32			_type;
 	uint32			_flags;
-	Label       _label;
+	Label       	_label;
 	uint16			field_2C;		// unused
 	uint16			field_2E;		// unused
-	TypeData	u;
+	TypeData		u;
 	Command 		*_commands;
 	Common::Point	_moveTo;
 
-	Zone() {
-		_left = _top = _right = _bottom = 0;
+	Zone();
+	virtual ~Zone();
 
-		_type = 0;
-		_flags = 0;
-		_commands = NULL;
-	}
-
-	virtual ~Zone() {}
-
-	void getRect(Common::Rect& r) const {
-		r.left = _left;
-		r.right = _right;
-		r.top = _top;
-		r.bottom = _bottom;
-	}
-
-	void translate(int16 x, int16 y) {
-		_left += x;
-		_right += x;
-		_top += y;
-		_bottom += y;
-	}
-
-	virtual uint16 width() const {
-		return _right - _left;
-	}
-
-	virtual uint16 height() const {
-		return _bottom - _top;
-	}
+	void getRect(Common::Rect& r) const;
+	void translate(int16 x, int16 y);
+	virtual uint16 width() const;
+	virtual uint16 height() const;
 };
 
 struct LocalVariable {
@@ -286,12 +262,8 @@
 	Instruction 	*_loopStart;
 	Instruction		_start;
 
-	Program() {
-		_locals = NULL;
-		_loopCounter = 0;
-		_ip = NULL;
-		_loopStart = NULL;
-	}
+	Program();
+	~Program();
 };
 
 
@@ -311,34 +283,12 @@
 	uint16		field_5C;		// unused
 	uint16		field_5E;		// unused
 
-	Animation() {
-		_cnv = NULL;
-		_program = NULL;
-		_frame = 0;
-		_z = 0;
-	}
-
-	virtual ~Animation() {}
-
-	virtual uint16 width() const {
-		if (!_cnv) return 0;
-		return _cnv->_width;
-	}
-
-	virtual uint16 height() const {
-		if (!_cnv) return 0;
-		return _cnv->_height;
-	}
-
-	uint16 getFrameNum() const {
-		if (!_cnv) return 0;
-		return _cnv->_count;
-	}
-
-	byte* getFrameData(uint32 index) const {
-		if (!_cnv) return NULL;
-		return _cnv->getFramePtr(index);
-	}
+	Animation();
+	virtual ~Animation();
+	virtual uint16 width() const;
+	virtual uint16 height() const;
+	uint16 getFrameNum() const;
+	byte* getFrameData(uint32 index) const;
 };
 
 


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