SCI: Simplified SongLibrary code a bit
svn-id: r41345
This commit is contained in:
parent
62f596821e
commit
21d948ec05
5 changed files with 18 additions and 40 deletions
|
@ -1530,7 +1530,7 @@ bool Console::cmdShowMap(int argc, const char **argv) {
|
||||||
bool Console::cmdSongLib(int argc, const char **argv) {
|
bool Console::cmdSongLib(int argc, const char **argv) {
|
||||||
DebugPrintf("Song library:\n");
|
DebugPrintf("Song library:\n");
|
||||||
|
|
||||||
Song *seeker = *(g_EngineState->_sound._songlib._lib);
|
Song *seeker = g_EngineState->_sound._songlib._lib;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
DebugPrintf(" %p", (void *)seeker);
|
DebugPrintf(" %p", (void *)seeker);
|
||||||
|
|
|
@ -408,14 +408,14 @@ static void sync_songlib_t(Common::Serializer &s, SongLibrary &obj) {
|
||||||
s.syncAsUint32LE(songcount);
|
s.syncAsUint32LE(songcount);
|
||||||
|
|
||||||
if (s.isLoading()) {
|
if (s.isLoading()) {
|
||||||
obj.initSounds();
|
obj._lib = 0;
|
||||||
while (songcount--) {
|
while (songcount--) {
|
||||||
Song *newsong = (Song *)calloc(1, sizeof(Song));
|
Song *newsong = (Song *)calloc(1, sizeof(Song));
|
||||||
sync_song_t(s, *newsong);
|
sync_song_t(s, *newsong);
|
||||||
obj.addSong(newsong);
|
obj.addSong(newsong);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Song *seeker = *(obj._lib);
|
Song *seeker = obj._lib;
|
||||||
while (seeker) {
|
while (seeker) {
|
||||||
seeker->_restoreTime = seeker->_it->getTimepos();
|
seeker->_restoreTime = seeker->_it->getTimepos();
|
||||||
sync_song_t(s, *seeker);
|
sync_song_t(s, *seeker);
|
||||||
|
@ -695,12 +695,7 @@ static void reconstruct_sounds(EngineState *s) {
|
||||||
Song *seeker;
|
Song *seeker;
|
||||||
SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0;
|
SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0;
|
||||||
|
|
||||||
if (s->_sound._songlib._lib)
|
seeker = s->_sound._songlib._lib;
|
||||||
seeker = *(s->_sound._songlib._lib);
|
|
||||||
else {
|
|
||||||
s->_sound._songlib.initSounds();
|
|
||||||
seeker = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (seeker) {
|
while (seeker) {
|
||||||
SongIterator *base, *ff;
|
SongIterator *base, *ff;
|
||||||
|
|
|
@ -638,7 +638,7 @@ static int sfx_play_iterator_pcm(SongIterator *it, SongHandle handle) {
|
||||||
#define DELAY (1000000 / SFX_TICKS_PER_SEC)
|
#define DELAY (1000000 / SFX_TICKS_PER_SEC)
|
||||||
|
|
||||||
void SfxState::sfx_init(ResourceManager *resmgr, int flags) {
|
void SfxState::sfx_init(ResourceManager *resmgr, int flags) {
|
||||||
_songlib.initSounds();
|
_songlib._lib = 0;
|
||||||
_song = NULL;
|
_song = NULL;
|
||||||
_flags = flags;
|
_flags = flags;
|
||||||
_soundSync = NULL;
|
_soundSync = NULL;
|
||||||
|
|
|
@ -78,14 +78,7 @@ void SongLibrary::addSong(Song *song) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*_lib == NULL) {
|
seeker = &_lib;
|
||||||
*_lib = song;
|
|
||||||
song->_next = NULL;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
seeker = _lib;
|
|
||||||
while (*seeker && ((*seeker)->_priority > pri))
|
while (*seeker && ((*seeker)->_priority > pri))
|
||||||
seeker = &((*seeker)->_next);
|
seeker = &((*seeker)->_next);
|
||||||
|
|
||||||
|
@ -93,13 +86,8 @@ void SongLibrary::addSong(Song *song) {
|
||||||
*seeker = song;
|
*seeker = song;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongLibrary::initSounds() {
|
|
||||||
_lib = &_s;
|
|
||||||
_s = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SongLibrary::freeSounds() {
|
void SongLibrary::freeSounds() {
|
||||||
Song *next = *_lib;
|
Song *next = _lib;
|
||||||
while (next) {
|
while (next) {
|
||||||
Song *song = next;
|
Song *song = next;
|
||||||
delete song->_it;
|
delete song->_it;
|
||||||
|
@ -107,12 +95,12 @@ void SongLibrary::freeSounds() {
|
||||||
next = song->_next;
|
next = song->_next;
|
||||||
delete song;
|
delete song;
|
||||||
}
|
}
|
||||||
*_lib = NULL;
|
_lib = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Song *SongLibrary::findSong(SongHandle handle) {
|
Song *SongLibrary::findSong(SongHandle handle) {
|
||||||
Song *seeker = *_lib;
|
Song *seeker = _lib;
|
||||||
|
|
||||||
while (seeker) {
|
while (seeker) {
|
||||||
if (seeker->_handle == handle)
|
if (seeker->_handle == handle)
|
||||||
|
@ -124,7 +112,7 @@ Song *SongLibrary::findSong(SongHandle handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Song *SongLibrary::findNextActive(Song *other) {
|
Song *SongLibrary::findNextActive(Song *other) {
|
||||||
Song *seeker = other ? other->_next : *_lib;
|
Song *seeker = other ? other->_next : _lib;
|
||||||
|
|
||||||
while (seeker) {
|
while (seeker) {
|
||||||
if ((seeker->_status == SOUND_STATUS_WAITING) ||
|
if ((seeker->_status == SOUND_STATUS_WAITING) ||
|
||||||
|
@ -146,13 +134,13 @@ Song *SongLibrary::findFirstActive() {
|
||||||
|
|
||||||
int SongLibrary::removeSong(SongHandle handle) {
|
int SongLibrary::removeSong(SongHandle handle) {
|
||||||
int retval;
|
int retval;
|
||||||
Song *goner = *_lib;
|
Song *goner = _lib;
|
||||||
|
|
||||||
if (!goner)
|
if (!goner)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (goner->_handle == handle)
|
if (goner->_handle == handle)
|
||||||
*_lib = goner->_next;
|
_lib = goner->_next;
|
||||||
|
|
||||||
else {
|
else {
|
||||||
while ((goner->_next) && (goner->_next->_handle != handle))
|
while ((goner->_next) && (goner->_next->_handle != handle))
|
||||||
|
@ -175,10 +163,10 @@ int SongLibrary::removeSong(SongHandle handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongLibrary::resortSong(Song *song) {
|
void SongLibrary::resortSong(Song *song) {
|
||||||
if (*_lib == song)
|
if (_lib == song)
|
||||||
*_lib = song->_next;
|
_lib = song->_next;
|
||||||
else {
|
else {
|
||||||
Song *seeker = *_lib;
|
Song *seeker = _lib;
|
||||||
|
|
||||||
while (seeker->_next && (seeker->_next != song))
|
while (seeker->_next && (seeker->_next != song))
|
||||||
seeker = seeker->_next;
|
seeker = seeker->_next;
|
||||||
|
@ -191,7 +179,7 @@ void SongLibrary::resortSong(Song *song) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int SongLibrary::countSongs() {
|
int SongLibrary::countSongs() {
|
||||||
Song *seeker = *_lib;
|
Song *seeker = _lib;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
while (seeker) {
|
while (seeker) {
|
||||||
|
|
|
@ -99,15 +99,10 @@ public:
|
||||||
|
|
||||||
class SongLibrary {
|
class SongLibrary {
|
||||||
public:
|
public:
|
||||||
Song **_lib;
|
Song *_lib;
|
||||||
protected:
|
|
||||||
Song *_s;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SongLibrary() {}
|
SongLibrary() : _lib(0) {}
|
||||||
|
|
||||||
/** Initializes a static song library */
|
|
||||||
void initSounds();
|
|
||||||
|
|
||||||
/** Frees a song library. */
|
/** Frees a song library. */
|
||||||
void freeSounds();
|
void freeSounds();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue