Skip to content

Commit

Permalink
Emulator poll for SDL events
Browse files Browse the repository at this point in the history
The emulator was ridiculously slow without this change.

Imagine dragging your mouse 100px over the emulator, you would queue
up 100 `MouseMotion` events to be processed.

These SDL events were previously being waited on (ONE AT A TIME) in
the main thread then queued for gesture recognition. The main thread
would then immediately block for 20ms on a gesture which wasn't ready
yet. This would process each event, taking 20ms each, until a gesture
was finally fired.

Instead of waiting for single SDL events, we should send everything we
have straight off to gesture recognition. Then we can wait for the
gesture to be processed.

This shouldn't consume any more CPU since we still have a 20ms wait
for gestures. We've just changed the app to be eager to process
events and happy to wait for gestures.

Fixes #225
  • Loading branch information
puffnfresh committed Feb 9, 2023
1 parent de66fd2 commit 9a4a599
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/emulator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn main() -> Result<(), Error> {

'outer: loop {
let mut event_pump = sdl_context.event_pump().unwrap();
if let Some(sdl_evt) = event_pump.wait_event_timeout(20) {
while let Some(sdl_evt) = event_pump.poll_event() {
match sdl_evt {
SdlEvent::Quit { .. } |
SdlEvent::KeyDown { keycode: Some(Keycode::Escape), keymod: Mod::NOMOD, .. } => {
Expand Down

0 comments on commit 9a4a599

Please sign in to comment.