Skip to content

Commit

Permalink
SCI: Give songs that start playing later higher priority
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Feb 15, 2015
1 parent 0aadd20 commit 0018bb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion engines/sci/sound/music.cpp
Expand Up @@ -144,6 +144,7 @@ void SciMusic::init() {
_globalReverb = _pMidiDrv->getReverb(); // Init global reverb for SCI0

_currentlyPlayingSample = NULL;
_timeCounter = 0;
}

void SciMusic::miditimerCallback(void *p) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -317,6 +320,8 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
track = digital;
}

pSnd->time = ++_timeCounter;

if (track) {
// Play digital sample
if (track->digitalChannelNr != -1) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -560,6 +566,7 @@ void SciMusic::soundSetPriority(MusicEntry *pSnd, byte prio) {
Common::StackLock lock(_mutex);

pSnd->priority = prio;
pSnd->time = ++_timeCounter;
sortPlayList();
}

Expand Down
5 changes: 5 additions & 0 deletions engines/sci/sound/music.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0018bb0

Please sign in to comment.