diff --git a/crates/snowbound/src/main.rs b/crates/snowbound/src/main.rs index c6e08f93776fadc3161769708fb56a262f2ed56d..d6bbeb052a5edabe50c825b301a233647b221124 100644 --- a/crates/snowbound/src/main.rs +++ b/crates/snowbound/src/main.rs @@ -417,7 +417,8 @@ enum Replay { /// Waits for nothing to be on its way, then writes the window's accessibility tree as /// text where given, and answers. Settle(Option, std::sync::mpsc::Sender<()>), - /// A frame during a wait, as a visible window's display would ask for. + /// A frame during a wait, as a visible window's display would ask for; one at a time + /// (`TICKING`), so a window drawing slower than the display falls no further behind. Tick, /// What the window sent itself when it found nothing on its way, at that instant: once it /// arrives, so has every event sent before. @@ -6645,6 +6646,9 @@ fn page_text(editor: &CanvasEditor) -> String { /// Work [`spawn`] started that has not ended. static RUNNING: AtomicUsize = AtomicUsize::new(0); +/// A replay's tick is on its way and not yet drawn. +static TICKING: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + fn spawn(work: impl FnOnce() + Send + 'static) { RUNNING.fetch_add(1, Ordering::Relaxed); let work = move || { @@ -6801,7 +6805,8 @@ impl State { Replay::Settle(path, settled) => { self.replay_settle = Some((path, settled, None)); } - Replay::Tick | Replay::Mark(_) | Replay::Quit => {} + Replay::Tick => TICKING.store(false, Ordering::Release), + Replay::Mark(_) | Replay::Quit => {} Replay::Appearance(appearance) => { self.window.set_theme(Some(appearance)); self.set_appearance(appearance); @@ -6972,6 +6977,7 @@ impl ApplicationHandler for App { UserEvent::Quit => self.close(event_loop), // A cold launch's documents arrive before the window opens. UserEvent::Open(paths) => self.opening.extend(paths), + UserEvent::Replay(Replay::Tick) => TICKING.store(false, Ordering::Release), _ => {} } return; @@ -7244,6 +7250,16 @@ fn write_png(path: &Path, size: [u32; 2], pixels: &[u8]) -> Result<(), Box) { + if !TICKING.swap(true, Ordering::AcqRel) + && proxy.send_event(UserEvent::Replay(Replay::Tick)).is_err() + { + TICKING.store(false, Ordering::Release); + } +} + /// Feeds a development script to the window from another thread, one command per line /// in logical pixels: `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, /// `pressure LEVEL|none`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] @@ -7388,15 +7404,20 @@ fn replay(script: String, proxy: EventLoopProxy) -> Result<(), Box= 60 { + eprintln!("The replay never settled"); + std::process::exit(1); + } + tick(&proxy); } } Err(duration) => { @@ -7409,7 +7430,7 @@ fn replay(script: String, proxy: EventLoopProxy) -> Result<(), Box