From e3a88ee5490e71edd6621dd630795b33b5c8a457 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 16 Feb 2023 16:38:02 +0100 Subject: [PATCH 1/2] Implement loading screen --- Cargo.lock | 12 ++++++++ Cargo.toml | 3 +- src/dev.rs | 5 +-- src/file_system_interaction/asset_loading.rs | 32 ++++++++++++++++++-- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c2cf3cf..5cd3e862 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,6 +367,7 @@ dependencies = [ "anyhow", "bevy", "bevy_asset_loader_derive", + "iyes_progress", ] [[package]] @@ -1993,6 +1994,7 @@ dependencies = [ "glob", "image 0.24.5", "indexmap", + "iyes_progress", "polyanya", "regex", "ron 0.8.0", @@ -2408,6 +2410,16 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "iyes_progress" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266c468795c5af070ab4c5fa01aca792a8f01f511e76feb9bea3878a1dbee144" +dependencies = [ + "bevy_app", + "bevy_ecs", +] + [[package]] name = "jni" version = "0.19.0" diff --git a/Cargo.toml b/Cargo.toml index 1156d329..56745350 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ wasm = [ [dependencies] bevy = { version = "^0.9.1", default-features = false } bevy_kira_audio = "0.13" -bevy_asset_loader = { git = "https://github.com/NiklasEi/bevy_asset_loader.git", rev = "9a7966c9e7a44026a2192292390b315d28c88ca7" } +bevy_asset_loader = { git = "https://github.com/NiklasEi/bevy_asset_loader.git", rev = "9a7966c9e7a44026a2192292390b315d28c88ca7", features = ["progress_tracking"] } bevy_common_assets = { version = "0.4.0", features = ["ron", "toml"] } bevy_egui = "0.19" serde = { version = "1", features = ["derive"] } @@ -63,6 +63,7 @@ glob = "0.3.1" polyanya = "0.2.0" bevy_pathmesh = "0.3.0" bitflags = "1.3.2" +iyes_progress = "0.7.1" # keep the following in sync with Bevy's dependencies winit = { version = "0.27", default-features = false } diff --git a/src/dev.rs b/src/dev.rs index d8971fb3..a684cbd6 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -1,5 +1,5 @@ use crate::dev::scene_editor::SceneEditorPlugin; -use bevy::diagnostic::LogDiagnosticsPlugin; +use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::prelude::*; use bevy_editor_pls::prelude::*; use bevy_prototype_debug_lines::DebugLinesPlugin; @@ -15,9 +15,10 @@ impl Plugin for DevPlugin { fn build(&self, app: &mut App) { { app.add_plugin(EditorPlugin) + .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(DebugLinesPlugin::default()) .add_plugin(SceneEditorPlugin) - .add_plugin(LogDiagnosticsPlugin::default()) + .add_plugin(LogDiagnosticsPlugin::filtered(vec![])) .add_plugin(RapierDebugRenderPlugin { enabled: false, ..default() diff --git a/src/file_system_interaction/asset_loading.rs b/src/file_system_interaction/asset_loading.rs index 43abfd13..992ee0d5 100644 --- a/src/file_system_interaction/asset_loading.rs +++ b/src/file_system_interaction/asset_loading.rs @@ -8,7 +8,10 @@ use bevy::utils::HashMap; use bevy_asset_loader::prelude::*; use bevy_common_assets::ron::RonAssetPlugin; use bevy_common_assets::toml::TomlAssetPlugin; +use bevy_egui::egui::ProgressBar; +use bevy_egui::{egui, EguiContext}; use bevy_kira_audio::AudioSource; +use iyes_progress::{ProgressCounter, ProgressPlugin}; pub struct LoadingPlugin; @@ -17,6 +20,7 @@ impl Plugin for LoadingPlugin { app.add_plugin(RonAssetPlugin::::new(&["lvl.ron"])) .add_plugin(RonAssetPlugin::::new(&["dlg.ron"])) .add_plugin(TomlAssetPlugin::::new(&["game.toml"])) + .add_plugin(ProgressPlugin::new(GameState::Loading).continue_to(GameState::Menu)) .add_loading_state( LoadingState::new(GameState::Loading) .with_collection::() @@ -26,9 +30,9 @@ impl Plugin for LoadingPlugin { .with_collection::() .with_collection::() .with_collection::() - .with_collection::() - .continue_to_state(GameState::Menu), - ); + .with_collection::(), + ) + .add_system_set(SystemSet::on_update(GameState::Loading).with_system(show_progress)); } } @@ -90,3 +94,25 @@ pub struct ConfigAssets { #[asset(path = "config/config.game.toml")] pub game: Handle, } + +fn show_progress( + progress: Option>, + mut egui_context: ResMut, + mut last_done: Local, +) { + if let Some(progress) = progress.map(|counter| counter.progress()) { + if progress.done > *last_done { + *last_done = progress.done; + } + + egui::CentralPanel::default().show(egui_context.ctx_mut(), |ui| { + ui.vertical_centered_justified(|ui| { + ui.add_space(100.0); + ui.heading("Loading..."); + ui.add( + ProgressBar::new(progress.done as f32 / progress.total as f32).animate(true), + ); + }); + }); + } +} From 1d67d5b8d6a4981330893cf32fe60d185c3ec0ea Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 16 Feb 2023 16:41:21 +0100 Subject: [PATCH 2/2] Improve default zoom --- src/player_control/camera/third_person.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player_control/camera/third_person.rs b/src/player_control/camera/third_person.rs index 61c6ee74..fc58c867 100644 --- a/src/player_control/camera/third_person.rs +++ b/src/player_control/camera/third_person.rs @@ -24,7 +24,7 @@ impl Default for ThirdPersonCamera { Self { up: Vec3::Y, transform: default(), - distance: 1., + distance: 5., target: default(), secondary_target: default(), config: default(),