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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Apr 11 22:01:07 CEST 2007


Revision: 26452
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26452&view=rev
Author:   peres001
Date:     2007-04-11 13:01:06 -0700 (Wed, 11 Apr 2007)

Log Message:
-----------
- Moved Zone and Animation to List<>.
- Removed any reference to Node from codebase.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/animation.cpp
    scummvm/trunk/engines/parallaction/callables.cpp
    scummvm/trunk/engines/parallaction/commands.h
    scummvm/trunk/engines/parallaction/defs.h
    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-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/animation.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -63,18 +63,14 @@
 
 Animation *Parallaction::findAnimation(const char *name) {
 
-	Animation *v4 = (Animation*)_animations._next;
+	for (AnimationList::iterator it = _animations.begin(); it != _animations.end(); it++)
+		if (!scumm_stricmp((*it)->_label._text, name)) return *it;
 
-	while (v4) {
-		if (!scumm_stricmp(name, v4->_label._text)) return v4;
-		v4 = (Animation*)v4->_next;
-	}
-
 	return NULL;
 }
 
 
-Animation *Parallaction::parseAnimation(Script& script, Node *list, char *name) {
+Animation *Parallaction::parseAnimation(Script& script, AnimationList &list, char *name) {
 //	printf("parseAnimation(%s)\n", name);
 
 	Animation *vD0 = new Animation;
@@ -82,7 +78,7 @@
 	vD0->_label._text = (char*)malloc(strlen(name)+1);
 	strcpy(vD0->_label._text, name);
 
-	addNode(list, vD0);
+	list.push_front(vD0);
 
 	fillBuffers(script, true);
 	while (scumm_stricmp(_tokens[0], "endanimation")) {
@@ -151,14 +147,7 @@
 
 
 void Parallaction::freeAnimations() {
-	Animation *v4 = (Animation*)_animations._next;
-
-	while (v4) {
-		Animation *v = (Animation*)v4->_next;
-		delete v4;
-		v4 = (Animation*)v;
-	}
-
+	_animations.clear();
 	return;
 }
 
@@ -167,13 +156,14 @@
 void jobDisplayAnimations(void *parm, Job *j) {
 //	printf("jobDisplayAnimations()...\n");
 
-	Animation *v18 = (Animation*)_vm->_animations._next;
 	StaticCnv v14;
 
 	uint16 _si = 0;
 
-	for ( ; v18; v18 = (Animation*)v18->_next) {
+	for (AnimationList::iterator it = _vm->_animations.begin(); it != _vm->_animations.end(); it++) {
 
+		Animation *v18 = *it;
+
 		if ((v18->_flags & kFlagsActive) && ((v18->_flags & kFlagsRemove) == 0))   {
 			v14._width = v18->width();
 			v14._height = v18->height();
@@ -211,9 +201,9 @@
 void jobEraseAnimations(void *arg_0, Job *j) {
 	debugC(3, kDebugJobs, "jobEraseAnimations");
 
-	Animation *a = (Animation*)_vm->_animations._next;
+	for (AnimationList::iterator it = _vm->_animations.begin(); it != _vm->_animations.end(); it++) {
 
-	for (; a; a=(Animation*)a->_next) {
+		Animation *a = *it;
 
 		if (((a->_flags & kFlagsActive) == 0) && ((a->_flags & kFlagsRemove) == 0)) continue;
 
@@ -460,13 +450,14 @@
 
 	static uint16 modCounter = 0;
 
-	Animation *a = (Animation*)_vm->_animations._next;
-
 	StaticCnv v18;
 
-	if (a->_flags & kFlagsCharacter) a->_z = a->_top + a->height();
-	for ( ; a; a = (Animation*)a->_next) {
+	for (AnimationList::iterator it = _vm->_animations.begin(); it != _vm->_animations.end(); it++) {
 
+		Animation *a = *it;
+
+		if (a->_flags & kFlagsCharacter) a->_z = a->_top + a->height();
+
 		if ((a->_flags & kFlagsActing) == 0) continue;
 		InstructionList::iterator inst = a->_program->_ip;
 
@@ -628,36 +619,15 @@
 	return;
 }
 
+int compareAnimationZ(const AnimationPointer &a1, const AnimationPointer &a2) {
+	if (a1->_z == a2->_z) return 0;
+	return (a1->_z < a2->_z ? -1 : 1);
+}
 
 
 void Parallaction::sortAnimations() {
-	Node v14;
-
 	_char._ani._z = _char._ani.height() + _char._ani._top;
-
-	Animation *vC = (Animation*)_animations._next;
-	Node *v8;
-	Animation *v4;
-
-	while (vC) {
-
-		v8 = &v14;
-
-		while ((v8->_next != NULL) && (vC->_z >= ((Animation*)(v8->_next))->_z)) {
-			v8 = v8->_next;
-		}
-
-		v4 = (Animation*)vC->_next;
-
-		addNode(v8, vC);
-
-		vC = v4;
-	}
-
-	_animations._prev = v14._prev;
-	_animations._next = v14._next;
-	_animations._next->_prev = &_animations;
-
+	_animations.sort(compareAnimationZ);
 	return;
 }
 

Modified: scummvm/trunk/engines/parallaction/callables.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/callables.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -403,7 +403,7 @@
 	}
 
 	// this code saves main character animation from being removed from the following code
-	removeNode(&_vm->_char._ani);
+	_vm->_animations.remove(&_vm->_char._ani);
 	_vm->_locationNames[0][0] = '\0';
 	_vm->_numLocations = 0;
 	_commandFlags = 0;
@@ -412,18 +412,16 @@
 	_engineFlags |= kEngineQuit;
 
 	// TODO (LIST): this sequence should be just _zones.clear()
-	_vm->freeZones(_vm->_zones._next);
-	_vm->_zones._next = NULL;
+	_vm->freeZones();
 
 	// TODO (LIST): this sequence should be just _animations.clear()
 	_vm->freeAnimations();
-	_vm->_animations._next = NULL;
 
 	// this dangerous flag can now be cleared
 	_engineFlags &= ~kEngineQuit;
 
 	// main character animation is restored
-	addNode(&_vm->_animations, &_vm->_char._ani);
+	_vm->_animations.push_front(&_vm->_char._ani);
 	_score = 0;
 
 	return;

Modified: scummvm/trunk/engines/parallaction/commands.h
===================================================================
--- scummvm/trunk/engines/parallaction/commands.h	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/commands.h	2007-04-11 20:01:06 UTC (rev 26452)
@@ -63,7 +63,7 @@
 	}
 };
 
-struct Command : public Node {
+struct Command {
 	uint16			_id;
 	CommandData 	u;
 	uint32			_flagsOn;

Modified: scummvm/trunk/engines/parallaction/defs.h
===================================================================
--- scummvm/trunk/engines/parallaction/defs.h	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/defs.h	2007-04-11 20:01:06 UTC (rev 26452)
@@ -28,21 +28,6 @@
 
 namespace Parallaction {
 
-// TODO (LIST): this struct won't be used anymore as soon as List<> is enforced throughout the code.
-struct Node {
-	Node*	_prev;
-	Node*	_next;
-
-	Node() {
-		_prev = 0;
-		_next = 0;
-	}
-
-	virtual ~Node() {
-
-	}
-};
-
 template <class T>
 class ManagedList : public Common::List<T> {
 
@@ -84,6 +69,31 @@
 		else
 			Common_List::insert(it, element);
 	}
+
+	// FIXME: this routine is a copy of the sort routine that can be found in common/func.cpp
+	// That wasn't usable because the 'less than' operator was hardcoded. Any comments or
+	// suggestions are welcome.
+	void sort(CompareFunction compare) {
+		iterator first = Common_List::begin();
+		iterator last = Common_List::end();
+
+		if (first == last)
+			return;
+
+		// Simple selection sort
+		iterator i(first);
+		for (; i != last; ++i) {
+			iterator minElem(i);
+			iterator j(i);
+			++j;
+			for (; j != last; ++j)
+				if (compare(*j, *minElem) < 0)
+					minElem = j;
+			if (minElem != i)
+				SWAP(*minElem, *i);
+		}
+	}
+
 };
 
 } // namespace Parallaction
@@ -94,3 +104,4 @@
 
 
 
+

Modified: scummvm/trunk/engines/parallaction/location.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/location.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/location.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -35,11 +35,9 @@
 
 void resolveLocationForwards();
 void switchBackground(const char* background, const char* mask);
-void parseWalkNodes(Script &script, Node *list);
 
 
 
-
 void Parallaction::parseLocation(const char *filename) {
 //	printf("parseLocation(%s)", filename);
     debugC(1, kDebugLocation, "parseLocation('%s')", filename);
@@ -142,13 +140,13 @@
 			_location._endComment = parseComment(*_locationScript);
 		}
 		if (!scumm_stricmp(_tokens[0], "ZONE")) {
-			parseZone(*_locationScript, &_zones, _tokens[1]);
+			parseZone(*_locationScript, _zones, _tokens[1]);
 		}
 		if (!scumm_stricmp(_tokens[0], "NODES")) {
 			parseWalkNodes(*_locationScript, _location._walkNodes);
 		}
 		if (!scumm_stricmp(_tokens[0], "ANIMATION")) {
-			parseAnimation(*_locationScript, &_animations, _tokens[1]);
+			parseAnimation(*_locationScript, _animations, _tokens[1]);
 		}
 		if (!scumm_stricmp(_tokens[0], "SOUND")) {
 			strcpy(_soundFile, _tokens[1]);
@@ -193,15 +191,10 @@
 	// 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;
-	freeZones(_zones._next);
-	_zones._next = helperNode._next;
-	_zones._prev = helperNode._prev;
+	freeZones();
 	debugC(7, kDebugLocation, "freeLocation: zones freed");
 
 	freeAnimations();
-	_animations._next = 0;
-	_animations._prev = 0;
 	debugC(7, kDebugLocation, "freeLocation: animations freed");
 
 	if (_location._comment) {
@@ -334,7 +327,7 @@
 		debugC(2, kDebugLocation, "changeLocation: changed cursor");
 	}
 
-	removeNode(&_char._ani);
+	_animations.remove(&_char._ani);
 	debugC(2, kDebugLocation, "changeLocation: removed character from the animation list");
 
 	freeLocation();
@@ -367,7 +360,7 @@
 		}
 	}
 
-	addNode(&_animations, &_char._ani);
+	_animations.push_front(&_char._ani);
 	debugC(2, kDebugLocation, "changeLocation: new character added to the animation list");
 
 	strcpy(_saveData1, list[0].c_str());

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -198,7 +198,7 @@
 
 	initInventory();
 
-	addNode(&_animations, &_vm->_char._ani);
+	_animations.push_front(&_vm->_char._ani);
 	_gfx = new Gfx(this);
 
 	int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
@@ -805,35 +805,6 @@
 	return;
 }
 
-// TODO (LIST): this routine will be removed
-void addNode(Node *list, Node *n) {
-
-	Node *v4 = list->_next;
-
-	if (v4 != NULL) {
-		v4->_prev = n;
-	}
-
-	n->_next = v4;
-	list->_next = n;
-	n->_prev = list;
-
-	return;
-}
-
-// TODO (LIST): this routine will be removed
-void removeNode(Node *n) {
-
-	Node *v4 = n->_next;
-	if (v4 != NULL) {
-		v4->_prev = n->_prev;
-	}
-
-	n->_prev->_next = n->_next;
-
-	return;
-}
-
 /*
 	helper function to provide *descending* ordering of the job list
 	(higher priorities values comes first in the list)

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-04-11 20:01:06 UTC (rev 26452)
@@ -200,12 +200,7 @@
 
 void waitUntilLeftClick();
 
-void addNode(Node *list, Node *n);
-void removeNode(Node *n);
 
-
-
-
 void jobRemovePickedItem(void*, Job *j);
 void jobDisplayDroppedItem(void*, Job *j);
 void jobToggleDoor(void*, Job *j);
@@ -321,7 +316,7 @@
 	Zone 		*findZone(const char *name);
 	Zone   		*hitZone(uint32 type, uint16 x, uint16 y);
 	uint16		runZone(Zone*);
-	void 		freeZones(Node *list);
+	void 		freeZones();
 
 	void 		runDialogue(SpeakData*);
 
@@ -371,8 +366,8 @@
 
 	Common::Point	_mousePos;
 
-	Node 	_zones;
-	Node 	_animations;
+	ZoneList 		_zones;
+	AnimationList 	_animations;
 
 protected:		// data
 
@@ -404,8 +399,6 @@
 
 	JobList		_jobs;
 
-	Node 		helperNode;			// used for freeZones: to be removed
-
 protected:		// members
 	bool detectGame(void);
 
@@ -435,13 +428,13 @@
 	void 		switchBackground(const char* background, const char* mask);
 	void 		freeLocation();
 
-	void		parseZone(Script &script, Node *list, char *name);
+	void		parseZone(Script &script, ZoneList &list, char *name);
 	void		parseZoneTypeBlock(Script &script, Zone *z);
 	void 		parseWalkNodes(Script& script, WalkNodeList &list);
 	void 		displayCharacterComment(ExamineData *data);
 	void 		displayItemComment(ExamineData *data);
 
-	Animation * parseAnimation(Script &script, Node *list, char *name);
+	Animation * parseAnimation(Script &script, AnimationList &list, char *name);
 	void		parseScriptLine(Instruction *inst, Animation *a, LocalVariable *locals);
 	void		loadProgram(Animation *a, char *filename);
 	LValue		getLValue(Instruction *inst, char *str, LocalVariable *locals, Animation *a);

Modified: scummvm/trunk/engines/parallaction/saveload.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/saveload.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/saveload.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -87,8 +87,7 @@
 	// need to invoke freeZones here with kEngineQuit set, because the
 	// call in changeLocation preserve certain zones.
 	_engineFlags |= kEngineQuit;
-	freeZones(_zones._next);
-	_zones._next = NULL;
+	freeZones();
 	_engineFlags &= ~kEngineQuit;
 
 	_numLocations = atoi(s);

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -181,6 +181,9 @@
 	buildSubPath(pos, stop);
 	_list->insert(_list->begin(), _subPath.begin(), _subPath.end());
 
+	for (WalkNodeList::iterator it = _list->begin(); it != _list->end(); it++)
+		printf("node (%i, %i)\n", (*it)->_x, (*it)->_y);
+
 	delete v44;
 	return _list;
 }

Modified: scummvm/trunk/engines/parallaction/zone.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/zone.cpp	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/zone.cpp	2007-04-11 20:01:06 UTC (rev 26452)
@@ -34,20 +34,16 @@
 
 Zone *Parallaction::findZone(const char *name) {
 
-	Zone *v4 = (Zone*)_zones._next;
+	for (ZoneList::iterator it = _zones.begin(); it != _zones.end(); it++)
+		if (!scumm_stricmp((*it)->_label._text, name)) return *it;
 
-	while (v4) {
-		if (!scumm_stricmp(name, v4->_label._text)) return v4;
-		v4 = (Zone*)v4->_next;
-	}
-
 	return findAnimation(name);
 }
 
 
 
 
-void Parallaction::parseZone(Script &script, Node *list, char *name) {
+void Parallaction::parseZone(Script &script, ZoneList &list, char *name) {
 //	printf("parseZone(%s)", name);
 
 	if (findZone(name)) {
@@ -62,7 +58,7 @@
 	z->_label._text = (char*)malloc(strlen(name)+1);
 	strcpy(z->_label._text, name);
 
-	addNode(list, z);
+	list.push_front(z);
 
 	fillBuffers(script, true);
 	while (scumm_stricmp(_tokens[0], "endzone")) {
@@ -112,14 +108,15 @@
 	return;
 }
 
-void Parallaction::freeZones(Node *list) {
+void Parallaction::freeZones() {
 	debugC(1, kDebugLocation, "freeZones: kEngineQuit = %i", _engineFlags & kEngineQuit);
 
-	Zone *z = (Zone*)list;
-	Zone *v8 = NULL;
+	ZoneList::iterator it = _zones.begin();
 
-	for (; z; ) {
+	while ( it != _zones.end() ) {
 
+		Zone* z = *it;
+
 		// WORKAROUND: this huge condition is needed because we made TypeData a collection of structs
 		// instead of an union. So, merge->_obj1 and get->_icon were just aliases in the original engine,
 		// but we need to check it separately here. The same workaround is applied in hitZone.
@@ -132,16 +129,12 @@
 
 			debugC(1, kDebugLocation, "freeZones preserving zone '%s'", z->_label._text);
 
-			v8 = (Zone*)z->_next;
-			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;
-		}
+			it++;
 
-		Zone *z2 = (Zone*)z->_next;
-		delete z;
-		z = z2;
+		} else
+
+			it = _zones.erase(it);
+
 	}
 
 	return;
@@ -514,11 +507,12 @@
 
 	uint16 _di = y;
 	uint16 _si = x;
-	Zone *z = (Zone*)_zones._next;
 
-	for (; z; z = (Zone*)z->_next) {
+	for (ZoneList::iterator it = _zones.begin(); it != _zones.end(); it++) {
 //		printf("Zone name: %s", z->_name);
 
+		Zone *z = *it;
+
 		if (z->_flags & kFlagsRemove) continue;
 
 		Common::Rect r;
@@ -573,11 +567,12 @@
 
 	}
 
-	Animation *a = (Animation*)_animations._next;
 
 	int16 _a, _b, _c, _d, _e, _f;
-	for (; a; a = (Animation*)a->_next) {
+	for (AnimationList::iterator it = _animations.begin(); it != _animations.end(); it++) {
 
+		Animation *a = *it;
+
 		_a = (a->_flags & kFlagsActive) ? 1 : 0;															   // _a: active Animation
 		_e = ((_si >= a->_left + a->width()) || (_si <= a->_left)) ? 0 : 1;		// _e: horizontal range
 		_f = ((_di >= a->_top + a->height()) || (_di <= a->_top)) ? 0 : 1;		// _f: vertical range

Modified: scummvm/trunk/engines/parallaction/zone.h
===================================================================
--- scummvm/trunk/engines/parallaction/zone.h	2007-04-10 18:46:34 UTC (rev 26451)
+++ scummvm/trunk/engines/parallaction/zone.h	2007-04-11 20:01:06 UTC (rev 26452)
@@ -189,7 +189,7 @@
 	}
 };
 
-struct Zone : public Node {
+struct Zone {
 	int16 			_left;
 	int16			_top;
 	int16			_right;
@@ -212,6 +212,9 @@
 	virtual uint16 height() const;
 };
 
+typedef Zone* ZonePointer;
+typedef ManagedList<ZonePointer> ZoneList;
+
 struct LocalVariable {
 	int16		_value;
 	int16		_min;
@@ -243,7 +246,7 @@
 
 struct Animation;
 
-struct Instruction : public Node {
+struct Instruction {
 	uint32	_index;
 	uint32	_flags;
 	struct {
@@ -302,6 +305,8 @@
 	byte* getFrameData(uint32 index) const;
 };
 
+typedef Animation* AnimationPointer;
+typedef ManagedList<AnimationPointer> AnimationList;
 
 void	dropItem(uint16 v);
 int16	pickupItem(Zone *z);


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