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-02 00:55:30 +00:00
|
|
|
struct RecordBuffer *buf;
|
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-02 00:55:30 +00:00
|
|
|
struct RecordBuffer *buf = args->buf;
|
|
|
|
free(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
|
|
|
|
success = WindowsBlockInput(buf);
|
|
|
|
#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-02 00:55:30 +00:00
|
|
|
void StartInput(Ctrl *ctrl, struct RecordBuffer *buf)
|
2024-04-01 22:39:21 +00:00
|
|
|
{
|
2024-04-02 00:55:30 +00:00
|
|
|
struct input_args *args = malloc(sizeof(struct input_args));
|
|
|
|
args->ctrl = ctrl;
|
|
|
|
args->buf = buf;
|
|
|
|
|
|
|
|
pthread_create(&ctrl->thread, nullptr, block_input, args);
|
2024-04-01 22:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|