| 60 | /////////////////////////////////////////// |
| 61 | |
| 62 | void input_keyboard_update() { |
| 63 | input_text_reset(); |
| 64 | |
| 65 | // Clear any just_in/active flags that were set on the last frame |
| 66 | array_t<keyboard_event_t> &evts = local.key_data.events; |
| 67 | for (int32_t i = 0; i < evts.count; i++) { |
| 68 | if (evts[i].down) |
| 69 | local.key_data.keys[evts[i].key] &= ~button_state_just_active; |
| 70 | else |
| 71 | local.key_data.keys[evts[i].key] &= ~button_state_just_inactive; |
| 72 | } |
| 73 | |
| 74 | // Thread safe copy new key events into the main thread |
| 75 | local.key_data.events .clear(); |
| 76 | local.key_data.characters.clear(); |
| 77 | ft_mutex_lock(local.key_pending_mtx); |
| 78 | local.key_data.events .add_range(local.key_pending .data, local.key_pending .count); |
| 79 | local.key_data.characters.add_range(local.chars_pending.data, local.chars_pending.count); |
| 80 | local.key_pending .clear(); |
| 81 | local.chars_pending.clear(); |
| 82 | ft_mutex_unlock(local.key_pending_mtx); |
| 83 | |
| 84 | // Set key activity flags based on the new event queue |
| 85 | evts = local.key_data.events; |
| 86 | for (int32_t i = 0; i < evts.count; i++) { |
| 87 | keyboard_event_t &evt = evts.get(i); |
| 88 | if (evt.down) { |
| 89 | local.key_data.keys[evt.key] |= button_state_just_active | button_state_active; |
| 90 | } else { |
| 91 | local.key_data.keys[evt.key] &= ~button_state_active; |
| 92 | local.key_data.keys[evt.key] |= button_state_just_inactive; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /////////////////////////////////////////// |
| 98 |
no test coverage detected