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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sat Apr 7 17:18:27 CEST 2007


Revision: 26407
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26407&view=rev
Author:   peres001
Date:     2007-04-07 08:18:26 -0700 (Sat, 07 Apr 2007)

Log Message:
-----------
Changed Commands to use List<>

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/animation.cpp
    scummvm/trunk/engines/parallaction/commands.cpp
    scummvm/trunk/engines/parallaction/commands.h
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/location.cpp
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    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 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/animation.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -93,7 +93,7 @@
 			loadProgram(vD0, _tokens[1]);
 		}
 		if (!scumm_stricmp(_tokens[0], "commands")) {
-			vD0->_commands = parseCommands(script);
+			 parseCommands(script, vD0->_commands);
 		}
 		if (!scumm_stricmp(_tokens[0], "type")) {
 			if (_tokens[2][0] != '\0') {

Modified: scummvm/trunk/engines/parallaction/commands.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/commands.cpp	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/commands.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -46,7 +46,7 @@
 #define CMD_STOP			16
 
 
-Command *Parallaction::parseCommands(Script &script) {
+void Parallaction::parseCommands(Script &script, CommandList& list) {
 //	printf("parseCommands()");
 
 	Node root;
@@ -189,30 +189,32 @@
 
 	}
 
-	return (Command*)root._next;
 }
 
 
-void Parallaction::freeCommands(Command *list) {
+void Parallaction::freeCommands(CommandList &list) {
 
-	Command *cmd = list;
+	CommandList::iterator it = list.begin();
 
-	while (cmd) {
-		Command *v4 = (Command*)cmd->_next;
-		delete cmd;
-		cmd = v4;
+	while ( it != list.end() ) {
+		delete *it;
+		it++;
 	}
 
+	list.clear();
+
 	return;
 }
 
 
 
-void Parallaction::runCommands(Command *list, Zone *z) {
+void Parallaction::runCommands(CommandList& list, Zone *z) {
 	debugC(1, kDebugLocation, "runCommands");
 
-	Command *cmd = list;
-	for ( ; cmd; cmd = (Command*)cmd->_next) {
+	CommandList::iterator it = list.begin();
+	for ( ; it != list.end(); it++) {
+
+		Command *cmd = *it;
 		CommandData *u = &cmd->u;
 		uint32 v8 = _localFlags[_vm->_currentLocationIndex];
 

Modified: scummvm/trunk/engines/parallaction/commands.h
===================================================================
--- scummvm/trunk/engines/parallaction/commands.h	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/commands.h	2007-04-07 15:18:26 UTC (rev 26407)
@@ -41,6 +41,7 @@
 struct Zone;
 struct Animation;
 
+
 // TODO: turn this into a struct
 union CommandData {
 	uint32			_flags;

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -133,7 +133,7 @@
 
 			fillBuffers(script, true);
 			if (!scumm_stricmp(_tokens[0], "commands")) {
-				vB4->_answers[_di]->_commands = parseCommands(script);
+				parseCommands(script, vB4->_answers[_di]->_commands);
 				fillBuffers(script, true);
 			}
 
@@ -355,7 +355,7 @@
 
 	_askPassword = false;
 	uint16 answer = 0;
-	Command *cmdlist = NULL;
+	CommandList *cmdlist = NULL;
 
 	Dialogue *q = data->_dialogue;
 	while (q) {
@@ -369,7 +369,7 @@
 
 			if (!displayAnswers(q)) break;
 			answer = getDialogueAnswer(q, _vm->_char._talk);
-			cmdlist = q->_answers[answer]->_commands;
+			cmdlist = &q->_answers[answer]->_commands;
 		}
 
 		q = (Dialogue*)q->_answers[answer]->_following._question;
@@ -384,7 +384,7 @@
 	}
 
 	exitDialogue();
-	runCommands(cmdlist);
+	runCommands(*cmdlist);
 
 	return;
 
@@ -488,7 +488,6 @@
 	_text = NULL;
 	_mood = 0;
 	_following._question =  NULL;
-	_commands = NULL;
 	_noFlags = 0;
 	_yesFlags = 0;
 }
@@ -497,8 +496,7 @@
 	if (_mood & 0x10)
 		delete _following._question;
 
-	if (_commands)
-		_vm->freeCommands(_commands);
+	_vm->freeCommands(_commands);
 
 	if (_text)
 		free(_text);

Modified: scummvm/trunk/engines/parallaction/location.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/location.cpp	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/location.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -112,10 +112,10 @@
 			}
 		}
 		if (!scumm_stricmp(_tokens[0], "COMMANDS")) {
-			_location._commands = parseCommands(*_locationScript);
+			 parseCommands(*_locationScript, _location._commands);
 		}
 		if (!scumm_stricmp(_tokens[0], "ACOMMANDS")) {
-			_location._aCommands = parseCommands(*_locationScript);
+			parseCommands(*_locationScript, _location._aCommands);
 		}
 		if (!scumm_stricmp(_tokens[0], "FLAGS")) {
 			if ((_localFlags[_currentLocationIndex] & kFlagsVisited) == 0) {
@@ -221,16 +221,10 @@
 	debugC(7, kDebugLocation, "freeLocation: comments freed");
 
 	// TODO (LIST): this should be _location._commands.clear();
-	if (_vm->_location._commands) {
-		freeNodeList(_vm->_location._commands);
-	}
-	_vm->_location._commands = NULL;
+	freeCommands(_vm->_location._commands);
 	debugC(7, kDebugLocation, "freeLocation: commands freed");
 
-	if (_vm->_location._aCommands) {
-		freeNodeList(_vm->_location._aCommands);
-	}
-	_vm->_location._aCommands = NULL;
+	freeCommands(_vm->_location._aCommands);
 	debugC(7, kDebugLocation, "freeLocation: acommands freed");
 
 	return;
@@ -412,7 +406,8 @@
 	for (uint16 _si = 0; _si < PALETTE_SIZE; _si++) palette[_si] = 0;
 	_gfx->extendPalette(palette);
 	_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
-	if (_location._commands) {
+
+	if (_location._commands.size() > 0) {
 		runCommands(_location._commands);
 		runJobs();
 		_gfx->swapBuffers();
@@ -429,7 +424,7 @@
 	_gfx->swapBuffers();
 
 	_gfx->extendPalette(_vm->_gfx->_palette);
-	if (_location._aCommands) {
+	if (_location._aCommands.size() > 0) {
 		runCommands(_location._aCommands);
 		debugC(1, kDebugLocation, "changeLocation: location acommands run");
 	}

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -195,8 +195,6 @@
 	else
 		strcpy(_location._name, "fogne");
 
-	_location._aCommands = NULL;
-	_location._commands = NULL;
 	_location._comment = NULL;
 	_location._endComment = NULL;
 
@@ -352,7 +350,7 @@
 
 	_gfx->copyScreen(Gfx::kBitBack, Gfx::kBit2);
 
-	if (_location._commands)
+	if (_location._commands.size() > 0)
 		runCommands(_location._commands);
 
 	runJobs();
@@ -364,7 +362,7 @@
 
 	changeCursor(kCursorArrow);
 
-	if (_location._aCommands)
+	if (_location._aCommands.size() > 0)
 		runCommands(_location._aCommands);
 
 	while ((_engineFlags & kEngineQuit) == 0) {

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-04-07 15:18:26 UTC (rev 26407)
@@ -226,6 +226,8 @@
 class Menu;
 class MidiPlayer;
 
+
+
 struct Location {
 
 	Common::Point	_startPosition;
@@ -233,8 +235,8 @@
 	Node		_walkNodes;
 	char		_name[100];
 
-	Command    *_aCommands;
-	Command    *_commands;
+	CommandList		_aCommands;
+	CommandList		_commands;
 	char	   *_comment;
 	char	   *_endComment;
 
@@ -317,7 +319,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 		freeCommands(CommandList& list);
 
 	void parseLocation(const char *filename);
 	void changeCursor(int32 index);
@@ -352,7 +354,7 @@
 
 	uint16		runZone(Zone*);
 	void 		runDialogue(SpeakData*);
-	void 		runCommands(Command *list, Zone *z = NULL);
+	void 		runCommands(CommandList& list, Zone *z = NULL);
 
 public:
 	int getGameType() const;
@@ -454,7 +456,7 @@
 	void 		pickMusic(const char *location);
 	void		selectCharacterMusic(const char *name);
 
-	Command 	*parseCommands(Script &script);
+	void		parseCommands(Script &script, CommandList&);
 	void 		freeCharacter();
 
 

Modified: scummvm/trunk/engines/parallaction/zone.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/zone.cpp	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/zone.cpp	2007-04-07 15:18:26 UTC (rev 26407)
@@ -90,7 +90,7 @@
 			}
 		}
 		if (!scumm_stricmp(_tokens[0], "commands")) {
-			z->_commands = parseCommands(script);
+			 parseCommands(script, z->_commands);
 		}
 		if (!scumm_stricmp(_tokens[0], "label")) {
 //			printf("label: %s", _tokens[1]);
@@ -603,7 +603,6 @@
 
 	_type = 0;
 	_flags = 0;
-	_commands = NULL;
 }
 
 Zone::~Zone() {

Modified: scummvm/trunk/engines/parallaction/zone.h
===================================================================
--- scummvm/trunk/engines/parallaction/zone.h	2007-04-07 14:01:37 UTC (rev 26406)
+++ scummvm/trunk/engines/parallaction/zone.h	2007-04-07 15:18:26 UTC (rev 26407)
@@ -68,6 +68,8 @@
 struct Command;
 struct Question;
 
+typedef Common::List<Command*> CommandList;
+
 struct Answer {
 	char*		_text;
 	uint16		_mood;
@@ -75,7 +77,7 @@
 		Question*	_question;
 		char*		_name;
 	} _following;
-	Command*	_commands;
+	CommandList	_commands;
 	uint32		_noFlags;
 	uint32		_yesFlags;
 
@@ -199,7 +201,7 @@
 	uint16			field_2C;		// unused
 	uint16			field_2E;		// unused
 	TypeData		u;
-	Command 		*_commands;
+	CommandList 	_commands;
 	Common::Point	_moveTo;
 
 	Zone();


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