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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Tue Mar 24 09:20:09 CET 2009


Revision: 39654
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39654&view=rev
Author:   peres001
Date:     2009-03-24 08:20:08 +0000 (Tue, 24 Mar 2009)

Log Message:
-----------
* Pushed evaluation of 'following question' from dialogue parsing to dialogue execution.
* Removed all the question forwards declaration code

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/objects.cpp
    scummvm/trunk/engines/parallaction/objects.h
    scummvm/trunk/engines/parallaction/parser.h
    scummvm/trunk/engines/parallaction/parser_ns.cpp

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2009-03-24 07:18:16 UTC (rev 39653)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2009-03-24 08:20:08 UTC (rev 39654)
@@ -388,7 +388,7 @@
 void DialogueManager::nextQuestion() {
 	debugC(9, kDebugDialogue, "nextQuestion\n");
 
-	_q = _q->_answers[_answerId]->_followingQuestion;
+	_q = _dialogue->findQuestion(_q->_answers[_answerId]->_followingName);
 	if (_q == 0) {
 		_state = DIALOGUE_OVER;
 	} else {

Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp	2009-03-24 07:18:16 UTC (rev 39653)
+++ scummvm/trunk/engines/parallaction/objects.cpp	2009-03-24 08:20:08 UTC (rev 39654)
@@ -212,6 +212,7 @@
 
 Dialogue::Dialogue() {
 	memset(_questions, 0, sizeof(_questions));
+	_numQuestions = 0;
 }
 
 Dialogue::~Dialogue() {
@@ -220,20 +221,31 @@
 	}
 }
 
+Question *Dialogue::findQuestion(const Common::String &name) const {
+	for (uint i = 0; _questions[i]; ++i) {
+		if (_questions[i]->_name == name) {
+			return _questions[i];
+		}
+	}
+	return 0;
+}
+
+void Dialogue::addQuestion(Question *q) {
+	assert(_numQuestions < NUM_QUESTIONS);
+	assert(q);
+	_questions[_numQuestions] = q;
+	_numQuestions++;
+}
+
 Answer::Answer() {
 	_mood = 0;
-	_followingQuestion =  NULL;
 	_noFlags = 0;
 	_yesFlags = 0;
 	_hasCounterCondition = false;
 }
 
-Question::Question() {
-	_mood = 0;
-
-	for (uint32 i = 0; i < NUM_ANSWERS; i++)
-		_answers[i] = NULL;
-
+Question::Question(const Common::String &name) : _name(name), _mood(0) {
+	memset(_answers, 0, sizeof(_answers));
 }
 
 Question::~Question() {

Modified: scummvm/trunk/engines/parallaction/objects.h
===================================================================
--- scummvm/trunk/engines/parallaction/objects.h	2009-03-24 07:18:16 UTC (rev 39653)
+++ scummvm/trunk/engines/parallaction/objects.h	2009-03-24 08:20:08 UTC (rev 39654)
@@ -160,9 +160,8 @@
 
 struct Answer {
 	Common::String	_text;
-	uint16		_mood;
-	Question*	_followingQuestion;
-	Common::String _followingName;
+	uint16			_mood;
+	Common::String 	_followingName;
 
 	CommandList	_commands;
 	uint32		_noFlags;
@@ -178,17 +177,22 @@
 };
 
 struct Question {
+	Common::String	_name;
 	Common::String	_text;
-	uint16		_mood;
-	Answer*		_answers[NUM_ANSWERS];
+	uint16			_mood;
+	Answer*			_answers[NUM_ANSWERS];
 
-	Question();
+	Question(const Common::String &name);
 	~Question();
 };
 
 struct Dialogue {
 	Question	*_questions[NUM_QUESTIONS];
+	uint		_numQuestions;
 
+	Question *findQuestion(const Common::String &name) const;
+	void addQuestion(Question *q);
+
 	Dialogue();
 	~Dialogue();
 };

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2009-03-24 07:18:16 UTC (rev 39653)
+++ scummvm/trunk/engines/parallaction/parser.h	2009-03-24 08:20:08 UTC (rev 39654)
@@ -190,11 +190,10 @@
 	Common::String	parseComment();
 	Common::String	parseDialogueString();
 	Dialogue	*parseDialogue();
-	void		resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards);
 	virtual Answer *parseAnswer();
 	void		parseAnswerFlags(Answer *answer);
 	void		parseAnswerBody(Answer *answer);
-	Question	*parseQuestion();
+	void		parseQuestion(Question *q);
 
 	uint32		buildZoneType(const char *t0, const char* t1);
 

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2009-03-24 07:18:16 UTC (rev 39653)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2009-03-24 08:20:08 UTC (rev 39654)
@@ -810,51 +810,39 @@
 Dialogue *LocationParser_ns::parseDialogue() {
 	debugC(7, kDebugParser, "parseDialogue()");
 
-	uint16 numQuestions = 0;
-
 	Dialogue *dialogue = new Dialogue;
 	assert(dialogue);
 
-	Table forwards(NUM_QUESTIONS);
-
 	_script->readLineToken(true);
 
 	while (scumm_stricmp(_tokens[0], "enddialogue")) {
-		if (scumm_stricmp(_tokens[0], "Question")) continue;
-
-		forwards.addData(_tokens[1]);
-
-		dialogue->_questions[numQuestions++] = parseQuestion();
-
+		if (!scumm_stricmp(_tokens[0], "question")) {
+			Question *q = new Question(_tokens[1]);
+			assert(q);
+			parseQuestion(q);
+			dialogue->addQuestion(q);
+		}
 		_script->readLineToken(true);
 	}
 
-	resolveDialogueForwards(dialogue, numQuestions, forwards);
-
 	debugC(7, kDebugParser, "parseDialogue() done");
 
 	return dialogue;
 }
 
-Question *LocationParser_ns::parseQuestion() {
+void LocationParser_ns::parseQuestion(Question *q) {
+	q->_text = parseDialogueString();
 
-	Question *question = new Question;
-	assert(question);
-
-	question->_text = parseDialogueString();
-
 	_script->readLineToken(true);
-	question->_mood = atoi(_tokens[0]);
+	q->_mood = atoi(_tokens[0]);
 
 	uint16 numAnswers = 0;
 
 	_script->readLineToken(true);
 	while (scumm_stricmp(_tokens[0], "endquestion")) {	// parse answers
-		question->_answers[numAnswers] = parseAnswer();
+		q->_answers[numAnswers] = parseAnswer();
 		numAnswers++;
 	}
-
-	return question;
 }
 
 void LocationParser_ns::parseAnswerBody(Answer *answer) {
@@ -918,28 +906,7 @@
 	return answer;
 }
 
-void LocationParser_ns::resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards) {
 
-	for (uint16 i = 0; i < numQuestions; i++) {
-		Question *question = dialogue->_questions[i];
-
-		for (uint16 j = 0; j < NUM_ANSWERS; j++) {
-			Answer *answer = question->_answers[j];
-			if (answer == 0) continue;
-
-			int16 index = forwards.lookup(answer->_followingName.c_str());
-			answer->_followingName.clear();
-
-			if (index == Table::notFound)
-				answer->_followingQuestion = 0;
-			else
-				answer->_followingQuestion = dialogue->_questions[index - 1];
-
-		}
-	}
-
-}
-
 Common::String LocationParser_ns::parseDialogueString() {
 	char buf[400];
 	char *line = _script->readLine(buf, 400);


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