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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Jun 1 16:05:39 CEST 2008


Revision: 32465
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32465&view=rev
Author:   peres001
Date:     2008-06-01 07:05:39 -0700 (Sun, 01 Jun 2008)

Log Message:
-----------
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.

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

Modified: scummvm/trunk/engines/parallaction/exec_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_br.cpp	2008-06-01 14:00:43 UTC (rev 32464)
+++ scummvm/trunk/engines/parallaction/exec_br.cpp	2008-06-01 14:05:39 UTC (rev 32465)
@@ -62,11 +62,13 @@
 
 
 
-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 @@
 
 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)
-	};
+	Common::Array<const Opcode*> *table = 0;
 
-	uint i;
-	for (i = 0; i < ARRAYSIZE(op1); i++)
-		_commandOpcodes.push_back(&op1[i]);
+	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);
 
-
-	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]);
-
-
+	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

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-06-01 14:00:43 UTC (rev 32464)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-06-01 14:05:39 UTC (rev 32465)
@@ -50,12 +50,13 @@
 #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 @@
 
 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)
-	};
+	Common::Array<const Opcode*> *table = 0;
 
-	uint i;
-	for (i = 0; i < ARRAYSIZE(op1); i++)
-		_instructionOpcodes.push_back(&op1[i]);
+	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);
 
-	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]);
-
+	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);
 }
 
 

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2008-06-01 14:00:43 UTC (rev 32464)
+++ scummvm/trunk/engines/parallaction/parser.h	2008-06-01 14:05:39 UTC (rev 32465)
@@ -59,31 +59,7 @@
 };
 
 
-
-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 @@
 	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 @@
 		delete _locationStmt;
 		delete _zoneTypeNames;
 		delete _zoneFlagNames;
+
+		delete _parser;
+
+		clearSet(_commandParsers);
+		clearSet(_locationAnimParsers);
+		clearSet(_locationZoneParsers);
+		clearSet(_locationParsers);
 	}
 
 	void parse(Script *script);
@@ -356,6 +344,11 @@
 	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 @@
 
 	virtual ~ProgramParser_ns() {
 		delete _instructionNames;
+		clearSet(_instructionParsers);
 	}
 
 	void parse(Script *script, ProgramPtr program);
@@ -395,6 +389,8 @@
 
 	virtual ~ProgramParser_br() {
 		delete _instructionNames;
+		delete _parser;
+
 	}
 
 };

Modified: scummvm/trunk/engines/parallaction/parser_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_br.cpp	2008-06-01 14:00:43 UTC (rev 32464)
+++ scummvm/trunk/engines/parallaction/parser_br.cpp	2008-06-01 14:05:39 UTC (rev 32465)
@@ -288,6 +288,20 @@
 };
 
 
+#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,17 +954,7 @@
 
 }
 
-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() {
 
 	_parser = new Parser;
@@ -963,118 +967,101 @@
 	_locationZoneStmt = new Table(ARRAYSIZE(_locationZoneStmtRes_br), _locationZoneStmtRes_br);
 	_locationAnimStmt = new Table(ARRAYSIZE(_locationAnimStmtRes_br), _locationAnimStmtRes_br);
 
+	Common::Array<const Opcode*> *table = 0;
 
-	int i;
+	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);
 
-	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)
-	};
+	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);
 
-	for (i = 0; i < ARRAYSIZE(op2); i++)
-		_commandParsers.push_back(&op2[i]);
+	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);
 
-	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]);
-
+	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 @@
 
 	_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)
-	};
+	Common::Array<const Opcode*> *table = 0;
 
-	uint i;
-	for (i = 0; i < ARRAYSIZE(op0); i++)
-		_instructionParsers.push_back(&op0[i]);
-
+	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) {

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2008-06-01 14:00:43 UTC (rev 32464)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2008-06-01 14:05:39 UTC (rev 32465)
@@ -1146,7 +1146,7 @@
 
 	return;
 }
-
+/*
 typedef OpcodeImpl<ProgramParser_ns> OpcodeV1;
 #define INSTRUCTION_PARSER(sig) OpcodeV1(this, &ProgramParser_ns::instParse_##sig)
 
@@ -1157,7 +1157,24 @@
 #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() {
 
 	_parser = new Parser;
@@ -1169,86 +1186,68 @@
 	_locationZoneStmt = new Table(ARRAYSIZE(_locationZoneStmtRes_ns), _locationZoneStmtRes_ns);
 	_locationAnimStmt = new Table(ARRAYSIZE(_locationAnimStmtRes_ns), _locationAnimStmtRes_ns);
 
-	uint i;
+	Common::Array<const Opcode*> *table = 0;
 
-	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
-	};
+	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
 
-	for (i = 0; i < ARRAYSIZE(op2); i++)
-		_commandParsers.push_back(&op2[i]);
+	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);
 
-	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)
-	};
+	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);
 
-	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]);
-
-
 }
 
 void ProgramParser_ns::init() {
@@ -1257,32 +1256,28 @@
 
 	_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);
 }
 
 //


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