about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-06-13 19:30:22 -0400
committerCharadon <dev@iotib.net>2022-06-13 19:30:22 -0400
commit1b5697b1e16055392932562f5053e2157eb6fdbc (patch)
treebd739bda0f3906dfa43b6b1be6e6a70d69f51758 /src
parent520a610a8db7c07423fec086806b48ff2890c9c0 (diff)
downloadPong-C-1b5697b1e16055392932562f5053e2157eb6fdbc.tar.gz
Revert "Maybe this will work"
This reverts commit 129c32fc63270fd622de10eb6bb336ba4702a4e6.
Diffstat (limited to 'src')
-rw-r--r--src/main.c29
-rw-r--r--src/title.c1
2 files changed, 16 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index d15877e..aebc6aa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,4 @@
 #include "pong.h"
-#include <SDL2/SDL_atomic.h>
-#include <SDL2/SDL_thread.h>
-#include <SDL2/SDL_timer.h>
 #include <raylib.h>
 
 int Difficulty = 1;
@@ -52,19 +49,25 @@ void set_screen_mode() {
 }
 
 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;
+	const struct timespec Delay = {
+		0, 9999
+	};
+	struct timespec Remaining = {
+		0, 0
+	};
+	double OldTime = GetTime();
 	while(GameGoing == true) {
-		NewTime = SDL_GetTicks()/1000.0f;
-		DeltaTime += (NewTime-OldTime)/Milliseconds;
-		OldTime = NewTime;
-		while(DeltaTime >= 1.0) {
+		//nanosleep(&Delay, &Remaining);
+		double NewTime = GetTime();
+		while((NewTime-OldTime) < (1.0/60.0f)) {
+			NewTime = GetTime();
+		}	
+		if((NewTime-OldTime) >= (1.0/60.0f)) {
 			SDL_AtomicAdd(&Ticks, 1);
-			DeltaTime--;
+			OldTime = GetTime();
 		}
+
+		printf("%lf,%lf,%d\n", GetTime(),(NewTime-OldTime), SDL_AtomicGet(&Ticks));
 	}
 	return(0);
 }
diff --git a/src/title.c b/src/title.c
index c5a15ce..5c8987c 100644
--- a/src/title.c
+++ b/src/title.c
@@ -397,7 +397,6 @@ int title_screen() {
 
     while(TitleScreenGoing == true && GameGoing == true) {
         
-	printf("%lf, %d\n", GetTime(), SDL_AtomicGet(&Ticks));
         if (WindowShouldClose()) { //Quit Game if the window is closed.
             GameGoing = false;
             TitleScreenGoing = false;