Skip to content

Commit

Permalink
The update_frame_count system should be placed in CorePlugin (bevye…
Browse files Browse the repository at this point in the history
…ngine#6676)

# Objective

Latest Release, "bevy 0.9" move the FrameCount updater into RenderPlugin, it leads to user who only run app with Core/Minimal Plugin cannot get the right number of FrameCount, it always return 0.

As for use cases like a server app, we don't want to add render dependencies to the app.

More detail in bevyengine#6656

## Solution

- Move the `update_frame_count` into CorePlugin
  • Loading branch information
phuocthanhdo authored and alradish committed Jan 22, 2023
1 parent e3b81c4 commit 5d61d29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/bevy_core/src/lib.rs
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 @@ -55,6 +55,7 @@ impl Plugin for CorePlugin {
register_math_types(app);

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

Expand Down Expand Up @@ -112,6 +113,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 @@ -149,4 +154,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
Expand Up @@ -19,12 +19,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

0 comments on commit 5d61d29

Please sign in to comment.