Fumofumotris/source/io/input.c

63 lines
1.2 KiB
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
struct input_args {
Ctrl *ctrl;
2024-04-01 22:39:21 +00:00
struct InputBuffer *buf;
pthread_mutex_t mutex;
2024-03-26 20:11:58 +00:00
};
2024-03-25 05:34:59 +00:00
2024-03-26 20:11:58 +00:00
void *block_input(void *args_ptr)
2024-03-25 05:34:59 +00:00
{
2024-03-26 20:11:58 +00:00
struct input_args *args = args_ptr;
Ctrl *ctrl = args->ctrl;
2024-04-01 22:39:21 +00:00
struct InputBuffer *buf = args->buf;
printf("RECIEVED BUF: %u, %u\n", args->ctrl, args->buf);
while (true) {
printf("\tIN LOOP\n");
bool success;
2024-03-25 05:34:59 +00:00
2024-04-01 22:39:21 +00:00
#ifdef _WIN32
success = WindowsBlockInput(buf);
#endif
2024-03-26 20:11:58 +00:00
2024-04-01 22:39:21 +00:00
printf("%llu\n", buf->records[0].timestamp.tv_sec);
2024-03-25 05:34:59 +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-01 22:39:21 +00:00
void StartInput(Ctrl *ctrl, struct InputBuffer *buf)
{
printf("START INPUT:%u\n", buf);
struct input_args args = {
.ctrl = ctrl,
.buf = buf,
.mutex = PTHREAD_MUTEX_INITIALIZER
};
pthread_mutex_lock(&args.mutex);
pthread_create(&ctrl->thread, nullptr, block_input, &args);
pthread_mutex_destroy();
}
void JoinInput(Ctrl *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
}