Fumofumotris/source/io/ctrl.h

69 lines
1.2 KiB
C
Raw Normal View History

2024-03-25 05:34:59 +00:00
#pragma once
#include <iso646.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "fumotris.h"
#include "gametime.h"
2024-04-18 05:04:44 +00:00
#include "input.h"
2024-04-16 22:14:53 +00:00
struct InputAxis {
struct Time last_pressed;
struct Time last_released;
2024-04-11 19:57:22 +00:00
2024-03-25 05:34:59 +00:00
union {
2024-04-10 14:03:57 +00:00
struct Button but;
struct Axis axis;
struct Joystick js;
2024-04-11 19:57:22 +00:00
union InputData data;
2024-04-09 22:10:30 +00:00
};
union InputID id;
u8 is_down;
u8 is_held;
u8 is_up;
2024-03-25 05:34:59 +00:00
};
static struct ctrl_bkt {
union InputID id;
struct InputAxis *axis;
};
2024-04-10 14:03:57 +00:00
static struct ctrl_dict {
struct ctrl_bkt *bkts;
2024-04-10 14:03:57 +00:00
u16f capacity;
u16f filled;
2024-04-01 22:39:21 +00:00
};
2024-03-25 05:34:59 +00:00
static struct axis_vec {
struct InputAxis *axes;
2024-04-01 22:39:21 +00:00
u16f size;
u16f len;
};
2024-04-10 14:03:57 +00:00
struct Controller {
struct InputBuffer buf;
2024-04-10 14:03:57 +00:00
struct {
struct InputAxis *axes[IO_BUF_SIZE];
u16f len;
2024-04-10 14:03:57 +00:00
} pending_buf;
struct axis_vec axis_vec;
struct ctrl_dict codes;
struct ctrl_dict binds;
2024-03-25 05:34:59 +00:00
};
bool NewCtrl(struct Controller *ctrl, size_t init_axes);
2024-04-09 07:00:48 +00:00
2024-04-09 22:10:30 +00:00
void FreeCtrl(struct Controller *ctrl);
2024-03-25 05:34:59 +00:00
bool CtrlMap(struct Controller *ctrl, u16f code, u16f type, u16f bind);
2024-03-25 05:34:59 +00:00
struct InputAxis *CtrlGet(struct Controller *ctrl, u16f code, u16f type);
2024-03-25 05:34:59 +00:00
2024-04-09 22:10:30 +00:00
bool CtrlPoll(struct Controller *ctrl);