From 3b3d3695088bfd2a3b05d9f9e6ee967a8f79160c Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 10 Jul 2023 13:05:33 +0700 Subject: [PATCH] with_bevy: Update to bevy 0.11 release. * Use `add_plugins` as `add_plugin` is deprecated. * Use `world.resource` instead of unwrapping `world.get_resource` as it gives better error messages. * Add the `VelloRenderer` to the render app in the `finish` method as the `Renderer` is async and may not have initialized by the time that the Vello plugin is being set up. --- examples/with_bevy/Cargo.toml | 2 +- examples/with_bevy/src/main.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/with_bevy/Cargo.toml b/examples/with_bevy/Cargo.toml index 17f84b0..1257adc 100644 --- a/examples/with_bevy/Cargo.toml +++ b/examples/with_bevy/Cargo.toml @@ -10,5 +10,5 @@ repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { git = "https://github.com/bevyengine/bevy", rev = "4d54ce14aaee8d7432380df37c41c03c28594b27" } +bevy = "0.11" vello = { path = "../../" } diff --git a/examples/with_bevy/src/main.rs b/examples/with_bevy/src/main.rs index 2e3dd91..39d50d5 100644 --- a/examples/with_bevy/src/main.rs +++ b/examples/with_bevy/src/main.rs @@ -21,8 +21,8 @@ struct VelloRenderer(Renderer); impl FromWorld for VelloRenderer { fn from_world(world: &mut World) -> Self { - let device = world.get_resource::().unwrap(); - let queue = world.get_resource::().unwrap(); + let device = world.resource::(); + let queue = world.resource::(); VelloRenderer( Renderer::new( @@ -42,10 +42,14 @@ struct VelloPlugin; impl Plugin for VelloPlugin { fn build(&self, app: &mut App) { let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return }; - render_app.init_resource::(); // This should probably use the render graph, but working out the dependencies there is awkward render_app.add_systems(Render, render_scenes.in_set(RenderSet::Render)); } + + fn finish(&self, app: &mut App) { + let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return }; + render_app.init_resource::(); + } } fn render_scenes( @@ -78,11 +82,11 @@ fn render_scenes( fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(VelloPlugin) + .add_plugins(VelloPlugin) .add_systems(Startup, setup) .add_systems(Update, bevy::window::close_on_esc) .add_systems(Update, cube_rotator_system) - .add_plugin(ExtractComponentPlugin::::default()) + .add_plugins(ExtractComponentPlugin::::default()) .add_systems(Update, render_fragment) .run() }