From a836e54ccbb853da8ec8a84d617195f8fd406a95 Mon Sep 17 00:00:00 2001 From: Julia <145168563+julia-aph@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:03:57 -0500 Subject: [PATCH] aa a --- source/io/ctrl.c | 11 +++++-- source/io/ctrl.h | 79 ++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/source/io/ctrl.c b/source/io/ctrl.c index 604d0b4..b5bf6b9 100644 --- a/source/io/ctrl.c +++ b/source/io/ctrl.c @@ -48,6 +48,8 @@ struct InputRecord { }; struct InputAxis { + u8 type; + union { struct Button but; struct Axis axis; @@ -105,7 +107,7 @@ struct Controller { struct { size_t indexes[IO_BUF_SIZE]; size_t len; - } pending_state_buf; + } pending_buf; }; 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 = { .len = 0, }, - .pending_state_buf = { + .pending_buf = { .len = 0, }, }; @@ -243,6 +245,7 @@ bool CtrlMap(struct Controller *ctrl, u16f code, u16f bind, u8f type) return false; bind_bkt->axis = code_bkt->axis; + code_bkt->axis->type = type; return true; } @@ -306,6 +309,10 @@ bool dispatch_update(struct InputAxis *axis, struct InputRecord *rec) 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++) { struct InputRecord *rec = &ctrl->input_buf.records[i]; printf("i:%hu\n", rec->bind); diff --git a/source/io/ctrl.h b/source/io/ctrl.h index 01cc646..b4380af 100644 --- a/source/io/ctrl.h +++ b/source/io/ctrl.h @@ -19,48 +19,40 @@ enum InputType { 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 { u16 bind; u8 type; union { - struct { - bool is_down; - bool is_up; - } button; - struct { - u64 value; - } axis; - struct { - u32 x; - u32 y; - } joystick; + struct Button but; + struct Axis axis; + struct Joystick js; }; struct timespec timestamp; }; -struct RecordBuffer { - struct InputRecord records[IO_BUF_SIZE]; - size_t count; - pthread_mutex_t mutex; -}; - struct InputAxis { union { - struct { - u32 value; - bool is_down; - bool is_held; - bool is_up; - } button; - struct { - u64 value; - } axis; - struct { - u32 x; - u32 y; - } joystick; + struct Button but; + struct Axis axis; + struct Joystick js; }; struct timespec last_pressed; @@ -84,17 +76,17 @@ enum CtrlCode { typedef u32 hashtype; -struct ctrl_bkt { - hashtype hash; - u16 value; - u8 type; - struct InputAxis *axis; -}; - struct ctrl_dict { size_t capacity; size_t filled; - struct ctrl_bkt *bkts; + + struct ctrl_bkt { + hashtype hash; + u16 value; + u8 type; + + struct InputAxis *axis; + } *bkts; }; struct Controller { @@ -102,8 +94,15 @@ struct Controller { struct ctrl_dict binds; struct InputAxis *axes; - struct RecordBuffer buf; - pthread_t thread; + struct { + 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);