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++) {
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)

View file

@ -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;

View file

@ -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();

View file

@ -125,15 +125,20 @@ 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);
if (rec->key.is_down)
str->head.len += UCS2ToUTF8(str->buf, rec->key.ucs2_char);
return true;
}
case MOUSE_MOVE: {
@ -161,7 +166,7 @@ bool dispatch_rec(struct InputRecord *out, struct win_rec *rec) {
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;
}

View file

@ -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");

BIN
test.exe

Binary file not shown.