2024-03-25 05:34:59 +00:00
|
|
|
#pragma once
|
|
|
|
#include <iso646.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-04-30 21:41:31 +00:00
|
|
|
#include "fumocommon.h"
|
2024-04-18 05:04:44 +00:00
|
|
|
#include "input.h"
|
2024-04-16 22:14:53 +00:00
|
|
|
|
2024-04-30 21:41:31 +00:00
|
|
|
|
2024-04-18 21:20:44 +00:00
|
|
|
struct InputAxis {
|
2024-04-22 22:13:13 +00:00
|
|
|
Time last_pressed;
|
|
|
|
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
|
|
|
};
|
2024-04-18 21:20:44 +00:00
|
|
|
|
|
|
|
union InputID id;
|
2024-04-23 20:33:32 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
u8f is_down : 1;
|
|
|
|
u8f is_held : 1;
|
|
|
|
u8f is_up : 1;
|
|
|
|
};
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-19 06:38:45 +00:00
|
|
|
struct ctrl_bkt {
|
2024-04-18 21:20:44 +00:00
|
|
|
struct InputAxis *axis;
|
2024-04-19 06:38:45 +00:00
|
|
|
union InputID id;
|
2024-04-18 21:20:44 +00:00
|
|
|
};
|
2024-04-10 14:03:57 +00:00
|
|
|
|
2024-04-19 06:38:45 +00:00
|
|
|
struct ctrl_dict {
|
2024-04-18 21:20:44 +00:00
|
|
|
struct ctrl_bkt *bkts;
|
|
|
|
u16f capacity;
|
|
|
|
u16f filled;
|
2024-04-01 22:39:21 +00:00
|
|
|
};
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-19 06:38:45 +00:00
|
|
|
struct ctrl_axis_vec {
|
2024-04-18 21:20:44 +00:00
|
|
|
struct InputAxis *axes;
|
|
|
|
u16f size;
|
|
|
|
u16f len;
|
|
|
|
};
|
2024-04-10 14:03:57 +00:00
|
|
|
|
2024-04-18 21:20:44 +00:00
|
|
|
struct Controller {
|
2024-04-23 06:35:19 +00:00
|
|
|
struct {
|
|
|
|
struct InputAxis *axes[IO_BUF_SIZE];
|
|
|
|
u8f len;
|
|
|
|
} pending_buf;
|
2024-04-18 21:20:44 +00:00
|
|
|
|
2024-04-19 06:38:45 +00:00
|
|
|
struct ctrl_axis_vec axis_vec;
|
2024-04-18 21:20:44 +00:00
|
|
|
struct ctrl_dict codes;
|
|
|
|
struct ctrl_dict binds;
|
2024-03-25 05:34:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-19 20:23:11 +00:00
|
|
|
bool CreateCtrl(struct Controller *ctrl);
|
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
|
|
|
|
2024-04-18 21:20:44 +00:00
|
|
|
bool CtrlMap(struct Controller *ctrl, u16f code, u16f type, u16f bind);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-18 21:20:44 +00:00
|
|
|
struct InputAxis *CtrlGet(struct Controller *ctrl, u16f code, u16f type);
|
2024-03-25 05:34:59 +00:00
|
|
|
|
2024-04-30 21:41:31 +00:00
|
|
|
void CtrlPoll(struct Controller *ctrl, struct InputRecordBuf *recs);
|
2024-04-19 06:38:45 +00:00
|
|
|
|
|
|
|
enum ControlCode {
|
|
|
|
LEFT,
|
|
|
|
RIGHT,
|
|
|
|
SOFT_DROP,
|
|
|
|
HARD_DROP,
|
|
|
|
ROTATE_CCW,
|
|
|
|
ROTATE_CW,
|
|
|
|
ROTATE_180,
|
|
|
|
SWAP,
|
|
|
|
ESC,
|
|
|
|
VSCROLL,
|
|
|
|
HSCROLL,
|
|
|
|
MOUSE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ControlBind {
|
|
|
|
enum ControlCode code;
|
|
|
|
u16 bind;
|
|
|
|
u8 type;
|
|
|
|
};
|
|
|
|
|
2024-04-19 20:23:11 +00:00
|
|
|
#define CODE_COUNT 12
|
|
|
|
/*const struct ControlBind ctrl_binds[12] = {
|
2024-04-19 06:38:45 +00:00
|
|
|
{ LEFT, 0x25, BUTTON },
|
|
|
|
{ RIGHT, 0x27, BUTTON },
|
|
|
|
{ SOFT_DROP, 0x28, BUTTON },
|
|
|
|
{ HARD_DROP, 0x20, BUTTON },
|
|
|
|
{ ROTATE_CCW, 'Z', BUTTON },
|
|
|
|
{ ROTATE_CW, 'X', BUTTON },
|
|
|
|
{ ROTATE_180, 'A', BUTTON },
|
|
|
|
{ SWAP, 'C', BUTTON },
|
|
|
|
{ ESC, 0x1B, BUTTON },
|
|
|
|
{ VSCROLL, 0, AXIS },
|
|
|
|
{ HSCROLL, 1, AXIS },
|
|
|
|
{ MOUSE, 0, JOYSTICK }
|
2024-04-19 20:23:11 +00:00
|
|
|
};*/
|