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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sat Jan 3 15:03:12 CET 2009


Revision: 35700
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35700&view=rev
Author:   peres001
Date:     2009-01-03 14:03:12 +0000 (Sat, 03 Jan 2009)

Log Message:
-----------
Dropped the script preprocessor introduced to fix the broken scripts. The parser has evolved in the meantime and can deal with it accordingly.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/parser.cpp
    scummvm/trunk/engines/parallaction/parser.h
    scummvm/trunk/engines/parallaction/parser_br.cpp

Modified: scummvm/trunk/engines/parallaction/parser.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser.cpp	2009-01-03 13:32:14 UTC (rev 35699)
+++ scummvm/trunk/engines/parallaction/parser.cpp	2009-01-03 14:03:12 UTC (rev 35700)
@@ -254,184 +254,4 @@
 }
 
 
-#define BLOCK_BASE	100
-
-class StatementDef {
-protected:
-	Common::String makeLineFromTokens() {
-		Common::String space(" ");
-		Common::String newLine("\n");
-		Common::String text;
-		for (int i = 0; i < _numTokens; i++)
-			text += (Common::String(_tokens[i]) + space);
-		text.deleteLastChar();
-		text += newLine;
-		return text;
-	}
-
-public:
-	uint _score;
-	const char*	_name;
-
-
-	StatementDef(uint score, const char *name) : _score(score), _name(name) { }
-	virtual ~StatementDef() { }
-
-	virtual Common::String makeLine(Script &script) = 0;
-
-};
-
-
-class SimpleStatementDef : public StatementDef {
-
-public:
-	SimpleStatementDef(uint score, const char *name) : StatementDef(score, name) { }
-
-	Common::String makeLine(Script &script) {
-		return makeLineFromTokens();
-	}
-
-};
-
-
-
-class BlockStatementDef : public StatementDef {
-
-	const char*	_ending1;
-	const char*	_ending2;
-
-public:
-	BlockStatementDef(uint score, const char *name, const char *ending1, const char *ending2 = 0) : StatementDef(score, name), _ending1(ending1),
-		_ending2(ending2) { }
-
-	Common::String makeLine(Script &script) {
-		Common::String text = makeLineFromTokens();
-		bool end;
-		do {
-			script.readLineToken(true);
-			text += makeLineFromTokens();
-			end = !scumm_stricmp(_ending1, _tokens[0]) || (_ending2 && !scumm_stricmp(_ending2, _tokens[0]));
-		} while (!end);
-		return text;
-	}
-
-};
-
-class CommentStatementDef : public StatementDef {
-
-	Common::String parseComment(Script &script) {
-		Common::String result;
-		char buf[401];
-		do {
-			char *line = script.readLine(buf, 400);
-			if (!scumm_stricmp(line, "endtext"))
-				break;
-			result += Common::String(line) + "\n";
-		} while (true);
-		result += "endtext\n";
-		return result;
-	}
-
-public:
-	CommentStatementDef(uint score, const char *name) : StatementDef(score, name) { }
-
-	Common::String makeLine(Script &script) {
-		Common::String text = makeLineFromTokens();
-		text += parseComment(script);
-		return text;
-	}
-
-};
-
-
-
-
-PreProcessor::PreProcessor() {
-	_defs.push_back(new SimpleStatementDef(1, "disk" ));
-	_defs.push_back(new SimpleStatementDef(2, "location" ));
-	_defs.push_back(new SimpleStatementDef(3, "localflags" ));
-	_defs.push_back(new SimpleStatementDef(4, "flags" ));
-	_defs.push_back(new SimpleStatementDef(5, "zeta" ));
-	_defs.push_back(new SimpleStatementDef(6, "music" ));
-	_defs.push_back(new SimpleStatementDef(7, "sound" ));
-	_defs.push_back(new SimpleStatementDef(8, "mask" ));
-	_defs.push_back(new SimpleStatementDef(9, "path" ));
-	_defs.push_back(new SimpleStatementDef(10, "character" ));
-	_defs.push_back(new CommentStatementDef(11, "comment" ));
-	_defs.push_back(new CommentStatementDef(12, "endcomment" ));
-	_defs.push_back(new BlockStatementDef(13,  "ifchar", "endif" ));
-	_defs.push_back(new BlockStatementDef(BLOCK_BASE, "zone", "endanimation", "endzone" ));
-	_defs.push_back(new BlockStatementDef(BLOCK_BASE, "animation", "endanimation", "endzone" ));
-	_defs.push_back(new BlockStatementDef(1000, "commands", "endcommands" ));
-	_defs.push_back(new BlockStatementDef(1001, "acommands", "endcommands" ));
-	_defs.push_back(new BlockStatementDef(1002, "escape", "endcommands" ));
-	_defs.push_back(new SimpleStatementDef(2000, "endlocation"));
-}
-
-PreProcessor::~PreProcessor() {
-	DefList::iterator it = _defs.begin();
-	for (; it != _defs.end(); it++) {
-		delete *it;
-	}
-}
-
-StatementDef* PreProcessor::findDef(const char* name) {
-	DefList::iterator it = _defs.begin();
-	for (; it != _defs.end(); it++) {
-		if (!scumm_stricmp((*it)->_name, name)) {
-			return *it;
-		}
-	}
-	return 0;
-}
-
-
-
-uint PreProcessor::getDefScore(StatementDef* def) {
-	if (def->_score == BLOCK_BASE) {
-		_numZones++;
-		return (_numZones + BLOCK_BASE);
-	}
-	return def->_score;
-}
-
-
-void PreProcessor::preprocessScript(Script &script, StatementList &list) {
-	_numZones = 0;
-	Common::String text;
-	do {
-		if (script.readLineToken(false) == 0)
-			break;
-
-		StatementDef *def = findDef(_tokens[0]);
-		if (!def) {
-			error("PreProcessor::preprocessScript: unknown statement '%s' found\n", _tokens[0]);
-		}
-
-		text = def->makeLine(script);
-		int score = getDefScore(def);
-		list.push_back(StatementListNode(score, def->_name, text));
-	} while (true);
-	Common::sort(list.begin(), list.end());
-}
-
-
-
-
-void testPreprocessing(Parallaction *vm, const char *filename) {
-	Script *script = vm->_disk->loadLocation(filename);
-	StatementList list;
-	PreProcessor pp;
-	pp.preprocessScript(*script, list);
-	delete script;
-	Common::DumpFile dump;
-	dump.open(filename);
-	StatementList::iterator it = list.begin();
-	for ( ; it != list.end(); it++) {
-		dump.write((*it)._text.c_str(), (*it)._text.size());
-	}
-	dump.close();
-}
-
-
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2009-01-03 13:32:14 UTC (rev 35699)
+++ scummvm/trunk/engines/parallaction/parser.h	2009-01-03 14:03:12 UTC (rev 35700)
@@ -415,119 +415,6 @@
 };
 
 
