Skip to content

Commit

Permalink
removed optional bevy_time dependency from bevy_gizmos
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecificProtagonist committed Jul 14, 2023
1 parent 0495ae7 commit cd8560c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
7 changes: 7 additions & 0 deletions crates/bevy_app/src/main_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ pub struct RunFixedUpdateLoop;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedUpdate;

/// Indicates that [`RunFixedUpdateLoop`] is currently active.
#[derive(Resource)]
pub struct FixedUpdateScheduleIsCurrentlyRunning {
/// Sequentially increasing with each fixed update.
pub update: u64,
}

/// The schedule that contains app logic.
/// This is run by the [`Main`] schedule.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_gizmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ keywords = ["bevy"]

[features]
webgl = []
fixed_update = ["dep:bevy_time"]

[dependencies]
# Bevy
Expand All @@ -26,4 +25,3 @@ bevy_core = { path = "../bevy_core", version = "0.12.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.12.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.12.0-dev" }
bevy_time = { path = "../bevy_time", version = "0.12.0-dev", optional = true }
15 changes: 4 additions & 11 deletions crates/bevy_gizmos/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{f32::consts::TAU, iter};

use bevy_app::FixedUpdateScheduleIsCurrentlyRunning;
use bevy_ecs::{
component::Tick,
system::{Resource, SystemBuffer, SystemMeta, SystemParam},
Expand Down Expand Up @@ -82,17 +83,9 @@ const _: () = {
type Item<'w, 's> = Gizmos<'s>;

fn init_state(world: &mut World, _system_meta: &mut SystemMeta) -> Self::State {
#[cfg(not(feature = "fixed_update"))]
let fixed_time_tick = None;
#[cfg(feature = "fixed_update")]
let fixed_time_update =
if world.contains_resource::<bevy_time::fixed_timestep::FixedUpdateScheduleIsCurrentlyRunning>() {
world
.get_resource::<bevy_time::prelude::FixedTime>()
.map(|time| time.times_expended())
} else {
None
};
let fixed_time_update = world
.get_resource::<FixedUpdateScheduleIsCurrentlyRunning>()
.map(|current| current.update);
Wrap(GizmoBuffer {
fixed_time_update,
list_positions: default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ bevy_text = { path = "../bevy_text", optional = true, version = "0.12.0-dev" }
bevy_ui = { path = "../bevy_ui", optional = true, version = "0.12.0-dev" }
bevy_winit = { path = "../bevy_winit", optional = true, version = "0.12.0-dev" }
bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.12.0-dev" }
bevy_gizmos = { path = "../bevy_gizmos", optional = true, version = "0.12.0-dev", default-features = false, features = ["fixed_update"] }
bevy_gizmos = { path = "../bevy_gizmos", optional = true, version = "0.12.0-dev", default-features = false }
10 changes: 4 additions & 6 deletions crates/bevy_time/src/fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! variants for game simulation, but rather use the value of [`FixedTime`] instead.

use crate::Time;
use bevy_app::FixedUpdate;
use bevy_app::{FixedUpdate, FixedUpdateScheduleIsCurrentlyRunning};
use bevy_ecs::{system::Resource, world::World};
use bevy_utils::Duration;
use thiserror::Error;
Expand Down Expand Up @@ -99,10 +99,6 @@ impl Default for FixedTime {
}
}

/// Indicates that [`run_fixed_update_schedule`] is currently active.
#[derive(Resource)]
pub struct FixedUpdateScheduleIsCurrentlyRunning;

/// An error returned when working with [`FixedTime`].
#[derive(Debug, Error)]
pub enum FixedUpdateError {
Expand All @@ -115,7 +111,9 @@ pub enum FixedUpdateError {

/// Ticks the [`FixedTime`] resource then runs the [`FixedUpdate`].
pub fn run_fixed_update_schedule(world: &mut World) {
world.insert_resource(FixedUpdateScheduleIsCurrentlyRunning);
world.insert_resource(FixedUpdateScheduleIsCurrentlyRunning {
update: world.resource::<FixedTime>().times_expended(),
});

// Tick the time
let delta_time = world.resource::<Time>().delta();
Expand Down

0 comments on commit cd8560c

Please sign in to comment.