Now using stacks to keep track of multiple levels when parsing location scripts.

svn-id: r28639
This commit is contained in:
Nicola Mettifogo 2007-08-16 19:47:22 +00:00
parent 47b2f533f0
commit eb0798d580
6 changed files with 61 additions and 36 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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<const Opcode*> _opcodes;
Common::Stack<Table*> _statements;
const Opcode *_currentOpcodes;
Table *_currentStatements;
void pushParserTables(const Opcode* opcodes, Table* statements);
void popParserTables();
void parseStatement();
struct {
Command *cmd;
int nextToken;

View File

@ -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;
}