diff --git a/source/io/ctrl.c b/source/io/ctrl.c index affe3ed..e99ce18 100644 --- a/source/io/ctrl.c +++ b/source/io/ctrl.c @@ -156,8 +156,6 @@ void CtrlPoll(struct Controller *ctrl) for (size_t i = 0; i < ctrl->recs.head.len; i++) { struct InputRecord *rec = &ctrl->recs.buf[i]; - if (rec->id.type == BUTTON and rec->is_down) - ctrl->str struct InputAxis *axis = find_axis(&ctrl->binds, rec->id); if (axis == nullptr) diff --git a/source/io/input.c b/source/io/input.c index 9440bff..24906c8 100644 --- a/source/io/input.c +++ b/source/io/input.c @@ -20,9 +20,10 @@ void *input_worker(void *arg) struct InputHandle *hand = arg; struct InputRecordBuf tmp_recs = { .head.len = 0, .head.start = 0 }; + struct InputStringBuf tmp_str = { .head.len = 0, .head.start = 0 }; while (!hand->is_terminating) { - if (!PlatformReadInput(&tmp_recs)) { + if (!PlatformReadInput(&tmp_recs, &tmp_str)) { hand->err = true; return nullptr; } @@ -40,6 +41,7 @@ void *input_worker(void *arg) } RingBufferTransfer(&IO_BUF_T, &hand->recs->head, &tmp_recs.head); + RingBufferTransfer(&STR_BUF_T, &hand->str->head, &tmp_str.head); if (pthread_mutex_unlock(&hand->mutex) != 0) { hand->err = true; diff --git a/source/io/platforms/platform.h b/source/io/platforms/platform.h index f4dd9ca..0938bf1 100644 --- a/source/io/platforms/platform.h +++ b/source/io/platforms/platform.h @@ -16,7 +16,7 @@ bool PlatformInit(); bool PlatformGetRefreshRate(u16f *out); -bool PlatformReadInput(struct InputRecordBuf *in); +bool PlatformReadInput(struct InputRecordBuf *in, struct InputStringBuf *str); bool PlatformStopInput(); diff --git a/source/io/platforms/win.c b/source/io/platforms/win.c index f6b91cf..66efe67 100644 --- a/source/io/platforms/win.c +++ b/source/io/platforms/win.c @@ -125,43 +125,48 @@ bool PlatformGetRefreshRate(u16f *out) return true; } -bool dispatch_rec(struct InputRecord *out, struct win_rec *rec) { - u8f type = rec->type - | (rec->is_mouse & rec->mouse.flags) - | (rec->is_key & rec->key.is_down); +bool dispatch_rec( + struct InputRecord *out, + struct InputStringBuf *str, + struct win_rec *rec +) { + u8f type = rec->type | (rec->is_mouse & rec->mouse.flags); switch (type) { - case KEY_EVENT: { - ReadButton(out, rec->key.vk_code, rec->key.is_down); + case KEY_EVENT: { + ReadButton(out, rec->key.vk_code, rec->key.is_down); - return true; - } - case MOUSE_MOVE: { - ReadJoystick(out, 0, rec->mouse.pos.x, rec->mouse.pos.y); + if (rec->key.is_down) + str->head.len += UCS2ToUTF8(str->buf, rec->key.ucs2_char); - return true; - } - case MOUSE_VWHEEL: { - ReadAxis(out, 0, rec->mouse.but); + return true; + } + case MOUSE_MOVE: { + ReadJoystick(out, 0, rec->mouse.pos.x, rec->mouse.pos.y); - return true; - } - case MOUSE_HWHEEL: { - ReadAxis(out, 1, rec->mouse.but); + return true; + } + case MOUSE_VWHEEL: { + ReadAxis(out, 0, rec->mouse.but); - return true; - } - case WINDOW_BUFFER_SIZE_EVENT: { - // TODO: Handle window resizing - - return false; - } + return true; + } + case MOUSE_HWHEEL: { + ReadAxis(out, 1, rec->mouse.but); + + return true; + } + case WINDOW_BUFFER_SIZE_EVENT: { + // TODO: Handle window resizing + + return false; + } } return false; } -bool PlatformReadInput(struct InputRecordBuf *recs) +bool PlatformReadInput(struct InputRecordBuf *recs, struct InputStringBuf *str) { DWORD read_max = RingBufferEmpty(&IO_BUF_T, &recs->head); union record win_buf[read_max]; @@ -175,7 +180,7 @@ bool PlatformReadInput(struct InputRecordBuf *recs) for (size_t i = 0; i < filled; i++) { struct InputRecord *rec = RingBufferNext(&IO_BUF_T, &recs->head); - if (dispatch_rec(rec, &win_buf->native + i)) { + if (dispatch_rec(rec, str, &win_buf->native + i)) { rec->time = now; recs->head.len += 1; } diff --git a/source/main.c b/source/main.c index 3d1091f..56c9fb5 100644 --- a/source/main.c +++ b/source/main.c @@ -27,6 +27,8 @@ struct Game { Time time; }; +struct Event hi; + int main() { if (!PlatformInit()) @@ -51,14 +53,6 @@ int main() CtrlPoll(&ctrl); - struct InputAxis *a = CtrlGet(&ctrl, 0, BUTTON); - printf("%u", a); - printf("\t%u\n", a->is_down); - - char silly[100] = { 0 }; - CtrlInputString(&ctrl, 100, silly); - printf("%s\n", silly); - if (!InputRelease(&input_hand)) ErrorExit("Release failed"); diff --git a/test.exe b/test.exe index cc8b6c2..c3eb1ce 100644 Binary files a/test.exe and b/test.exe differ