diff --git a/src/include/sound.h b/src/include/sound.h index 2cb6dc689..5528e2495 100644 --- a/src/include/sound.h +++ b/src/include/sound.h @@ -68,6 +68,7 @@ typedef struct _game_sound_ { } GameSound; typedef enum _play_section_type_ { + PlaySectionUnknown = -1, /// Unknown PlaySectionGame, /// Game PlaySectionBriefing, /// Briefing PlaySectionStats, /// Stats diff --git a/src/sound/music.cpp b/src/sound/music.cpp index cf39e7e71..a86d1d798 100644 --- a/src/sound/music.cpp +++ b/src/sound/music.cpp @@ -84,6 +84,8 @@ global struct cdrom_tocentry CDtocentry[64]; global struct cdrom_read_audio CDdata; #endif +global PlaySectionType CurrentPlaySection; + /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ @@ -447,10 +449,16 @@ global void PlaySectionMusic(PlaySectionType section) int found; int numfiles; + printf("in playsecmu\n"); + if (NumPlaySections == 0) { return; } + if (section == PlaySectionUnknown) { + section = CurrentPlaySection; + } + if (section == PlaySectionStats) { if (GameResult == GameVictory) { section = PlaySectionStatsVictory; @@ -465,6 +473,7 @@ global void PlaySectionMusic(PlaySectionType section) break; } } + CurrentPlaySection = PlaySections[i].Type; #ifdef USE_LIBCDA if (CDMode == CDModeDefined) { @@ -473,11 +482,16 @@ global void PlaySectionMusic(PlaySectionType section) if ( (1 << track) & PlaySections[i].CDTracks ) { newtrack = 0; } else { + if ( !((1 << CDTrack) & PlaySections[i].CDTracks) ) { + CDTrack = 0; + } if (PlaySections[i].CDOrder == PlaySectionOrderAll) { - for (j = 1; j < 32; ++j) { + for (j = CDTrack + 1; j != CDTrack; ++j) { if ( (1 << j) & PlaySections[i].CDTracks ) { newtrack = j; break; + } else if (j == 31) { + j = 0; } } } else if (PlaySections[i].CDOrder == PlaySectionOrderRandom) { @@ -489,6 +503,7 @@ global void PlaySectionMusic(PlaySectionType section) } if (newtrack) { cd_play(newtrack); + CDTrack = newtrack; } } else if (PlaySections[i].Files && (CDMode == CDModeOff || CDMode == CDModeStopped)) { #else diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp index 869a8e57e..f9a1f7fb1 100644 --- a/src/sound/sound_server.cpp +++ b/src/sound/sound_server.cpp @@ -233,36 +233,19 @@ global int CDRomCheck(void *unused __attribute__ ((unused))) if (CDMode != CDModeOff && CDMode != CDModeStopped && SDL_CDStatus(CDRom) == 1) { DebugLevel0Fn("Playing new track\n"); - if (CDMode == CDModeAll) { - PlayCDRom(CDModeAll); - } else if (CDMode == CDModeRandom) { - PlayCDRom(CDModeRandom); - } + PlayCDRom(CDMode); } #elif defined(USE_LIBCDA) if (CDMode != CDModeOff && CDMode != CDModeStopped && !cd_current_track() && CDMode != CDModeDefined) { DebugLevel0Fn("Playing new track\n"); PlayCDRom(CDMode); - } else if (CDMode != CDModeOff && CDMode != CDModeStopped) { - if (CDMode == CDModeDefined) { - PlayCDRom(CDMode); - } - DebugLevel0Fn("get track\n"); - CDTrack = cd_current_track() + 1; - if (CDTrack > NumCDTracks) { - CDTrack = 1; - } } #elif defined(USE_CDDA) if (CDMode != CDModeOff && CDMode != CDModeStopped && !PlayingMusic) { DebugLevel0Fn("Playing new track\n"); - if (CDMode == CDModeAll) { - PlayCDRom(CDModeAll); - } else if (CDMode == CDModeRandom) { - PlayCDRom(CDModeRandom); - } + PlayCDRom(CDMode); } #endif return 0; diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index 4a0a34032..d9f66bbbb 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -729,6 +729,11 @@ global void GameMainLoop(void) CDRomCheck(NULL); #endif break; + case 10: + if ( !(GameCycle%2) ) { + PlaySectionMusic(PlaySectionUnknown); + } + break; } #endif }