diff --git a/bevy_asset_loader/examples/progress_tracking.rs b/bevy_asset_loader/examples/progress_tracking.rs index 068cabc..4b316f3 100644 --- a/bevy_asset_loader/examples/progress_tracking.rs +++ b/bevy_asset_loader/examples/progress_tracking.rs @@ -1,5 +1,6 @@ use bevy::app::AppExit; use bevy::asset::LoadState; +use bevy::diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin}; use bevy::prelude::*; use bevy_asset_loader::prelude::*; use iyes_progress::{ProgressCounter, ProgressPlugin}; @@ -7,7 +8,7 @@ use iyes_progress::{ProgressCounter, ProgressPlugin}; /// This example shows how to track the loading progress of your collections using `iyes_progress` /// /// Running it will print the current progress for every frame. The five assets from -/// the two collections will be loaded rather quickly (one or two frames). The final task +/// the two collections will be loaded rather quickly (one/a few frames). The final task /// completes after one second. At that point, `iyes_progress` will continue to the next state /// and the app will terminate. fn main() { @@ -19,17 +20,24 @@ fn main() { ) .add_state(MyStates::AssetLoading) .add_plugins(DefaultPlugins) + .add_plugin(FrameTimeDiagnosticsPlugin::default()) // track progress during `MyStates::AssetLoading` and continue to `MyStates::Next` when progress is completed .add_plugin(ProgressPlugin::new(MyStates::AssetLoading).continue_to(MyStates::Next)) // gracefully quit the app when `MyStates::Next` is reached .add_system_set(SystemSet::on_enter(MyStates::Next).with_system(expect)) .add_system_set( - SystemSet::on_update(MyStates::AssetLoading).with_system(track_fake_long_task), + SystemSet::on_update(MyStates::AssetLoading) + .with_system(track_fake_long_task.before(print_progress)), ) - .add_system_to_stage(CoreStage::PostUpdate, print_progress) + .add_system(print_progress) .run(); } +// Time in seconds to complete a custom long-running task. +// If assets are loaded earlier, the current state will not +// be changed until the 'fake long task' is completed (thanks to 'iyes_progress') +const DURATION_LONG_TASK_IN_SECS: f64 = 2.0; + #[derive(AssetCollection)] struct AudioAssets { #[asset(path = "audio/background.ogg")] @@ -50,8 +58,8 @@ struct TextureAssets { } fn track_fake_long_task(time: Res