From eb0798d58095abab2dee11206440c3c2d5e204cd Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Thu, 16 Aug 2007 19:47:22 +0000 Subject: Now using stacks to keep track of multiple levels when parsing location scripts. svn-id: r28639 --- engines/parallaction/animation.cpp | 28 ++++++++++++++-------------- engines/parallaction/commands.cpp | 10 ++-------- engines/parallaction/location.cpp | 7 ++++--- engines/parallaction/parallaction.cpp | 27 +++++++++++++++++++++++++++ engines/parallaction/parallaction.h | 12 +++++++++++- engines/parallaction/zone.cpp | 13 +++---------- 6 files changed, 61 insertions(+), 36 deletions(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp index c73617ce35..47c5454be1 100644 --- a/engines/parallaction/animation.cpp +++ b/engines/parallaction/animation.cpp @@ -95,7 +95,12 @@ DECLARE_ANIM_PARSER(type) { } } - _locAnimParseCtxt.end = true; + _locAnimParseCtxt.a->_oldPos.x = -1000; + _locAnimParseCtxt.a->_oldPos.y = -1000; + + _locAnimParseCtxt.a->_flags |= 0x1000000; + + popParserTables(); } @@ -141,7 +146,13 @@ DECLARE_ANIM_PARSER(moveto) { DECLARE_ANIM_PARSER(endanimation) { - _locAnimParseCtxt.end = true; + + _locAnimParseCtxt.a->_oldPos.x = -1000; + _locAnimParseCtxt.a->_oldPos.y = -1000; + + _locAnimParseCtxt.a->_flags |= 0x1000000; + + popParserTables(); } Animation *Parallaction::parseAnimation(Script& script, AnimationList &list, char *name) { @@ -157,18 +168,7 @@ Animation *Parallaction::parseAnimation(Script& script, AnimationList &list, cha _locAnimParseCtxt.end = false; _locAnimParseCtxt.script = &script; - do { - fillBuffers(script, true); - - int index = _locationAnimStmt->lookup(_tokens[0]); - (this->*_locationAnimParsers[index])(); - - } while (!_locAnimParseCtxt.end); - - a->_oldPos.x = -1000; - a->_oldPos.y = -1000; - - a->_flags |= 0x1000000; + pushParserTables(_locationAnimParsers, _locationAnimStmt); return a; } diff --git a/engines/parallaction/commands.cpp b/engines/parallaction/commands.cpp index 0654ef4934..41deaf49a0 100644 --- a/engines/parallaction/commands.cpp +++ b/engines/parallaction/commands.cpp @@ -154,7 +154,7 @@ DECLARE_COMMAND_PARSER(invalid) { } DECLARE_COMMAND_PARSER(endcommands) { - _cmdParseCtxt.end = true; + popParserTables(); } void Parallaction::parseCommandFlags() { @@ -238,13 +238,7 @@ void Parallaction::parseCommands(Script &script, CommandList& list) { _cmdParseCtxt.list = &list; _cmdParseCtxt.end = false; - do { - fillBuffers(script, true); - - _lookup = _commandsNames->lookup(_tokens[0]); - (this->*_commandParsers[_lookup])(); - - } while (!_cmdParseCtxt.end); + pushParserTables(_commandParsers, _commandsNames); } diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp index 177480927f..0bac727f88 100644 --- a/engines/parallaction/location.cpp +++ b/engines/parallaction/location.cpp @@ -165,20 +165,21 @@ void Parallaction::parseLocation(const char *filename) { _gfx->setFont(_labelFont); _hasLocationSound = false; - _locParseCtxt.end = false;; + _locParseCtxt.end = false; _locParseCtxt.script = script; _locParseCtxt.filename = filename; + pushParserTables(_locationParsers, _locationStmt); do { fillBuffers(*script, true); - int index = _locationStmt->lookup(_tokens[0]); - (this->*_locationParsers[index])(); + parseStatement(); } while (!_locParseCtxt.end); + popParserTables(); delete script; diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index b2893ebfca..af0a34e409 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -849,6 +849,30 @@ int Table::lookup(const char* s) { return notFound; } +void Parallaction::pushParserTables(const Opcode* opcodes, Table *statements) { + + _opcodes.push(_currentOpcodes); + _statements.push(_currentStatements); + + _currentOpcodes = opcodes; + _currentStatements = statements; + +} + +void Parallaction::popParserTables() { + assert(_opcodes.size() > 0); + + _currentOpcodes = _opcodes.pop(); + _currentStatements = _statements.pop(); +} + +void Parallaction::parseStatement() { + assert(_currentOpcodes != 0); + + _lookup = _currentStatements->lookup(_tokens[0]); + (this->*(_currentOpcodes[_lookup]))(); +} + void Parallaction::initOpcodes() { static const Opcode op0[] = { @@ -998,6 +1022,9 @@ void Parallaction::initOpcodes() { _locationAnimParsers = op6; + _currentOpcodes = 0; + _currentStatements = 0; + } } // namespace Parallaction diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 43564b4743..28551341df 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -27,7 +27,7 @@ #define PARALLACTION_H #include "common/str.h" - +#include "common/stack.h" #include "engines/engine.h" @@ -348,6 +348,16 @@ public: uint _lookup; + Common::Stack _opcodes; + Common::Stack _statements; + + const Opcode *_currentOpcodes; + Table *_currentStatements; + + void pushParserTables(const Opcode* opcodes, Table* statements); + void popParserTables(); + void parseStatement(); + struct { Command *cmd; int nextToken; diff --git a/engines/parallaction/zone.cpp b/engines/parallaction/zone.cpp index 7179e7c67d..64ef933167 100644 --- a/engines/parallaction/zone.cpp +++ b/engines/parallaction/zone.cpp @@ -48,7 +48,7 @@ DECLARE_ZONE_PARSER(invalid) { } DECLARE_ZONE_PARSER(endzone) { - _locZoneParseCtxt.end = true; + popParserTables(); } DECLARE_ZONE_PARSER(limits) { @@ -75,7 +75,7 @@ DECLARE_ZONE_PARSER(type) { parseZoneTypeBlock(*_locZoneParseCtxt.script, _locZoneParseCtxt.z); } - _locZoneParseCtxt.end = true; + popParserTables(); } @@ -120,14 +120,7 @@ void Parallaction::parseZone(Script &script, ZoneList &list, char *name) { list.push_front(z); - do { - - fillBuffers(script, true); - - int index = _locationZoneStmt->lookup(_tokens[0]); - (this->*_locationZoneParsers[index])(); - - } while (!_locZoneParseCtxt.end); + pushParserTables(_locationZoneParsers, _locationZoneStmt); return; } -- cgit v1.2.3