From b611b54575f649a7037a37c5bb0c45b30aef5228 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 02:51:46 +0300 Subject: [PATCH] Switch to threads.h --- include/input.h | 2 +- src/input.c | 4 ++-- src/main.c | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/input.h b/include/input.h index 70bd425..cdbb432 100644 --- a/include/input.h +++ b/include/input.h @@ -9,6 +9,6 @@ typedef struct input_args_t bool *alive; } InputArgs; -void *input(void *vargp); +int input(void *vargp); #endif /* __INPUT_H__ */ diff --git a/src/input.c b/src/input.c index 05b411a..e6bb53b 100644 --- a/src/input.c +++ b/src/input.c @@ -22,7 +22,7 @@ char getch(void) return buf; } -void *input(void *vargp) +int input(void *vargp) { char *out = ((InputArgs *)vargp)->out; bool *alive = ((InputArgs *)vargp)->alive; @@ -31,5 +31,5 @@ void *input(void *vargp) { *out = getch(); } - return NULL; + return 0; } diff --git a/src/main.c b/src/main.c index e8db39b..997da19 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,7 @@ #include #include #include -#include -#include +#include #include #include "input.h" @@ -33,7 +32,7 @@ int main(int argc, char **argv) Player *player = playerCreate(DOWN, 0, 0, 0); Screen *screen = screenCreate(10, 10, ' '); PlayerNode *node; - pthread_t input_thread; + thrd_t input_thread; int head_x, head_y; Food food = generateFood(player); @@ -41,7 +40,7 @@ int main(int argc, char **argv) char *key = malloc(sizeof(char)); *key = 0; InputArgs input_args = (InputArgs){ key, running }; - pthread_create(&input_thread, NULL, input, &input_args); + thrd_create(&input_thread, input, &input_args); while (*running) { switch (*key) @@ -56,7 +55,6 @@ int main(int argc, char **argv) player->direction = DOWN; break; case 'a': player->direction = LEFT; break; - sleep(1); } if (playerDoTick(player, food)) @@ -79,7 +77,7 @@ int main(int argc, char **argv) *screenGetPoint(screen, food.x, food.y) = '@'; screenShow(screen); - sleep(1); + thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); } return 0; }