about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c79
1 files changed, 38 insertions, 41 deletions
diff --git a/src/main.c b/src/main.c
index 4091596..9f91def 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,14 +17,14 @@ void set_screen_mode() {
 	ClearWindowState(FLAG_WINDOW_TOPMOST);
 	ClearWindowState(FLAG_WINDOW_UNDECORATED);
 	ClearWindowState(FLAG_FULLSCREEN_MODE);
-	switch(GlobalSettings.Fullscreen) {
+	switch (GlobalSettings.Fullscreen) {
 		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. */
-			while(GetScreenHeight() != GetMonitorHeight(GetCurrentMonitor())) {
+			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;
 				}
 			}
@@ -39,9 +39,9 @@ void set_screen_mode() {
 			SetWindowSize(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
 			break;
 		default:
-			FullScreenFailed:
+		FullScreenFailed:
 			SetWindowSize(1280, 720);
-			SetWindowPosition(GetMonitorHeight(GetCurrentMonitor())/5, GetMonitorHeight(GetCurrentMonitor())/5);
+			SetWindowPosition(GetMonitorHeight(GetCurrentMonitor()) / 5, GetMonitorHeight(GetCurrentMonitor()) / 5);
 			break;
 	}
 	return;
@@ -49,20 +49,19 @@ void set_screen_mode() {
 
 double Started;
 static int internal_clock() {
-	static const double Framerate = 1.0/60.0f;
+	static const double Framerate = 1.0 / 60.0f;
 	double OldTime = GetTime();
 	double DeltaTime = 0;
 	double NewTime = 0;
 	Started = GetTime();
 	struct timespec SleepFor = {
-		0, 99999
-	};
-	while(GameGoing == true) {
+		0, 99999};
+	while (GameGoing == true) {
 		nanosleep(&SleepFor, NULL); /* Reduces CPU usage */
 		NewTime = GetTime();
-		DeltaTime += (NewTime - OldTime)/Framerate;
+		DeltaTime += (NewTime - OldTime) / Framerate;
 		OldTime = NewTime;
-		while(DeltaTime >= 1.0) {
+		while (DeltaTime >= 1.0) {
 			SDL_AtomicAdd(&Ticks, 1);
 			DeltaTime--;
 		}
@@ -72,7 +71,7 @@ static int internal_clock() {
 		}
 	}
 
-	return(0);
+	return (0);
 }
 
 static int audio() {
@@ -86,15 +85,14 @@ static int audio() {
 	Mix_Chunk *PlayerScore = Mix_LoadWAV("resources/score_player.wav");
 	Mix_Chunk *EnemyScore = Mix_LoadWAV("resources/score_enemy.wav");
 	const struct timespec Delay = {
-		0, 20000000
-	};
+		0, 20000000};
 	struct timespec Remaining;
 	SDL_AtomicSet(&AudioInitializing, 1);
-	while(GameGoing == true) {
-		for(i = 0; i < 20; i++) {
-			if(AudioQueue[i] != -1){
+	while (GameGoing == true) {
+		for (i = 0; i < 20; i++) {
+			if (AudioQueue[i] != -1) {
 				Mix_Volume(-1, GlobalSettings.SoundVolume);
-				switch(AudioQueue[i]) {
+				switch (AudioQueue[i]) {
 					case 0: /* Play bounce sound. */
 						Mix_PlayChannel(-1, Bounce, 0);
 						break;
@@ -123,19 +121,19 @@ static int audio() {
 		}
 		nanosleep(&Delay, &Remaining);
 	}
-	return(0);
+	return (0);
 }
 
 bool play_audio(int SoundEffect) {
 	unsigned int i;
 	SDL_LockMutex(AudioQueueBeingModified);
-	for(i = 1; i != 20; i++) {
-		if (AudioQueue[i-1] == -1) {
-			AudioQueue[i-1] = AudioQueue[i];
+	for (i = 1; i != 20; i++) {
+		if (AudioQueue[i - 1] == -1) {
+			AudioQueue[i - 1] = AudioQueue[i];
 		}
 	}
-	for(i = 0; AudioQueue[i] != -1; i++) {
-		if(i > sizeof(AudioQueue)) {
+	for (i = 0; AudioQueue[i] != -1; i++) {
+		if (i > sizeof(AudioQueue)) {
 			SDL_UnlockMutex(AudioQueueBeingModified);
 			return false;
 		}
@@ -168,10 +166,10 @@ int main(int argc, char *argv[]) {
 
 	/* Init Variables */
 	strncpy(VersionString, "Version 0.4 - APOLLO", sizeof(VersionString));
-	
+
 	/* Populate Audio Queue */
 	unsigned int i = 0;
-	for(i = 0; i < 20; i++) {
+	for (i = 0; i < 20; i++) {
 		AudioQueue[i] = -1;
 	}
 
@@ -185,10 +183,10 @@ int main(int argc, char *argv[]) {
 	char SettingsFilePath[8192];
 	snprintf(SettingsFilePath, sizeof(SettingsFilePath), "%s/settings.txt", SettingsDirectory);
 	FILE *SettingsFile;
-	reopen:
+reopen:
 	/* Create settings file if it doesn't exist. */
 	if ((SettingsFile = fopen(SettingsFilePath, "r")) == NULL) {
-		if(SettingsFile != NULL) {
+		if (SettingsFile != NULL) {
 			fclose(SettingsFile);
 		}
 		if ((SettingsFile = fopen(SettingsFilePath, "w")) == NULL) {
@@ -201,36 +199,35 @@ int main(int argc, char *argv[]) {
 		fclose(SettingsFile);
 		goto reopen; /* Try opening again. */
 	}
-	
+
 	/* Parse the settings file. */
 	char Option[2048];
 	int Value;
-	while(!feof(SettingsFile)) {
+	while (!feof(SettingsFile)) {
 		fscanf(SettingsFile, "%s %i", Option, &Value);
-		if(strcmp(Option, "sound_volume") == 0) {
+		if (strcmp(Option, "sound_volume") == 0) {
 			GlobalSettings.SoundVolume = Value;
-		} else if(strcmp(Option, "music_volume") == 0) {
+		} else if (strcmp(Option, "music_volume") == 0) {
 			GlobalSettings.MusicVolume = Value;
-		} else if(strcmp(Option, "fullscreen") == 0) {
+		} else if (strcmp(Option, "fullscreen") == 0) {
 			GlobalSettings.Fullscreen = Value;
 		}
 	}
 	fclose(SettingsFile);
-	
+
 	set_screen_mode();
 
 	/* Wait for audio to finish initializing. */
 	struct timespec a = {
-		0, 5000000
-	};
+		0, 5000000};
 	struct timespec b;
-	while(SDL_AtomicGet(&AudioInitializing) == 0) {
+	while (SDL_AtomicGet(&AudioInitializing) == 0) {
 		nanosleep(&a, &b); /* Prevent heavy cpu usage */
 	}
 
 	/* Launch Game */
 	while (GameGoing == true) {
-		switch(title_screen()) {
+		switch (title_screen()) {
 			case 0: /* Versus */
 				play_audio(STOP_ALL_SOUNDS);
 				versus_main();
@@ -243,11 +240,11 @@ int main(int argc, char *argv[]) {
 				break;
 		}
 	}
-	
+
 	GameGoing = false; /* Make sure the game is going to end. */
 	SDL_WaitThread(InternalClock, NULL);
 	SDL_WaitThread(AudioThread, NULL);
 	SDL_Quit();
 	CloseWindow();
-	return(0);
+	return (0);
 }