Fumofumotris/source/io/input.c

43 lines
733 B
C
Raw Normal View History

2024-03-25 05:34:59 +00:00
#include <iso646.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "ctrl.h"
#include "fumotris.h"
#ifdef _WIN32
#include "win.h"
#endif
2024-03-26 20:11:58 +00:00
void *block_input(void *args_ptr)
2024-03-25 05:34:59 +00:00
{
2024-04-09 07:00:48 +00:00
struct RecordBuffer *rec_buf = args_ptr;
2024-04-01 22:39:21 +00:00
while (true) {
bool success;
2024-03-25 05:34:59 +00:00
2024-04-01 22:39:21 +00:00
#ifdef _WIN32
2024-04-09 07:00:48 +00:00
success = WindowsBlockInput(rec_buf);
2024-04-01 22:39:21 +00:00
#endif
2024-04-02 00:55:30 +00:00
2024-04-01 22:39:21 +00:00
if (!success) {
printf("winfail");
exit(1);
}
}
2024-03-25 05:34:59 +00:00
return nullptr;
}
2024-04-09 22:10:30 +00:00
void StartInput(struct Controller *ctrl)
2024-04-01 22:39:21 +00:00
{
2024-04-09 07:00:48 +00:00
pthread_create(&ctrl->thread, nullptr, block_input, &ctrl->buf);
2024-04-01 22:39:21 +00:00
}
2024-04-09 22:10:30 +00:00
void JoinInput(struct Controller *ctrl)
2024-03-25 05:34:59 +00:00
{
2024-04-01 22:39:21 +00:00
pthread_join(ctrl->thread, nullptr);
2024-03-25 05:34:59 +00:00
}