From 1b5697b1e16055392932562f5053e2157eb6fdbc Mon Sep 17 00:00:00 2001 From: Charadon Date: Mon, 13 Jun 2022 19:30:22 -0400 Subject: Revert "Maybe this will work" This reverts commit 129c32fc63270fd622de10eb6bb336ba4702a4e6. --- src/main.c | 29 ++++++++++++++++------------- src/title.c | 1 - 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'src') 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 -#include -#include #include 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; -- cgit 1.4.1-2-gfad0 tion value='author'>author
blob: aca1b557029c63347cef4d51a6a5a63ce9768f2c (plain) (blame)
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