the hub
This commit is contained in:
Julia 2024-04-22 00:19:54 -05:00
parent a94a0949a7
commit 599c41ef1b
5 changed files with 20 additions and 6 deletions

View file

@ -29,26 +29,30 @@ void InputBufferAdd(struct InputBuffer *buf, struct InputRecord *rec)
*buf_get(buf, buf->len++) = *rec; *buf_get(buf, buf->len++) = *rec;
} }
void *input_thread_loop(struct InputThreadHandle *hand) void *input_thread_loop(void *arg)
{ {
struct InputThreadHandle *hand = arg;
struct InputBuffer tmp_buf = { .len = 0, .start = 0 }; struct InputBuffer tmp_buf = { .len = 0, .start = 0 };
while (!hand->is_terminating) { while (!hand->is_terminating) {
printf("\tinput cycle");
if (!PlatformReadInput(&tmp_buf)) { if (!PlatformReadInput(&tmp_buf)) {
hand->err = true; hand->err = true;
return; return nullptr;
} }
hand->err = pthread_mutex_lock(&hand->mutex); hand->err = pthread_mutex_lock(&hand->mutex);
if (hand->err) if (hand->err)
return; return nullptr;
InputBufferTransfer(&tmp_buf, hand->buf); InputBufferTransfer(&tmp_buf, hand->buf);
hand->err = pthread_mutex_unlock(&hand->mutex); hand->err = pthread_mutex_unlock(&hand->mutex);
if (hand->err) if (hand->err)
return; return nullptr;
} }
return nullptr;
} }
bool BeginInputThread(struct InputThreadHandle *hand, struct InputBuffer *buf) bool BeginInputThread(struct InputThreadHandle *hand, struct InputBuffer *buf)

View file

@ -88,7 +88,7 @@ bool copy_mouse_event(struct InputRecord *rec, MOUSE_EVENT_RECORD *win_mouse)
return true; return true;
} }
if (win_mouse->dwEventFlags & (MOUSE_WHEELED | MOUSE_HWHEELED) != 0) { if ((win_mouse->dwEventFlags & (MOUSE_WHEELED | MOUSE_HWHEELED)) != 0) {
rec->type = AXIS; rec->type = AXIS;
rec->bind = win_mouse->dwEventFlags == MOUSE_WHEELED; rec->bind = win_mouse->dwEventFlags == MOUSE_WHEELED;
rec->axis.value = win_mouse->dwButtonState; rec->axis.value = win_mouse->dwButtonState;

View file

@ -33,7 +33,17 @@ int main()
if (!BeginInputThread(&input, &ctrl.buf)) if (!BeginInputThread(&input, &ctrl.buf))
ErrorExit("Input handle failed to initialize"); ErrorExit("Input handle failed to initialize");
printf("woah"); CtrlMap(&ctrl, 0, BUTTON, 'A');
while (true) {
bool poll = CtrlPoll(&ctrl);
printf("poll: %u\n", poll);
struct InputAxis *a = CtrlGet(&ctrl, 0, BUTTON);
printf("get: %llu\n", a);
printf("val: %u\n", a->but.value);
}
return 0; return 0;
} }

BIN
test.exe

Binary file not shown.