;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++) {
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue