svn-id: r33006
This commit is contained in:
Nicola Mettifogo 2008-07-11 13:36:22 +00:00
parent 273129330a
commit 8ba56e98cf
3 changed files with 108 additions and 109 deletions

View file

@ -65,7 +65,7 @@ typedef Common::Functor0Mem<void, ProgramExec_ns> OpcodeV2;
DECLARE_INSTRUCTION_OPCODE(on) {
InstructionPtr inst = *_instRunCtxt.inst;
InstructionPtr inst = *_ctxt.inst;
inst->_a->_flags |= kFlagsActive;
inst->_a->_flags &= ~kFlagsRemove;
@ -73,31 +73,31 @@ DECLARE_INSTRUCTION_OPCODE(on) {
DECLARE_INSTRUCTION_OPCODE(off) {
(*_instRunCtxt.inst)->_a->_flags |= kFlagsRemove;
(*_ctxt.inst)->_a->_flags |= kFlagsRemove;
}
DECLARE_INSTRUCTION_OPCODE(loop) {
InstructionPtr inst = *_instRunCtxt.inst;
InstructionPtr inst = *_ctxt.inst;
_instRunCtxt.program->_loopCounter = inst->_opB.getRValue();
_instRunCtxt.program->_loopStart = _instRunCtxt.inst;
_ctxt.program->_loopCounter = inst->_opB.getRValue();
_ctxt.program->_loopStart = _ctxt.inst;
}
DECLARE_INSTRUCTION_OPCODE(endloop) {
if (--_instRunCtxt.program->_loopCounter > 0) {
_instRunCtxt.inst = _instRunCtxt.program->_loopStart;
if (--_ctxt.program->_loopCounter > 0) {
_ctxt.inst = _ctxt.program->_loopStart;
}
}
DECLARE_INSTRUCTION_OPCODE(inc) {
InstructionPtr inst = *_instRunCtxt.inst;
InstructionPtr inst = *_ctxt.inst;
int16 _si = inst->_opB.getRValue();
if (inst->_flags & kInstMod) { // mod
int16 _bx = (_si > 0 ? _si : -_si);
if (_instRunCtxt.modCounter % _bx != 0) return;
if (_modCounter % _bx != 0) return;
_si = (_si > 0 ? 1 : -1);
}
@ -118,7 +118,7 @@ DECLARE_INSTRUCTION_OPCODE(inc) {
DECLARE_INSTRUCTION_OPCODE(set) {
InstructionPtr inst = *_instRunCtxt.inst;
InstructionPtr inst = *_ctxt.inst;
int16 _si = inst->_opB.getRValue();
int16 *lvalue = inst->_opA.getLValue();
@ -129,7 +129,7 @@ DECLARE_INSTRUCTION_OPCODE(set) {
DECLARE_INSTRUCTION_OPCODE(put) {
InstructionPtr inst = *_instRunCtxt.inst;
InstructionPtr inst = *_ctxt.inst;
Graphics::Surface v18;
v18.w = inst->_a->width();
v18.h = inst->_a->height();
@ -147,32 +147,32 @@ DECLARE_INSTRUCTION_OPCODE(null) {
}
DECLARE_INSTRUCTION_OPCODE(invalid) {
error("Can't execute invalid opcode %i", (*_instRunCtxt.inst)->_index);
error("Can't execute invalid opcode %i", (*_ctxt.inst)->_index);
}
DECLARE_INSTRUCTION_OPCODE(call) {
_vm->callFunction((*_instRunCtxt.inst)->_immediate, 0);
_vm->callFunction((*_ctxt.inst)->_immediate, 0);
}
DECLARE_INSTRUCTION_OPCODE(wait) {
if (_engineFlags & kEngineWalking)
_instRunCtxt.suspend = true;
_ctxt.suspend = true;
}
DECLARE_INSTRUCTION_OPCODE(start) {
(*_instRunCtxt.inst)->_a->_flags |= (kFlagsActing | kFlagsActive);
(*_ctxt.inst)->_a->_flags |= (kFlagsActing | kFlagsActive);
}
DECLARE_INSTRUCTION_OPCODE(sound) {
_vm->_activeZone = (*_instRunCtxt.inst)->_z;
_vm->_activeZone = (*_ctxt.inst)->_z;
}
DECLARE_INSTRUCTION_OPCODE(move) {
InstructionPtr inst = (*_instRunCtxt.inst);
InstructionPtr inst = (*_ctxt.inst);
int16 x = inst->_opA.getRValue();
int16 y = inst->_opB.getRValue();
@ -181,82 +181,82 @@ DECLARE_INSTRUCTION_OPCODE(move) {
}
DECLARE_INSTRUCTION_OPCODE(endscript) {
if ((_instRunCtxt.anim->_flags & kFlagsLooping) == 0) {
_instRunCtxt.anim->_flags &= ~kFlagsActing;
_vm->_cmdExec->run(_instRunCtxt.anim->_commands, _instRunCtxt.anim);
_instRunCtxt.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;
}
_instRunCtxt.program->_ip = _instRunCtxt.program->_instructions.begin();
_ctxt.program->_ip = _ctxt.program->_instructions.begin();
_instRunCtxt.suspend = true;
_ctxt.suspend = true;
}
DECLARE_COMMAND_OPCODE(invalid) {
error("Can't execute invalid command '%i'", _cmdRunCtxt.cmd->_id);
error("Can't execute invalid command '%i'", _ctxt.cmd->_id);
}
DECLARE_COMMAND_OPCODE(set) {
if (_cmdRunCtxt.cmd->u._flags & kFlagsGlobal) {
_cmdRunCtxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags |= _cmdRunCtxt.cmd->u._flags;
if (_ctxt.cmd->u._flags & kFlagsGlobal) {
_ctxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags |= _ctxt.cmd->u._flags;
} else {
_vm->setLocationFlags(_cmdRunCtxt.cmd->u._flags);
_vm->setLocationFlags(_ctxt.cmd->u._flags);
}
}
DECLARE_COMMAND_OPCODE(clear) {
if (_cmdRunCtxt.cmd->u._flags & kFlagsGlobal) {
_cmdRunCtxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags &= ~_cmdRunCtxt.cmd->u._flags;
if (_ctxt.cmd->u._flags & kFlagsGlobal) {
_ctxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags &= ~_ctxt.cmd->u._flags;
} else {
_vm->clearLocationFlags(_cmdRunCtxt.cmd->u._flags);
_vm->clearLocationFlags(_ctxt.cmd->u._flags);
}
}
DECLARE_COMMAND_OPCODE(start) {
_cmdRunCtxt.cmd->u._zone->_flags |= kFlagsActing;
_ctxt.cmd->u._zone->_flags |= kFlagsActing;
}
DECLARE_COMMAND_OPCODE(speak) {
_vm->_activeZone = _cmdRunCtxt.cmd->u._zone;
_vm->_activeZone = _ctxt.cmd->u._zone;
}
DECLARE_COMMAND_OPCODE(get) {
_cmdRunCtxt.cmd->u._zone->_flags &= ~kFlagsFixed;
_vm->runZone(_cmdRunCtxt.cmd->u._zone);
_ctxt.cmd->u._zone->_flags &= ~kFlagsFixed;
_vm->runZone(_ctxt.cmd->u._zone);
}
DECLARE_COMMAND_OPCODE(location) {
_vm->scheduleLocationSwitch(_cmdRunCtxt.cmd->u._string);
_vm->scheduleLocationSwitch(_ctxt.cmd->u._string);
}
DECLARE_COMMAND_OPCODE(open) {
_cmdRunCtxt.cmd->u._zone->_flags &= ~kFlagsClosed;
if (_cmdRunCtxt.cmd->u._zone->u.door->gfxobj) {
_vm->updateDoor(_cmdRunCtxt.cmd->u._zone);
_ctxt.cmd->u._zone->_flags &= ~kFlagsClosed;
if (_ctxt.cmd->u._zone->u.door->gfxobj) {
_vm->updateDoor(_ctxt.cmd->u._zone);
}
}
DECLARE_COMMAND_OPCODE(close) {
_cmdRunCtxt.cmd->u._zone->_flags |= kFlagsClosed;
if (_cmdRunCtxt.cmd->u._zone->u.door->gfxobj) {
_vm->updateDoor(_cmdRunCtxt.cmd->u._zone);
_ctxt.cmd->u._zone->_flags |= kFlagsClosed;
if (_ctxt.cmd->u._zone->u.door->gfxobj) {
_vm->updateDoor(_ctxt.cmd->u._zone);
}
}
DECLARE_COMMAND_OPCODE(on) {
ZonePtr z = _cmdRunCtxt.cmd->u._zone;
ZonePtr z = _ctxt.cmd->u._zone;
// WORKAROUND: the original DOS-based engine didn't check u->_zone before dereferencing
// the pointer to get structure members, thus leading to crashes in systems with memory
// protection.
@ -274,27 +274,27 @@ DECLARE_COMMAND_OPCODE(on) {
DECLARE_COMMAND_OPCODE(off) {
_cmdRunCtxt.cmd->u._zone->_flags |= kFlagsRemove;
_ctxt.cmd->u._zone->_flags |= kFlagsRemove;
}
DECLARE_COMMAND_OPCODE(call) {
_vm->callFunction(_cmdRunCtxt.cmd->u._callable, &_cmdRunCtxt.z);
_vm->callFunction(_ctxt.cmd->u._callable, &_ctxt.z);
}
DECLARE_COMMAND_OPCODE(toggle) {
if (_cmdRunCtxt.cmd->u._flags & kFlagsGlobal) {
_cmdRunCtxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags ^= _cmdRunCtxt.cmd->u._flags;
if (_ctxt.cmd->u._flags & kFlagsGlobal) {
_ctxt.cmd->u._flags &= ~kFlagsGlobal;
_commandFlags ^= _ctxt.cmd->u._flags;
} else {
_vm->toggleLocationFlags(_cmdRunCtxt.cmd->u._flags);
_vm->toggleLocationFlags(_ctxt.cmd->u._flags);
}
}
DECLARE_COMMAND_OPCODE(drop){
_vm->dropItem( _cmdRunCtxt.cmd->u._object );
_vm->dropItem( _ctxt.cmd->u._object );
}
@ -304,12 +304,12 @@ DECLARE_COMMAND_OPCODE(quit) {
DECLARE_COMMAND_OPCODE(move) {
_vm->_char.scheduleWalk(_cmdRunCtxt.cmd->u._move.x, _cmdRunCtxt.cmd->u._move.y);
_vm->_char.scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y);
}
DECLARE_COMMAND_OPCODE(stop) {
_cmdRunCtxt.cmd->u._zone->_flags &= ~kFlagsActing;
_ctxt.cmd->u._zone->_flags &= ~kFlagsActing;
}
@ -365,8 +365,6 @@ void ProgramExec::runScripts(ProgramList::iterator first, ProgramList::iterator
debugC(9, kDebugExec, "runScripts");
static uint16 modCounter = 0;
for (ProgramList::iterator it = first; it != last; it++) {
AnimationPtr a = (*it)->_anim;
@ -384,17 +382,16 @@ void ProgramExec::runScripts(ProgramList::iterator first, ProgramList::iterator
debugC(9, kDebugExec, "Animation: %s, instruction: %i", a->_name, (*inst)->_index); //_instructionNamesRes[(*inst)->_index - 1]);
_instRunCtxt.inst = inst;
_instRunCtxt.anim = AnimationPtr(a);
_instRunCtxt.program = *it;
_instRunCtxt.modCounter = modCounter;
_instRunCtxt.suspend = false;
_ctxt.inst = inst;
_ctxt.anim = AnimationPtr(a);
_ctxt.program = *it;
_ctxt.suspend = false;
(*_opcodes[(*inst)->_index])();
inst = _instRunCtxt.inst; // handles endloop correctly
inst = _ctxt.inst; // handles endloop correctly
if (_instRunCtxt.suspend)
if (_ctxt.suspend)
goto label1;
inst++;
@ -407,7 +404,7 @@ label1:
a->_z = a->_top + a->height();
}
modCounter++;
_modCounter++;
return;
}
@ -437,8 +434,8 @@ void CommandExec::run(CommandList& list, ZonePtr z) {
if ((cmd->_flagsOn & v8) != cmd->_flagsOn) continue;
if ((cmd->_flagsOff & ~v8) != cmd->_flagsOff) continue;
_cmdRunCtxt.z = z;
_cmdRunCtxt.cmd = cmd;
_ctxt.z = z;
_ctxt.cmd = cmd;
(*_opcodes[cmd->_id])();
}
@ -711,7 +708,7 @@ void ProgramExec_ns::init() {
}
ProgramExec_ns::ProgramExec_ns(Parallaction_ns *vm) : _vm(vm) {
}
}
ProgramExec_ns::~ProgramExec_ns() {
}