Fumofumotris/source/io/input.c

49 lines
868 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-04-10 20:05:56 +00:00
struct Input {
struct Controller ctrl;
pthread_t thread;
pthread_mutex_t access_mutex;
};
2024-03-26 20:11:58 +00:00
void *block_input(void *args_ptr)
2024-03-25 05:34:59 +00:00
{
2024-04-10 20:05:56 +00:00
struct Input *in = args_ptr;
struct InputBuffer tmp_buf = { .len = 0 };
2024-04-01 22:39:21 +00:00
while (true) {
2024-04-15 19:29:51 +00:00
if (!PlatformBlockInput(&tmp_buf))
2024-04-10 20:05:56 +00:00
return false;
pthread_mutex_lock(&in->access_mutex);
2024-04-15 19:29:51 +00:00
{
2024-04-01 22:39:21 +00:00
}
2024-04-10 20:05:56 +00:00
pthread_mutex_unlock(&in->access_mutex);
2024-04-01 22:39:21 +00:00
}
2024-03-25 05:34:59 +00:00
return nullptr;
}
2024-04-10 20:05:56 +00:00
bool StartInput(struct Input *in)
2024-04-01 22:39:21 +00:00
{
2024-04-10 20:05:56 +00:00
return pthread_create(&in->thread, nullptr, block_input, in) == 0;
2024-04-01 22:39:21 +00:00
}
2024-04-10 20:05:56 +00:00
bool JoinInput(struct Input *in)
2024-03-25 05:34:59 +00:00
{
2024-04-10 20:05:56 +00:00
return pthread_join(in->thread, nullptr) == 0;
2024-03-25 05:34:59 +00:00
}