a
This commit is contained in:
Julia 2024-04-10 09:03:57 -05:00
parent 879e8f2af2
commit a836e54ccb
2 changed files with 48 additions and 42 deletions

View file

@ -48,6 +48,8 @@ struct InputRecord {
}; };
struct InputAxis { struct InputAxis {
u8 type;
union { union {
struct Button but; struct Button but;
struct Axis axis; struct Axis axis;
@ -105,7 +107,7 @@ struct Controller {
struct { struct {
size_t indexes[IO_BUF_SIZE]; size_t indexes[IO_BUF_SIZE];
size_t len; size_t len;
} pending_state_buf; } pending_buf;
}; };
bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap) bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap)
@ -137,7 +139,7 @@ bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap)
.input_buf = { .input_buf = {
.len = 0, .len = 0,
}, },
.pending_state_buf = { .pending_buf = {
.len = 0, .len = 0,
}, },
}; };
@ -243,6 +245,7 @@ bool CtrlMap(struct Controller *ctrl, u16f code, u16f bind, u8f type)
return false; return false;
bind_bkt->axis = code_bkt->axis; bind_bkt->axis = code_bkt->axis;
code_bkt->axis->type = type;
return true; return true;
} }
@ -306,6 +309,10 @@ bool dispatch_update(struct InputAxis *axis, struct InputRecord *rec)
bool CtrlPoll(struct Controller *ctrl) bool CtrlPoll(struct Controller *ctrl)
{ {
for (size_t i = 0; i < ctrl->pending_buf.len; i++) {
}
for (size_t i = 0; i < ctrl->input_buf.len; i++) { for (size_t i = 0; i < ctrl->input_buf.len; i++) {
struct InputRecord *rec = &ctrl->input_buf.records[i]; struct InputRecord *rec = &ctrl->input_buf.records[i];
printf("i:%hu\n", rec->bind); printf("i:%hu\n", rec->bind);

View file

@ -19,48 +19,40 @@ enum InputType {
ESCAPE ESCAPE
}; };
struct Button {
u32 value;
bool is_down;
bool is_held;
bool is_up;
};
struct Axis {
i64 value;
};
struct Joystick {
i32 x;
i32 y;
};
struct InputRecord { struct InputRecord {
u16 bind; u16 bind;
u8 type; u8 type;
union { union {
struct { struct Button but;
bool is_down; struct Axis axis;
bool is_up; struct Joystick js;
} button;
struct {
u64 value;
} axis;
struct {
u32 x;
u32 y;
} joystick;
}; };
struct timespec timestamp; struct timespec timestamp;
}; };
struct RecordBuffer {
struct InputRecord records[IO_BUF_SIZE];
size_t count;
pthread_mutex_t mutex;
};
struct InputAxis { struct InputAxis {
union { union {
struct { struct Button but;
u32 value; struct Axis axis;
bool is_down; struct Joystick js;
bool is_held;
bool is_up;
} button;
struct {
u64 value;
} axis;
struct {
u32 x;
u32 y;
} joystick;
}; };
struct timespec last_pressed; struct timespec last_pressed;
@ -84,17 +76,17 @@ enum CtrlCode {
typedef u32 hashtype; typedef u32 hashtype;
struct ctrl_bkt {
hashtype hash;
u16 value;
u8 type;
struct InputAxis *axis;
};
struct ctrl_dict { struct ctrl_dict {
size_t capacity; size_t capacity;
size_t filled; size_t filled;
struct ctrl_bkt *bkts;
struct ctrl_bkt {
hashtype hash;
u16 value;
u8 type;
struct InputAxis *axis;
} *bkts;
}; };
struct Controller { struct Controller {
@ -102,8 +94,15 @@ struct Controller {
struct ctrl_dict binds; struct ctrl_dict binds;
struct InputAxis *axes; struct InputAxis *axes;
struct RecordBuffer buf; struct {
pthread_t thread; struct InputRecord records[IO_BUF_SIZE];
size_t len;
} input_buf;
struct {
size_t indexes[IO_BUF_SIZE];
size_t len;
} pending_buf;
}; };
bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap); bool NewCtrl(struct Controller *ctrl, size_t code_cap, size_t bind_cap);