mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
The update_frame_count
system should be placed in CorePlugin (#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 #6656 ## Solution - Move the `update_frame_count` into CorePlugin
This commit is contained in:
parent
bdd5cee92a
commit
ed2ea0d417
3 changed files with 22 additions and 23 deletions
|
@ -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::*;
|
||||
|
@ -53,6 +53,7 @@ impl Plugin for CorePlugin {
|
|||
register_math_types(app);
|
||||
|
||||
app.init_resource::<FrameCount>();
|
||||
app.add_system(update_frame_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::*;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue