Add windows support
parent
793db5f00a
commit
0b74ef8618
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
typedef struct input_args_t
|
typedef struct input_args_t
|
||||||
{
|
{
|
||||||
char *out;
|
int *out;
|
||||||
bool *alive;
|
bool *alive;
|
||||||
} InputArgs;
|
} InputArgs;
|
||||||
|
|
||||||
|
|
14
src/input.c
14
src/input.c
|
@ -1,10 +1,17 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <conio.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
char getch(void)
|
#ifdef WIN32
|
||||||
|
#define getch _getch
|
||||||
|
#else
|
||||||
|
int getch(void)
|
||||||
{
|
{
|
||||||
char buf = 0;
|
char buf = 0;
|
||||||
struct termios old = { 0 };
|
struct termios old = { 0 };
|
||||||
|
@ -19,12 +26,13 @@ char getch(void)
|
||||||
old.c_lflag |= ICANON; // local modes = Canonical mode
|
old.c_lflag |= ICANON; // local modes = Canonical mode
|
||||||
old.c_lflag |= ECHO; // local modes = Enable echo.
|
old.c_lflag |= ECHO; // local modes = Enable echo.
|
||||||
if (tcsetattr(0, TCSADRAIN, &old) < 0) perror ("tcsetattr ~ICANON");
|
if (tcsetattr(0, TCSADRAIN, &old) < 0) perror ("tcsetattr ~ICANON");
|
||||||
return buf;
|
return (int)buf;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int input(void *vargp)
|
int input(void *vargp)
|
||||||
{
|
{
|
||||||
char *out = ((InputArgs *)vargp)->out;
|
int *out = ((InputArgs *)vargp)->out;
|
||||||
bool *alive = ((InputArgs *)vargp)->alive;
|
bool *alive = ((InputArgs *)vargp)->alive;
|
||||||
|
|
||||||
while (*alive)
|
while (*alive)
|
||||||
|
|
|
@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
||||||
Food food = generateFood(player);
|
Food food = generateFood(player);
|
||||||
|
|
||||||
bool *running = malloc(sizeof(bool)); *running = true;
|
bool *running = malloc(sizeof(bool)); *running = true;
|
||||||
char *key = malloc(sizeof(char)); *key = 0;
|
int *key = malloc(sizeof(char)); *key = 0;
|
||||||
bool stopped = false;
|
bool stopped = false;
|
||||||
InputArgs input_args = (InputArgs){ key, running };
|
InputArgs input_args = (InputArgs){ key, running };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue