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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Wed Jul 30 09:58:25 CEST 2008


Revision: 33437
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33437&view=rev
Author:   peres001
Date:     2008-07-30 07:58:25 +0000 (Wed, 30 Jul 2008)

Log Message:
-----------
* Unified implementation of flow control opcodes in NS and BRA
* Simplified script execution loop and context

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/exec.h
    scummvm/trunk/engines/parallaction/exec_br.cpp
    scummvm/trunk/engines/parallaction/exec_ns.cpp

Modified: scummvm/trunk/engines/parallaction/exec.h
===================================================================
--- scummvm/trunk/engines/parallaction/exec.h	2008-07-30 07:39:41 UTC (rev 33436)
+++ scummvm/trunk/engines/parallaction/exec.h	2008-07-30 07:58:25 UTC (rev 33437)
@@ -165,6 +165,7 @@
 		AnimationPtr	anim;
 		ProgramPtr		program;
 		InstructionList::iterator inst;
+		InstructionList::iterator ip;
 		uint16		modCounter;
 		bool		suspend;
 	} _ctxt;
@@ -174,6 +175,7 @@
 	OpcodeSet	_opcodes;
 
 	uint16	_modCounter;
+	void runScript(ProgramPtr script, AnimationPtr a);
 
 public:
 	virtual void init() = 0;
@@ -197,7 +199,7 @@
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(off);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(loop);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endloop);
-	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(null);
+	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(show);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(call);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(inc);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(set);
@@ -222,7 +224,6 @@
 protected:
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(on);
  	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(off);
-	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(loop);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(inc);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(dec);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(set);
@@ -242,7 +243,6 @@
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(ifgt);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endif);
 	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(stop);
-	DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endscript);
 
 public:
 	void init();

Modified: scummvm/trunk/engines/parallaction/exec_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_br.cpp	2008-07-30 07:39:41 UTC (rev 33436)
+++ scummvm/trunk/engines/parallaction/exec_br.cpp	2008-07-30 07:58:25 UTC (rev 33437)
@@ -374,14 +374,7 @@
 }
 
 
-DECLARE_INSTRUCTION_OPCODE(loop) {
-	InstructionPtr inst = *_ctxt.inst;
 
-	_ctxt.program->_loopCounter = inst->_opB.getRValue();
-	_ctxt.program->_loopStart = _ctxt.inst;
-}
-
-
 DECLARE_INSTRUCTION_OPCODE(inc) {
 	InstructionPtr inst = *_ctxt.inst;
 
@@ -504,17 +497,7 @@
 	warning("Parallaction_br::instOp_stop not yet implemented");
 }
 
-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;
-	}
-	_ctxt.program->_ip = _ctxt.program->_instructions.begin();
 
-	_ctxt.suspend = true;
-}
-
 void CommandExec_br::init() {
 	Common::Array<const Opcode*> *table = 0;
 
@@ -585,7 +568,7 @@
 	INSTRUCTION_OPCODE(set);		// f
 	INSTRUCTION_OPCODE(loop);
 	INSTRUCTION_OPCODE(endloop);
-	INSTRUCTION_OPCODE(null);		// show
+	INSTRUCTION_OPCODE(show);		// show
 	INSTRUCTION_OPCODE(inc);
 	INSTRUCTION_OPCODE(inc);		// dec
 	INSTRUCTION_OPCODE(set);

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-07-30 07:39:41 UTC (rev 33436)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-07-30 07:58:25 UTC (rev 33437)
@@ -81,13 +81,13 @@
 	InstructionPtr inst = *_ctxt.inst;
 
 	_ctxt.program->_loopCounter = inst->_opB.getRValue();
-	_ctxt.program->_loopStart = _ctxt.inst;
+	_ctxt.program->_loopStart = _ctxt.ip;
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(endloop) {
 	if (--_ctxt.program->_loopCounter > 0) {
-		_ctxt.inst = _ctxt.program->_loopStart;
+		_ctxt.ip = _ctxt.program->_loopStart;
 	}
 }
 
@@ -97,7 +97,7 @@
 
 	if (inst->_flags & kInstMod) {	// mod
 		int16 _bx = (_si > 0 ? _si : -_si);
-		if (_modCounter % _bx != 0) return;
+		if (_ctxt.modCounter % _bx != 0) return;
 
 		_si = (_si > 0 ?  1 : -1);
 	}
@@ -142,8 +142,8 @@
 	_vm->_gfx->patchBackground(v18, x, y, mask);
 }
 
-DECLARE_INSTRUCTION_OPCODE(null) {
-
+DECLARE_INSTRUCTION_OPCODE(show) {
+	_ctxt.suspend = true;
 }
 
 DECLARE_INSTRUCTION_OPCODE(invalid) {
@@ -156,8 +156,10 @@
 
 
 DECLARE_INSTRUCTION_OPCODE(wait) {
-	if (_engineFlags & kEngineWalking)
+	if (_engineFlags & kEngineWalking) {
+		_ctxt.ip--;
 		_ctxt.suspend = true;
+	}
 }
 
 
@@ -186,8 +188,8 @@
 		_vm->_cmdExec->run(_ctxt.anim->_commands, _ctxt.anim);
 		_ctxt.program->_status = kProgramDone;
 	}
-	_ctxt.program->_ip = _ctxt.program->_instructions.begin();
 
+	_ctxt.ip = _ctxt.program->_instructions.begin();
 	_ctxt.suspend = true;
 }
 
@@ -376,14 +378,41 @@
 	return;
 }
 
+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;
 	}
 
-	debugC(9, kDebugExec, "runScripts");
-
 	for (ProgramList::iterator it = first; it != last; it++) {
 
 		AnimationPtr a = (*it)->_anim;
@@ -394,31 +423,8 @@
 		if ((a->_flags & kFlagsActing) == 0)
 			continue;
 
-		InstructionList::iterator inst = (*it)->_ip;
-		while (((*inst)->_index != INST_SHOW) && (a->_flags & kFlagsActing)) {
+		runScript(*it, a);
 
-			(*it)->_status = kProgramRunning;
-
-			debugC(9, kDebugExec, "anim: %s, inst[%02i]: %s", a->_name, (*inst)->_index, _instructionNames[(*inst)->_index - 1]);
-
-			_ctxt.inst = inst;
-			_ctxt.anim = AnimationPtr(a);
-			_ctxt.program = *it;
-			_ctxt.suspend = false;
-
-			(*_opcodes[(*inst)->_index])();
-
-			inst = _ctxt.inst;		// handles endloop correctly
-
-			if (_ctxt.suspend)
-				goto label1;
-
-			inst++;
-		}
-
-		(*it)->_ip = ++inst;
-
-label1:
 		if (a->_flags & kFlagsCharacter)
 			a->_z = a->_top + a->height();
 	}
@@ -796,7 +802,7 @@
 	INSTRUCTION_OPCODE(set);		// f
 	INSTRUCTION_OPCODE(loop);
 	INSTRUCTION_OPCODE(endloop);
-	INSTRUCTION_OPCODE(null);
+	INSTRUCTION_OPCODE(show);
 	INSTRUCTION_OPCODE(inc);
 	INSTRUCTION_OPCODE(inc);		// dec
 	INSTRUCTION_OPCODE(set);


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