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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Thu Feb 26 07:16:35 CET 2009


Revision: 38892
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38892&view=rev
Author:   peres001
Date:     2009-02-26 06:16:35 +0000 (Thu, 26 Feb 2009)

Log Message:
-----------
Cleanup of CommandExec and ProgramExec, and pushed down dependencies from exec.h.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/callables_ns.cpp
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/exec.h
    scummvm/trunk/engines/parallaction/exec_br.cpp
    scummvm/trunk/engines/parallaction/exec_ns.cpp
    scummvm/trunk/engines/parallaction/input.cpp
    scummvm/trunk/engines/parallaction/module.mk
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_br.cpp
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp
    scummvm/trunk/engines/parallaction/walk.cpp

Added Paths:
-----------
    scummvm/trunk/engines/parallaction/exec.cpp

Modified: scummvm/trunk/engines/parallaction/callables_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables_ns.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/callables_ns.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -30,6 +30,8 @@
 
 #include "graphics/primitives.h"			// for Graphics::drawLine
 
+
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/parallaction.h"
 #include "parallaction/saveload.h"

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -24,7 +24,7 @@
  */
 
 #include "common/events.h"
-
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/parallaction.h"
 

Added: scummvm/trunk/engines/parallaction/exec.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec.cpp	                        (rev 0)
+++ scummvm/trunk/engines/parallaction/exec.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -0,0 +1,196 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "parallaction/exec.h"
+#include "parallaction/parallaction.h"
+
+namespace Parallaction {
+
+void ProgramExec::runScript(ProgramPtr script, AnimationPtr a) {
+	debugC(9, kDebugExec, "runScript(Animation = %s)", a->_name);
+
+	_ctxt._ip = script->_ip;
+	_ctxt._anim = a;
+	_ctxt._program = script;
+	_ctxt._suspend = false;
+	_ctxt._modCounter = _modCounter;
+
+	InstructionList::iterator inst;
+	for ( ; (a->_flags & kFlagsActing) ; ) {
+
+		inst = _ctxt._ip;
+		_ctxt._inst = inst;
+		++_ctxt._ip;
+
+		debugC(9, kDebugExec, "inst [%02i] %s\n", (*inst)->_index, _instructionNames[(*inst)->_index - 1]);
+
+		script->_status = kProgramRunning;
+
+		(*_opcodes[(*inst)->_index])(_ctxt);
+
+		if (_ctxt._suspend)
+			break;
+
+	}
+	script->_ip = _ctxt._ip;
+
+}
+
+void ProgramExec::runScripts(ProgramList::iterator first, ProgramList::iterator last) {
+	if (_engineFlags & kEnginePauseJobs) {
+		return;
+	}
+
+	for (ProgramList::iterator it = first; it != last; ++it) {
+
+		AnimationPtr a = (*it)->_anim;
+
+		if (a->_flags & kFlagsCharacter)
+			a->resetZ();
+
+		if ((a->_flags & kFlagsActing) == 0)
+			continue;
+
+		runScript(*it, a);
+
+		if (a->_flags & kFlagsCharacter)
+			a->resetZ();
+	}
+
+	_modCounter++;
+
+	return;
+}
+
+ProgramExec::ProgramExec() : _modCounter(0) {
+}
+
+
+void CommandExec::runList(CommandList::iterator first, CommandList::iterator last) {
+
+	uint32 useFlags = 0;
+	bool useLocalFlags;
+
+	_suspend = false;
+	_running = true;
+
+	for ( ; first != last; ++first) {
+		if (_vm->shouldQuit())
+			break;
+
+		CommandPtr cmd = *first;
+
+		if (cmd->_flagsOn & kFlagsGlobal) {
+			useFlags = _globalFlags | kFlagsGlobal;
+			useLocalFlags = false;
+		} else {
+			useFlags = _vm->getLocationFlags();
+			useLocalFlags = true;
+		}
+
+		bool onMatch = (cmd->_flagsOn & useFlags) == cmd->_flagsOn;
+		bool offMatch = (cmd->_flagsOff & ~useFlags) == cmd->_flagsOff;
+
+		debugC(3, kDebugExec, "runCommands[%i] (on: %x, off: %x), (%s = %x)", cmd->_id,  cmd->_flagsOn, cmd->_flagsOff,
+			useLocalFlags ? "LOCALFLAGS" : "GLOBALFLAGS", useFlags);
+
+		if (!onMatch || !offMatch) continue;
+
+		_ctxt._z = _execZone;
+		_ctxt._cmd = cmd;
+
+		(*_opcodes[cmd->_id])(_ctxt);
+
+		if (_suspend) {
+			createSuspendList(++first, last);
+			return;
+		}
+	}
+
+	_running = false;
+
+}
+
+void CommandExec::run(CommandList& list, ZonePtr z) {
+	if (list.size() == 0) {
+		debugC(3, kDebugExec, "runCommands: nothing to do");
+		return;
+	}
+
+	_execZone = z;
+
+	debugC(3, kDebugExec, "runCommands starting");
+	runList(list.begin(), list.end());
+	debugC(3, kDebugExec, "runCommands completed");
+}
+
+void CommandExec::createSuspendList(CommandList::iterator first, CommandList::iterator last) {
+	if (first == last) {
+		return;
+	}
+
+	debugC(3, kDebugExec, "CommandExec::createSuspendList()");
+
+	_suspendedCtxt._valid = true;
+	_suspendedCtxt._first = first;
+	_suspendedCtxt._last = last;
+	_suspendedCtxt._zone = _execZone;
+}
+
+void CommandExec::cleanSuspendedList() {
+	debugC(3, kDebugExec, "CommandExec::cleanSuspended()");
+
+	_suspendedCtxt._valid = false;
+	_suspendedCtxt._first = _suspendedCtxt._last;
+	_suspendedCtxt._zone = nullZonePtr;
+}
+
+void CommandExec::suspend() {
+	if (!_running)
+		return;
+
+	_suspend = true;
+}
+
+void CommandExec::runSuspended() {
+	if (_engineFlags & kEngineWalking) {
+		return;
+	}
+
+	if (_suspendedCtxt._valid) {
+		debugC(3, kDebugExec, "CommandExec::runSuspended()");
+
+		_execZone = _suspendedCtxt._zone;
+		runList(_suspendedCtxt._first, _suspendedCtxt._last);
+		cleanSuspendedList();
+	}
+}
+
+
+CommandExec::CommandExec(Parallaction *vm) : _vm(vm), _suspend(false), _running(false) {
+	_suspendedCtxt._valid = false;
+}
+
+}


