aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2008-02-09 23:26:45 +0000
committerNicola Mettifogo2008-02-09 23:26:45 +0000
commit435c437f6d118842ded3a0020168a1080ea2d0c9 (patch)
treebf16e7da40a22b13e993d997b901b7428f108108
parentcf724e889ce551082a1c3e443b11e9523f068e8d (diff)
downloadscummvm-rg350-435c437f6d118842ded3a0020168a1080ea2d0c9.tar.gz
scummvm-rg350-435c437f6d118842ded3a0020168a1080ea2d0c9.tar.bz2
scummvm-rg350-435c437f6d118842ded3a0020168a1080ea2d0c9.zip
More refactoring for command parsing/execution.
svn-id: r30841
-rw-r--r--engines/parallaction/exec_br.cpp4
-rw-r--r--engines/parallaction/exec_ns.cpp4
-rw-r--r--engines/parallaction/objects.h1
-rw-r--r--engines/parallaction/parallaction.cpp7
-rw-r--r--engines/parallaction/parallaction.h12
-rw-r--r--engines/parallaction/parser_br.cpp24
-rw-r--r--engines/parallaction/parser_ns.cpp53
7 files changed, 41 insertions, 64 deletions
diff --git a/engines/parallaction/exec_br.cpp b/engines/parallaction/exec_br.cpp
index 0e63b5e216..874d9d97a2 100644
--- a/engines/parallaction/exec_br.cpp
+++ b/engines/parallaction/exec_br.cpp
@@ -165,11 +165,11 @@ DECLARE_COMMAND_OPCODE(move) {
}
DECLARE_COMMAND_OPCODE(start) {
- _cmdRunCtxt.cmd->u._animation->_flags |= kFlagsActing;
+ _cmdRunCtxt.cmd->u._zone->_flags |= kFlagsActing;
}
DECLARE_COMMAND_OPCODE(stop) {
- _cmdRunCtxt.cmd->u._animation->_flags &= ~kFlagsActing;
+ _cmdRunCtxt.cmd->u._zone->_flags &= ~kFlagsActing;
}
diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp
index f86930a56e..821d058ac9 100644
--- a/engines/parallaction/exec_ns.cpp
+++ b/engines/parallaction/exec_ns.cpp
@@ -225,7 +225,7 @@ DECLARE_COMMAND_OPCODE(clear) {
DECLARE_COMMAND_OPCODE(start) {
- _cmdRunCtxt.cmd->u._animation->_flags |= kFlagsActing;
+ _cmdRunCtxt.cmd->u._zone->_flags |= kFlagsActing;
}
@@ -315,7 +315,7 @@ DECLARE_COMMAND_OPCODE(move) {
DECLARE_COMMAND_OPCODE(stop) {
- _cmdRunCtxt.cmd->u._animation->_flags &= ~kFlagsActing;
+ _cmdRunCtxt.cmd->u._zone->_flags &= ~kFlagsActing;
}
diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h
index 10cfb5333b..d1ad943625 100644
--- a/engines/parallaction/objects.h
+++ b/engines/parallaction/objects.h
@@ -93,7 +93,6 @@ enum CommandFlags {
struct CommandData {
uint32 _flags;
- Animation * _animation;
Zone* _zone;
char* _string;
uint16 _callable;
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index dcacf900be..9f70fa1805 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -55,13 +55,6 @@ uint32 _engineFlags = 0;
uint16 _score = 1;
char _password[8];
-Command * _forwardedCommands[MAX_FORWARDS] = {
- NULL
-};
-
-char _forwardedAnimationNames[MAX_FORWARDS][20];
-uint16 _numForwards = 0;
-
uint32 _commandFlags = 0;
uint16 _introSarcData3 = 200;
uint16 _introSarcData2 = 1;
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 09d0eabb73..dfc83f04c1 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -150,9 +150,6 @@ extern uint16 _score;
extern uint16 _language;
extern uint32 _engineFlags;
#define MAX_FORWARDS 50
-extern Command *_forwardedCommands[];
-extern char _forwardedAnimationNames[][20];
-extern uint16 _numForwards;
extern char _slideText[][MAX_TOKEN_LEN];
extern uint16 _introSarcData3; // sarcophagus stuff to be saved
extern uint16 _introSarcData2; // sarcophagus stuff to be saved
@@ -757,11 +754,19 @@ protected:
Animation *parseAnimation(Script &script, AnimationList &list, char *name);
void parseCommands(Script &script, CommandList&);
void parseCommandFlags();
+ void saveCommandForward(const char *name, Command* cmd);
+ void resolveCommandForwards();
void createCommand(uint id);
void addCommand();
void initOpcodes();
void initParsers();
+ struct CommandForwardReference {
+ char name[20];
+ Command* cmd;
+ } _forwardedCommands[MAX_FORWARDS];
+ uint _numForwardedCommands;
+
// program parser
OpcodeSet _instructionParsers;
Table *_instructionNames;
@@ -954,7 +959,6 @@ private:
DECLARE_UNQUALIFIED_LOCATION_PARSER(null);
DECLARE_UNQUALIFIED_COMMAND_PARSER(ifchar);
DECLARE_UNQUALIFIED_COMMAND_PARSER(endif);
- DECLARE_UNQUALIFIED_COMMAND_PARSER(zone);
DECLARE_UNQUALIFIED_COMMAND_PARSER(location);
DECLARE_UNQUALIFIED_COMMAND_PARSER(toggle);
DECLARE_UNQUALIFIED_COMMAND_PARSER(string);
diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp
index e193ab86b9..4e75b09355 100644
--- a/engines/parallaction/parser_br.cpp
+++ b/engines/parallaction/parser_br.cpp
@@ -420,26 +420,6 @@ DECLARE_COMMAND_PARSER(music) {
}
-DECLARE_COMMAND_PARSER(zone) {
- debugC(7, kDebugParser, "COMMAND_PARSER(zone) ");
-
- createCommand(_lookup);
-
- _locParseCtxt.cmd->u._zone = findZone(_tokens[_locParseCtxt.nextToken]);
- _locParseCtxt.nextToken++;
-
- if (_locParseCtxt.cmd->u._zone == NULL) {
- assert(_numForwards < MAX_FORWARDS);
- strcpy(_forwardedAnimationNames[_numForwards], _tokens[_locParseCtxt.nextToken-1]);
- _forwardedCommands[_numForwards] = _locParseCtxt.cmd;
- _numForwards++;
- }
-
- parseCommandFlags();
- addCommand();
-}
-
-
DECLARE_COMMAND_PARSER(zeta) {
debugC(7, kDebugParser, "COMMAND_PARSER(zeta) ");
@@ -824,7 +804,7 @@ void Parallaction_br::initParsers() {
WARNING_PARSER(unexpected),
COMMAND_PARSER(flags), // set
COMMAND_PARSER(flags), // clear
- COMMAND_PARSER(animation), // start
+ COMMAND_PARSER(zone), // start
COMMAND_PARSER(zone), // speak
COMMAND_PARSER(zone), // get
COMMAND_PARSER(location),
@@ -837,7 +817,7 @@ void Parallaction_br::initParsers() {
COMMAND_PARSER(drop),
COMMAND_PARSER(simple), // quit
COMMAND_PARSER(move),
- COMMAND_PARSER(animation), // stop
+ COMMAND_PARSER(zone), // stop
COMMAND_PARSER(string), // character
COMMAND_PARSER(string), // followme
COMMAND_PARSER(simple), // onmouse
diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp
index 4775344da7..319a32eb0d 100644
--- a/engines/parallaction/parser_ns.cpp
+++ b/engines/parallaction/parser_ns.cpp
@@ -495,30 +495,15 @@ DECLARE_COMMAND_PARSER(flags) {
}
-DECLARE_COMMAND_PARSER(animation) {
- debugC(7, kDebugParser, "COMMAND_PARSER(animation) ");
-
- createCommand(_lookup);
-
- _locParseCtxt.cmd->u._animation = findAnimation(_tokens[_locParseCtxt.nextToken]);
- _locParseCtxt.nextToken++;
- if (_locParseCtxt.cmd->u._animation == NULL) {
- strcpy(_forwardedAnimationNames[_numForwards], _tokens[_locParseCtxt.nextToken-1]);
- _forwardedCommands[_numForwards] = _locParseCtxt.cmd;
- _numForwards++;
- }
-
- parseCommandFlags();
- addCommand();
-}
-
-
DECLARE_COMMAND_PARSER(zone) {
debugC(7, kDebugParser, "COMMAND_PARSER(zone) ");
createCommand(_lookup);
_locParseCtxt.cmd->u._zone = findZone(_tokens[_locParseCtxt.nextToken]);
+ if (_locParseCtxt.cmd->u._zone == NULL) {
+ saveCommandForward(_tokens[_locParseCtxt.nextToken], _locParseCtxt.cmd);
+ }
_locParseCtxt.nextToken++;
parseCommandFlags();
@@ -670,6 +655,25 @@ void Parallaction_ns::createCommand(uint id) {
}
+void Parallaction_ns::saveCommandForward(const char *name, Command* cmd) {
+ assert(_numForwardedCommands < MAX_FORWARDS);
+
+ strcpy(_forwardedCommands[_numForwardedCommands].name, name);
+ _forwardedCommands[_numForwardedCommands].cmd = cmd;
+
+ _numForwardedCommands++;
+}
+
+void Parallaction_ns::resolveCommandForwards() {
+ for (uint i = 0; i < _numForwardedCommands; i++) {
+ _forwardedCommands[i].cmd->u._zone = findZone(_forwardedCommands[i].name);
+ if (_forwardedCommands[i].cmd->u._zone == 0) {
+ warning("Cannot find zone '%s' into current location script. This may be a bug in the original scripts.\n", _forwardedCommands[i].name);
+ }
+ }
+ _numForwardedCommands = 0;
+}
+
void Parallaction_ns::parseCommands(Script &script, CommandList& list) {
debugC(5, kDebugParser, "parseCommands()");
@@ -975,6 +979,8 @@ void Parallaction_ns::parseLocation(const char *filename) {
allocateLocationSlot(filename);
// printf("got location slot #%i for %s\n", _currentLocationIndex, filename);
+ _numForwardedCommands = 0;
+
Script *script = _disk->loadLocation(filename);
// TODO: the following two lines are specific to Nippon Safes
@@ -994,12 +1000,7 @@ void Parallaction_ns::parseLocation(const char *filename) {
delete script;
- // this resolves any forward references in the script
- for (uint16 _si = 0; _forwardedCommands[_si]; _si++) {
- _forwardedCommands[_si]->u._animation = findAnimation(_forwardedAnimationNames[_si]);
- _forwardedCommands[_si] = NULL;
- }
- _numForwards = 0;
+ resolveCommandForwards();
// this loads animation scripts
AnimationList::iterator it = _animations.begin();
@@ -1081,7 +1082,7 @@ void Parallaction_ns::initParsers() {
WARNING_PARSER(unexpected),
COMMAND_PARSER(flags), // set
COMMAND_PARSER(flags), // clear
- COMMAND_PARSER(animation), // start
+ COMMAND_PARSER(zone), // start
COMMAND_PARSER(zone), // speak
COMMAND_PARSER(zone), // get
COMMAND_PARSER(location), // location
@@ -1094,7 +1095,7 @@ void Parallaction_ns::initParsers() {
COMMAND_PARSER(drop), // drop
COMMAND_PARSER(simple), // quit
COMMAND_PARSER(move), // move
- COMMAND_PARSER(animation), // stop
+ COMMAND_PARSER(zone), // stop
COMMAND_PARSER(endcommands), // endcommands
COMMAND_PARSER(endcommands) // endzone
};