pasky / speedread

A simple terminal-based open source Spritz-alike (per-word RSVP aligned on optimal reading points)
MIT License
1.06k stars 93 forks source link

More accurate timing and responsive UI #6

Closed and-reas-se closed 8 years ago

and-reas-se commented 10 years ago

I noticed that the UI wasn't very responsive, if you pressed a button it didn't respond until the next word was displayed, so how fast the UI was responding was depending on what WPM you had set. Try going down to <50 WPM you'll see the problem clearly.

This patch changes it so it'll sleep for shorter intervals and keep checking for key presses at regular intervals even if the word hasn't changed. With this method it will check for key presses 20 times per second, independently of how often the word is updated. That way the UI will appear to respond instantly to key presses, no matter what WPM you have set. It keeps track of when the word is to be changed and when to check for key presses independently of each other, so it'll update the word at the right time even if you have a very high WPM that changes the word more often than 20 times per second.

The new method also keeps track of what time the last word was displayed and sets the time the next word is to be displayed to that time + delay, rather than just sleeping for the delay. That way we don't get longer than intended delays because of overhead, and since overhead isn't a factor, we could accurately predict how long it would take to display a set of words if we wanted to.

I also added in the change to when the resume message should be displayed that you requested.

pasky commented 8 years ago

Thanks! And sorry for totally missing this pull request up to now.