WerWolv / libtesla

The support library for Tesla overlays
GNU General Public License v2.0
218 stars 49 forks source link

Improve input detection at low framerate #13

Closed diwo closed 4 years ago

diwo commented 4 years ago

This PR fixes 2 issues:

  1. keysDown is sometimes missed on main thread when framerate is low
  2. When triggering combo, the keys used are also being handled by overlay

The first issue happens when the hid thread loops twice, setting keysDown and then unsetting it in the second loop before the main thread has a chance to read the keys state. The hid thread now aggregates key downs into keysDownPending shared data, which is only cleared by the main thread when it has a chance to read it. This solution also works for very low fps situation where the user presses and releases a key within the duration of a single frame.

The second issue happens because handleInput in the main thread is called even while overlay is fading in/out. I moved the overlay hide/show blocks in the hid thread into the mutex block because there's a race condition in which the main thread could read the combo before the hid thread sets the fading flags. Didn't notice any fps drop from this change.