forked from nakidai/csnake
Switch to threads.h
parent
758dbf9cc2
commit
b611b54575
|
@ -9,6 +9,6 @@ typedef struct input_args_t
|
|||
bool *alive;
|
||||
} InputArgs;
|
||||
|
||||
void *input(void *vargp);
|
||||
int input(void *vargp);
|
||||
|
||||
#endif /* __INPUT_H__ */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -1,8 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <threads.h>
|
||||
#include <time.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue