From fa5b606deb6d16515c9cfa2e7f5bb99d835656de Mon Sep 17 00:00:00 2001 From: Joy <51241057+maniwani@users.noreply.github.com> Date: Thu, 28 Jul 2022 17:28:20 -0700 Subject: [PATCH 1/3] main changes --- crates/bevy_time/src/fixed_timestep.rs | 583 +++++++++++++++---------- crates/bevy_time/src/lib.rs | 84 +++- crates/bevy_time/src/time.rs | 376 +++++++++++++--- 3 files changed, 721 insertions(+), 322 deletions(-) diff --git a/crates/bevy_time/src/fixed_timestep.rs b/crates/bevy_time/src/fixed_timestep.rs index 78fdfca797c50..d5564d1df8fa2 100644 --- a/crates/bevy_time/src/fixed_timestep.rs +++ b/crates/bevy_time/src/fixed_timestep.rs @@ -1,302 +1,401 @@ use crate::Time; -use bevy_ecs::{ - archetype::ArchetypeComponentId, - component::ComponentId, - query::Access, - schedule::ShouldRun, - system::{IntoSystem, Res, ResMut, System}, - world::World, -}; -use bevy_utils::HashMap; -use std::borrow::Cow; - -/// The internal state of each [`FixedTimestep`]. -#[derive(Debug)] -pub struct FixedTimestepState { - step: f64, - accumulator: f64, + +use bevy_ecs::world::{FromWorld, World}; +use bevy_utils::{Duration, Instant}; + +/// A [`Time`] variant that is synchronized to the main `Time` resource, but only advances +/// in increments of a constant [`delta`](FixedTime::delta). +#[derive(Debug, Clone)] +pub struct FixedTime { + startup: Instant, + first_update: Option, + last_update: Option, + delta: Duration, + delta_seconds: f32, + delta_seconds_f64: f64, + elapsed_since_startup: Duration, + seconds_since_startup: f32, + seconds_since_startup_f64: f64, } -impl FixedTimestepState { - /// The amount of time each step takes. - pub fn step(&self) -> f64 { - self.step +impl FromWorld for FixedTime { + fn from_world(world: &mut World) -> Self { + let time = world.resource::