diff -ur freecraft-030311-old/src/clone/clone.c freecraft-030311/src/clone/clone.c --- freecraft-030311-old/src/clone/clone.c 2003-03-05 13:31:28.000000000 -0500 +++ freecraft-030311/src/clone/clone.c 2005-06-24 22:04:25.000000000 -0500 @@ -191,6 +191,7 @@ #ifdef USE_SDL #include "SDL.h" +#include "SDL_thread.h" #endif #ifdef __MINGW32__ @@ -225,6 +226,12 @@ extern SCM CclUnits(void); #endif +#ifdef USE_SDLCD +extern global SDL_mutex *cdromcheck_mutex; +extern global SDL_cond *cdromcheck_cond; +extern global int cdromcheck_done; +#endif + /*---------------------------------------------------------------------------- -- Variables ----------------------------------------------------------------------------*/ @@ -1393,6 +1400,10 @@ */ global int main(int argc,char** argv) { +#ifdef USE_SDLCD + SDL_Thread *SDLCD_Sound_Thread; +#endif + #ifdef USE_BEOS // // Parse arguments for BeOS @@ -1537,8 +1548,26 @@ InitCcl(); // init CCL and load configurations! LoadCcl(); +#ifdef USE_SDLCD + cdromcheck_mutex = SDL_CreateMutex(); + cdromcheck_cond = SDL_CreateCond(); + cdromcheck_done = 0; + SDLCD_Sound_Thread = SDL_CreateThread(CDRomCheck, NULL); +#endif + main1(argc,argv); +#ifdef USE_SDLCD + // Signal SDLCD_Sound_Thread to exit, then clean up. + SDL_mutexP(cdromcheck_mutex); + cdromcheck_done = 1; + SDL_CondSignal(cdromcheck_cond); + SDL_mutexV(cdromcheck_mutex); + SDL_WaitThread(SDLCD_Sound_Thread, NULL); + SDL_DestroyCond(cdromcheck_cond); + SDL_DestroyMutex(cdromcheck_mutex); +#endif + return 0; } diff -ur freecraft-030311-old/src/clone/mainloop.c freecraft-030311/src/clone/mainloop.c --- freecraft-030311-old/src/clone/mainloop.c 2003-03-04 12:11:07.000000000 -0500 +++ freecraft-030311/src/clone/mainloop.c 2005-06-24 21:58:17.000000000 -0500 @@ -69,6 +69,12 @@ #include "SDL_thread.h" #endif +#ifdef USE_SDLCD +extern global SDL_mutex *cdromcheck_mutex; +extern global SDL_cond *cdromcheck_cond; +extern global int cdromcheck_done; +#endif + //---------------------------------------------------------------------------- // Variables //---------------------------------------------------------------------------- @@ -726,7 +732,9 @@ case 0: // Check cd-rom #if defined(USE_SDLCD) if ( !(GameCycle%4) ) { // every 2nd second - SDL_CreateThread(CDRomCheck, NULL); + SDL_mutexP(cdromcheck_mutex); + SDL_CondSignal(cdromcheck_cond); + SDL_mutexV(cdromcheck_mutex); } #elif defined(USE_LIBCDA) || defined(USE_CDDA) CDRomCheck(NULL); @@ -735,7 +743,6 @@ } #endif } - UpdateMessages(); // update messages // @@ -822,6 +829,7 @@ } } + // // Game over // diff -ur freecraft-030311-old/src/sound/sound_server.c freecraft-030311/src/sound/sound_server.c --- freecraft-030311-old/src/sound/sound_server.c 2003-02-17 00:34:38.000000000 -0500 +++ freecraft-030311/src/sound/sound_server.c 2005-06-24 21:58:18.000000000 -0500 @@ -81,6 +81,7 @@ #if defined(USE_SDLCD) #include "SDL.h" +#include "SDL_thread.h" #elif defined(USE_LIBCDA) #include "libcda.h" #elif defined(USE_CDDA) @@ -108,6 +109,12 @@ -- Variables ----------------------------------------------------------------------------*/ +#ifdef USE_SDLCD +global SDL_mutex *cdromcheck_mutex; // Make the CDRomCheck thread once +global SDL_cond *cdromcheck_cond; // and use these three variables to +global int cdromcheck_done = 0; // interact with it. +#endif + global int SoundFildes = -1; /// audio file descriptor global int PlayingMusic; /// flag true if playing music global int CallbackMusic; /// flag true callback ccl if stops @@ -230,40 +237,48 @@ global int CDRomCheck(void *unused __attribute__ ((unused))) { #if defined(USE_SDLCD) - 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); - } - } + SDL_mutexP(cdromcheck_mutex); + while (!cdromcheck_done) + { + SDL_CondWait(cdromcheck_cond, cdromcheck_mutex); + 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); + } + } #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; - } - } + 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); - } + if (CDMode != CDModeOff && CDMode != CDModeStopped + && !PlayingMusic) { + DebugLevel0Fn("Playing new track\n"); + if (CDMode == CDModeAll) { + PlayCDRom(CDModeAll); + } else if (CDMode == CDModeRandom) { + PlayCDRom(CDModeRandom); + } + } +#endif +#if defined(USE_SDLCD) } + SDL_mutexV(cdromcheck_mutex); #endif return 0; }