diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c index 8c907d0..7d760b6 100644 --- a/src/main.c +++ b/src/main.c @@ -8,7 +8,7 @@ char VersionString[256]; struct Settings GlobalSettings; SDL_mutex *AudioQueueBeingModified; -SDL_mutex *AudioInitializing; +SDL_atomic_t AudioInitializing; int AudioQueue[20]; @@ -25,7 +25,6 @@ int internal_clock() { } int audio() { - SDL_TryLockMutex(AudioInitializing); int i; Mix_Init(0); Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024); @@ -40,7 +39,7 @@ int audio() { 0, 20000000 }; struct timespec Remaining; - SDL_UnlockMutex(AudioInitializing); + SDL_AtomicSet(&AudioInitializing, 1); while(GameGoing == true) { for(i = 0; i < 20; i++) { if(AudioQueue[i] != -1){ @@ -114,7 +113,7 @@ int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_AUDIO); //Init Variables - strncpy(VersionString, "Version 0.2 - AEOLUS", sizeof(VersionString)); + strncpy(VersionString, "Version 0.3 - Charon", sizeof(VersionString)); //Populate Audio Queue for(unsigned int i = 0; i < 20; i++) { @@ -123,17 +122,18 @@ int main(int argc, char *argv[]) { //Threading AudioQueueBeingModified = SDL_CreateMutex(); - AudioInitializing = SDL_CreateMutex(); SDL_AtomicSet(&Ticks, 0); SDL_Thread *InternalClock = SDL_CreateThread(internal_clock, "Internal Clock", NULL); SDL_Thread *AudioThread = SDL_CreateThread(audio, "Audio", NULL); + SDL_AtomicSet(&AudioInitializing, 0); //Load Settings - char *SettingsDirectory = SDL_GetPrefPath("iotib.net", "Pong"); + char *SettingsDirectory = SDL_GetPrefPath("iotib", "Pong"); char SettingsFilePath[8192]; snprintf(SettingsFilePath, sizeof(SettingsFilePath), "%s/settings.txt", SettingsDirectory); FILE *SettingsFile; reopen: + //Create settings file if it doesn't exist. if ((SettingsFile = fopen(SettingsFilePath, "r")) == NULL) { if(SettingsFile != NULL) { fclose(SettingsFile); @@ -146,9 +146,10 @@ int main(int argc, char *argv[]) { fprintf(SettingsFile, "music_volume 100\n"); fprintf(SettingsFile, "fullscreen 0"); fclose(SettingsFile); - goto reopen; + goto reopen; //Try opening again. } + // Parse the settings file. char Option[2048]; int Value; while(!feof(SettingsFile)) { @@ -161,10 +162,17 @@ int main(int argc, char *argv[]) { GlobalSettings.Fullscreen = Value; } } + fclose(SettingsFile); // Wait for audio to finish initializing. - SDL_LockMutex(AudioInitializing); - + struct timespec a = { + 0, 5000000 + }; + struct timespec b; + while(SDL_AtomicGet(&AudioInitializing) == 0) { + nanosleep(&a, &b); //Prevent heavy cpu usage + } + // Launch Game while (GameGoing == true) { switch(title_screen()) { |