@@ -13,7 +13,7 @@ use ruffle_render::backend::ViewportDimensions;
13
13
use std:: cell:: RefCell ;
14
14
use std:: rc:: Rc ;
15
15
use std:: sync:: Arc ;
16
- use std:: time:: { Duration , Instant } ;
16
+ use std:: time:: Instant ;
17
17
use url:: Url ;
18
18
use winit:: application:: ApplicationHandler ;
19
19
use winit:: dpi:: { LogicalSize , PhysicalPosition , PhysicalSize , Size } ;
@@ -563,18 +563,23 @@ impl ApplicationHandler<RuffleEvent> for App {
563
563
self . next_frame_time = None ;
564
564
}
565
565
self . check_redraw ( ) ;
566
- // After polling events, sleep the event loop until the next event or the next frame.
567
- event_loop. set_control_flow ( if matches ! ( self . loaded, LoadingState :: Loaded ) {
568
- if let Some ( next_frame_time) = self . next_frame_time {
569
- ControlFlow :: WaitUntil ( next_frame_time)
570
- } else {
571
- // prevent 100% cpu use
572
- // TODO: use set_request_repaint_callback to correctly get egui repaint requests.
573
- ControlFlow :: WaitUntil ( Instant :: now ( ) + Duration :: from_millis ( 10 ) )
574
- }
575
- } else {
576
- ControlFlow :: Wait
577
- } ) ;
566
+ }
567
+ }
568
+
569
+ // The event loop is finished; let's find out how long we need to wait for
570
+ // (but don't change something that's already requesting a sooner update, or we'll delay it)
571
+ if let Some ( next_frame_time) = self . next_frame_time {
572
+ match event_loop. control_flow ( ) {
573
+ // A "Wait" has no time limit, set ours
574
+ ControlFlow :: Wait => {
575
+ event_loop. set_control_flow ( ControlFlow :: WaitUntil ( next_frame_time) )
576
+ }
577
+ // If the existing "WaitUntil" is later than ours, update it
578
+ ControlFlow :: WaitUntil ( next) if next > next_frame_time => {
579
+ event_loop. set_control_flow ( ControlFlow :: WaitUntil ( next_frame_time) ) ;
580
+ }
581
+ // It's sooner than ours, don't delay it
582
+ _ => { }
578
583
}
579
584
}
580
585
}
0 commit comments