MYST3: Sound background scripts are now ran

This commit is contained in:
Bastien Bouclet 2012-01-23 17:56:19 +01:00
parent 794d7e7d31
commit a86bcd3b1a
5 changed files with 53 additions and 0 deletions

View File

@ -505,6 +505,23 @@ void Myst3Engine::runScriptsFromNode(uint16 nodeID, uint32 roomID, uint32 ageID)
}
}
void Myst3Engine::runBackgroundSoundScriptsFromNode(uint16 nodeID, uint32 roomID, uint32 ageID) {
if (roomID == 0)
roomID = _state->getLocationRoom();
if (ageID == 0)
ageID = _state->getLocationAge();
NodePtr nodeData = _db->getNodeData(nodeID, roomID, ageID);
for (uint j = 0; j < nodeData->backgroundSoundScripts.size(); j++) {
if (_state->evaluate(nodeData->backgroundSoundScripts[j].condition)) {
if (!_scriptEngine->run(&nodeData->backgroundSoundScripts[j].script))
break;
}
}
}
void Myst3Engine::loadMovie(uint16 id, uint16 condition, bool resetCond, bool loop) {
ScriptedMovie *movie;

View File

@ -100,6 +100,7 @@ public:
void runNodeInitScripts();
void runNodeBackgroundScripts();
void runScriptsFromNode(uint16 nodeID, uint32 roomID = 0, uint32 ageID = 0);
void runBackgroundSoundScriptsFromNode(uint16 nodeID, uint32 roomID = 0, uint32 ageID = 0);
void loadMovie(uint16 id, uint16 condition, bool resetCond, bool loop);
void playSimpleMovie(uint16 id);

View File

@ -207,6 +207,9 @@ Script::Script(Myst3Engine *vm):
OP_2(206, soundPlayVolume, kEvalValue, kEvalValue );
OP_3(207, soundPlayVolumeDirection, kEvalValue, kEvalValue, kEvalValue );
OP_4(208, soundPlayVolumeDirectionAtt, kEvalValue, kEvalValue, kEvalValue, kEvalValue );
OP_1(231, runSoundScriptNode, kEvalValue );
OP_2(232, runSoundScriptNodeRoom, kEvalValue, kEvalValue );
OP_3(233, runSoundScriptNodeRoomAge, kEvalValue, kEvalValue, kEvalValue );
OP_0(239, drawOneFrame );
OP_0(249, newGame );
@ -2101,6 +2104,33 @@ void Script::soundPlayVolumeDirectionAtt(Context &c, const Opcode &cmd) {
_vm->_sound->play(cmd.args[0], volume, heading, att);
}
void Script::runSoundScriptNode(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Run sound script for node %d",
cmd.op, cmd.args[0]);
int32 node = _vm->_state->valueOrVarValue(cmd.args[0]);
_vm->runBackgroundSoundScriptsFromNode(node);
}
void Script::runSoundScriptNodeRoom(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Run sound script for node %d, room %d",
cmd.op, cmd.args[1], cmd.args[0]);
int32 node = _vm->_state->valueOrVarValue(cmd.args[1]);
int32 room = _vm->_state->valueOrVarValue(cmd.args[0]);
_vm->runBackgroundSoundScriptsFromNode(node, room);
}
void Script::runSoundScriptNodeRoomAge(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Run sound script for node %d, room %d, age %d",
cmd.op, cmd.args[2], cmd.args[1], cmd.args[0]);
int32 node = _vm->_state->valueOrVarValue(cmd.args[2]);
int32 room = _vm->_state->valueOrVarValue(cmd.args[1]);
int32 age = _vm->_state->valueOrVarValue(cmd.args[0]);
_vm->runBackgroundSoundScriptsFromNode(node, room, age);
}
void Script::drawOneFrame(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Draw one frame", cmd.op);

View File

@ -257,6 +257,9 @@ private:
DECLARE_OPCODE(soundPlayVolume);
DECLARE_OPCODE(soundPlayVolumeDirection);
DECLARE_OPCODE(soundPlayVolumeDirectionAtt);
DECLARE_OPCODE(runSoundScriptNode);
DECLARE_OPCODE(runSoundScriptNodeRoom);
DECLARE_OPCODE(runSoundScriptNodeRoomAge);
DECLARE_OPCODE(drawOneFrame);
DECLARE_OPCODE(newGame);

View File

@ -63,6 +63,8 @@ SoundChannel *Sound::getChannelForSound(uint32 id, uint priority) {
void Sound::update() {
for (uint i = 0; i < kNumChannels; i++)
_channels[i]->update();
_vm->runBackgroundSoundScriptsFromNode(_vm->_state->getLocationNode());
}
SoundChannel::SoundChannel(Myst3Engine *vm) :