Property changes on: scummvm/trunk/engines/parallaction/exec.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/engines/parallaction/exec.h
===================================================================
--- scummvm/trunk/engines/parallaction/exec.h	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/exec.h	2009-02-26 06:16:35 UTC (rev 38892)
@@ -33,64 +33,91 @@
 
 namespace Parallaction {
 
-typedef Common::Functor0<void> Opcode;
-typedef Common::Array<const Opcode*>	OpcodeSet;
-
-#define DECLARE_UNQUALIFIED_COMMAND_OPCODE(op) void cmdOp_##op()
-#define DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(op) void instOp_##op()
-
 class Parallaction_ns;
 class Parallaction_br;
 
-class CommandExec {
+/* NOTE: CommandExec and ProgramExec perform similar tasks on different data.
+   CommandExec executes commands found in location scripts, while ProgramExec
+   runs animation programs.
+
+   The main difference is how suspension is handled. CommandExec is coded with
+   the assumption that there may be at most one suspended list of commands at any
+   moment, and thus stores the suspended context itself. It also offers a
+   runSuspended() routine that resumes execution on request.
+   ProgramExec instead stores the suspension information in the programs themselves.
+   Programs are in fact meant to be run (almost) regularly on each frame .
+ */
+
+struct CommandContext {
+	CommandPtr _cmd;
+	ZonePtr	_z;
+
+	// TODO: add a way to invoke CommandExec::suspend() from the context. With that
+	// in place, opcodes dependency on CommandExec would be zero, and they could
+	// be moved into a Game object, together with the non-infrastructural code now
+	// in Parallaction_XX
+};
+typedef Common::Functor1<CommandContext&, void> CommandOpcode;
+typedef Common::Array<const CommandOpcode*>	CommandOpcodeSet;
+#define DECLARE_UNQUALIFIED_COMMAND_OPCODE(op) void cmdOp_##op(CommandContext &)
+
+struct ProgramContext {
+	AnimationPtr	_anim;
+	ProgramPtr		_program;
+	InstructionList::iterator _inst;
+	InstructionList::iterator _ip;
+	uint16		_modCounter;
+	bool		_suspend;
+};
+typedef Common::Functor1<ProgramContext&, void> ProgramOpcode;
+typedef Common::Array<const ProgramOpcode*>	ProgramOpcodeSet;
+#define DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(op) void instOp_##op(ProgramContext &)
+
+
+template <class OpcodeSet>
+class Exec {
 protected:
+	OpcodeSet _opcodes;
+	typedef typename OpcodeSet::iterator OpIt;
+public:
+	virtual ~Exec() {
+		for (OpIt i = _opcodes.begin(); i != _opcodes.end(); ++i)
+			delete *i;
+		_opcodes.clear();
+	}
+};
+
+class CommandExec : public Exec<CommandOpcodeSet> {
+protected:
 	Parallaction *_vm;
 
-	struct ParallactionStruct1 {
-		CommandPtr cmd;
-		ZonePtr	z;
-	} _ctxt;
+	CommandContext _ctxt;
+	ZonePtr	_execZone;
+	bool _running;
+	bool _suspend;
 
-	OpcodeSet	_opcodes;
-
 	struct SuspendedContext {
-		bool valid;
-		CommandList::iterator first;
-		CommandList::iterator last;
-		ZonePtr	zone;
+		bool _valid;
+		CommandList::iterator _first;
+		CommandList::iterator _last;
+		ZonePtr	_zone;
 	} _suspendedCtxt;
 
-	ZonePtr	_execZone;
 	void runList(CommandList::iterator first, CommandList::iterator last);
 	void createSuspendList(CommandList::iterator first, CommandList::iterator last);
 	void cleanSuspendedList();
-
-	bool _running;
-	bool _suspend;
-
 public:
-	virtual void init() = 0;
-	virtual void run(CommandList &list, ZonePtr z = nullZonePtr);
+	CommandExec(Parallaction *vm);
+
+	void run(CommandList &list, ZonePtr z = nullZonePtr);
 	void runSuspended();
 	void suspend();
-
-	CommandExec(Parallaction *vm) : _vm(vm) {
-		_suspendedCtxt.valid = false;
-		_suspend = false;
-		_running = false;
-	}
-	virtual ~CommandExec() {
-		for (Common::Array<const Opcode*>::iterator i = _opcodes.begin(); i != _opcodes.end(); ++i)
-			delete *i;
-		_opcodes.clear();
-	}
 };
 
 class CommandExec_ns : public CommandExec {
-
+protected:
 	Parallaction_ns	*_vm;
 
-protected:
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(invalid);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(set);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(clear);
@@ -108,16 +135,11 @@
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(quit);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(move);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(stop);
-
 public:
-	void init();
-
 	CommandExec_ns(Parallaction_ns* vm);
-	~CommandExec_ns();
 };
 
 class CommandExec_br : public CommandExec {
-
 protected:
 	Parallaction_br	*_vm;
 
@@ -128,7 +150,6 @@
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(get);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(toggle);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(quit);
-
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(location);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(open);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(close);
@@ -164,49 +185,29 @@
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(ret);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(onsave);
 	DECLARE_UNQUALIFIED_COMMAND_OPCODE(offsave);
-
 public:
-	void		init();
-
 	CommandExec_br(Parallaction_br* vm);
-	~CommandExec_br();
 };
 
-class ProgramExec {
-protected:
-	struct ParallactionStruct2 {
-		AnimationPtr	anim;
-		ProgramPtr		program;
-		InstructionList::iterator inst;
-		InstructionList::iterator ip;
-		uint16		modCounter;
-		bool		suspend;
-	} _ctxt;
 
-	const char **_instructionNames;
 
-	OpcodeSet	_opcodes;
 
+class ProgramExec : public Exec<ProgramOpcodeSet> {
+protected:
+	ProgramContext _ctxt;
 	uint16	_modCounter;
-	void runScript(ProgramPtr script, AnimationPtr a);
+	const char **_instructionNames;
 
+	void runScript(ProgramPtr script, AnimationPtr a);
 public:
-	virtual void init() = 0;
-	virtual void runScripts(ProgramList::iterator first, ProgramList::iterator last);
-	ProgramExec() : _modCounter(0) {
-	}
-	virtual ~ProgramExec() {
-		for (Common::Array<const Opcode*>::iterator i = _opcodes.begin(); i != _opcodes.end(); ++i)
-			delete *i;
-		_opcodes.clear();
-	}
+	void runScripts(ProgramList::iterator first, ProgramList::iterator last);
+	ProgramExec();
 };
 
 class ProgramExec_ns : public ProgramExec {
-
+protected:
 	Parallaction_ns *_vm;
 
-protected:
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(invalid);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(on);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(off);
@@ -222,19 +223,14 @@
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(sound);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(move);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endscript);
-
 public:
-	void init();
-
 	ProgramExec_ns(Parallaction_ns *vm);
-	~ProgramExec_ns();
 };
 
 class ProgramExec_br : public ProgramExec {
-
+protected:
 	Parallaction_br *_vm;
 
-protected:
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(invalid);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(loop);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endloop);
@@ -262,11 +258,8 @@
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(ifgt);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endif);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(stop);
-
 public:
-	void init();
 	ProgramExec_br(Parallaction_br *vm);
-	~ProgramExec_br();
 };
 
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/exec_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_br.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/exec_br.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -63,13 +63,13 @@
 
 #define SetOpcodeTable(x) table = &x;
 
