Skip to content

Commit

Permalink
fix some rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed May 26, 2022
1 parent b92ffca commit f008662
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
1 change: 0 additions & 1 deletion crates/bevy_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.8.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }

# other
crossbeam-channel = "0.5.0"
bytemuck = "1.5"
1 change: 1 addition & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev" }
bevy_encase_derive = { path = "../bevy_encase_derive", version = "0.8.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.8.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] }
bevy_time = { path = "../bevy_time", version = "0.8.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.8.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.8.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Plugin for RenderPlugin {
.insert_resource(asset_server)
.init_resource::<RenderGraph>();

let (sender, receiver) = bevy_core::create_time_channels();
let (sender, receiver) = bevy_time::create_time_channels();
app.insert_resource(receiver);
render_app.insert_resource(sender);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
settings::{WgpuSettings, WgpuSettingsPriority},
view::{ExtractedWindows, ViewTarget},
};
use bevy_core::TimeSender;
use bevy_ecs::prelude::*;
use bevy_time::TimeSender;
use bevy_utils::Instant;
use std::sync::Arc;
use wgpu::{AdapterInfo, CommandEncoder, Instance, Queue, RequestAdapterOptions};
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ bevy_app = { path = "../bevy_app", version = "0.8.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev", features = ["bevy_reflect"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] }
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }

# other
crossbeam-channel = "0.5.0"
38 changes: 36 additions & 2 deletions crates/bevy_time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub use stopwatch::*;
pub use time::*;
pub use timer::*;

use bevy_ecs::system::{Local, Res, ResMut};
use bevy_utils::{tracing::warn, Instant};
use crossbeam_channel::{Receiver, Sender};

pub mod prelude {
//! The Bevy Time Prelude.
#[doc(hidden)]
Expand Down Expand Up @@ -41,6 +45,36 @@ impl Plugin for TimePlugin {
}
}

fn time_system(mut time: ResMut<Time>) {
time.update();
/// channel resource used to receive time from render world
pub struct TimeReceiver(pub Receiver<Instant>);
/// channel resource used to send time from render world
pub struct TimeSender(pub Sender<Instant>);

/// create channels used for sending time between render world and app world
pub fn create_time_channels() -> (TimeSender, TimeReceiver) {
// bound the channel to 2 since when pipelined the render phase can finish before
// the time system runs.
let (s, r) = crossbeam_channel::bounded::<Instant>(2);
(TimeSender(s), TimeReceiver(r))
}

/// The system used to update the time. If there is a render world the time is sent from
/// there to this system through channels. Otherwise the time is updated in this system.]
fn time_system(
mut time: ResMut<Time>,
time_recv: Option<Res<TimeReceiver>>,
mut has_received_time: Local<bool>,
) {
if let Some(time_recv) = time_recv {
// TODO: delay checking channel on start by 2 frames when pipelined rendering
// is enabled. This is to make sure we always read the N-2 frame's time.
if let Ok(new_time) = time_recv.0.try_recv() {
time.update_with_instant(new_time);
*has_received_time = true;
} else if *has_received_time {
warn!("time_system did not receive time from render world! Calculations depending on the time may be incorrect.");
}
} else {
time.update();
}
}
38 changes: 1 addition & 37 deletions crates/bevy_time/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use bevy_ecs::system::{Local, Res, ResMut};
use bevy_utils::{tracing::warn, Duration, Instant};
use crossbeam_channel::{Receiver, Sender};
use bevy_utils::{Duration, Instant};

/// Tracks elapsed time since the last update and since the App has started
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -144,40 +142,6 @@ impl Time {
}
}

/// channel resource used to receive time from render world
pub struct TimeReceiver(pub Receiver<Instant>);
/// channel resource used to send time from render world
pub struct TimeSender(pub Sender<Instant>);

/// create channels used for sending time between render world and app world
pub fn create_time_channels() -> (TimeSender, TimeReceiver) {
// bound the channel to 2 since when pipelined the render phase can finish before
// the time system runs.
let (s, r) = crossbeam_channel::bounded::<Instant>(2);
(TimeSender(s), TimeReceiver(r))
}

/// The system used to update the time. If there is a render world the time is sent from
/// there to this system through channels. Otherwise the time is updated in this system.
pub(crate) fn time_system(
mut time: ResMut<Time>,
time_recv: Option<Res<TimeReceiver>>,
mut has_received_time: Local<bool>,
) {
if let Some(time_recv) = time_recv {
// TODO: delay checking channel on start by 2 frames when pipelined rendering
// is enabled. This is to make sure we always read the N-2 frame's time.
if let Ok(new_time) = time_recv.0.try_recv() {
time.update_with_instant(new_time);
*has_received_time = true;
} else if *has_received_time {
warn!("time_system did not receive time from render world! Calculations depending on the time may be incorrect.");
}
} else {
time.update();
}
}

#[cfg(test)]
#[allow(clippy::float_cmp)]
mod tests {
Expand Down

0 comments on commit f008662

Please sign in to comment.