kl;
This commit is contained in:
Julia 2024-04-30 01:04:25 -05:00
parent f65cc081b3
commit 9db68c9754
6 changed files with 38 additions and 39 deletions

View file

@ -156,8 +156,6 @@ void CtrlPoll(struct Controller *ctrl)
for (size_t i = 0; i < ctrl->recs.head.len; i++) { for (size_t i = 0; i < ctrl->recs.head.len; i++) {
struct InputRecord *rec = &ctrl->recs.buf[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); struct InputAxis *axis = find_axis(&ctrl->binds, rec->id);
if (axis == nullptr) if (axis == nullptr)

View file

@ -20,9 +20,10 @@ void *input_worker(void *arg)
struct InputHandle *hand = arg; struct InputHandle *hand = arg;
struct InputRecordBuf tmp_recs = { .head.len = 0, .head.start = 0 }; struct InputRecordBuf tmp_recs = { .head.len = 0, .head.start = 0 };
struct InputStringBuf tmp_str = { .head.len = 0, .head.start = 0 };
while (!hand->is_terminating) { while (!hand->is_terminating) {
if (!PlatformReadInput(&tmp_recs)) { if (!PlatformReadInput(&tmp_recs, &tmp_str)) {
hand->err = true; hand->err = true;
return nullptr; return nullptr;
} }
@ -40,6 +41,7 @@ void *input_worker(void *arg)
} }
RingBufferTransfer(&IO_BUF_T, &hand->recs->head, &tmp_recs.head); 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) { if (pthread_mutex_unlock(&hand->mutex) != 0) {
hand->err = true; hand->err = true;

View file

@ -16,7 +16,7 @@ bool PlatformInit();
bool PlatformGetRefreshRate(u16f *out); bool PlatformGetRefreshRate(u16f *out);
bool PlatformReadInput(struct InputRecordBuf *in); bool PlatformReadInput(struct InputRecordBuf *in, struct InputStringBuf *str);
bool PlatformStopInput(); bool PlatformStopInput();

View file

@ -125,43 +125,48 @@ bool PlatformGetRefreshRate(u16f *out)
return true; return true;
} }
bool dispatch_rec(struct InputRecord *out, struct win_rec *rec) { bool dispatch_rec(
u8f type = rec->type struct InputRecord *out,
| (rec->is_mouse & rec->mouse.flags) struct InputStringBuf *str,
| (rec->is_key & rec->key.is_down); struct win_rec *rec
) {
u8f type = rec->type | (rec->is_mouse & rec->mouse.flags);
switch (type) { switch (type) {
case KEY_EVENT: { case KEY_EVENT: {
ReadButton(out, rec->key.vk_code, rec->key.is_down); ReadButton(out, rec->key.vk_code, rec->key.is_down);
return true; if (rec->key.is_down)
} str->head.len += UCS2ToUTF8(str->buf, rec->key.ucs2_char);
case MOUSE_MOVE: {
ReadJoystick(out, 0, rec->mouse.pos.x, rec->mouse.pos.y);
return true; return true;
} }
case MOUSE_VWHEEL: { case MOUSE_MOVE: {
ReadAxis(out, 0, rec->mouse.but); ReadJoystick(out, 0, rec->mouse.pos.x, rec->mouse.pos.y);
return true; return true;
} }
case MOUSE_HWHEEL: { case MOUSE_VWHEEL: {
ReadAxis(out, 1, rec->mouse.but); ReadAxis(out, 0, rec->mouse.but);
return true; return true;
} }
case WINDOW_BUFFER_SIZE_EVENT: { case MOUSE_HWHEEL: {
// TODO: Handle window resizing ReadAxis(out, 1, rec->mouse.but);
return false; return true;
} }
case WINDOW_BUFFER_SIZE_EVENT: {
// TODO: Handle window resizing
return false;
}
} }
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); DWORD read_max = RingBufferEmpty(&IO_BUF_T, &recs->head);
union record win_buf[read_max]; union record win_buf[read_max];
@ -175,7 +180,7 @@ bool PlatformReadInput(struct InputRecordBuf *recs)
for (size_t i = 0; i < filled; i++) { for (size_t i = 0; i < filled; i++) {
struct InputRecord *rec = RingBufferNext(&IO_BUF_T, &recs->head); 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; rec->time = now;
recs->head.len += 1; recs->head.len += 1;
} }

View file

@ -27,6 +27,8 @@ struct Game {
Time time; Time time;
}; };
struct Event hi;
int main() int main()
{ {
if (!PlatformInit()) if (!PlatformInit())
@ -51,14 +53,6 @@ int main()
CtrlPoll(&ctrl); 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)) if (!InputRelease(&input_hand))
ErrorExit("Release failed"); ErrorExit("Release failed");

BIN
test.exe

Binary file not shown.