-/*
-	This simple stream is temporarily needed to hook the
-	preprocessor output to the parser. It will go away
-	when the parser is rewritten to fully exploit the
-	statement list provided by the preprocessor.
-*/
-
-class ReadStringStream : public Common::ReadStream {
-
-	char *_text;
-	uint32	_pos;
-	uint32	_size;
-	bool _eos;
-
-public:
-	ReadStringStream(const Common::String &text) {
-		_text = new char[text.size() + 1];
-		strcpy(_text, text.c_str());
-		_size = text.size();
-		_pos = 0;
-		_eos = false;
-	}
-
-	~ReadStringStream() {
-		delete []_text;
-	}
-
-	uint32 read(void *buffer, uint32 size) {
-		if (_pos + size > _size) {
-			size = _size - _pos;
-			_eos = true;
-		}
-		memcpy(buffer, _text + _pos, size);
-		_pos += size;
-		return size;
-	}
-
-	bool eos() const {
-		return _eos;
-	}
-
-};
-
-
-/*
-	Demented as it may sound, the success of a parsing operation in the
-	original BRA depends on what has been parsed before. The game features
-	an innovative chaos system that involves the parser and the very game
-	engine, in order to inflict the user an unforgettable game experience.
-
-	Ok, now for the serious stuff.
-
-	The PreProcessor implemented here fixes the location scripts before
-	they are fed to the parser. It tries to do so by a preliminary scan
-	of the text file, during which a score is assigned to each statement
-	(more on this later). When the whole file has been analyzed, the
-	statements are sorted according to their score, to create a parsable
-	sequence.
-
-	For parsing, the statements in location scripts can be conveniently
-	divided into 3 groups:
-
-	* location definitions
-	* element definitions
-	* start-up commands
-
-	Since the parsing of element definitions requires location parameters
-	to be set, location definitions should be encountered first in the
-	script. Start-up commands in turn may reference elements, so they can
-	be parsed last. The first goal is to make sure the parser gets these
-	three sets in this order.
-
-	Location definitions must also be presented in a certain sequence,
-	because resource files are not fully self-describing. In short, some
-	critical game data in contained in certain files, that must obviously
-	be read before any other can be analyzed. This is the second goal.
-
-	TODO: some words about actual implementation.
-*/
-
-class StatementDef;
-
-struct StatementListNode {
-	int	_score;
-	Common::String	_name;
-	Common::String	_text;
-
-	StatementListNode(int score, const Common::String &name, const Common::String &text) : _score(score), _name(name), _text(text) { }
-
-	bool operator<(const StatementListNode& node) const {
-		return _score < node._score;
-	}
-};
-typedef Common::List<StatementListNode> StatementList;
-
-
-class PreProcessor {
-	typedef Common::List<StatementDef*> DefList;
-
-	int _numZones;
-	DefList _defs;
-
-	StatementDef* findDef(const char* name);
-	uint getDefScore(StatementDef*);
-
-public:
-	PreProcessor();
-	~PreProcessor();
-	void preprocessScript(Script &script, StatementList &list);
-};
-
-
-
 } // namespace Parallaction
 
 #endif

Modified: scummvm/trunk/engines/parallaction/parser_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_br.cpp	2009-01-03 13:32:14 UTC (rev 35699)
+++ scummvm/trunk/engines/parallaction/parser_br.cpp	2009-01-03 14:03:12 UTC (rev 35700)
@@ -1210,32 +1210,12 @@
 	INSTRUCTION_PARSER(endscript);
 }
 
-
-/*
-	Ancillary routine to support hooking preprocessor and
-	parser.
-*/
-Common::ReadStream *getStream(StatementList &list) {
-	Common::String text;
-	StatementList::iterator it = list.begin();
-	for ( ; it != list.end(); it++) {
-		text += (*it)._text;
-	}
-	return new ReadStringStream(text);
-}
-
 void LocationParser_br::parse(Script *script) {
-
-	PreProcessor pp;
-	StatementList list;
-	pp.preprocessScript(*script, list);
-	Script *script2 = new Script(getStream(list), true);
-
 	ctxt.numZones = 0;
 	ctxt.characterName = 0;
 	ctxt.info = new BackgroundInfo;
 
-	LocationParser_ns::parse(script2);
+	LocationParser_ns::parse(script);
 
 	_vm->_gfx->setBackground(kBackgroundLocation, ctxt.info);
 
@@ -1250,8 +1230,6 @@
 	}
 
 	free(ctxt.characterName);
-
-	delete script2;
 }
 
 } // namespace Parallaction


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