From 0018bb0f6f36fd1798ec92d2e7e6654e026fe19b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 19 Oct 2014 13:01:56 +0200 Subject: [PATCH] SCI: Give songs that start playing later higher priority --- engines/sci/sound/music.cpp | 9 ++++++++- engines/sci/sound/music.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index 62b17b206452..2b73bcf8b320 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -144,6 +144,7 @@ void SciMusic::init() { _globalReverb = _pMidiDrv->getReverb(); // Init global reverb for SCI0 _currentlyPlayingSample = NULL; + _timeCounter = 0; } void SciMusic::miditimerCallback(void *p) { @@ -285,8 +286,10 @@ byte SciMusic::getCurrentReverb() { return _pMidiDrv->getReverb(); } +// A larger priority value has higher priority. For equal priority values, +// songs that have been added later have higher priority. static bool musicEntryCompare(const MusicEntry *l, const MusicEntry *r) { - return (l->priority > r->priority); + return (l->priority > r->priority) || (l->priority == r->priority && l->time > r->time); } void SciMusic::sortPlayList() { @@ -317,6 +320,8 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) { track = digital; } + pSnd->time = ++_timeCounter; + if (track) { // Play digital sample if (track->digitalChannelNr != -1) { @@ -415,6 +420,7 @@ void SciMusic::soundPlay(MusicEntry *pSnd) { _playList.push_back(pSnd); } + pSnd->time = ++_timeCounter; sortPlayList(); _mutex.unlock(); // unlock to perform mixer-related calls @@ -560,6 +566,7 @@ void SciMusic::soundSetPriority(MusicEntry *pSnd, byte prio) { Common::StackLock lock(_mutex); pSnd->priority = prio; + pSnd->time = ++_timeCounter; sortPlayList(); } diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h index 0fbd5a0c0eed..134717705448 100644 --- a/engines/sci/sound/music.h +++ b/engines/sci/sound/music.h @@ -75,6 +75,8 @@ class MusicEntry : public Common::Serializable { SoundResource *soundRes; uint16 resourceId; + int time; // "tim"estamp to indicate in which order songs have been added + bool isQueued; // for SCI0 only! uint16 dataInc; @@ -267,6 +269,9 @@ class SciMusic : public Common::Serializable { int _driverLastChannel; MusicEntry *_currentlyPlayingSample; + + int _timeCounter; // Used to keep track of the order in which MusicEntries + // are added, for priority purposes. }; } // End of namespace Sci