main
sandyx86 1 year ago
parent dd57a901fb
commit afa86a41d1

@ -3,26 +3,18 @@
#include <stdbool.h>
#include "timer.h"
static inline struct timespec subts(volatile struct timespec t1, volatile struct timespec t2) {
return (struct timespec) {
.tv_sec = t2.tv_sec - t1.tv_sec,
.tv_nsec = t2.tv_nsec - t1.tv_nsec,
};
}
int main(void) {
Timer *t = [[Timer alloc] init];
char buffer[100];
InitWindow(400, 400, "raytime");
InitWindow(400, 400, "ghost");
SetTargetFPS(60);
Color theColor = BLACK;
[t start];
while (!WindowShouldClose()) {
sprintf(buffer, "%jd", (intmax_t)[t time].tv_sec);
if (IsKeyPressed(KEY_SPACE)) {
if (t->paused) {
@ -33,9 +25,9 @@ int main(void) {
[t pause];
}
}
[t tick];
[t tick];
BeginDrawing();
ClearBackground(WHITE);
DrawText([t timeString], 400/2 - 50, 400/2 - 50, 100, theColor);

@ -1,15 +1,15 @@
CC=g++
CC=gcc
INCLUDE= -I /home/sandyx/code/objc/wow/include
main: main.o timer.o
g++ main.o timer.o -o main -L /home/sandyx/code/objc/wow/lib/linux64 -lraylib -lobjc -lyeslib
$(CC) main.o timer.o -o main -L /home/sandyx/code/objc/wow/lib/linux64 -lraylib -lobjc -lyeslib -lm
main.o:
g++ $(INCLUDE) main.mm -c
$(CC) $(INCLUDE) main.m -c
timer.o:
g++ $(INCLUDE) timer.mm -c
$(CC) $(INCLUDE) timer.m -c
clean:
rm main *.o

@ -4,6 +4,7 @@
#include <time.h>
#include <stdint.h>
#include <yeslib.h>
#include <stdbool.h>
#include <stdio.h>
#define NSEC_PER_SEC 1000000000

@ -7,13 +7,6 @@ struct timespec subts(struct timespec t1, struct timespec t2) {
};
}
struct timespec negts(struct timespec t) {
return (struct timespec) {
.tv_sec = -t.tv_sec,
.tv_nsec = -t.tv_nsec,
};
}
struct timespec addts(struct timespec t1, struct timespec t2) {
return (struct timespec) {
.tv_sec = t1.tv_sec + t2.tv_sec,
@ -21,10 +14,6 @@ struct timespec addts(struct timespec t1, struct timespec t2) {
};
}
void print_ts(struct timespec t) {
printf("time: %ld.%ld\n", (unsigned long)t.tv_sec, (unsigned long)t.tv_nsec);
}
double timespec_to_double(struct timespec ts) {
return ((double)(ts.tv_sec) + ((double)(ts.tv_nsec) / NSEC_PER_SEC));
}
@ -34,11 +23,11 @@ double timespec_to_double(struct timespec ts) {
self = [super init];
running = false;
paused = false;
pause_start = {0};
pause_current = {0};
start = {0};
current = {0};
diff = {0};
pause_start = (struct timespec){0};
pause_current = (struct timespec){0};
start = (struct timespec){0};
current = (struct timespec){0};
diff = (struct timespec){0};
return self;
}
@ -73,7 +62,6 @@ double timespec_to_double(struct timespec ts) {
clock_gettime(CLOCK_REALTIME, &current);
} else {
clock_gettime(CLOCK_REALTIME, &pause_current);
//pause_current = subts(pause_current, pause_start);
}
}

Loading…
Cancel
Save