-typedef Common::Functor0Mem<void, CommandExec_br> OpcodeV1;
+typedef Common::Functor1Mem<CommandContext&, void, CommandExec_br> OpcodeV1;
 #define COMMAND_OPCODE(op) table->push_back(new OpcodeV1(this, &CommandExec_br::cmdOp_##op))
-#define DECLARE_COMMAND_OPCODE(op) void CommandExec_br::cmdOp_##op()
+#define DECLARE_COMMAND_OPCODE(op) void CommandExec_br::cmdOp_##op(CommandContext &ctxt)
 
-typedef Common::Functor0Mem<void, ProgramExec_br> OpcodeV2;
+typedef Common::Functor1Mem<ProgramContext&, void, ProgramExec_br> OpcodeV2;
 #define INSTRUCTION_OPCODE(op) table->push_back(new OpcodeV2(this, &ProgramExec_br::instOp_##op))
-#define DECLARE_INSTRUCTION_OPCODE(op) void ProgramExec_br::instOp_##op()
+#define DECLARE_INSTRUCTION_OPCODE(op) void ProgramExec_br::instOp_##op(ProgramContext &ctxt)
 
 extern const char *_instructionNamesRes_br[];
 
@@ -116,70 +116,70 @@
 DECLARE_COMMAND_OPCODE(location) {
 	warning("Parallaction_br::cmdOp_location command not yet implemented");
 
-	_vm->_location._startPosition = _ctxt.cmd->u._startPos;
+	_vm->_location._startPosition = ctxt._cmd->u._startPos;
 	_vm->_location._startFrame = 0; // TODO: verify this against the disassembly!f
-	_vm->_location._followerStartPosition = _ctxt.cmd->u._startPos2;
+	_vm->_location._followerStartPosition = ctxt._cmd->u._startPos2;
 	_vm->_location._followerStartFrame = 0;
 
 	// TODO: handle startPos and startPos2
-	_vm->scheduleLocationSwitch(_ctxt.cmd->u._string);
+	_vm->scheduleLocationSwitch(ctxt._cmd->u._string);
 }
 
 
 DECLARE_COMMAND_OPCODE(open) {
 	warning("Parallaction_br::cmdOp_open command not yet implemented");
-	_vm->updateDoor(_ctxt.cmd->u._zone, false);
+	_vm->updateDoor(ctxt._cmd->u._zone, false);
 }
 
 
 DECLARE_COMMAND_OPCODE(close) {
 	warning("Parallaction_br::cmdOp_close not yet implemented");
-	_vm->updateDoor(_ctxt.cmd->u._zone, true);
+	_vm->updateDoor(ctxt._cmd->u._zone, true);
 }
 
 
 DECLARE_COMMAND_OPCODE(on) {
-	_vm->showZone(_ctxt.cmd->u._zone, true);
+	_vm->showZone(ctxt._cmd->u._zone, true);
 }
 
 
 DECLARE_COMMAND_OPCODE(off) {
-	_vm->showZone(_ctxt.cmd->u._zone, false);
+	_vm->showZone(ctxt._cmd->u._zone, false);
 }
 
 
 DECLARE_COMMAND_OPCODE(call) {
-	_vm->callFunction(_ctxt.cmd->u._callable, &_ctxt.z);
+	_vm->callFunction(ctxt._cmd->u._callable, &ctxt._z);
 }
 
 
 DECLARE_COMMAND_OPCODE(drop) {
-	_vm->dropItem(_ctxt.cmd->u._object);
+	_vm->dropItem(ctxt._cmd->u._object);
 }
 
 
 DECLARE_COMMAND_OPCODE(move) {
-	_vm->scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y, false);
+	_vm->scheduleWalk(ctxt._cmd->u._move.x, ctxt._cmd->u._move.y, false);
 	suspend();
 }
 
 DECLARE_COMMAND_OPCODE(start) {
-	_ctxt.cmd->u._zone->_flags |= kFlagsActing;
+	ctxt._cmd->u._zone->_flags |= kFlagsActing;
 }
 
 DECLARE_COMMAND_OPCODE(stop) {
-	_ctxt.cmd->u._zone->_flags &= ~kFlagsActing;
+	ctxt._cmd->u._zone->_flags &= ~kFlagsActing;
 }
 
 
 DECLARE_COMMAND_OPCODE(character) {
-	debugC(9, kDebugExec, "Parallaction_br::cmdOp_character(%s)", _ctxt.cmd->u._string);
-	_vm->changeCharacter(_ctxt.cmd->u._string);
+	debugC(9, kDebugExec, "Parallaction_br::cmdOp_character(%s)", ctxt._cmd->u._string);
+	_vm->changeCharacter(ctxt._cmd->u._string);
 }
 
 
 DECLARE_COMMAND_OPCODE(followme) {
-	Common::String s(_ctxt.cmd->u._string);
+	Common::String s(ctxt._cmd->u._string);
 	if (!s.compareToIgnoreCase("NULL")) {
 		s.clear();
 	}
@@ -198,7 +198,7 @@
 
 
 DECLARE_COMMAND_OPCODE(add) {
-	_vm->addInventoryItem(_ctxt.cmd->u._object);
+	_vm->addInventoryItem(ctxt._cmd->u._object);
 }
 
 
@@ -208,14 +208,14 @@
 
 
 DECLARE_COMMAND_OPCODE(inc) {
-	int v = _vm->getCounterValue(_ctxt.cmd->u._counterName);
-	_vm->setCounterValue(_ctxt.cmd->u._counterName, v + _ctxt.cmd->u._counterValue);
+	int v = _vm->getCounterValue(ctxt._cmd->u._counterName);
+	_vm->setCounterValue(ctxt._cmd->u._counterName, v + ctxt._cmd->u._counterValue);
 }
 
 
 DECLARE_COMMAND_OPCODE(dec) {
-	int v = _vm->getCounterValue(_ctxt.cmd->u._counterName);
-	_vm->setCounterValue(_ctxt.cmd->u._counterName, v - _ctxt.cmd->u._counterValue);
+	int v = _vm->getCounterValue(ctxt._cmd->u._counterName);
+	_vm->setCounterValue(ctxt._cmd->u._counterName, v - ctxt._cmd->u._counterValue);
 }
 
 // these definitions must match those in parser_br.cpp
@@ -224,20 +224,20 @@
 #define CMD_TEST_LT		27
 
 DECLARE_COMMAND_OPCODE(ifeq) {
-	_vm->testCounterCondition(_ctxt.cmd->u._counterName, CMD_TEST, _ctxt.cmd->u._counterValue);
+	_vm->testCounterCondition(ctxt._cmd->u._counterName, CMD_TEST, ctxt._cmd->u._counterValue);
 }
 
 DECLARE_COMMAND_OPCODE(iflt) {
-	_vm->testCounterCondition(_ctxt.cmd->u._counterName, CMD_TEST_LT, _ctxt.cmd->u._counterValue);
+	_vm->testCounterCondition(ctxt._cmd->u._counterName, CMD_TEST_LT, ctxt._cmd->u._counterValue);
 }
 
 DECLARE_COMMAND_OPCODE(ifgt) {
-	_vm->testCounterCondition(_ctxt.cmd->u._counterName, CMD_TEST_GT, _ctxt.cmd->u._counterValue);
+	_vm->testCounterCondition(ctxt._cmd->u._counterName, CMD_TEST_GT, ctxt._cmd->u._counterValue);
 }
 
 
 DECLARE_COMMAND_OPCODE(let) {
-	_vm->setCounterValue(_ctxt.cmd->u._counterName, _ctxt.cmd->u._counterValue);
+	_vm->setCounterValue(ctxt._cmd->u._counterName, ctxt._cmd->u._counterValue);
 }
 
 
@@ -247,19 +247,19 @@
 
 
 DECLARE_COMMAND_OPCODE(fix) {
-	_ctxt.cmd->u._zone->_flags |= kFlagsFixed;
+	ctxt._cmd->u._zone->_flags |= kFlagsFixed;
 }
 
 
 DECLARE_COMMAND_OPCODE(unfix) {
-	_ctxt.cmd->u._zone->_flags &= ~kFlagsFixed;
+	ctxt._cmd->u._zone->_flags &= ~kFlagsFixed;
 }
 
 
 DECLARE_COMMAND_OPCODE(zeta) {
-	_vm->_location._zeta0 = _ctxt.cmd->u._zeta0;
-	_vm->_location._zeta1 = _ctxt.cmd->u._zeta1;
-	_vm->_location._zeta2 = _ctxt.cmd->u._zeta2;
+	_vm->_location._zeta0 = ctxt._cmd->u._zeta0;
+	_vm->_location._zeta1 = ctxt._cmd->u._zeta1;
+	_vm->_location._zeta2 = ctxt._cmd->u._zeta2;
 }
 
 
@@ -279,7 +279,7 @@
 
 
 DECLARE_COMMAND_OPCODE(text) {
-	CommandData *data = &_ctxt.cmd->u;
+	CommandData *data = &ctxt._cmd->u;
 	_vm->setupSubtitles(data->_string, data->_string2, data->_zeta0);
 }
 
@@ -310,38 +310,38 @@
 }
 
 DECLARE_INSTRUCTION_OPCODE(invalid) {
-	error("Can't execute invalid opcode %i", (*_ctxt.inst)->_index);
+	error("Can't execute invalid opcode %i", (*ctxt._inst)->_index);
 }
 
 DECLARE_COMMAND_OPCODE(clear) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags &= ~_ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags &= ~ctxt._cmd->u._flags;
 	} else {
-		_vm->clearLocationFlags(_ctxt.cmd->u._flags);
+		_vm->clearLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
 DECLARE_COMMAND_OPCODE(speak) {
-	if (ACTIONTYPE(_ctxt.cmd->u._zone) == kZoneSpeak) {
-		_vm->enterDialogueMode(_ctxt.cmd->u._zone);
+	if (ACTIONTYPE(ctxt._cmd->u._zone) == kZoneSpeak) {
+		_vm->enterDialogueMode(ctxt._cmd->u._zone);
 	} else {
-		_vm->_activeZone = _ctxt.cmd->u._zone;
+		_vm->_activeZone = ctxt._cmd->u._zone;
 	}
 }
 
 
 DECLARE_COMMAND_OPCODE(get) {
-	_ctxt.cmd->u._zone->_flags &= ~kFlagsFixed;
-	_vm->runZone(_ctxt.cmd->u._zone);
+	ctxt._cmd->u._zone->_flags &= ~kFlagsFixed;
+	_vm->runZone(ctxt._cmd->u._zone);
 }
 
 DECLARE_COMMAND_OPCODE(toggle) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags ^= _ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags ^= ctxt._cmd->u._flags;
 	} else {
-		_vm->toggleLocationFlags(_ctxt.cmd->u._flags);
+		_vm->toggleLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
@@ -350,45 +350,45 @@
 }
 
 DECLARE_COMMAND_OPCODE(invalid) {
-	error("Can't execute invalid command '%i'", _ctxt.cmd->_id);
+	error("Can't execute invalid command '%i'", ctxt._cmd->_id);
 }
 
 DECLARE_COMMAND_OPCODE(set) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags |= _ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags |= ctxt._cmd->u._flags;
 	} else {
-		_vm->setLocationFlags(_ctxt.cmd->u._flags);
+		_vm->setLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
 
 
 DECLARE_INSTRUCTION_OPCODE(on) {
-	_vm->showZone((*_ctxt.inst)->_z, true);
+	_vm->showZone((*ctxt._inst)->_z, true);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(off) {
-	_vm->showZone((*_ctxt.inst)->_z, false);
+	_vm->showZone((*ctxt._inst)->_z, false);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(set) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 	inst->_opA.setValue(inst->_opB.getValue());
 }
 
 
 
 DECLARE_INSTRUCTION_OPCODE(inc) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 
 	int16 rvalue = inst->_opB.getValue();
 
 	if (inst->_flags & kInstMod) {	// mod
 		int16 _bx = (rvalue > 0 ? rvalue : -rvalue);
-		if (_ctxt.modCounter % _bx != 0) return;
+		if (ctxt._modCounter % _bx != 0) return;
 
 		rvalue = (rvalue > 0 ?  1 : -1);
 	}
@@ -433,12 +433,12 @@
 
 
 DECLARE_INSTRUCTION_OPCODE(start) {
-	(*_ctxt.inst)->_z->_flags |= kFlagsActing;
+	(*ctxt._inst)->_z->_flags |= kFlagsActing;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(process) {
-	_vm->_activeZone2 = (*_ctxt.inst)->_z;
+	_vm->_activeZone2 = (*ctxt._inst)->_z;
 }
 
 
@@ -448,14 +448,14 @@
 
 
 DECLARE_INSTRUCTION_OPCODE(color) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 	_vm->_gfx->_palette.setEntry(inst->_opB.getValue(), inst->_colors[0], inst->_colors[1], inst->_colors[2]);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(mask) {
 #if 0
-	Instruction *inst = *_ctxt.inst;
+	Instruction *inst = *ctxt._inst;
 	_gfx->_bgLayers[0] = inst->_opA.getRValue();
 	_gfx->_bgLayers[1] = inst->_opB.getRValue();
 	_gfx->_bgLayers[2] = inst->_opC.getRValue();
@@ -468,7 +468,7 @@
 }
 
 DECLARE_INSTRUCTION_OPCODE(text) {
-	InstructionPtr inst = (*_ctxt.inst);
+	InstructionPtr inst = (*ctxt._inst);
 	_vm->setupSubtitles(inst->_text, inst->_text2, inst->_y);
 }
 
@@ -498,42 +498,42 @@
 }
 
 DECLARE_INSTRUCTION_OPCODE(loop) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 
-	_ctxt.program->_loopCounter = inst->_opB.getValue();
-	_ctxt.program->_loopStart = _ctxt.ip;
+	ctxt._program->_loopCounter = inst->_opB.getValue();
+	ctxt._program->_loopStart = ctxt._ip;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(endloop) {
-	if (--_ctxt.program->_loopCounter > 0) {
-		_ctxt.ip = _ctxt.program->_loopStart;
+	if (--ctxt._program->_loopCounter > 0) {
+		ctxt._ip = ctxt._program->_loopStart;
 	}
 }
 
 DECLARE_INSTRUCTION_OPCODE(show) {
-	_ctxt.suspend = true;
+	ctxt._suspend = true;
 }
 
 DECLARE_INSTRUCTION_OPCODE(call) {
-	_vm->callFunction((*_ctxt.inst)->_immediate, 0);
+	_vm->callFunction((*ctxt._inst)->_immediate, 0);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(endscript) {
-	if ((_ctxt.anim->_flags & kFlagsLooping) == 0) {
-		_ctxt.anim->_flags &= ~kFlagsActing;
-		_vm->_cmdExec->run(_ctxt.anim->_commands, _ctxt.anim);
-		_ctxt.program->_status = kProgramDone;
+	if ((ctxt._anim->_flags & kFlagsLooping) == 0) {
+		ctxt._anim->_flags &= ~kFlagsActing;
+		_vm->_cmdExec->run(ctxt._anim->_commands, ctxt._anim);
+		ctxt._program->_status = kProgramDone;
 	}
 
-	_ctxt.ip = _ctxt.program->_instructions.begin();
-	_ctxt.suspend = true;
+	ctxt._ip = ctxt._program->_instructions.begin();
+	ctxt._suspend = true;
 }
 
 
-void CommandExec_br::init() {
-	Common::Array<const Opcode*> *table = 0;
+CommandExec_br::CommandExec_br(Parallaction_br* vm) : CommandExec(vm), _vm(vm) {
+	CommandOpcodeSet *table = 0;
 
 	SetOpcodeTable(_opcodes);
 	COMMAND_OPCODE(invalid);
@@ -580,18 +580,12 @@
 	COMMAND_OPCODE(offsave);
 }
 
-CommandExec_br::CommandExec_br(Parallaction_br* vm) : CommandExec(vm), _vm(vm) {
 
-}
+ProgramExec_br::ProgramExec_br(Parallaction_br *vm) : _vm(vm) {
+	_instructionNames = _instructionNamesRes_br;
 
-CommandExec_br::~CommandExec_br() {
+	ProgramOpcodeSet *table = 0;
 
-}
-
-void ProgramExec_br::init() {
-
-	Common::Array<const Opcode*> *table = 0;
-
 	SetOpcodeTable(_opcodes);
 	INSTRUCTION_OPCODE(invalid);
 	INSTRUCTION_OPCODE(on);
@@ -627,12 +621,6 @@
 	INSTRUCTION_OPCODE(endscript);
 }
 
-ProgramExec_br::ProgramExec_br(Parallaction_br *vm) : _vm(vm) {
-	_instructionNames = _instructionNamesRes_br;
-}
 
-ProgramExec_br::~ProgramExec_br() {
-}
 
-
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -53,19 +53,21 @@
 
 #define SetOpcodeTable(x) table = &x;
 
-typedef Common::Functor0Mem<void, CommandExec_ns> OpcodeV1;
+
+
+typedef Common::Functor1Mem<CommandContext&, void, CommandExec_ns> OpcodeV1;
 #define COMMAND_OPCODE(op) table->push_back(new OpcodeV1(this, &CommandExec_ns::cmdOp_##op))
-#define DECLARE_COMMAND_OPCODE(op) void CommandExec_ns::cmdOp_##op()
+#define DECLARE_COMMAND_OPCODE(op) void CommandExec_ns::cmdOp_##op(CommandContext& ctxt)
 
-typedef Common::Functor0Mem<void, ProgramExec_ns> OpcodeV2;
+typedef Common::Functor1Mem<ProgramContext&, void, ProgramExec_ns> OpcodeV2;
 #define INSTRUCTION_OPCODE(op) table->push_back(new OpcodeV2(this, &ProgramExec_ns::instOp_##op))
-#define DECLARE_INSTRUCTION_OPCODE(op) void ProgramExec_ns::instOp_##op()
+#define DECLARE_INSTRUCTION_OPCODE(op) void ProgramExec_ns::instOp_##op(ProgramContext& ctxt)
 
 extern const char *_instructionNamesRes_ns[];
 
 
 DECLARE_INSTRUCTION_OPCODE(on) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 
 	inst->_a->_flags |= kFlagsActive;
 	inst->_a->_flags &= ~kFlagsRemove;
@@ -73,31 +75,31 @@
 
 
 DECLARE_INSTRUCTION_OPCODE(off) {
-	(*_ctxt.inst)->_a->_flags |= kFlagsRemove;
+	(*ctxt._inst)->_a->_flags |= kFlagsRemove;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(loop) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 
-	_ctxt.program->_loopCounter = inst->_opB.getValue();
-	_ctxt.program->_loopStart = _ctxt.ip;
+	ctxt._program->_loopCounter = inst->_opB.getValue();
+	ctxt._program->_loopStart = ctxt._ip;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(endloop) {
-	if (--_ctxt.program->_loopCounter > 0) {
-		_ctxt.ip = _ctxt.program->_loopStart;
+	if (--ctxt._program->_loopCounter > 0) {
+		ctxt._ip = ctxt._program->_loopStart;
 	}
 }
 
 DECLARE_INSTRUCTION_OPCODE(inc) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 	int16 _si = inst->_opB.getValue();
 
 	if (inst->_flags & kInstMod) {	// mod
 		int16 _bx = (_si > 0 ? _si : -_si);
-		if (_ctxt.modCounter % _bx != 0) return;
+		if (ctxt._modCounter % _bx != 0) return;
 
 		_si = (_si > 0 ?  1 : -1);
 	}
@@ -116,13 +118,13 @@
 
 
 DECLARE_INSTRUCTION_OPCODE(set) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 	inst->_opA.setValue(inst->_opB.getValue());
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(put) {
-	InstructionPtr inst = *_ctxt.inst;
+	InstructionPtr inst = *ctxt._inst;
 	Common::Rect r;
 	inst->_a->getFrameRect(r);
 
@@ -139,38 +141,38 @@
 }
 
 DECLARE_INSTRUCTION_OPCODE(show) {
-	_ctxt.suspend = true;
+	ctxt._suspend = true;
 }
 
 DECLARE_INSTRUCTION_OPCODE(invalid) {
-	error("Can't execute invalid opcode %i", (*_ctxt.inst)->_index);
+	error("Can't execute invalid opcode %i", (*ctxt._inst)->_index);
 }
 
 DECLARE_INSTRUCTION_OPCODE(call) {
-	_vm->callFunction((*_ctxt.inst)->_immediate, 0);
+	_vm->callFunction((*ctxt._inst)->_immediate, 0);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(wait) {
 	if (_engineFlags & kEngineWalking) {
-		_ctxt.ip--;
-		_ctxt.suspend = true;
+		ctxt._ip--;
+		ctxt._suspend = true;
 	}
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(start) {
-	(*_ctxt.inst)->_a->_flags |= (kFlagsActing | kFlagsActive);
+	(*ctxt._inst)->_a->_flags |= (kFlagsActing | kFlagsActive);
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(sound) {
-	_vm->_activeZone = (*_ctxt.inst)->_z;
+	_vm->_activeZone = (*ctxt._inst)->_z;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(move) {
-	InstructionPtr inst = (*_ctxt.inst);
+	InstructionPtr inst = (*ctxt._inst);
 
 	int16 x = inst->_opA.getValue();
 	int16 y = inst->_opB.getValue();
@@ -179,104 +181,104 @@
 }
 
 DECLARE_INSTRUCTION_OPCODE(endscript) {
-	if ((_ctxt.anim->_flags & kFlagsLooping) == 0) {
-		_ctxt.anim->_flags &= ~kFlagsActing;
-		_vm->_cmdExec->run(_ctxt.anim->_commands, _ctxt.anim);
-		_ctxt.program->_status = kProgramDone;
+	if ((ctxt._anim->_flags & kFlagsLooping) == 0) {
+		ctxt._anim->_flags &= ~kFlagsActing;
+		_vm->_cmdExec->run(ctxt._anim->_commands, ctxt._anim);
+		ctxt._program->_status = kProgramDone;
 	}
 
-	_ctxt.ip = _ctxt.program->_instructions.begin();
-	_ctxt.suspend = true;
+	ctxt._ip = ctxt._program->_instructions.begin();
+	ctxt._suspend = true;
 }
 
 
 
 
 DECLARE_COMMAND_OPCODE(invalid) {
-	error("Can't execute invalid command '%i'", _ctxt.cmd->_id);
+	error("Can't execute invalid command '%i'", ctxt._cmd->_id);
 }
 
 DECLARE_COMMAND_OPCODE(set) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags |= _ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags |= ctxt._cmd->u._flags;
 	} else {
-		_vm->setLocationFlags(_ctxt.cmd->u._flags);
+		_vm->setLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
 
 DECLARE_COMMAND_OPCODE(clear) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags &= ~_ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags &= ~ctxt._cmd->u._flags;
 	} else {
-		_vm->clearLocationFlags(_ctxt.cmd->u._flags);
+		_vm->clearLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
 
 DECLARE_COMMAND_OPCODE(start) {
-	_ctxt.cmd->u._zone->_flags |= kFlagsActing;
+	ctxt._cmd->u._zone->_flags |= kFlagsActing;
 }
 
 
 DECLARE_COMMAND_OPCODE(speak) {
-	if (ACTIONTYPE(_ctxt.cmd->u._zone) == kZoneSpeak) {
-		_vm->enterDialogueMode(_ctxt.cmd->u._zone);
+	if (ACTIONTYPE(ctxt._cmd->u._zone) == kZoneSpeak) {
+		_vm->enterDialogueMode(ctxt._cmd->u._zone);
 	} else {
-		_vm->_activeZone = _ctxt.cmd->u._zone;
+		_vm->_activeZone = ctxt._cmd->u._zone;
 	}
 }
 
 
 DECLARE_COMMAND_OPCODE(get) {
-	_ctxt.cmd->u._zone->_flags &= ~kFlagsFixed;
-	_vm->runZone(_ctxt.cmd->u._zone);
+	ctxt._cmd->u._zone->_flags &= ~kFlagsFixed;
+	_vm->runZone(ctxt._cmd->u._zone);
 }
 
 
 DECLARE_COMMAND_OPCODE(location) {
-	_vm->scheduleLocationSwitch(_ctxt.cmd->u._string);
+	_vm->scheduleLocationSwitch(ctxt._cmd->u._string);
 }
 
 
 DECLARE_COMMAND_OPCODE(open) {
-	_vm->updateDoor(_ctxt.cmd->u._zone, false);
+	_vm->updateDoor(ctxt._cmd->u._zone, false);
 }
 
 
 DECLARE_COMMAND_OPCODE(close) {
-	_vm->updateDoor(_ctxt.cmd->u._zone, true);
+	_vm->updateDoor(ctxt._cmd->u._zone, true);
 }
 
 DECLARE_COMMAND_OPCODE(on) {
-	_vm->showZone(_ctxt.cmd->u._zone, true);
+	_vm->showZone(ctxt._cmd->u._zone, true);
 }
 
 
 DECLARE_COMMAND_OPCODE(off) {
-	_vm->showZone(_ctxt.cmd->u._zone, false);
+	_vm->showZone(ctxt._cmd->u._zone, false);
 }
 
 
 DECLARE_COMMAND_OPCODE(call) {
-	_vm->callFunction(_ctxt.cmd->u._callable, &_ctxt.z);
+	_vm->callFunction(ctxt._cmd->u._callable, &ctxt._z);
 }
 
 
 DECLARE_COMMAND_OPCODE(toggle) {
-	if (_ctxt.cmd->u._flags & kFlagsGlobal) {
-		_ctxt.cmd->u._flags &= ~kFlagsGlobal;
-		_globalFlags ^= _ctxt.cmd->u._flags;
+	if (ctxt._cmd->u._flags & kFlagsGlobal) {
+		ctxt._cmd->u._flags &= ~kFlagsGlobal;
+		_globalFlags ^= ctxt._cmd->u._flags;
 	} else {
-		_vm->toggleLocationFlags(_ctxt.cmd->u._flags);
+		_vm->toggleLocationFlags(ctxt._cmd->u._flags);
 	}
 }
 
 
 DECLARE_COMMAND_OPCODE(drop){
-	_vm->dropItem( _ctxt.cmd->u._object );
+	_vm->dropItem( ctxt._cmd->u._object );
 }
 
 
@@ -286,182 +288,17 @@
 
 
 DECLARE_COMMAND_OPCODE(move) {
-	_vm->scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y, false);
+	_vm->scheduleWalk(ctxt._cmd->u._move.x, ctxt._cmd->u._move.y, false);
 }
 
 
 DECLARE_COMMAND_OPCODE(stop) {
-	_ctxt.cmd->u._zone->_flags &= ~kFlagsActing;
+	ctxt._cmd->u._zone->_flags &= ~kFlagsActing;
 }
 
-
-void ProgramExec::runScript(ProgramPtr script, AnimationPtr a) {
-	debugC(9, kDebugExec, "runScript(Animation = %s)", a->_name);
-
-	_ctxt.ip = script->_ip;
-	_ctxt.anim = a;
-	_ctxt.program = script;
-	_ctxt.suspend = false;
-	_ctxt.modCounter = _modCounter;
-
-	InstructionList::iterator inst;
-	for ( ; (a->_flags & kFlagsActing) ; ) {
-
-		inst = _ctxt.ip;
-		_ctxt.inst = inst;
-		++_ctxt.ip;
-
-		debugC(9, kDebugExec, "inst [%02i] %s\n", (*inst)->_index, _instructionNames[(*inst)->_index - 1]);
-
-		script->_status = kProgramRunning;
-
-		(*_opcodes[(*inst)->_index])();
-
-		if (_ctxt.suspend)
-			break;
-
-	}
-	script->_ip = _ctxt.ip;
-
-}
-
-void ProgramExec::runScripts(ProgramList::iterator first, ProgramList::iterator last) {
-	if (_engineFlags & kEnginePauseJobs) {
-		return;
-	}
-
-	for (ProgramList::iterator it = first; it != last; ++it) {
-
-		AnimationPtr a = (*it)->_anim;
-
-		if (a->_flags & kFlagsCharacter)
-			a->resetZ();
-
-		if ((a->_flags & kFlagsActing) == 0)
-			continue;
-
-		runScript(*it, a);
-
-		if (a->_flags & kFlagsCharacter)
-			a->resetZ();
-	}
-
-	_modCounter++;
-
-	return;
-}
-
-void CommandExec::runList(CommandList::iterator first, CommandList::iterator last) {
-
-	uint32 useFlags = 0;
-	bool useLocalFlags;
-
-	_suspend = false;
-	_running = true;
-
-	for ( ; first != last; ++first) {
-		if (_vm->shouldQuit())
-			break;
-
-		CommandPtr cmd = *first;
-
-		if (cmd->_flagsOn & kFlagsGlobal) {
-			useFlags = _globalFlags | kFlagsGlobal;
-			useLocalFlags = false;
-		} else {
-			useFlags = _vm->getLocationFlags();
-			useLocalFlags = true;
-		}
-
-		bool onMatch = (cmd->_flagsOn & useFlags) == cmd->_flagsOn;
-		bool offMatch = (cmd->_flagsOff & ~useFlags) == cmd->_flagsOff;
-
-		debugC(3, kDebugExec, "runCommands[%i] (on: %x, off: %x), (%s = %x)", cmd->_id,  cmd->_flagsOn, cmd->_flagsOff,
-			useLocalFlags ? "LOCALFLAGS" : "GLOBALFLAGS", useFlags);
-
-		if (!onMatch || !offMatch) continue;
-
-		_ctxt.z = _execZone;
-		_ctxt.cmd = cmd;
-
-		(*_opcodes[cmd->_id])();
-
-		if (_suspend) {
-			createSuspendList(++first, last);
-			return;
-		}
-	}
-
-	_running = false;
-
-}
-
-void CommandExec::run(CommandList& list, ZonePtr z) {
-	if (list.size() == 0) {
-		debugC(3, kDebugExec, "runCommands: nothing to do");
-		return;
-	}
-
-	_execZone = z;
-
-	debugC(3, kDebugExec, "runCommands starting");
-	runList(list.begin(), list.end());
-	debugC(3, kDebugExec, "runCommands completed");
-}
-
-void CommandExec::createSuspendList(CommandList::iterator first, CommandList::iterator last) {
-	if (first == last) {
-		return;
-	}
-
-	debugC(3, kDebugExec, "CommandExec::createSuspendList()");
-
-	_suspendedCtxt.valid = true;
-	_suspendedCtxt.first = first;
-	_suspendedCtxt.last = last;
-	_suspendedCtxt.zone = _execZone;
-}
-
-void CommandExec::cleanSuspendedList() {
-	debugC(3, kDebugExec, "CommandExec::cleanSuspended()");
-
-	_suspendedCtxt.valid = false;
-	_suspendedCtxt.first = _suspendedCtxt.last;
-	_suspendedCtxt.zone = nullZonePtr;
-}
-
-void CommandExec::suspend() {
-	if (!_running)
-		return;
-
-	_suspend = true;
-}
-
-void CommandExec::runSuspended() {
-	if (_engineFlags & kEngineWalking) {
-		return;
-	}
-
-	if (_suspendedCtxt.valid) {
-		debugC(3, kDebugExec, "CommandExec::runSuspended()");
-
-		_execZone = _suspendedCtxt.zone;
-		runList(_suspendedCtxt.first, _suspendedCtxt.last);
-		cleanSuspendedList();
-	}
-}
-
 CommandExec_ns::CommandExec_ns(Parallaction_ns* vm) : CommandExec(vm), _vm(vm) {
+	CommandOpcodeSet *table = 0;
 
-}
-
-CommandExec_ns::~CommandExec_ns() {
-
-}
-
-void CommandExec_ns::init() {
-	Common::Array<const Opcode*> *table = 0;
-
 	SetOpcodeTable(_opcodes);
 	COMMAND_OPCODE(invalid);
 	COMMAND_OPCODE(set);
@@ -482,9 +319,10 @@
 	COMMAND_OPCODE(stop);
 }
 
-void ProgramExec_ns::init() {
+ProgramExec_ns::ProgramExec_ns(Parallaction_ns *vm) : _vm(vm) {
+	_instructionNames = _instructionNamesRes_ns;
 
-	Common::Array<const Opcode*> *table = 0;
+	ProgramOpcodeSet *table = 0;
 
 	SetOpcodeTable(_opcodes);
 	INSTRUCTION_OPCODE(invalid);
@@ -507,14 +345,6 @@
 	INSTRUCTION_OPCODE(sound);
 	INSTRUCTION_OPCODE(move);
 	INSTRUCTION_OPCODE(endscript);
-
 }
 
-ProgramExec_ns::ProgramExec_ns(Parallaction_ns *vm) : _vm(vm) {
-	_instructionNames = _instructionNamesRes_ns;
-}
-
-ProgramExec_ns::~ProgramExec_ns() {
-}
-
 }	// namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/input.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/input.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/input.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -26,6 +26,7 @@
 #include "common/events.h"
 #include "common/system.h"
 
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/parallaction.h"
 #include "parallaction/debug.h"

Modified: scummvm/trunk/engines/parallaction/module.mk
===================================================================
--- scummvm/trunk/engines/parallaction/module.mk	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/module.mk	2009-02-26 06:16:35 UTC (rev 38892)
@@ -9,6 +9,7 @@
 	dialogue.o \
 	disk_br.o \
 	disk_ns.o \
+	exec.o \
 	exec_br.o \
 	exec_ns.o \
 	font.o \

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -33,6 +33,7 @@
 #include "sound/mixer.h"
 
 
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/parallaction.h"
 #include "parallaction/debug.h"

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2009-02-26 06:16:35 UTC (rev 38892)
@@ -34,7 +34,6 @@
 
 #include "engines/engine.h"
 
-#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/inventory.h"
 #include "parallaction/parser.h"
@@ -124,6 +123,8 @@
 class PathBuilder_NS;
 class PathWalker_NS;
 class PathWalker_BR;
+class CommandExec;
+class ProgramExec;
 
 
 struct Location {

Modified: scummvm/trunk/engines/parallaction/parallaction_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_br.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/parallaction_br.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -27,6 +27,7 @@
 #include "common/util.h"
 
 #include "parallaction/parallaction.h"
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/saveload.h"
 #include "parallaction/sound.h"
@@ -77,9 +78,7 @@
 	_programParser->init();
 
 	_cmdExec = new CommandExec_br(this);
-	_cmdExec->init();
 	_programExec = new ProgramExec_br(this);
-	_programExec->init();
 
 	_walker = new PathWalker_BR;
 

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -28,6 +28,7 @@
 #include "common/config-manager.h"
 
 #include "parallaction/parallaction.h"
+#include "parallaction/exec.h"
 #include "parallaction/input.h"
 #include "parallaction/saveload.h"
 #include "parallaction/sound.h"
@@ -181,9 +182,7 @@
 	_programParser->init();
 
 	_cmdExec = new CommandExec_ns(this);
-	_cmdExec->init();
 	_programExec = new ProgramExec_ns(this);
-	_programExec->init();
 
 	_builder = new PathBuilder_NS(&_char);
 	_walker = new PathWalker_NS(&_char);

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2009-02-26 02:21:55 UTC (rev 38891)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2009-02-26 06:16:35 UTC (rev 38892)
@@ -23,6 +23,7 @@
  *
  */
 
+#include "parallaction/exec.h"
 #include "parallaction/parallaction.h"
 #include "parallaction/walk.h"
 


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