From 1f543652b7cb6a092896f626aa334e56a55c47ec Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 1 Apr 2011 14:43:22 +0200 Subject: MOHAWK: Handle waiting for sound cues in LBAnimation. --- engines/mohawk/livingbooks.cpp | 39 ++++++++++++++++++++++++++++++--------- engines/mohawk/livingbooks.h | 6 +++++- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index 74dbfb3437..26bb09a645 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -1360,12 +1360,17 @@ NodeState LBAnimationNode::update(bool seeking) { break; } - assert(entry.size == 4); - uint16 strLen = READ_BE_UINT16(entry.data + 2); - - if (strLen) { - warning("Named wave file encountered (strlen %04x, id %d)", strLen, soundResourceId); + Common::String cue; + uint pos = 2; + while (pos < entry.size) { + char in = entry.data[pos]; + if (!in) + break; + pos++; + cue += in; } + if (pos == entry.size) + error("Cue in sound kLBAnimOp wasn't null-terminated"); switch (entry.opcode) { case kLBAnimOpPlaySound: @@ -1378,7 +1383,7 @@ NodeState LBAnimationNode::update(bool seeking) { if (seeking) break; debug(4, "b: WaitForSound(%0d)", soundResourceId); - if (!_parent->soundPlaying(soundResourceId)) + if (!_parent->soundPlaying(soundResourceId, cue)) break; _currentEntry--; return kLBNodeWaiting; @@ -1744,11 +1749,27 @@ void LBAnimation::stop() { void LBAnimation::playSound(uint16 resourceId) { _currentSound = resourceId; - _vm->_sound->playSound(_currentSound); + _vm->_sound->playSound(_currentSound, Audio::Mixer::kMaxChannelVolume, false, &_cueList); } -bool LBAnimation::soundPlaying(uint16 resourceId) { - return _currentSound == resourceId && _vm->_sound->isPlaying(_currentSound); +bool LBAnimation::soundPlaying(uint16 resourceId, const Common::String &cue) { + if (_currentSound != resourceId) + return false; + if (!_vm->_sound->isPlaying(_currentSound)) + return false; + + if (cue.empty()) + return true; + + uint samples = _vm->_sound->getNumSamplesPlayed(_currentSound); + for (uint i = 0; i < _cueList.pointCount; i++) { + if (_cueList.points[i].sampleFrame > samples) + break; + if (_cueList.points[i].name == cue) + return false; + } + + return true; } bool LBAnimation::transparentAt(int x, int y) { diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index 7138078c00..e55f14bc2c 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -29,6 +29,7 @@ #include "mohawk/mohawk.h" #include "mohawk/console.h" #include "mohawk/graphics.h" +#include "mohawk/sound.h" #include "common/config-file.h" #include "common/substream.h" @@ -313,7 +314,7 @@ public: void stop(); void playSound(uint16 resourceId); - bool soundPlaying(uint16 resourceId); + bool soundPlaying(uint16 resourceId, const Common::String &cue); bool transparentAt(int x, int y); @@ -335,7 +336,10 @@ protected: Common::Array _nodes; uint16 _tempo; + uint16 _currentSound; + CueList _cueList; + uint32 _lastTime, _currentFrame; bool _running; -- cgit v1.2.3