only run one update per frame drawn (#14023)
# Objective - Fixes #13965 ## Solution - Don't run multiple updates for a single frame
This commit is contained in:
		
							parent
							
								
									0ee9827ba2
								
							
						
					
					
						commit
						3a04d38832
					
				| @ -58,6 +58,8 @@ struct WinitAppRunnerState<T: Event> { | |||||||
|     user_event_received: bool, |     user_event_received: bool, | ||||||
|     /// Is `true` if the app has requested a redraw since the last update.
 |     /// Is `true` if the app has requested a redraw since the last update.
 | ||||||
|     redraw_requested: bool, |     redraw_requested: bool, | ||||||
|  |     /// Is `true` if the app has already updated since the last redraw.
 | ||||||
|  |     ran_update_since_last_redraw: bool, | ||||||
|     /// Is `true` if enough time has elapsed since `last_update` to run another update.
 |     /// Is `true` if enough time has elapsed since `last_update` to run another update.
 | ||||||
|     wait_elapsed: bool, |     wait_elapsed: bool, | ||||||
|     /// Number of "forced" updates to trigger on application start
 |     /// Number of "forced" updates to trigger on application start
 | ||||||
| @ -104,6 +106,7 @@ impl<T: Event> WinitAppRunnerState<T> { | |||||||
|             device_event_received: false, |             device_event_received: false, | ||||||
|             user_event_received: false, |             user_event_received: false, | ||||||
|             redraw_requested: false, |             redraw_requested: false, | ||||||
|  |             ran_update_since_last_redraw: false, | ||||||
|             wait_elapsed: false, |             wait_elapsed: false, | ||||||
|             // 3 seems to be enough, 5 is a safe margin
 |             // 3 seems to be enough, 5 is a safe margin
 | ||||||
|             startup_forced_updates: 5, |             startup_forced_updates: 5, | ||||||
| @ -369,6 +372,9 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> { | |||||||
|             WindowEvent::Destroyed => { |             WindowEvent::Destroyed => { | ||||||
|                 self.winit_events.send(WindowDestroyed { window }); |                 self.winit_events.send(WindowDestroyed { window }); | ||||||
|             } |             } | ||||||
|  |             WindowEvent::RedrawRequested => { | ||||||
|  |                 self.ran_update_since_last_redraw = false; | ||||||
|  |             } | ||||||
|             _ => {} |             _ => {} | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -499,7 +505,12 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> { | |||||||
| 
 | 
 | ||||||
|         if should_update { |         if should_update { | ||||||
|             // Not redrawing, but the timeout elapsed.
 |             // Not redrawing, but the timeout elapsed.
 | ||||||
|  |             if !self.ran_update_since_last_redraw { | ||||||
|                 self.run_app_update(); |                 self.run_app_update(); | ||||||
|  |                 self.ran_update_since_last_redraw = true; | ||||||
|  |             } else { | ||||||
|  |                 self.redraw_requested = true; | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             // Running the app may have changed the WinitSettings resource, so we have to re-extract it.
 |             // Running the app may have changed the WinitSettings resource, so we have to re-extract it.
 | ||||||
|             let (config, windows) = focused_windows_state.get(self.world()); |             let (config, windows) = focused_windows_state.get(self.world()); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 François Mockers
						François Mockers