;lk'
kl;
This commit is contained in:
parent
f65cc081b3
commit
9db68c9754
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -125,15 +125,20 @@ 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);
|
||||||
|
|
||||||
|
if (rec->key.is_down)
|
||||||
|
str->head.len += UCS2ToUTF8(str->buf, rec->key.ucs2_char);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MOUSE_MOVE: {
|
case MOUSE_MOVE: {
|
||||||
|
@ -161,7 +166,7 @@ bool dispatch_rec(struct InputRecord *out, struct win_rec *rec) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue