MystScript MystScriptParser::readScript(Common::SeekableReadStream *stream, MystScriptType type) { assert(stream); assert(type != kMystScriptNone); MystScript script = MystScript(new Common::Array<MystScriptEntry>()); uint16 opcodeCount = stream->readUint16LE(); script->resize(opcodeCount); for (uint16 i = 0; i < opcodeCount; i++) { MystScriptEntry &entry = (*script)[i]; entry.type = type; // Resource ID only exists in INIT and EXIT scripts if (type != kMystScriptNormal) entry.resourceId = stream->readUint16LE(); entry.opcode = stream->readUint16LE(); entry.var = stream->readUint16LE(); entry.argc = stream->readUint16LE(); if (entry.argc > 0) { entry.argv = new uint16[entry.argc]; for (uint16 j = 0; j < entry.argc; j++) entry.argv[j] = stream->readUint16LE(); } // u1 exists only in EXIT scripts if (type == kMystScriptExit) entry.u1 = stream->readUint16LE(); } return script; }
void MystScriptParser::runScript(MystScript script, MystResource *invokingResource) { debugC(kDebugScript, "Script Size: %d", script->size()); for (uint16 i = 0; i < script->size(); i++) { MystScriptEntry &entry = script->operator[](i); debugC(kDebugScript, "\tOpcode %d: %d", i, entry.opcode); if (entry.type == kMystScriptNormal) _invokingResource = invokingResource; else _invokingResource = _vm->_resources[entry.resourceId]; runOpcode(entry.opcode, entry.var, entry.argc, entry.argv); } }
void MystScriptParser::runScript(MystScript script, MystArea *invokingResource) { debugC(kDebugScript, "Script Size: %d", script->size()); // Scripted drawing takes more time to simulate older hardware // This way opcodes can't overwrite what the previous ones drew too quickly _vm->_gfx->enableDrawingTimeSimulation(true); for (uint16 i = 0; i < script->size(); i++) { MystScriptEntry &entry = (*script)[i]; debugC(kDebugScript, "\tOpcode %d: %d", i, entry.opcode); if (entry.type == kMystScriptNormal) _invokingResource = invokingResource; else _invokingResource = _vm->_resources[entry.resourceId]; runOpcode(entry.opcode, entry.var, entry.argc, entry.argv); } _vm->_gfx->enableDrawingTimeSimulation(false); }
void MystScriptParser::runScript(const MystScript &script, MystArea *invokingResource) { _scriptNestingLevel++; for (uint16 i = 0; i < script.size(); i++) { const MystScriptEntry &entry = script[i]; if (entry.type == kMystScriptNormal) _invokingResource = invokingResource; else _invokingResource = _vm->getCard()->getResource<MystArea>(entry.resourceId); runOpcode(entry.opcode, entry.var, entry.args); } _scriptNestingLevel--; }