Add pausing
This commit is contained in:
11
input.c
11
input.c
@@ -19,6 +19,7 @@ static int input_fd;
|
||||
static input_callback_t restart;
|
||||
static input_callback_t quit;
|
||||
static input_callback_t shoot;
|
||||
static input_callback_t pause_;
|
||||
|
||||
static void key_press(int key)
|
||||
{
|
||||
@@ -46,6 +47,9 @@ static void key_press(int key)
|
||||
if (shoot != nullptr)
|
||||
shoot();
|
||||
break;
|
||||
case KEY_P:
|
||||
if (pause_ != nullptr)
|
||||
pause_();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +78,7 @@ static void key_repeat(int key)
|
||||
int input_init()
|
||||
{
|
||||
memset(&input, 0, sizeof(input));
|
||||
shoot = nullptr;
|
||||
shoot = restart = quit = pause_ = nullptr;
|
||||
|
||||
input_fd = open("/dev/input/event0", O_RDONLY);
|
||||
assert(input_fd != -1);
|
||||
@@ -105,6 +109,11 @@ void input_on_quit(input_callback_t cb)
|
||||
quit = cb;
|
||||
}
|
||||
|
||||
void input_on_pause(input_callback_t cb)
|
||||
{
|
||||
pause_ = cb;
|
||||
}
|
||||
|
||||
void input_handle()
|
||||
{
|
||||
struct input_event ev;
|
||||
|
||||
Reference in New Issue
Block a user