about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.txt1
-rw-r--r--src/ball.c4
-rw-r--r--src/enemy.c4
-rw-r--r--src/main.c38
-rw-r--r--src/marathon.c3
-rw-r--r--src/pong.h10
-rw-r--r--src/title.c4
-rw-r--r--src/versus.c8
8 files changed, 38 insertions, 34 deletions
diff --git a/README.txt b/README.txt
index 493360b..b2125bd 100644
--- a/README.txt
+++ b/README.txt
@@ -52,3 +52,4 @@ Build:
         1. Install homebrew (https://brew.sh/)
         2. Follow the instructions from the unix section.
 ===============================================================================
+If you like my work and want to support me, consider donating to me on https://liberapay.com/Charadon/
diff --git a/src/ball.c b/src/ball.c
index af210bb..20d3c09 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -8,7 +8,7 @@ void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerSc
 	}
 
 	// Moves 
-	int CurrentTick = SDL_AtomicGet(&Ticks);
+	int CurrentTick = Ticks;
 	if(Ball->NextTick <= CurrentTick){
 		int RunThisManyTimes = 0;
 		if (CurrentTick > Ball->NextTick) {
@@ -61,7 +61,7 @@ void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerSc
 				play_audio(SOUND_BOUNCE);
 			}
 		}
-		Ball->NextTick = SDL_AtomicGet(&Ticks)+1;
+		Ball->NextTick = Ticks+1;
 //		printf("%d,%d\n", SDL_AtomicGet(&Ticks), Ball->NextTick);
 	}
 //	printf("%d,%d\n", SDL_AtomicGet(&Ticks), Ball->NextTick);
diff --git a/src/enemy.c b/src/enemy.c
index 56c7d87..6c24c8d 100644
--- a/src/enemy.c
+++ b/src/enemy.c
@@ -2,7 +2,7 @@
 #include <SDL2/SDL_atomic.h>
 
 void enemy(struct Players *Enemy, struct Balls ball) {
-	int CurrentTick = SDL_AtomicGet(&Ticks);
+	int CurrentTick = Ticks;
 	int RunThisManyTimes = 0;
 	if (Enemy->NextTick <= CurrentTick) {
 		if(CurrentTick > Enemy->NextTick) {
@@ -43,7 +43,7 @@ void enemy(struct Players *Enemy, struct Balls ball) {
 			Enemy->HitBox.y = Enemy->Y;
 			Enemy->BallDetector.y = Enemy->Y+80;
 		}
-		Enemy->NextTick = SDL_AtomicGet(&Ticks)+1;
+		Enemy->NextTick = Ticks+1;
 	}
 	return;
 }
diff --git a/src/main.c b/src/main.c
index d15877e..4e5d412 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,6 @@
 #include "pong.h"
-#include <SDL2/SDL_atomic.h>
-#include <SDL2/SDL_thread.h>
-#include <SDL2/SDL_timer.h>
-#include <raylib.h>
 
 int Difficulty = 1;
-SDL_atomic_t Ticks;
 bool GameGoing = true;
 char VersionString[256];
 
@@ -24,11 +19,12 @@ void set_screen_mode() {
 	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.
+			int Timeout = Ticks+300; //Set the timeout for 5 seconds.
 			while(GetScreenHeight() != GetMonitorHeight(GetCurrentMonitor())) {
+				internal_clock();
 				BeginDrawing();
 				EndDrawing();
-				if(SDL_AtomicGet(&Ticks) >= Timeout) { //Default to windowed if fullscreen fails for whatever reason.
+				if(Ticks >= Timeout) { //Default to windowed if fullscreen fails for whatever reason.
 					goto FullScreenFailed;
 				}
 			}
@@ -51,20 +47,19 @@ void set_screen_mode() {
 	return;
 }
 
-static int internal_clock() {
-	SDL_SetThreadPriority(SDL_THREAD_PRIORITY_TIME_CRITICAL);
-	double NewTime = 0;
-	double OldTime = 0;
-	double Milliseconds = (1000.0/60)/1000.0;
-	double DeltaTime = 0;
-	while(GameGoing == true) {
-		NewTime = SDL_GetTicks()/1000.0f;
-		DeltaTime += (NewTime-OldTime)/Milliseconds;
-		OldTime = NewTime;
-		while(DeltaTime >= 1.0) {
-			SDL_AtomicAdd(&Ticks, 1);
-			DeltaTime--;
-		}
+double NewTime = 0;
+double OldTime = 0;
+double Milliseconds = (1000.0/60)/1000.0;
+double DeltaTime = 0;
+int Ticks = 0;
+
+int internal_clock() {
+	NewTime = SDL_GetTicks()/1000.0f;
+	DeltaTime += (NewTime-OldTime)/Milliseconds;
+	OldTime = NewTime;
+	while(DeltaTime >= 1.0) {
+		Ticks++;
+		DeltaTime--;
 	}
 	return(0);
 }
@@ -172,7 +167,6 @@ int main(int argc, char *argv[]) {
 
 	//Threading
 	AudioQueueBeingModified = 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);
diff --git a/src/marathon.c b/src/marathon.c
index a04519a..7d38242 100644
--- a/src/marathon.c
+++ b/src/marathon.c
@@ -85,7 +85,7 @@ void marathon_main() {
 	Ball.Direction = LEFT;
 	Ball.Speed = 3.0f;
 	Ball.Angle = 0.0f;
-    Ball.NextTick = SDL_AtomicGet(&Ticks)+1;
+    Ball.NextTick = Ticks+1;
 
     // Init Player
     struct Players Player;
@@ -110,6 +110,7 @@ void marathon_main() {
         MainCamera.rotation = 0;
     bool MarathonGoing = true;
     while(MarathonGoing == true && GameGoing == true) {
+	internal_clock();
         if (WindowShouldClose()) { //Quit Game if the window is closed.
             GameGoing = false;
         }
diff --git a/src/pong.h b/src/pong.h
index eef1150..b847a8a 100644
--- a/src/pong.h
+++ b/src/pong.h
@@ -8,6 +8,7 @@
 #include <SDL2/SDL_mutex.h>
 #include <SDL2/SDL_thread.h>
 #include <SDL2/SDL_atomic.h>
+#include <SDL2/SDL_timer.h>
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
@@ -50,10 +51,16 @@ extern struct Settings GlobalSettings;
 
 extern int Difficulty;
 extern bool GameGoing;
-extern SDL_atomic_t Ticks;
 extern char VersionString[256];
 extern SDL_atomic_t AudioInitializing;
 
+//Clock
+extern double NewTime;
+extern double OldTime;
+extern double Milliseconds;
+extern double DeltaTime;
+extern int Ticks;
+
 void enemy(struct Players *Enemy, struct Balls ball);
 void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore);
 bool play_audio(int SoundEffect);
@@ -61,5 +68,6 @@ int title_screen();
 void versus_main();
 void marathon_main();
 void set_screen_mode();
+int internal_clock();
 
 #endif
diff --git a/src/title.c b/src/title.c
index c5a15ce..7a58fb9 100644
--- a/src/title.c
+++ b/src/title.c
@@ -396,8 +396,8 @@ int title_screen() {
     DisableCursor();
 
     while(TitleScreenGoing == true && GameGoing == true) {
-        
-	printf("%lf, %d\n", GetTime(), SDL_AtomicGet(&Ticks));
+        internal_clock();
+	printf("%lf, %d\n", GetTime(), Ticks);
         if (WindowShouldClose()) { //Quit Game if the window is closed.
             GameGoing = false;
             TitleScreenGoing = false;
diff --git a/src/versus.c b/src/versus.c
index 34914bc..4e13f8a 100644
--- a/src/versus.c
+++ b/src/versus.c
@@ -42,11 +42,11 @@ void versus_main() {
         MainCamera.offset = (Vector2){0, 0};
         MainCamera.rotation = 0;
 	bool VersusGoing = true;
-	Ball.NextTick = SDL_AtomicGet(&Ticks);
-	Enemy.NextTick = SDL_AtomicGet(&Ticks);
+	Ball.NextTick = Ticks;
+	Enemy.NextTick = Ticks;
     while(VersusGoing == true && GameGoing == true) {
-		
-		if (WindowShouldClose()) { //Quit Game if the window is closed.
+	internal_clock();
+	if (WindowShouldClose()) { //Quit Game if the window is closed.
             GameGoing = false;
         }