MOHAWK: Handle LB item sound priorities.

This commit is contained in:
Alyssa Milburn 2011-03-29 16:28:24 +02:00
parent bd526aac1d
commit bcc0adb8fa
2 changed files with 62 additions and 5 deletions

View file

@ -270,6 +270,10 @@ Common::String MohawkEngine_LivingBooks::stringForMode(LBMode mode) {
void MohawkEngine_LivingBooks::destroyPage() { void MohawkEngine_LivingBooks::destroyPage() {
_sound->stopSound(); _sound->stopSound();
_lastSoundOwner = 0;
_lastSoundId = 0;
_soundLockOwner = 0;
_gfx->clearCache(); _gfx->clearCache();
_video->stopVideos(); _video->stopVideos();
@ -554,6 +558,49 @@ void MohawkEngine_LivingBooks::queueDelayedEvent(DelayedEvent event) {
_eventQueue.push(event); _eventQueue.push(event);
} }
bool MohawkEngine_LivingBooks::playSound(LBItem *source, uint16 resourceId) {
if (_lastSoundId && !_sound->isPlaying(_lastSoundId))
_lastSoundId = 0;
if (!_soundLockOwner) {
if (_lastSoundId && _lastSoundOwner != source->getId())
if (source->getSoundPriority() >= _lastSoundPriority)
return false;
} else {
if (_soundLockOwner != source->getId() && source->getSoundPriority() >= _maxSoundPriority)
return false;
}
_sound->stopSound();
_sound->playSound(resourceId);
_lastSoundId = resourceId;
_lastSoundOwner = source->getId();
_lastSoundPriority = source->getSoundPriority();
return true;
}
void MohawkEngine_LivingBooks::lockSound(LBItem *owner, bool lock) {
if (!lock) {
_soundLockOwner = 0;
return;
}
if (_soundLockOwner)
return;
if (_lastSoundId && !_sound->isPlaying(_lastSoundId))
_lastSoundId = 0;
_soundLockOwner = owner->getId();
_maxSoundPriority = owner->getSoundPriority();
if (_lastSoundId && _lastSoundPriority < _maxSoundPriority) {
_sound->stopSound(_lastSoundId);
_lastSoundId = 0;
}
}
// Only 1 VSRN resource per stack, Id 1000 // Only 1 VSRN resource per stack, Id 1000
uint16 MohawkEngine_LivingBooks::getResourceVersion() { uint16 MohawkEngine_LivingBooks::getResourceVersion() {
Common::SeekableReadStream *versionStream = getResource(ID_VRSN, 1000); Common::SeekableReadStream *versionStream = getResource(ID_VRSN, 1000);
@ -1642,7 +1689,7 @@ void LBAnimation::stop() {
void LBAnimation::playSound(uint16 resourceId) { void LBAnimation::playSound(uint16 resourceId) {
_currentSound = resourceId; _currentSound = resourceId;
_vm->_sound->playSound(_currentSound); _vm->playSound(_parent, _currentSound);
} }
bool LBAnimation::soundPlaying(uint16 resourceId) { bool LBAnimation::soundPlaying(uint16 resourceId) {
@ -2165,7 +2212,7 @@ bool LBItem::togglePlaying(bool playing, bool restart) {
if (_controlMode >= kLBControlHideMouse) { if (_controlMode >= kLBControlHideMouse) {
debug(2, "Hiding cursor"); debug(2, "Hiding cursor");
_vm->_cursor->hideCursor(); _vm->_cursor->hideCursor();
// TODO: lock sound? _vm->lockSound(this, true);
if (_controlMode >= kLBControlPauseItems) { if (_controlMode >= kLBControlPauseItems) {
debug(2, "Disabling all"); debug(2, "Disabling all");
@ -2203,7 +2250,7 @@ void LBItem::done(bool onlyNotify) {
if (_controlMode >= kLBControlHideMouse) { if (_controlMode >= kLBControlHideMouse) {
debug(2, "Showing cursor"); debug(2, "Showing cursor");
_vm->_cursor->showCursor(); _vm->_cursor->showCursor();
// TODO: unlock sound? _vm->lockSound(this, false);
if (_controlMode >= kLBControlPauseItems) { if (_controlMode >= kLBControlPauseItems) {
debug(2, "Enabling all"); debug(2, "Enabling all");
@ -2864,7 +2911,8 @@ bool LBSoundItem::togglePlaying(bool playing, bool restart) {
return false; return false;
_running = true; _running = true;
_vm->_sound->playSound(_resourceId, Audio::Mixer::kMaxChannelVolume, false); debug(4, "sound %d play for item %d (%s)", _resourceId, _itemId, _desc.c_str());
_vm->playSound(this, _resourceId);
return true; return true;
} }
@ -3259,7 +3307,7 @@ void LBLiveTextItem::handleMouseDown(Common::Point pos) {
return; return;
} }
_currentWord = i; _currentWord = i;
_vm->_sound->playSound(soundId); _vm->playSound(this, soundId);
paletteUpdate(_currentWord, true); paletteUpdate(_currentWord, true);
return; return;
} }

View file

@ -365,6 +365,7 @@ public:
virtual void notify(uint16 data, uint16 from); // 0x1A virtual void notify(uint16 data, uint16 from); // 0x1A
uint16 getId() { return _itemId; } uint16 getId() { return _itemId; }
uint16 getSoundPriority() { return _soundMode; }
protected: protected:
MohawkEngine_LivingBooks *_vm; MohawkEngine_LivingBooks *_vm;
@ -598,6 +599,9 @@ public:
void notifyAll(uint16 data, uint16 from); void notifyAll(uint16 data, uint16 from);
void queueDelayedEvent(DelayedEvent event); void queueDelayedEvent(DelayedEvent event);
bool playSound(LBItem *source, uint16 resourceId);
void lockSound(LBItem *owner, bool lock);
bool isBigEndian() const { return getGameType() != GType_LIVINGBOOKSV1 || getPlatform() == Common::kPlatformMacintosh; } bool isBigEndian() const { return getGameType() != GType_LIVINGBOOKSV1 || getPlatform() == Common::kPlatformMacintosh; }
bool isPreMohawk() const; bool isPreMohawk() const;
@ -632,6 +636,11 @@ private:
bool loadPage(LBMode mode, uint page, uint subpage); bool loadPage(LBMode mode, uint page, uint subpage);
void updatePage(); void updatePage();
uint16 _lastSoundOwner, _lastSoundId;
uint16 _lastSoundPriority;
uint16 _soundLockOwner;
uint16 _maxSoundPriority;
uint16 getResourceVersion(); uint16 getResourceVersion();
void loadBITL(uint16 resourceId); void loadBITL(uint16 resourceId);
void loadSHP(uint16 resourceId); void loadSHP(uint16 resourceId);