diff options
author | Nicola Mettifogo | 2008-06-01 14:05:39 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2008-06-01 14:05:39 +0000 |
commit | 22d63345e33795c3ce2de4bb67db160ef8b8ea6d (patch) | |
tree | 1d8d0bb87406e1f60f3591abec74f7e3ad82a948 | |
parent | ec93c8957b95b0ad633cf342094ad0c25db42b18 (diff) | |
download | scummvm-rg350-22d63345e33795c3ce2de4bb67db160ef8b8ea6d.tar.gz scummvm-rg350-22d63345e33795c3ce2de4bb67db160ef8b8ea6d.tar.bz2 scummvm-rg350-22d63345e33795c3ce2de4bb67db160ef8b8ea6d.zip |
Got rid of the static arrays for initialization of parsers and exec opcodes, to make returning to launcher easier. The code has been borrowed by Kyra, after suggestion by LordHoto.
svn-id: r32465
-rw-r--r-- | engines/parallaction/exec_br.cpp | 176 | ||||
-rw-r--r-- | engines/parallaction/exec_ns.cpp | 99 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 46 | ||||
-rw-r--r-- | engines/parallaction/parser_br.cpp | 305 | ||||
-rw-r--r-- | engines/parallaction/parser_ns.cpp | 207 |
5 files changed, 396 insertions, 437 deletions
diff --git a/engines/parallaction/exec_br.cpp b/engines/parallaction/exec_br.cpp index 07ed3f5d78..2aeec6358d 100644 --- a/engines/parallaction/exec_br.cpp +++ b/engines/parallaction/exec_br.cpp @@ -62,11 +62,13 @@ namespace Parallaction { -typedef OpcodeImpl<Parallaction_br> OpcodeV2; -#define COMMAND_OPCODE(op) OpcodeV2(this, &Parallaction_br::cmdOp_##op) +#define SetOpcodeTable(x) table = &x; + +typedef Common::Functor0Mem<void, Parallaction_br> OpcodeV2; +#define COMMAND_OPCODE(op) table->push_back(new OpcodeV2(this, &Parallaction_br::cmdOp_##op)) #define DECLARE_COMMAND_OPCODE(op) void Parallaction_br::cmdOp_##op() -#define INSTRUCTION_OPCODE(op) OpcodeV2(this, &Parallaction_br::instOp_##op) +#define INSTRUCTION_OPCODE(op) table->push_back(new OpcodeV2(this, &Parallaction_br::instOp_##op)) #define DECLARE_INSTRUCTION_OPCODE(op) void Parallaction_br::instOp_##op() void Parallaction_br::setupSubtitles(char *s, char *s2, int y) { @@ -498,95 +500,85 @@ DECLARE_INSTRUCTION_OPCODE(endscript) { void Parallaction_br::initOpcodes() { - static const OpcodeV2 op1[] = { - COMMAND_OPCODE(invalid), - COMMAND_OPCODE(set), - COMMAND_OPCODE(clear), - COMMAND_OPCODE(start), - COMMAND_OPCODE(speak), - COMMAND_OPCODE(get), - COMMAND_OPCODE(location), - COMMAND_OPCODE(open), - COMMAND_OPCODE(close), - COMMAND_OPCODE(on), - COMMAND_OPCODE(off), - COMMAND_OPCODE(call), - COMMAND_OPCODE(toggle), - COMMAND_OPCODE(drop), - COMMAND_OPCODE(quit), - COMMAND_OPCODE(move), - COMMAND_OPCODE(stop), - COMMAND_OPCODE(character), - COMMAND_OPCODE(followme), - COMMAND_OPCODE(onmouse), - COMMAND_OPCODE(offmouse), - COMMAND_OPCODE(add), - COMMAND_OPCODE(leave), - COMMAND_OPCODE(inc), - COMMAND_OPCODE(dec), - COMMAND_OPCODE(ifeq), - COMMAND_OPCODE(iflt), - COMMAND_OPCODE(ifgt), - COMMAND_OPCODE(let), - COMMAND_OPCODE(music), - COMMAND_OPCODE(fix), - COMMAND_OPCODE(unfix), - COMMAND_OPCODE(zeta), - COMMAND_OPCODE(scroll), - COMMAND_OPCODE(swap), - COMMAND_OPCODE(give), - COMMAND_OPCODE(text), - COMMAND_OPCODE(part), - COMMAND_OPCODE(testsfx), - COMMAND_OPCODE(ret), - COMMAND_OPCODE(onsave), - COMMAND_OPCODE(offsave) - }; - - uint i; - for (i = 0; i < ARRAYSIZE(op1); i++) - _commandOpcodes.push_back(&op1[i]); - - - static const OpcodeV2 op2[] = { - INSTRUCTION_OPCODE(invalid), - INSTRUCTION_OPCODE(on), - INSTRUCTION_OPCODE(off), - INSTRUCTION_OPCODE(set), // x - INSTRUCTION_OPCODE(set), // y - INSTRUCTION_OPCODE(set), // z - INSTRUCTION_OPCODE(set), // f - INSTRUCTION_OPCODE(loop), - INSTRUCTION_OPCODE(endloop), - INSTRUCTION_OPCODE(null), // show - INSTRUCTION_OPCODE(inc), - INSTRUCTION_OPCODE(inc), // dec - INSTRUCTION_OPCODE(set), - INSTRUCTION_OPCODE(put), - INSTRUCTION_OPCODE(call), - INSTRUCTION_OPCODE(wait), - INSTRUCTION_OPCODE(start), - INSTRUCTION_OPCODE(process), - INSTRUCTION_OPCODE(move), - INSTRUCTION_OPCODE(color), - INSTRUCTION_OPCODE(process), // sound - INSTRUCTION_OPCODE(mask), - INSTRUCTION_OPCODE(print), - INSTRUCTION_OPCODE(text), - INSTRUCTION_OPCODE(inc), // mul - INSTRUCTION_OPCODE(inc), // div - INSTRUCTION_OPCODE(ifeq), - INSTRUCTION_OPCODE(iflt), - INSTRUCTION_OPCODE(ifgt), - INSTRUCTION_OPCODE(endif), - INSTRUCTION_OPCODE(stop), - INSTRUCTION_OPCODE(endscript) - }; - - for (i = 0; i < ARRAYSIZE(op2); i++) - _instructionOpcodes.push_back(&op2[i]); - - + Common::Array<const Opcode*> *table = 0; + + SetOpcodeTable(_commandOpcodes); + COMMAND_OPCODE(invalid); + COMMAND_OPCODE(set); + COMMAND_OPCODE(clear); + COMMAND_OPCODE(start); + COMMAND_OPCODE(speak); + COMMAND_OPCODE(get); + COMMAND_OPCODE(location); + COMMAND_OPCODE(open); + COMMAND_OPCODE(close); + COMMAND_OPCODE(on); + COMMAND_OPCODE(off); + COMMAND_OPCODE(call); + COMMAND_OPCODE(toggle); + COMMAND_OPCODE(drop); + COMMAND_OPCODE(quit); + COMMAND_OPCODE(move); + COMMAND_OPCODE(stop); + COMMAND_OPCODE(character); + COMMAND_OPCODE(followme); + COMMAND_OPCODE(onmouse); + COMMAND_OPCODE(offmouse); + COMMAND_OPCODE(add); + COMMAND_OPCODE(leave); + COMMAND_OPCODE(inc); + COMMAND_OPCODE(dec); + COMMAND_OPCODE(ifeq); + COMMAND_OPCODE(iflt); + COMMAND_OPCODE(ifgt); + COMMAND_OPCODE(let); + COMMAND_OPCODE(music); + COMMAND_OPCODE(fix); + COMMAND_OPCODE(unfix); + COMMAND_OPCODE(zeta); + COMMAND_OPCODE(scroll); + COMMAND_OPCODE(swap); + COMMAND_OPCODE(give); + COMMAND_OPCODE(text); + COMMAND_OPCODE(part); + COMMAND_OPCODE(testsfx); + COMMAND_OPCODE(ret); + COMMAND_OPCODE(onsave); + COMMAND_OPCODE(offsave); + + SetOpcodeTable(_instructionOpcodes); + INSTRUCTION_OPCODE(invalid); + INSTRUCTION_OPCODE(on); + INSTRUCTION_OPCODE(off); + INSTRUCTION_OPCODE(set); // x + INSTRUCTION_OPCODE(set); // y + INSTRUCTION_OPCODE(set); // z + INSTRUCTION_OPCODE(set); // f + INSTRUCTION_OPCODE(loop); + INSTRUCTION_OPCODE(endloop); + INSTRUCTION_OPCODE(null); // show + INSTRUCTION_OPCODE(inc); + INSTRUCTION_OPCODE(inc); // dec + INSTRUCTION_OPCODE(set); + INSTRUCTION_OPCODE(put); + INSTRUCTION_OPCODE(call); + INSTRUCTION_OPCODE(wait); + INSTRUCTION_OPCODE(start); + INSTRUCTION_OPCODE(process); + INSTRUCTION_OPCODE(move); + INSTRUCTION_OPCODE(color); + INSTRUCTION_OPCODE(process); // sound + INSTRUCTION_OPCODE(mask); + INSTRUCTION_OPCODE(print); + INSTRUCTION_OPCODE(text); + INSTRUCTION_OPCODE(inc); // mul + INSTRUCTION_OPCODE(inc); // div + INSTRUCTION_OPCODE(ifeq); + INSTRUCTION_OPCODE(iflt); + INSTRUCTION_OPCODE(ifgt); + INSTRUCTION_OPCODE(endif); + INSTRUCTION_OPCODE(stop); + INSTRUCTION_OPCODE(endscript); } #if 0 diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp index 68ae91c73e..a4b372f42a 100644 --- a/engines/parallaction/exec_ns.cpp +++ b/engines/parallaction/exec_ns.cpp @@ -50,12 +50,13 @@ namespace Parallaction { #define INST_MOVE 18 #define INST_ENDSCRIPT 19 +#define SetOpcodeTable(x) table = &x; -typedef OpcodeImpl<Parallaction_ns> OpcodeV1; -#define COMMAND_OPCODE(op) OpcodeV1(this, &Parallaction_ns::cmdOp_##op) +typedef Common::Functor0Mem<void, Parallaction_ns> OpcodeV2; +#define COMMAND_OPCODE(op) table->push_back(new OpcodeV2(this, &Parallaction_ns::cmdOp_##op)) #define DECLARE_COMMAND_OPCODE(op) void Parallaction_ns::cmdOp_##op() -#define INSTRUCTION_OPCODE(op) OpcodeV1(this, &Parallaction_ns::instOp_##op) +#define INSTRUCTION_OPCODE(op) table->push_back(new OpcodeV2(this, &Parallaction_ns::instOp_##op)) #define DECLARE_INSTRUCTION_OPCODE(op) void Parallaction_ns::instOp_##op() @@ -653,56 +654,48 @@ ZonePtr Parallaction::hitZone(uint32 type, uint16 x, uint16 y) { void Parallaction_ns::initOpcodes() { - static const OpcodeV1 op1[] = { - INSTRUCTION_OPCODE(invalid), - INSTRUCTION_OPCODE(on), - INSTRUCTION_OPCODE(off), - INSTRUCTION_OPCODE(set), // x - INSTRUCTION_OPCODE(set), // y - INSTRUCTION_OPCODE(set), // z - INSTRUCTION_OPCODE(set), // f - INSTRUCTION_OPCODE(loop), - INSTRUCTION_OPCODE(endloop), - INSTRUCTION_OPCODE(null), - INSTRUCTION_OPCODE(inc), - INSTRUCTION_OPCODE(inc), // dec - INSTRUCTION_OPCODE(set), - INSTRUCTION_OPCODE(put), - INSTRUCTION_OPCODE(call), - INSTRUCTION_OPCODE(wait), - INSTRUCTION_OPCODE(start), - INSTRUCTION_OPCODE(sound), - INSTRUCTION_OPCODE(move), - INSTRUCTION_OPCODE(endscript) - }; - - uint i; - for (i = 0; i < ARRAYSIZE(op1); i++) - _instructionOpcodes.push_back(&op1[i]); - - static const OpcodeV1 op3[] = { - COMMAND_OPCODE(invalid), - COMMAND_OPCODE(set), - COMMAND_OPCODE(clear), - COMMAND_OPCODE(start), - COMMAND_OPCODE(speak), - COMMAND_OPCODE(get), - COMMAND_OPCODE(location), - COMMAND_OPCODE(open), - COMMAND_OPCODE(close), - COMMAND_OPCODE(on), - COMMAND_OPCODE(off), - COMMAND_OPCODE(call), - COMMAND_OPCODE(toggle), - COMMAND_OPCODE(drop), - COMMAND_OPCODE(quit), - COMMAND_OPCODE(move), - COMMAND_OPCODE(stop) - }; - - for (i = 0; i < ARRAYSIZE(op3); i++) - _commandOpcodes.push_back(&op3[i]); - + Common::Array<const Opcode*> *table = 0; + + SetOpcodeTable(_instructionOpcodes); + INSTRUCTION_OPCODE(invalid); + INSTRUCTION_OPCODE(on); + INSTRUCTION_OPCODE(off); + INSTRUCTION_OPCODE(set); // x + INSTRUCTION_OPCODE(set); // y + INSTRUCTION_OPCODE(set); // z + INSTRUCTION_OPCODE(set); // f + INSTRUCTION_OPCODE(loop); + INSTRUCTION_OPCODE(endloop); + INSTRUCTION_OPCODE(null); + INSTRUCTION_OPCODE(inc); + INSTRUCTION_OPCODE(inc); // dec + INSTRUCTION_OPCODE(set); + INSTRUCTION_OPCODE(put); + INSTRUCTION_OPCODE(call); + INSTRUCTION_OPCODE(wait); + INSTRUCTION_OPCODE(start); + INSTRUCTION_OPCODE(sound); + INSTRUCTION_OPCODE(move); + INSTRUCTION_OPCODE(endscript); + + SetOpcodeTable(_commandOpcodes); + COMMAND_OPCODE(invalid); + COMMAND_OPCODE(set); + COMMAND_OPCODE(clear); + COMMAND_OPCODE(start); + COMMAND_OPCODE(speak); + COMMAND_OPCODE(get); + COMMAND_OPCODE(location); + COMMAND_OPCODE(open); + COMMAND_OPCODE(close); + COMMAND_OPCODE(on); + COMMAND_OPCODE(off); + COMMAND_OPCODE(call); + COMMAND_OPCODE(toggle); + COMMAND_OPCODE(drop); + COMMAND_OPCODE(quit); + COMMAND_OPCODE(move); + COMMAND_OPCODE(stop); } diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index d600f9eb9d..fa5d0527ed 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -59,31 +59,7 @@ public: }; - -class Opcode { - -public: - virtual void operator()() const = 0; - virtual ~Opcode() { } -}; - -template <class T> -class OpcodeImpl : public Opcode { - - typedef void (T::*Fn)(); - - T* _instance; - Fn _fn; - -public: - OpcodeImpl(T* instance, const Fn &fn) : _instance(instance), _fn(fn) { } - - void operator()() const { - (_instance->*_fn)(); - } - -}; - +typedef Common::Functor0<void> Opcode; typedef Common::Array<const Opcode*> OpcodeSet; @@ -232,6 +208,11 @@ protected: uint _numForwardedCommands; void init(); + void clearSet(OpcodeSet &opcodes) { + for (Common::Array<const Opcode*>::iterator i = opcodes.begin(); i != opcodes.end(); ++i) + delete *i; + opcodes.clear(); + } public: LocationParser_ns(Parallaction_ns *vm) : _vm(vm) { @@ -243,6 +224,13 @@ public: delete _locationStmt; delete _zoneTypeNames; delete _zoneFlagNames; + + delete _parser; + + clearSet(_commandParsers); + clearSet(_locationAnimParsers); + clearSet(_locationZoneParsers); + clearSet(_locationParsers); } void parse(Script *script); @@ -356,6 +344,11 @@ protected: virtual void parseRValue(ScriptVar &var, const char *str); void init(); + void clearSet(OpcodeSet &opcodes) { + for (Common::Array<const Opcode*>::iterator i = opcodes.begin(); i != opcodes.end(); ++i) + delete *i; + opcodes.clear(); + } public: ProgramParser_ns(Parallaction_ns *vm) : _vm(vm) { @@ -364,6 +357,7 @@ public: virtual ~ProgramParser_ns() { delete _instructionNames; + clearSet(_instructionParsers); } void parse(Script *script, ProgramPtr program); @@ -395,6 +389,8 @@ public: virtual ~ProgramParser_br() { delete _instructionNames; + delete _parser; + } }; diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index d9dd2ef5c8..cebda4b5ed 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -288,6 +288,20 @@ const char *_instructionNamesRes_br[] = { }; +#define SetOpcodeTable(x) table = &x; + +typedef Common::Functor0Mem<void, ProgramParser_br> OpcodeV1; +#define INSTRUCTION_PARSER(sig) table->push_back(new OpcodeV1(this, &ProgramParser_br::instParse_##sig)) + +typedef Common::Functor0Mem<void, LocationParser_br> OpcodeV2; +#define ZONE_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::locZoneParse_##sig)) +#define ANIM_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::locAnimParse_##sig)) +#define LOCATION_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::locParse_##sig)) +#define COMMAND_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::cmdParse_##sig)) + +#define WARNING_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::warning_##sig)) + + #define DECLARE_ZONE_PARSER(sig) void LocationParser_br::locZoneParse_##sig() #define DECLARE_ANIM_PARSER(sig) void LocationParser_br::locAnimParse_##sig() #define DECLARE_COMMAND_PARSER(sig) void LocationParser_br::cmdParse_##sig() @@ -940,16 +954,6 @@ void ProgramParser_br::parseRValue(ScriptVar &v, const char *str) { } -typedef OpcodeImpl<LocationParser_br> OpcodeV2; -#define ZONE_PARSER(sig) OpcodeV2(this, &LocationParser_br::locZoneParse_##sig) -#define ANIM_PARSER(sig) OpcodeV2(this, &LocationParser_br::locAnimParse_##sig) -#define LOCATION_PARSER(sig) OpcodeV2(this, &LocationParser_br::locParse_##sig) -#define COMMAND_PARSER(sig) OpcodeV2(this, &LocationParser_br::cmdParse_##sig) -#define WARNING_PARSER(sig) OpcodeV2(this, &LocationParser_br::warning_##sig) - -typedef OpcodeImpl<ProgramParser_br> OpcodeV3; -#define INSTRUCTION_PARSER(sig) OpcodeV3(this, &ProgramParser_br::instParse_##sig) - void LocationParser_br::init() { @@ -963,118 +967,101 @@ void LocationParser_br::init() { _locationZoneStmt = new Table(ARRAYSIZE(_locationZoneStmtRes_br), _locationZoneStmtRes_br); _locationAnimStmt = new Table(ARRAYSIZE(_locationAnimStmtRes_br), _locationAnimStmtRes_br); - - int i; - - static const OpcodeV2 op2[] = { - WARNING_PARSER(unexpected), - COMMAND_PARSER(flags), // set - COMMAND_PARSER(flags), // clear - COMMAND_PARSER(zone), // start - COMMAND_PARSER(zone), // speak - COMMAND_PARSER(zone), // get - COMMAND_PARSER(location), - COMMAND_PARSER(zone), // open - COMMAND_PARSER(zone), // close - COMMAND_PARSER(zone), // on - COMMAND_PARSER(zone), // off - COMMAND_PARSER(call), - COMMAND_PARSER(flags), // toggle - COMMAND_PARSER(drop), - COMMAND_PARSER(simple), // quit - COMMAND_PARSER(move), - COMMAND_PARSER(zone), // stop - COMMAND_PARSER(string), // character - COMMAND_PARSER(string), // followme - COMMAND_PARSER(simple), // onmouse - COMMAND_PARSER(simple), // offmouse - COMMAND_PARSER(drop), // add - COMMAND_PARSER(zone), // leave - COMMAND_PARSER(math), // inc - COMMAND_PARSER(math), // dec - COMMAND_PARSER(test), // test - WARNING_PARSER(unexpected), - WARNING_PARSER(unexpected), - COMMAND_PARSER(math), // let - COMMAND_PARSER(music), - COMMAND_PARSER(zone), // fix - COMMAND_PARSER(zone), // unfix - COMMAND_PARSER(zeta), - COMMAND_PARSER(unary), // scroll - COMMAND_PARSER(string), // swap - COMMAND_PARSER(give), - COMMAND_PARSER(text), - COMMAND_PARSER(unary), // part - WARNING_PARSER(unexpected), - COMMAND_PARSER(simple), // return - COMMAND_PARSER(simple), // onsave - COMMAND_PARSER(simple), // offsave - COMMAND_PARSER(endcommands), // endcommands - COMMAND_PARSER(ifchar), - COMMAND_PARSER(endif) - }; - - for (i = 0; i < ARRAYSIZE(op2); i++) - _commandParsers.push_back(&op2[i]); - - static const OpcodeV2 op4[] = { - WARNING_PARSER(unexpected), - LOCATION_PARSER(character), - LOCATION_PARSER(endlocation), - LOCATION_PARSER(ifchar), - LOCATION_PARSER(null), // endif - LOCATION_PARSER(location), - LOCATION_PARSER(mask), - LOCATION_PARSER(path), - LOCATION_PARSER(null), // disk - LOCATION_PARSER(localflags), - LOCATION_PARSER(commands), - LOCATION_PARSER(escape), - LOCATION_PARSER(acommands), - LOCATION_PARSER(flags), - LOCATION_PARSER(comment), - LOCATION_PARSER(endcomment), - LOCATION_PARSER(zone), - LOCATION_PARSER(animation), - LOCATION_PARSER(zeta), - LOCATION_PARSER(music), - LOCATION_PARSER(sound) - }; - - for (i = 0; i < ARRAYSIZE(op4); i++) - _locationParsers.push_back(&op4[i]); - - static const OpcodeV2 op5[] = { - WARNING_PARSER(unexpected), - ZONE_PARSER(endzone), - ZONE_PARSER(limits), - ZONE_PARSER(moveto), - ZONE_PARSER(type), - ZONE_PARSER(commands), - ZONE_PARSER(label), - ZONE_PARSER(flags) - }; - - for (i = 0; i < ARRAYSIZE(op5); i++) - _locationZoneParsers.push_back(&op5[i]); - - static const OpcodeV2 op6[] = { - WARNING_PARSER(unexpected), - ANIM_PARSER(endanimation), - ANIM_PARSER(endanimation), // endzone - ANIM_PARSER(script), - ANIM_PARSER(commands), - ANIM_PARSER(type), - ANIM_PARSER(label), - ANIM_PARSER(flags), - ANIM_PARSER(file), - ANIM_PARSER(position), - ANIM_PARSER(moveto) - }; - - for (i = 0; i < ARRAYSIZE(op6); i++) - _locationAnimParsers.push_back(&op6[i]); - + Common::Array<const Opcode*> *table = 0; + + SetOpcodeTable(_commandParsers); + WARNING_PARSER(unexpected); + COMMAND_PARSER(flags); // set + COMMAND_PARSER(flags); // clear + COMMAND_PARSER(zone); // start + COMMAND_PARSER(zone); // speak + COMMAND_PARSER(zone); // get + COMMAND_PARSER(location); + COMMAND_PARSER(zone); // open + COMMAND_PARSER(zone); // close + COMMAND_PARSER(zone); // on + COMMAND_PARSER(zone); // off + COMMAND_PARSER(call); + COMMAND_PARSER(flags); // toggle + COMMAND_PARSER(drop); + COMMAND_PARSER(simple); // quit + COMMAND_PARSER(move); + COMMAND_PARSER(zone); // stop + COMMAND_PARSER(string); // character + COMMAND_PARSER(string); // followme + COMMAND_PARSER(simple); // onmouse + COMMAND_PARSER(simple); // offmouse + COMMAND_PARSER(drop); // add + COMMAND_PARSER(zone); // leave + COMMAND_PARSER(math); // inc + COMMAND_PARSER(math); // dec + COMMAND_PARSER(test); // test + WARNING_PARSER(unexpected); + WARNING_PARSER(unexpected); + COMMAND_PARSER(math); // let + COMMAND_PARSER(music); + COMMAND_PARSER(zone); // fix + COMMAND_PARSER(zone); // unfix + COMMAND_PARSER(zeta); + COMMAND_PARSER(unary); // scroll + COMMAND_PARSER(string); // swap + COMMAND_PARSER(give); + COMMAND_PARSER(text); + COMMAND_PARSER(unary); // part + WARNING_PARSER(unexpected); + COMMAND_PARSER(simple); // return + COMMAND_PARSER(simple); // onsave + COMMAND_PARSER(simple); // offsave + COMMAND_PARSER(endcommands); // endcommands + COMMAND_PARSER(ifchar); + COMMAND_PARSER(endif); + + SetOpcodeTable(_locationParsers); + WARNING_PARSER(unexpected); + LOCATION_PARSER(character); + LOCATION_PARSER(endlocation); + LOCATION_PARSER(ifchar); + LOCATION_PARSER(null); // endif + LOCATION_PARSER(location); + LOCATION_PARSER(mask); + LOCATION_PARSER(path); + LOCATION_PARSER(null); // disk + LOCATION_PARSER(localflags); + LOCATION_PARSER(commands); + LOCATION_PARSER(escape); + LOCATION_PARSER(acommands); + LOCATION_PARSER(flags); + LOCATION_PARSER(comment); + LOCATION_PARSER(endcomment); + LOCATION_PARSER(zone); + LOCATION_PARSER(animation); + LOCATION_PARSER(zeta); + LOCATION_PARSER(music); + LOCATION_PARSER(sound); + + SetOpcodeTable(_locationZoneParsers); + WARNING_PARSER(unexpected); + ZONE_PARSER(endzone); + ZONE_PARSER(limits); + ZONE_PARSER(moveto); + ZONE_PARSER(type); + ZONE_PARSER(commands); + ZONE_PARSER(label); + ZONE_PARSER(flags); + + + SetOpcodeTable(_locationAnimParsers); + WARNING_PARSER(unexpected); + ANIM_PARSER(endanimation); + ANIM_PARSER(endanimation); // endzone + ANIM_PARSER(script); + ANIM_PARSER(commands); + ANIM_PARSER(type); + ANIM_PARSER(label); + ANIM_PARSER(flags); + ANIM_PARSER(file); + ANIM_PARSER(position); + ANIM_PARSER(moveto); } void ProgramParser_br::init() { @@ -1083,45 +1070,41 @@ void ProgramParser_br::init() { _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_br), _instructionNamesRes_br); - static const OpcodeV3 op0[] = { - INSTRUCTION_PARSER(defLocal), // invalid opcode -> local definition - INSTRUCTION_PARSER(zone), // on - INSTRUCTION_PARSER(zone), // off - INSTRUCTION_PARSER(x), - INSTRUCTION_PARSER(y), - INSTRUCTION_PARSER(z), - INSTRUCTION_PARSER(f), - INSTRUCTION_PARSER(loop), - INSTRUCTION_PARSER(null), // endloop - INSTRUCTION_PARSER(null), // show - INSTRUCTION_PARSER(inc), - INSTRUCTION_PARSER(inc), // dec - INSTRUCTION_PARSER(set), - INSTRUCTION_PARSER(put), - INSTRUCTION_PARSER(call), - INSTRUCTION_PARSER(null), // wait - INSTRUCTION_PARSER(zone), // start - INSTRUCTION_PARSER(zone), // process - INSTRUCTION_PARSER(move), - INSTRUCTION_PARSER(color), - INSTRUCTION_PARSER(zone), // sound - INSTRUCTION_PARSER(mask), - INSTRUCTION_PARSER(print), - INSTRUCTION_PARSER(text), - INSTRUCTION_PARSER(inc), // mul - INSTRUCTION_PARSER(inc), // div - INSTRUCTION_PARSER(if_op), - INSTRUCTION_PARSER(null), - INSTRUCTION_PARSER(null), - INSTRUCTION_PARSER(endif), - INSTRUCTION_PARSER(zone), // stop - INSTRUCTION_PARSER(endscript) - }; - - uint i; - for (i = 0; i < ARRAYSIZE(op0); i++) - _instructionParsers.push_back(&op0[i]); - + Common::Array<const Opcode*> *table = 0; + + SetOpcodeTable(_instructionParsers); + INSTRUCTION_PARSER(defLocal); // invalid opcode -> local definition + INSTRUCTION_PARSER(zone); // on + INSTRUCTION_PARSER(zone); // off + INSTRUCTION_PARSER(x); + INSTRUCTION_PARSER(y); + INSTRUCTION_PARSER(z); + INSTRUCTION_PARSER(f); + INSTRUCTION_PARSER(loop); + INSTRUCTION_PARSER(null); // endloop + INSTRUCTION_PARSER(null); // show + INSTRUCTION_PARSER(inc); + INSTRUCTION_PARSER(inc); // dec + INSTRUCTION_PARSER(set); + INSTRUCTION_PARSER(put); + INSTRUCTION_PARSER(call); + INSTRUCTION_PARSER(null); // wait + INSTRUCTION_PARSER(zone); // start + INSTRUCTION_PARSER(zone); // process + INSTRUCTION_PARSER(move); + INSTRUCTION_PARSER(color); + INSTRUCTION_PARSER(zone); // sound + INSTRUCTION_PARSER(mask); + INSTRUCTION_PARSER(print); + INSTRUCTION_PARSER(text); + INSTRUCTION_PARSER(inc); // mul + INSTRUCTION_PARSER(inc); // div + INSTRUCTION_PARSER(if_op); + INSTRUCTION_PARSER(null); + INSTRUCTION_PARSER(null); + INSTRUCTION_PARSER(endif); + INSTRUCTION_PARSER(zone); // stop + INSTRUCTION_PARSER(endscript); } void LocationParser_br::parse(Script *script) { diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 4966d46ad3..96a4fced71 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -1146,7 +1146,7 @@ void LocationParser_ns::parseWalkNodes(WalkNodeList &list) { return; } - +/* typedef OpcodeImpl<ProgramParser_ns> OpcodeV1; #define INSTRUCTION_PARSER(sig) OpcodeV1(this, &ProgramParser_ns::instParse_##sig) @@ -1157,6 +1157,23 @@ typedef OpcodeImpl<LocationParser_ns> OpcodeV2; #define COMMAND_PARSER(sig) OpcodeV2(this, &LocationParser_ns::cmdParse_##sig) #define WARNING_PARSER(sig) OpcodeV2(this, &LocationParser_br::warning_##sig) +*/ + +#define SetOpcodeTable(x) table = &x; + + +typedef Common::Functor0Mem<void, ProgramParser_ns> OpcodeV1; +#define SetOpcodeTable(x) table = &x; +#define INSTRUCTION_PARSER(sig) table->push_back(new OpcodeV1(this, &ProgramParser_ns::instParse_##sig)) + +typedef Common::Functor0Mem<void, LocationParser_ns> OpcodeV2; +#define ZONE_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_ns::locZoneParse_##sig)) +#define ANIM_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_ns::locAnimParse_##sig)) +#define LOCATION_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_ns::locParse_##sig)) +#define COMMAND_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_ns::cmdParse_##sig)) + +#define WARNING_PARSER(sig) table->push_back(new OpcodeV2(this, &LocationParser_br::warning_##sig)) + void LocationParser_ns::init() { @@ -1169,85 +1186,67 @@ void LocationParser_ns::init() { _locationZoneStmt = new Table(ARRAYSIZE(_locationZoneStmtRes_ns), _locationZoneStmtRes_ns); _locationAnimStmt = new Table(ARRAYSIZE(_locationAnimStmtRes_ns), _locationAnimStmtRes_ns); - uint i; - - static const OpcodeV2 op2[] = { - WARNING_PARSER(unexpected), - COMMAND_PARSER(flags), // set - COMMAND_PARSER(flags), // clear - COMMAND_PARSER(zone), // start - COMMAND_PARSER(zone), // speak - COMMAND_PARSER(zone), // get - COMMAND_PARSER(location), // location - COMMAND_PARSER(zone), // open - COMMAND_PARSER(zone), // close - COMMAND_PARSER(zone), // on - COMMAND_PARSER(zone), // off - COMMAND_PARSER(call), // call - COMMAND_PARSER(flags), // toggle - COMMAND_PARSER(drop), // drop - COMMAND_PARSER(simple), // quit - COMMAND_PARSER(move), // move - COMMAND_PARSER(zone), // stop - COMMAND_PARSER(endcommands), // endcommands - COMMAND_PARSER(endcommands) // endzone - }; - - for (i = 0; i < ARRAYSIZE(op2); i++) - _commandParsers.push_back(&op2[i]); - - - static const OpcodeV2 op4[] = { - WARNING_PARSER(unexpected), - LOCATION_PARSER(endlocation), - LOCATION_PARSER(location), - LOCATION_PARSER(disk), - LOCATION_PARSER(nodes), - LOCATION_PARSER(zone), - LOCATION_PARSER(animation), - LOCATION_PARSER(localflags), - LOCATION_PARSER(commands), - LOCATION_PARSER(acommands), - LOCATION_PARSER(flags), - LOCATION_PARSER(comment), - LOCATION_PARSER(endcomment), - LOCATION_PARSER(sound), - LOCATION_PARSER(music) - }; - - for (i = 0; i < ARRAYSIZE(op4); i++) - _locationParsers.push_back(&op4[i]); - - static const OpcodeV2 op5[] = { - WARNING_PARSER(unexpected), - ZONE_PARSER(limits), - ZONE_PARSER(moveto), - ZONE_PARSER(type), - ZONE_PARSER(commands), - ZONE_PARSER(label), - ZONE_PARSER(flags), - ZONE_PARSER(endzone) - }; - - for (i = 0; i < ARRAYSIZE(op5); i++) - _locationZoneParsers.push_back(&op5[i]); - - static const OpcodeV2 op6[] = { - WARNING_PARSER(unexpected), - ANIM_PARSER(script), - ANIM_PARSER(commands), - ANIM_PARSER(type), - ANIM_PARSER(label), - ANIM_PARSER(flags), - ANIM_PARSER(file), - ANIM_PARSER(position), - ANIM_PARSER(moveto), - ANIM_PARSER(endanimation) - }; - - for (i = 0; i < ARRAYSIZE(op6); i++) - _locationAnimParsers.push_back(&op6[i]); - + Common::Array<const Opcode*> *table = 0; + + SetOpcodeTable(_commandParsers); + WARNING_PARSER(unexpected); + COMMAND_PARSER(flags); // set + COMMAND_PARSER(flags); // clear + COMMAND_PARSER(zone); // start + COMMAND_PARSER(zone); // speak + COMMAND_PARSER(zone); // get + COMMAND_PARSER(location); // location + COMMAND_PARSER(zone); // open + COMMAND_PARSER(zone); // close + COMMAND_PARSER(zone); // on + COMMAND_PARSER(zone); // off + COMMAND_PARSER(call); // call + COMMAND_PARSER(flags); // toggle + COMMAND_PARSER(drop); // drop + COMMAND_PARSER(simple); // quit + COMMAND_PARSER(move); // move + COMMAND_PARSER(zone); // stop + COMMAND_PARSER(endcommands); // endcommands + COMMAND_PARSER(endcommands); // endzone + + SetOpcodeTable(_locationParsers); + WARNING_PARSER(unexpected); + LOCATION_PARSER(endlocation); + LOCATION_PARSER(location); + LOCATION_PARSER(disk); + LOCATION_PARSER(nodes); + LOCATION_PARSER(zone); + LOCATION_PARSER(animation); + LOCATION_PARSER(localflags); + LOCATION_PARSER(commands); + LOCATION_PARSER(acommands); + LOCATION_PARSER(flags); + LOCATION_PARSER(comment); + LOCATION_PARSER(endcomment); + LOCATION_PARSER(sound); + LOCATION_PARSER(music); + + SetOpcodeTable(_locationZoneParsers); + WARNING_PARSER(unexpected); + ZONE_PARSER(limits); + ZONE_PARSER(moveto); + ZONE_PARSER(type); + ZONE_PARSER(commands); + ZONE_PARSER(label); + ZONE_PARSER(flags); + ZONE_PARSER(endzone); + + SetOpcodeTable(_locationAnimParsers); + WARNING_PARSER(unexpected); + ANIM_PARSER(script); + ANIM_PARSER(commands); + ANIM_PARSER(type); + ANIM_PARSER(label); + ANIM_PARSER(flags); + ANIM_PARSER(file); + ANIM_PARSER(position); + ANIM_PARSER(moveto); + ANIM_PARSER(endanimation); } @@ -1257,32 +1256,28 @@ void ProgramParser_ns::init() { _instructionNames = new Table(ARRAYSIZE(_instructionNamesRes_ns), _instructionNamesRes_ns); - static const OpcodeV1 op0[] = { - INSTRUCTION_PARSER(defLocal), // invalid opcode -> local definition - INSTRUCTION_PARSER(animation), // on - INSTRUCTION_PARSER(animation), // off - INSTRUCTION_PARSER(x), - INSTRUCTION_PARSER(y), - INSTRUCTION_PARSER(z), - INSTRUCTION_PARSER(f), - INSTRUCTION_PARSER(loop), - INSTRUCTION_PARSER(null), // endloop - INSTRUCTION_PARSER(null), // show - INSTRUCTION_PARSER(inc), - INSTRUCTION_PARSER(inc), // dec - INSTRUCTION_PARSER(set), - INSTRUCTION_PARSER(put), - INSTRUCTION_PARSER(call), - INSTRUCTION_PARSER(null), // wait - INSTRUCTION_PARSER(animation), // start - INSTRUCTION_PARSER(sound), - INSTRUCTION_PARSER(move), - INSTRUCTION_PARSER(endscript) - }; - - for (uint i = 0; i < ARRAYSIZE(op0); i++) - _instructionParsers.push_back(&op0[i]); - + Common::Array<const Opcode*> *table = 0; + SetOpcodeTable(_instructionParsers); + INSTRUCTION_PARSER(defLocal); // invalid opcode -> local definition + INSTRUCTION_PARSER(animation); // on + INSTRUCTION_PARSER(animation); // off + INSTRUCTION_PARSER(x); + INSTRUCTION_PARSER(y); + INSTRUCTION_PARSER(z); + INSTRUCTION_PARSER(f); + INSTRUCTION_PARSER(loop); + INSTRUCTION_PARSER(null); // endloop + INSTRUCTION_PARSER(null); // show + INSTRUCTION_PARSER(inc); + INSTRUCTION_PARSER(inc); // dec + INSTRUCTION_PARSER(set); + INSTRUCTION_PARSER(put); + INSTRUCTION_PARSER(call); + INSTRUCTION_PARSER(null); // wait + INSTRUCTION_PARSER(animation); // start + INSTRUCTION_PARSER(sound); + INSTRUCTION_PARSER(move); + INSTRUCTION_PARSER(endscript); } // |