Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - The update_frame_count system should be placed in CorePlugin #6676

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod name;
mod serde;
mod task_pool_options;

use bevy_ecs::system::Resource;
use bevy_ecs::system::{ResMut, Resource};
pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable};
pub use name::*;
pub use task_pool_options::*;
Expand Down Expand Up @@ -53,6 +53,7 @@ impl Plugin for CorePlugin {
register_math_types(app);

app.init_resource::<FrameCount>();
app.add_system(update_frame_count);
}
}

Expand Down Expand Up @@ -108,6 +109,10 @@ fn register_math_types(app: &mut App) {
#[derive(Default, Resource, Clone, Copy)]
pub struct FrameCount(pub u32);

fn update_frame_count(mut frame_count: ResMut<FrameCount>) {
frame_count.0 = frame_count.0.wrapping_add(1);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -145,4 +150,14 @@ mod tests {
compute_rx.try_recv().unwrap();
io_rx.try_recv().unwrap();
}

#[test]
fn frame_counter_update() {
let mut app = App::new();
app.add_plugin(CorePlugin::default());
app.update();

let frame_count = app.world.resource::<FrameCount>();
assert_eq!(1, frame_count.0);
}
}
5 changes: 5 additions & 0 deletions crates/bevy_render/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ impl Plugin for GlobalsPlugin {
render_app
.init_resource::<GlobalsBuffer>()
.init_resource::<Time>()
.add_system_to_stage(RenderStage::Extract, extract_frame_count)
.add_system_to_stage(RenderStage::Extract, extract_time)
.add_system_to_stage(RenderStage::Prepare, prepare_globals_buffer);
}
}
}

fn extract_frame_count(mut commands: Commands, frame_count: Extract<Res<FrameCount>>) {
commands.insert_resource(**frame_count);
}

fn extract_time(mut commands: Commands, time: Extract<Res<Time>>) {
commands.insert_resource(time.clone());
}
Expand Down
23 changes: 1 addition & 22 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mod spatial_bundle;
pub mod texture;
pub mod view;

use bevy_core::FrameCount;
use bevy_hierarchy::ValidParentCheckPlugin;
pub use extract_param::Extract;

Expand Down Expand Up @@ -333,8 +332,7 @@ impl Plugin for RenderPlugin {
.add_plugin(CameraPlugin)
.add_plugin(ViewPlugin)
.add_plugin(MeshPlugin)
.add_plugin(GlobalsPlugin)
.add_plugin(FrameCountPlugin);
.add_plugin(GlobalsPlugin);
}
}

Expand Down Expand Up @@ -368,22 +366,3 @@ fn extract(app_world: &mut World, render_app: &mut App) {
// see <https://github.com/bevyengine/bevy/issues/5082>
extract.apply_buffers(running_world);
}

pub struct FrameCountPlugin;
impl Plugin for FrameCountPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.add_system(update_frame_count);

if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app.add_system_to_stage(RenderStage::Extract, extract_frame_count);
}
}
}

fn update_frame_count(mut frame_count: ResMut<FrameCount>) {
frame_count.0 = frame_count.0.wrapping_add(1);
}

fn extract_frame_count(mut commands: Commands, frame_count: Extract<Res<FrameCount>>) {
commands.insert_resource(**frame_count);
}