diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/main.c b/src/main.c index 4a383f4..54f5b1b 100644 --- a/src/main.c +++ b/src/main.c @@ -18,13 +18,13 @@ void set_screen_mode() { ClearWindowState(FLAG_WINDOW_UNDECORATED); ClearWindowState(FLAG_FULLSCREEN_MODE); switch(GlobalSettings.Fullscreen) { - case 1: //Real Fullscreen is fickle as fuck. So it needs a timeout. + case 1: /* Real Fullscreen is fickle as fuck. So it needs a timeout. */ SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor())); - int Timeout = SDL_AtomicGet(&Ticks)+300; //Set the timeout for 5 seconds. + int Timeout = SDL_AtomicGet(&Ticks)+300; /* Set the timeout for 5 seconds. */ while(GetScreenHeight() != GetMonitorHeight(GetCurrentMonitor())) { BeginDrawing(); EndDrawing(); - if(SDL_AtomicGet(&Ticks) >= Timeout) { //Default to windowed if fullscreen fails for whatever reason. + if(SDL_AtomicGet(&Ticks) >= Timeout) { /* Default to windowed if fullscreen fails for whatever reason. */ goto FullScreenFailed; } } @@ -58,7 +58,7 @@ static int internal_clock() { 0, 99999 }; while(GameGoing == true) { - nanosleep(&SleepFor, NULL); //Reduces CPU usage + nanosleep(&SleepFor, NULL); /* Reduces CPU usage */ NewTime = GetTime(); DeltaTime += (NewTime - OldTime)/Framerate; OldTime = NewTime; @@ -77,7 +77,6 @@ static int audio() { Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024); Mix_AllocateChannels(64); Mix_Chunk *Bounce = Mix_LoadWAV("resources/bounce.wav"); - //Mix_Chunk *TitleScreen = Mix_LoadWAV("resources/title.wav"); Mix_Chunk *Victory = Mix_LoadWAV("resources/victory.wav"); Mix_Chunk *Defeat = Mix_LoadWAV("resources/defeat.wav"); Mix_Chunk *PlayerScore = Mix_LoadWAV("resources/score_player.wav"); @@ -92,25 +91,22 @@ static int audio() { if(AudioQueue[i] != -1){ Mix_Volume(-1, GlobalSettings.SoundVolume); switch(AudioQueue[i]) { - case 0: //Play bounce sound. + case 0: /* Play bounce sound. */ Mix_PlayChannel(-1, Bounce, 0); break; - case 1: //Play game over + case 1: /* Play game over */ Mix_PlayChannel(-1, Defeat, 0); break; - case 2: //Play win + case 2: /* Play win */ Mix_PlayChannel(-1, Victory, 0); break; - //case 3: //Title Screen - // Mix_PlayChannel(-1, TitleScreen, 0); - // break; - case 4: //Player Score + case 4: /* Player Score */ Mix_PlayChannel(-1, PlayerScore, 0); break; - case 5: //Enemy Score + case 5: /* Enemy Score */ Mix_PlayChannel(-1, EnemyScore, 0); break; - case 99: //Stop All Sounds + case 99: /* Stop All Sounds */ Mix_HaltChannel(-1); break; default: @@ -146,7 +142,7 @@ bool play_audio(int SoundEffect) { } int main(int argc, char *argv[]) { - //Raylib Init + /* Raylib Init */ InitWindow(1280, 720, "Pong"); SDL_Init(SDL_INIT_AUDIO); SDL_AtomicSet(&Ticks, 0); @@ -159,31 +155,32 @@ int main(int argc, char *argv[]) { SetWindowState(FLAG_WINDOW_RESIZABLE); SetWindowMinSize(1280, 720); - //Settings declaration to prevent undefined behavior. + /* Settings declaration to prevent undefined behavior. */ GlobalSettings.Fullscreen = 0; GlobalSettings.SoundVolume = 0; GlobalSettings.MusicVolume = 0; - //Init Variables + /* Init Variables */ strncpy(VersionString, "Version 0.4 - APOLLO", sizeof(VersionString)); - //Populate Audio Queue - for(unsigned int i = 0; i < 20; i++) { + /* Populate Audio Queue */ + unsigned int i = 0; + for(i = 0; i < 20; i++) { AudioQueue[i] = -1; } - //Threading + /* Threading */ AudioQueueBeingModified = SDL_CreateMutex(); SDL_Thread *AudioThread = SDL_CreateThread(audio, "Audio", NULL); SDL_AtomicSet(&AudioInitializing, 0); - //Load Settings + /* Load Settings */ 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. + /* Create settings file if it doesn't exist. */ if ((SettingsFile = fopen(SettingsFilePath, "r")) == NULL) { if(SettingsFile != NULL) { fclose(SettingsFile); @@ -196,10 +193,10 @@ int main(int argc, char *argv[]) { fprintf(SettingsFile, "music_volume 100\n"); fprintf(SettingsFile, "fullscreen 0"); fclose(SettingsFile); - goto reopen; //Try opening again. + goto reopen; /* Try opening again. */ } - // Parse the settings file. + /* Parse the settings file. */ char Option[2048]; int Value; while(!feof(SettingsFile)) { @@ -216,23 +213,23 @@ int main(int argc, char *argv[]) { set_screen_mode(); - // Wait for audio to finish initializing. + /* Wait for audio to finish initializing. */ struct timespec a = { 0, 5000000 }; struct timespec b; while(SDL_AtomicGet(&AudioInitializing) == 0) { - nanosleep(&a, &b); //Prevent heavy cpu usage + nanosleep(&a, &b); /* Prevent heavy cpu usage */ } - // Launch Game + /* Launch Game */ while (GameGoing == true) { switch(title_screen()) { - case 0: //Versus + case 0: /* Versus */ play_audio(STOP_ALL_SOUNDS); versus_main(); break; - case 1: //Marathon + case 1: /* Marathon */ play_audio(STOP_ALL_SOUNDS); marathon_main(); break; @@ -241,7 +238,7 @@ int main(int argc, char *argv[]) { } } - GameGoing = false; // Make sure the game is going to end. + GameGoing = false; /* Make sure the game is going to end. */ SDL_WaitThread(InternalClock, NULL); SDL_WaitThread(AudioThread, NULL); SDL_Quit(); |