MYST3 - Implement opcodes 172 and 173 - While loop

This commit is contained in:
Bastien Bouclet 2012-02-07 13:21:38 +01:00
parent e8a33ad712
commit c7b4e9893a
2 changed files with 28 additions and 0 deletions

View File

@ -198,6 +198,8 @@ Script::Script(Myst3Engine *vm):
OP_3(166, changeNodeRoomAge, kValue, kValue, kValue );
OP_1(169, drawXFrames, kValue );
OP_1(171, drawWhileCond, kCondition );
OP_1(172, whileStart, kCondition );
OP_0(173, whileEnd );
OP_2(174, runScriptWhileCond, kCondition, kValue );
OP_3(175, runScriptWhileCondEachXFrames,kCondition, kValue, kValue );
OP_4(176, runScriptForVar, kVar, kValue, kValue, kValue );
@ -1970,6 +1972,29 @@ void Script::drawWhileCond(Context &c, const Opcode &cmd) {
}
}
void Script::whileStart(Context &c, const Opcode &cmd) {
c.whileStart = c.op - 1;
// Check the while condition
if (!_vm->_state->evaluate(cmd.args[0])) {
// Condition is false, go to the next opcode after the end of the while loop
do {
c.op++;
} while (c.op != c.script->end()
&& c.op->op != 173);
}
_vm->processInput(true);
_vm->drawFrame();
}
void Script::whileEnd(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: End of while condition", cmd.op);
// Go to while start
c.op = c.whileStart;
}
void Script::runScriptWhileCond(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: While condition %d, run script %d", cmd.op, cmd.args[0], cmd.args[1]);

View File

@ -47,6 +47,7 @@ private:
bool result;
const Common::Array<Opcode> *script;
Common::Array<Opcode>::const_iterator op;
Common::Array<Opcode>::const_iterator whileStart;
};
typedef void (Script::*CommandProc)(Context &c, const Opcode &cmd);
@ -248,6 +249,8 @@ private:
DECLARE_OPCODE(changeNodeRoomAge);
DECLARE_OPCODE(drawXFrames);
DECLARE_OPCODE(drawWhileCond);
DECLARE_OPCODE(whileStart);
DECLARE_OPCODE(whileEnd);
DECLARE_OPCODE(runScriptWhileCond);
DECLARE_OPCODE(runScriptWhileCondEachXFrames);
DECLARE_OPCODE(runScriptForVar);