| ... | @@ -417,7 +417,8 @@ enum Replay { | ... | @@ -417,7 +417,8 @@ enum Replay { |
| 417 | /// Waits for nothing to be on its way, then writes the window's accessibility tree as | 417 | /// Waits for nothing to be on its way, then writes the window's accessibility tree as |
| 418 | /// text where given, and answers. | 418 | /// text where given, and answers. |
| 419 | Settle(Option<PathBuf>, std::sync::mpsc::Sender<()>), | 419 | Settle(Option<PathBuf>, std::sync::mpsc::Sender<()>), |
| 420 | /// A frame during a wait, as a visible window's display would ask for. | 420 | /// A frame during a wait, as a visible window's display would ask for; one at a time |
| | 421 | /// (`TICKING`), so a window drawing slower than the display falls no further behind. |
| 421 | Tick, | 422 | Tick, |
| 422 | /// What the window sent itself when it found nothing on its way, at that instant: once it | 423 | /// What the window sent itself when it found nothing on its way, at that instant: once it |
| 423 | /// arrives, so has every event sent before. | 424 | /// arrives, so has every event sent before. |
| ... | @@ -6645,6 +6646,9 @@ fn page_text(editor: &CanvasEditor) -> String { | ... | @@ -6645,6 +6646,9 @@ fn page_text(editor: &CanvasEditor) -> String { |
| 6645 | /// Work [`spawn`] started that has not ended. | 6646 | /// Work [`spawn`] started that has not ended. |
| 6646 | static RUNNING: AtomicUsize = AtomicUsize::new(0); | 6647 | static RUNNING: AtomicUsize = AtomicUsize::new(0); |
| 6647 | | 6648 | |
| | 6649 | /// A replay's tick is on its way and not yet drawn. |
| | 6650 | static TICKING: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); |
| | 6651 | |
| 6648 | fn spawn(work: impl FnOnce() + Send + 'static) { | 6652 | fn spawn(work: impl FnOnce() + Send + 'static) { |
| 6649 | RUNNING.fetch_add(1, Ordering::Relaxed); | 6653 | RUNNING.fetch_add(1, Ordering::Relaxed); |
| 6650 | let work = move || { | 6654 | let work = move || { |
| ... | @@ -6801,7 +6805,8 @@ impl State { | ... | @@ -6801,7 +6805,8 @@ impl State { |
| 6801 | Replay::Settle(path, settled) => { | 6805 | Replay::Settle(path, settled) => { |
| 6802 | self.replay_settle = Some((path, settled, None)); | 6806 | self.replay_settle = Some((path, settled, None)); |
| 6803 | } | 6807 | } |
| 6804 | Replay::Tick | Replay::Mark(_) | Replay::Quit => {} | 6808 | Replay::Tick => TICKING.store(false, Ordering::Release), |
| | 6809 | Replay::Mark(_) | Replay::Quit => {} |
| 6805 | Replay::Appearance(appearance) => { | 6810 | Replay::Appearance(appearance) => { |
| 6806 | self.window.set_theme(Some(appearance)); | 6811 | self.window.set_theme(Some(appearance)); |
| 6807 | self.set_appearance(appearance); | 6812 | self.set_appearance(appearance); |
| ... | @@ -6972,6 +6977,7 @@ impl ApplicationHandler<UserEvent> for App { | ... | @@ -6972,6 +6977,7 @@ impl ApplicationHandler<UserEvent> for App { |
| 6972 | UserEvent::Quit => self.close(event_loop), | 6977 | UserEvent::Quit => self.close(event_loop), |
| 6973 | // A cold launch's documents arrive before the window opens. | 6978 | // A cold launch's documents arrive before the window opens. |
| 6974 | UserEvent::Open(paths) => self.opening.extend(paths), | 6979 | UserEvent::Open(paths) => self.opening.extend(paths), |
| | 6980 | UserEvent::Replay(Replay::Tick) => TICKING.store(false, Ordering::Release), |
| 6975 | _ => {} | 6981 | _ => {} |
| 6976 | } | 6982 | } |
| 6977 | return; | 6983 | return; |
| ... | @@ -7244,6 +7250,16 @@ fn write_png(path: &Path, size: [u32; 2], pixels: &[u8]) -> Result<(), Box<dyn E | ... | @@ -7244,6 +7250,16 @@ fn write_png(path: &Path, size: [u32; 2], pixels: &[u8]) -> Result<(), Box<dyn E |
| 7244 | Ok(()) | 7250 | Ok(()) |
| 7245 | } | 7251 | } |
| 7246 | | 7252 | |
| | 7253 | #[cfg(not(target_arch = "wasm32"))] |
| | 7254 | /// Asks for a replay's frame, unless the last one asked for is not yet drawn. |
| | 7255 | fn tick(proxy: &EventLoopProxy<UserEvent>) { |
| | 7256 | if !TICKING.swap(true, Ordering::AcqRel) |
| | 7257 | && proxy.send_event(UserEvent::Replay(Replay::Tick)).is_err() |
| | 7258 | { |
| | 7259 | TICKING.store(false, Ordering::Release); |
| | 7260 | } |
| | 7261 | } |
| | 7262 | |
| 7247 | /// Feeds a development script to the window from another thread, one command per line | 7263 | /// Feeds a development script to the window from another thread, one command per line |
| 7248 | /// in logical pixels: `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, | 7264 | /// in logical pixels: `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, |
| 7249 | /// `pressure LEVEL|none`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] | 7265 | /// `pressure LEVEL|none`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] |
| ... | @@ -7388,15 +7404,20 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy | ... | @@ -7388,15 +7404,20 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy |
| 7388 | } | 7404 | } |
| 7389 | let settling = matches!(replay, Replay::Settle(..)); | 7405 | let settling = matches!(replay, Replay::Settle(..)); |
| 7390 | let _ = proxy.send_event(UserEvent::Replay(replay)); | 7406 | let _ = proxy.send_event(UserEvent::Replay(replay)); |
| 7391 | // Frames tick until settled; a minute bounds a page that never lands. | 7407 | // Frames tick until settled; a minute bounds a page that never lands, and |
| | 7408 | // a replay that waited out its minute fails rather than going on without |
| | 7409 | // what the step was to write. |
| 7392 | let start = Instant::now(); | 7410 | let start = Instant::now(); |
| 7393 | while settling | 7411 | while settling |
| 7394 | && start.elapsed().as_secs() < 60 | | |
| 7395 | && settled | 7412 | && settled |
| 7396 | .recv_timeout(std::time::Duration::from_micros(16_667)) | 7413 | .recv_timeout(std::time::Duration::from_micros(16_667)) |
| 7397 | .is_err() | 7414 | .is_err() |
| 7398 | { | 7415 | { |
| 7399 | let _ = proxy.send_event(UserEvent::Replay(Replay::Tick)); | 7416 | if start.elapsed().as_secs() >= 60 { |
| | 7417 | eprintln!("The replay never settled"); |
| | 7418 | std::process::exit(1); |
| | 7419 | } |
| | 7420 | tick(&proxy); |
| 7400 | } | 7421 | } |
| 7401 | } | 7422 | } |
| 7402 | Err(duration) => { | 7423 | Err(duration) => { |
| ... | @@ -7409,7 +7430,7 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy | ... | @@ -7409,7 +7430,7 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy |
| 7409 | tick += period; | 7430 | tick += period; |
| 7410 | } | 7431 | } |
| 7411 | std::thread::sleep(tick - Instant::now()); | 7432 | std::thread::sleep(tick - Instant::now()); |
| 7412 | let _ = proxy.send_event(UserEvent::Replay(Replay::Tick)); | 7433 | self::tick(&proxy); |
| 7413 | } | 7434 | } |
| 7414 | } | 7435 | } |
| 7415 | } | 7436 | } |