mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Add Key State Tracker
This commit is contained in:
parent
68aadd4343
commit
736b4835df
5 changed files with 89 additions and 0 deletions
|
@ -96,6 +96,13 @@ static inline void chiaki_gkcrypt_free(ChiakiGKCrypt *gkcrypt)
|
|||
free(gkcrypt);
|
||||
}
|
||||
|
||||
typedef struct chiaki_key_state_t {
|
||||
uint64_t prev;
|
||||
} ChiakiKeyState;
|
||||
|
||||
CHIAKI_EXPORT void chiaki_key_state_init(ChiakiKeyState *state);
|
||||
CHIAKI_EXPORT uint64_t chiaki_key_state_request_pos(ChiakiKeyState *state, uint32_t low);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -542,3 +542,19 @@ static void *gkcrypt_thread_func(void *user)
|
|||
chiaki_mutex_unlock(&gkcrypt->key_buf_mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_key_state_init(ChiakiKeyState *state)
|
||||
{
|
||||
state->prev = 0;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT uint64_t chiaki_key_state_request_pos(ChiakiKeyState *state, uint32_t low)
|
||||
{
|
||||
uint32_t prev_low = (uint32_t)state->prev;
|
||||
uint32_t high = (uint32_t)(state->prev >> 32);
|
||||
if(chiaki_seq_num_32_gt(low, prev_low) && low < prev_low)
|
||||
high++;
|
||||
else if(chiaki_seq_num_32_lt(low, prev_low) && low > prev_low && high)
|
||||
high--;
|
||||
return state->prev = (((uint64_t)high) << 32) | ((uint64_t)low);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue