diff --git a/engine/bevy-plugins/src/bridge.rs b/engine/bevy-plugins/src/bridge.rs index 3c8259a4..bb7ce249 100644 --- a/engine/bevy-plugins/src/bridge.rs +++ b/engine/bevy-plugins/src/bridge.rs @@ -184,7 +184,7 @@ fn open(names: &[String], fps: f64, serve: Option) -> R { // no plugin named: the clock still steps by frames let dt = Duration::from_secs_f64(1.0 / fps.max(1.0)); app.world_mut().resource_mut::>().set_timestep(dt); - app.insert_resource(PluginClock { stepped: 0, dt, advancing: false, steps: 0 }); + app.insert_resource(PluginClock { stepped: 0, dt, advancing: false, steps: 0, pure: false }); } if let Some(port) = serve { #[cfg(feature = "remote")] diff --git a/engine/render/src/engine/load.rs b/engine/render/src/engine/load.rs index ab81ce64..04019d4f 100644 --- a/engine/render/src/engine/load.rs +++ b/engine/render/src/engine/load.rs @@ -15,6 +15,12 @@ impl Engine { } // kept (and the frames before a frame stepped through: catch_up) only when the rows need steps (#77) self.replay = (plugins::active(self.app.world()) && plugins::steps(inserted)).then(|| (prog.clone(), inserted.to_vec())); + // without them, the plugins' clock steps nothing: Time and the keyed rows are each frame's however it's reached + // (a still at frame 200, a batch's second frame, a seek), not frozen at the first frame drawn (#162) + let pure = self.replay.is_none(); + if let Some(mut c) = self.app.world_mut().get_resource_mut::() { + c.pure = pure; + } self.drawn = None; let world = self.app.world_mut(); let g = world.resource::().0; diff --git a/runtime/plugins/src/lib.rs b/runtime/plugins/src/lib.rs index 1de45e55..961eb4b5 100644 --- a/runtime/plugins/src/lib.rs +++ b/runtime/plugins/src/lib.rs @@ -15,6 +15,9 @@ //! by zero. A frame reached by a jump is stepped to through the frames between, and a frame before the last stepped one //! reloads the edit and steps from 0, so a plugin's state at frame f is always f steps from the load, however f was //! reached (a render of one frame, a play, a seek). +//! +//! A load whose rows give the plugins nothing to carry from frame to frame (`steps` false) isn't stepped (#77): its +//! clock is `pure`, and Time and the keyed rows are the frame drawn's, f / fps from 0, however it was reached (#162). use std::any::TypeId; use std::collections::BTreeMap; @@ -92,6 +95,11 @@ pub struct PluginClock { pub dt: Duration, pub advancing: bool, pub steps: u64, + /// the load gives the plugins nothing to step (`steps` false): nothing is stepped, and Time and the keyed rows are + /// the frame drawn's however it was reached (pure_time, keyed_rows). Stepping only on the frame after the last + /// stepped one froze them: a still at frame 200 sampled globals.time 0, and a batch's second frame drew the + /// first's uniforms (#162) + pub pure: bool, } /// A mesh whose Transform a plugin owns (sync_meshes leaves it alone). @@ -200,7 +208,28 @@ fn install_list(app: &mut App, fps: f64, list: Vec) { } app.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::ZERO)); app.world_mut().resource_mut::>().set_timestep(dt); - app.insert_resource(PluginClock { stepped: 0, dt, advancing: false, steps: 0 }); + app.insert_resource(PluginClock { stepped: 0, dt, advancing: false, steps: 0, pure: false }); + app.add_systems(First, pure_time.after(bevy::time::TimeSystems)); +} + +/// A pure clock's Time: the frame drawn's, f / fps from 0, whatever was drawn before it (a still alone, a batch's +/// next frame, a seek back in live play); Time too, which the fixed loop copies back into Time. It moves by +/// one step on an update that draws another frame than the last, and by none on the same frame drawn again. +fn pure_time(clock: Option>, pc: Option>, mut virt: ResMut>, mut time: ResMut