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.c26
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()) {
nger/commit/README?h=v1.8.1&id=0a32b6845829751de8fc2fd4957c360bb4162ace'>0a32b684 ^
4ad365fc ^
0a32b684 ^
2144cf26 ^
36e4e71e ^

4ea0f69a ^

36e4e71e ^




78a7d762 ^
36e4e71e ^

78a7d762 ^
36e4e71e ^


4ea0f69a ^

36e4e71e ^
bd088c49 ^
36e4e71e ^
0a32b684 ^
36e4e71e ^

f6ae504c ^
4ea0f69a ^

0a32b684 ^

4ea0f69a ^
0a32b684 ^
4ea0f69a ^


0a32b684 ^

4ea0f69a ^



36e4e71e ^
7582555b ^
36e4e71e ^
7582555b ^








36e4e71e ^
4ea0f69a ^


36e4e71e ^




4ea0f69a ^
e71c8103 ^

36e4e71e ^

f6ae504c ^
4ea0f69a ^
36e4e71e ^

4ea0f69a ^

36e4e71e ^






4ea0f69a ^

306c76d8 ^






b6aff4c3 ^

306c76d8 ^
4ea0f69a ^

45cf5174 ^







fab4dc54 ^
45cf5174 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137