From 6618fed0843a38abcd9b95d4c9c542acb237ebc6 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 19 Jun 2024 09:34:41 +0200 Subject: [PATCH 1/3] wip update to bevy 0.14 --- Cargo.toml | 21 +++++++++++---------- examples/generate_docs.rs | 14 +++++++------- examples/schedule_graph_compare.rs | 2 +- examples/schedule_graph_testing.rs | 2 +- src/lib.rs | 6 +++--- src/render_graph/mod.rs | 2 +- src/schedule_graph/settings.rs | 9 +++++++-- src/schedule_graph/system_style.rs | 21 +++++++++++---------- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 43d49df..1a18613 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,24 +15,25 @@ default = ["render_graph"] render_graph = [] [dependencies] -bevy_ecs = { version = "0.13" } -bevy_app = { version = "0.13" } -bevy_utils = { version = "0.13" } -bevy_render = { version = "0.13" } +bevy_ecs = { version = "0.14.0-rc.3" } +bevy_app = { version = "0.14.0-rc.3" } +bevy_utils = { version = "0.14.0-rc.3" } +bevy_render = { version = "0.14.0-rc.3" } +bevy_color = { version = "0.14.0-rc.3" } pretty-type-name = "1.0" petgraph = "0.6" once_cell = "1.17" [dev-dependencies] -bevy = { version = "0.13" } +bevy = { version = "0.14.0-rc.3" } [[example]] name = "print_render_graph" required-features = ["render_graph"] # [patch.crates-io] -# bevy_ecs = { path = "/home/jakob/dev/rust/bevy/crates/bevy_ecs" } -# bevy_app = { path = "/home/jakob/dev/rust/bevy/crates/bevy_app" } -# bevy_utils = { path = "/home/jakob/dev/rust/bevy/crates/bevy_utils" } -# bevy_render = { path = "/home/jakob/dev/rust/bevy/crates/bevy_render" } -# bevy = { path = "/home/jakob/dev/rust/bevy" } +# bevy_ecs = { path = "../bevy/crates/bevy_ecs" } +# bevy_app = { path = "../bevy/crates/bevy_app" } +# bevy_utils = { path = "../bevy/crates/bevy_utils" } +# bevy_render = { path = "../bevy/crates/bevy_render" } +# bevy = { path = "../bevy" } diff --git a/examples/generate_docs.rs b/examples/generate_docs.rs index 049d4a8..d910e29 100644 --- a/examples/generate_docs.rs +++ b/examples/generate_docs.rs @@ -22,7 +22,7 @@ fn main() -> Result<(), std::io::Error> { let style_light = Style::light(); let style_dark = Style::dark_github(); - app.world + app.world_mut() .resource_scope::(|world, mut schedules| { initialize_schedules(&mut schedules, world)?; @@ -56,7 +56,7 @@ fn main() -> Result<(), std::io::Error> { with_main_world_in_render_app(&mut app, |render_app| { render_app - .world + .world_mut() .resource_scope::(|world, mut schedules| { let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone(); @@ -140,23 +140,23 @@ fn initialize_schedules( }) } -fn with_main_world_in_render_app(app: &mut App, f: impl Fn(&mut App) -> T) -> T { +fn with_main_world_in_render_app(app: &mut App, f: impl Fn(&mut SubApp) -> T) -> T { // temporarily add the app world to the render world as a resource - let inserted_world = std::mem::take(&mut app.world); + let inserted_world = std::mem::take(app.world_mut()); let mut render_main_world = bevy_render::MainWorld::default(); *render_main_world = inserted_world; let render_app = app.sub_app_mut(RenderApp); - render_app.world.insert_resource(render_main_world); + render_app.world().insert_resource(render_main_world); let ret = f(render_app); // move the app world back, as if nothing happened. let mut inserted_world = render_app - .world + .world() .remove_resource::() .unwrap(); - app.world = std::mem::take(&mut *inserted_world); + app.world_mut() = std::mem::take(&mut *inserted_world); ret } diff --git a/examples/schedule_graph_compare.rs b/examples/schedule_graph_compare.rs index 2d29cce..1543378 100644 --- a/examples/schedule_graph_compare.rs +++ b/examples/schedule_graph_compare.rs @@ -14,7 +14,7 @@ fn main() -> Result<(), std::io::Error> { let mut app = App::new(); app.add_plugins(DefaultPlugins); - app.world + app.world_mut() .resource_scope::(|world, mut schedules| { let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone(); diff --git a/examples/schedule_graph_testing.rs b/examples/schedule_graph_testing.rs index e9686d7..c59f773 100644 --- a/examples/schedule_graph_testing.rs +++ b/examples/schedule_graph_testing.rs @@ -30,7 +30,7 @@ fn main() -> Result<(), std::io::Error> { // app.configure_sets((TestSet::A, TestSet::B).chain().in_set(TestSet::C)); app.add_plugins(DefaultPlugins.build().disable::()); - app.world + app.world_mut() .resource_scope::(|world, mut schedules| { let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone(); let schedule_label = Main; diff --git a/src/lib.rs b/src/lib.rs index 37f12df..a658096 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ pub fn schedule_graph_dot( label: impl ScheduleLabel, settings: &schedule_graph::Settings, ) -> String { - app.world + app.world_mut() .resource_scope::(|world, mut schedules| { let ignored_ambiguities = schedules.ignored_scheduling_ambiguities.clone(); @@ -61,8 +61,8 @@ pub fn render_graph_dot(app: &App, settings: &render_graph::Settings) -> String let render_app = app .get_sub_app(bevy_render::RenderApp) - .unwrap_or_else(|_| panic!("no render app")); - let render_graph = render_app.world.get_resource::().unwrap(); + .unwrap_or_else(|| panic!("no render app")); + let render_graph = render_app.world().get_resource::().unwrap(); render_graph::render_graph_dot(render_graph, &settings) } diff --git a/src/render_graph/mod.rs b/src/render_graph/mod.rs index 080f423..603d247 100644 --- a/src/render_graph/mod.rs +++ b/src/render_graph/mod.rs @@ -1,6 +1,6 @@ pub mod settings; -use bevy_utils::intern::Interned; +use bevy_ecs::intern::Interned; pub use settings::Settings; use self::iter_utils::sorted; diff --git a/src/schedule_graph/settings.rs b/src/schedule_graph/settings.rs index a90dd28..b6cb187 100644 --- a/src/schedule_graph/settings.rs +++ b/src/schedule_graph/settings.rs @@ -1,7 +1,7 @@ use std::any::TypeId; +use bevy_color::{Color, Hsla}; use bevy_ecs::{component::ComponentId, system::System, world::World}; -use bevy_render::color::Color; use super::system_style::{color_to_hex, system_to_style, SystemStyle}; @@ -221,7 +221,12 @@ impl Settings { let style = (self.system_style)(system); // Check if bg is dark - let [h, s, l, _] = style.bg_color.as_hsla_f32(); + let Hsla { + hue: h, + saturation: s, + lightness: l, + alpha: _, + } = Hsla::from(style.bg_color); // TODO Fix following: https://ux.stackexchange.com/q/107318 let is_dark = l < 0.6; diff --git a/src/schedule_graph/system_style.rs b/src/schedule_graph/system_style.rs index d817207..0a37d96 100644 --- a/src/schedule_graph/system_style.rs +++ b/src/schedule_graph/system_style.rs @@ -1,8 +1,8 @@ use once_cell::sync::Lazy; use std::borrow::Cow; +use bevy_color::{Color, Srgba}; use bevy_ecs::system::System; -use bevy_render::color::Color; use bevy_utils::HashMap; static CRATE_COLORS: Lazy> = Lazy::new(|| { @@ -47,9 +47,9 @@ pub struct SystemStyle { pub fn color_to_hex(color: Color) -> String { format!( "#{:0>2x}{:0>2x}{:0>2x}", - (color.r() * 255.0) as u8, - (color.g() * 255.0) as u8, - (color.b() * 255.0) as u8, + (color.to_srgba().red * 255.0) as u8, + (color.to_srgba().green * 255.0) as u8, + (color.to_srgba().blue * 255.0) as u8, ) } @@ -64,17 +64,18 @@ pub fn system_to_style(system: &dyn System) -> SystemStyle { if is_apply_system_buffers { SystemStyle { - bg_color: Color::hex("E70000").unwrap(), - text_color: Some(Color::hex("ffffff").unwrap()), - border_color: Some(Color::hex("5A0000").unwrap()), + bg_color: Srgba::hex("E70000").unwrap().into(), + text_color: Some(Srgba::hex("ffffff").unwrap().into()), + border_color: Some(Srgba::hex("5A0000").unwrap().into()), border_width: 2.0, } } else { let bg_color = crate_name .and_then(|n| CRATE_COLORS.get(n)) - .map(Color::hex) - .unwrap_or(Color::hex("eff1f3")) - .unwrap(); + .map(Srgba::hex) + .unwrap_or(Srgba::hex("eff1f3")) + .unwrap() + .into(); SystemStyle { bg_color, From 73fac9904850ca823131b42b7dd2ad7444554c43 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 19 Jun 2024 09:47:13 +0200 Subject: [PATCH 2/3] clearer error --- examples/generate_docs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/generate_docs.rs b/examples/generate_docs.rs index d910e29..615a293 100644 --- a/examples/generate_docs.rs +++ b/examples/generate_docs.rs @@ -156,7 +156,8 @@ fn with_main_world_in_render_app(app: &mut App, f: impl Fn(&mut SubApp) -> T) .world() .remove_resource::() .unwrap(); - app.world_mut() = std::mem::take(&mut *inserted_world); + // FIXME: bevy 0.14 does not expose world anymore, so this pattern is not possible to my knowledge. + app.world = std::mem::take(&mut *inserted_world); ret } From a1e4ddc4c247a7d22f86271a3a8775d2352192c4 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Mon, 24 Jun 2024 13:46:16 +0200 Subject: [PATCH 3/3] fix generate_docs.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristoffer Søholm <160317+kristoff3r@users.noreply.github.com> --- examples/generate_docs.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/generate_docs.rs b/examples/generate_docs.rs index 615a293..898d2ec 100644 --- a/examples/generate_docs.rs +++ b/examples/generate_docs.rs @@ -147,17 +147,16 @@ fn with_main_world_in_render_app(app: &mut App, f: impl Fn(&mut SubApp) -> T) *render_main_world = inserted_world; let render_app = app.sub_app_mut(RenderApp); - render_app.world().insert_resource(render_main_world); + render_app.world_mut().insert_resource(render_main_world); let ret = f(render_app); // move the app world back, as if nothing happened. let mut inserted_world = render_app - .world() + .world_mut() .remove_resource::() .unwrap(); - // FIXME: bevy 0.14 does not expose world anymore, so this pattern is not possible to my knowledge. - app.world = std::mem::take(&mut *inserted_world); + *app.world_mut() = std::mem::take(&mut *inserted_world); ret }