aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2008-07-30 07:58:25 +0000
committerNicola Mettifogo2008-07-30 07:58:25 +0000
commit3dbeeaf8a10a07491465657f6effebe341251635 (patch)
treeeb791b2c95193556ff97cf032db1eb027391f0b2
parent1e2988b7f75adc471e3dc39aa42eb99e33727023 (diff)
downloadscummvm-rg350-3dbeeaf8a10a07491465657f6effebe341251635.tar.gz
scummvm-rg350-3dbeeaf8a10a07491465657f6effebe341251635.tar.bz2
scummvm-rg350-3dbeeaf8a10a07491465657f6effebe341251635.zip
* Unified implementation of flow control opcodes in NS and BRA
* Simplified script execution loop and context svn-id: r33437
-rw-r--r--engines/parallaction/exec.h6
-rw-r--r--engines/parallaction/exec_br.cpp19
-rw-r--r--engines/parallaction/exec_ns.cpp74
3 files changed, 44 insertions, 55 deletions
diff --git a/engines/parallaction/exec.h b/engines/parallaction/exec.h
index 03526617c6..22e75744f1 100644
--- a/engines/parallaction/exec.h
+++ b/engines/parallaction/exec.h
@@ -165,6 +165,7 @@ protected:
AnimationPtr anim;
ProgramPtr program;
InstructionList::iterator inst;
+ InstructionList::iterator ip;
uint16 modCounter;
bool suspend;
} _ctxt;
@@ -174,6 +175,7 @@ protected:
OpcodeSet _opcodes;
uint16 _modCounter;
+ void runScript(ProgramPtr script, AnimationPtr a);
public:
virtual void init() = 0;
@@ -197,7 +199,7 @@ protected:
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 @@ class ProgramExec_br : public ProgramExec_ns {
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 @@ protected:
DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(ifgt);
DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endif);
DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(stop);
- DECLARE_UNQUALIFIED_INSTRUCTION_OPCODE(endscript);
public:
void init();
diff --git a/engines/parallaction/exec_br.cpp b/engines/parallaction/exec_br.cpp
index a2efe8b90c..0b7400f0f7 100644
--- a/engines/parallaction/exec_br.cpp
+++ b/engines/parallaction/exec_br.cpp
@@ -374,13 +374,6 @@ DECLARE_INSTRUCTION_OPCODE(set) {
}
-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,16 +497,6 @@ DECLARE_INSTRUCTION_OPCODE(stop) {
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 @@ void ProgramExec_br::init() {
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);
diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp
index 32dafef92b..3e3ee19a03 100644
--- a/engines/parallaction/exec_ns.cpp
+++ b/engines/parallaction/exec_ns.cpp
@@ -81,13 +81,13 @@ DECLARE_INSTRUCTION_OPCODE(loop) {
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 @@ DECLARE_INSTRUCTION_OPCODE(inc) {
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 @@ DECLARE_INSTRUCTION_OPCODE(put) {
_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(call) {
DECLARE_INSTRUCTION_OPCODE(wait) {
- if (_engineFlags & kEngineWalking)
+ if (_engineFlags & kEngineWalking) {
+ _ctxt.ip--;
_ctxt.suspend = true;
+ }
}
@@ -186,8 +188,8 @@ DECLARE_INSTRUCTION_OPCODE(endscript) {
_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 @@ void Parallaction_ns::drawAnimations() {
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 @@ void ProgramExec::runScripts(ProgramList::iterator first, ProgramList::iterator
if ((a->_flags & kFlagsActing) == 0)
continue;
- InstructionList::iterator inst = (*it)->_ip;
- while (((*inst)->_index != INST_SHOW) && (a->_flags & kFlagsActing)) {
-
- (*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;
+ runScript(*it, a);
-label1:
if (a->_flags & kFlagsCharacter)
a->_z = a->_top + a->height();
}
@@ -796,7 +802,7 @@ void ProgramExec_ns::init() {
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);