From 6b40c4b0f4a68bf2bcba8891ff2ad59274b3f1c7 Mon Sep 17 00:00:00 2001 From: caelwarner Date: Fri, 7 Apr 2023 19:12:03 -0700 Subject: [PATCH] Update bevy to 0.10 - Update bevy to 0.10 and update all other bevy crates to their respective versions --- Cargo.toml | 8 +++---- src/main.rs | 47 +++++++++++++++++++++++------------------ src/pipeline/mod.rs | 9 +++++--- src/plugin.rs | 51 ++++++++++++++++++++++----------------------- 4 files changed, 62 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ec853a7..a81e1dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = "0.8.1" -bevy_embedded_assets = "0.4.0" -bevy-inspector-egui = "0.13.0" -bevy-inspector-egui-derive = "0.13.0" +bevy = "0.10.1" +bevy_embedded_assets = "0.7.0" +bevy-inspector-egui = "0.18.3" +bevy-inspector-egui-derive = "0.18.1" bytemuck = "1.12.2" rand = "0.8.5" serde = { version = "1.0.159", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 9b2ad48..157ab91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::fs; use bevy::asset::AssetPlugin; use bevy::DefaultPlugins; use bevy::prelude::*; -use bevy::window::{PresentMode, WindowMode, WindowResized}; +use bevy::window::{PresentMode, WindowMode, WindowResized, WindowResolution}; use bevy_embedded_assets::EmbeddedAssetPlugin; use serde::{Deserialize, Serialize}; @@ -28,31 +28,38 @@ fn main() { }, }; + let mut window_resolution = WindowResolution::new( + config.window.width as f32, + config.window.height as f32, + ); + window_resolution.set_scale_factor_override(if config.window.override_scale_factor { Some(1.0) } else { None }); + App::new() .insert_resource(ClearColor(Color::BLACK)) - .insert_resource(WindowDescriptor { - title: String::from("Slime Simulation"), - width: config.window.width as f32, - height: config.window.height as f32, - resizable: config.window.resizable, - mode: if config.window.fullscreen { WindowMode::Fullscreen } else { WindowMode::Windowed }, - present_mode: if config.window.vsync { PresentMode::AutoVsync } else { PresentMode::AutoNoVsync }, - scale_factor_override: if config.window.override_scale_factor { Some(1.0) } else { None }, - ..default() - }) - .insert_resource(config) - .add_plugins_with(DefaultPlugins, |group| group.add_before::(EmbeddedAssetPlugin)) - .add_plugin(SlimeSimulationPlugin) - .add_startup_system_to_stage( - StartupStage::PostStartup, - setup, + .insert_resource(config.clone()) + .add_plugins(DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: String::from("Slime Simulation"), + resolution: window_resolution, + resizable: config.window.resizable, + mode: if config.window.fullscreen { WindowMode::Fullscreen } else { WindowMode::Windowed }, + present_mode: if config.window.vsync { PresentMode::AutoVsync } else { PresentMode::AutoNoVsync }, + ..default() + }), + ..default() + }) + .build() + .add_before::(EmbeddedAssetPlugin), ) + .add_plugin(SlimeSimulationPlugin) + .add_startup_system(setup.in_base_set(StartupSet::PostStartup)) .add_system(on_window_resize) .run(); } fn setup(mut commands: Commands, images: Res, config: Res) { - commands.spawn_bundle(SpriteBundle { + commands.spawn(SpriteBundle { sprite: Sprite { custom_size: Some(Vec2::new( config.window.width as f32, @@ -64,7 +71,7 @@ fn setup(mut commands: Commands, images: Res, config: Res>, } @@ -95,7 +96,8 @@ fn run_shader( workgroup_size: WorkgroupSize, ) { if let CachedPipelineState::Ok(_) = pipeline_cache.get_compute_pipeline_state(pipeline) { - let mut compute_pass = render_context.command_encoder + let mut compute_pass = render_context + .command_encoder() .begin_compute_pass(&ComputePassDescriptor::default()); compute_pass.set_bind_group(0, bind_group.expect("bind group to exist"), &[]); @@ -124,7 +126,8 @@ fn get_compute_pipeline_id( .queue_compute_pipeline( ComputePipelineDescriptor { label: Some(Cow::from(label)), - layout: Some(vec![bind_group_layout]), + layout: vec![bind_group_layout], + push_constant_ranges: vec![], shader, shader_defs: vec![], entry_point: Cow::from(entry_point), @@ -163,7 +166,7 @@ impl Default for PipelineData { } } -#[derive(Clone, Deref, ExtractResource)] +#[derive(Clone, Deref, ExtractResource, Resource)] pub struct PipelineImages(pub Vec>); #[derive(Default)] diff --git a/src/plugin.rs b/src/plugin.rs index 34647fc..c041038 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,12 +1,13 @@ use bevy::prelude::*; -use bevy::render::{RenderApp, RenderStage}; +use bevy::render::{RenderApp, RenderSet}; use bevy::render::extract_resource::{ExtractResource, ExtractResourcePlugin}; use bevy::render::main_graph::node::CAMERA_DRIVER; use bevy::render::render_asset::RenderAssets; use bevy::render::render_graph::RenderGraph; use bevy::render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages}; use bevy::render::renderer::{RenderDevice, RenderQueue}; -use bevy_inspector_egui::{Inspectable, InspectorPlugin}; +use bevy_inspector_egui::prelude::*; +use bevy_inspector_egui::quick::ResourceInspectorPlugin; use crate::AppConfig; use crate::pipeline::{MainShaderPipeline, PipelineImages, ShaderPipelineNode}; @@ -16,27 +17,23 @@ pub struct SlimeSimulationPlugin; impl Plugin for SlimeSimulationPlugin { fn build(&self, app: &mut App) { app - .add_startup_system(create_images) - .add_plugin(InspectorPlugin::::new()) - .add_plugin(ExtractResourcePlugin::::default()) + .init_resource::() + .register_type::() + .add_plugin(ResourceInspectorPlugin::::default()) .add_plugin(ExtractResourcePlugin::::default()) - .add_plugin(ExtractResourcePlugin::::default()); + .add_plugin(ExtractResourcePlugin::::default()) + .add_plugin(ExtractResourcePlugin::::default()) + .add_startup_system(create_images); let app_config = app.world.get_resource::().cloned().unwrap(); let render_app = app.sub_app_mut(RenderApp); - render_app.insert_resource(app_config); render_app + .insert_resource(app_config) .init_resource::() .init_resource::() - .add_system_to_stage( - RenderStage::Queue, - queue_bind_groups, - ) - .add_system_to_stage( - RenderStage::Prepare, - prepare_data, - ); + .add_system(queue_bind_groups.in_set(RenderSet::Queue)) + .add_system(prepare_data.in_set(RenderSet::Prepare)); let mut render_graph = render_app.world.resource_mut::(); render_graph.add_node( @@ -46,7 +43,7 @@ impl Plugin for SlimeSimulationPlugin { render_graph.add_node_edge( "simulation", CAMERA_DRIVER, - ).unwrap(); + ); } } @@ -94,29 +91,30 @@ fn prepare_data( pipeline.prepare_data(render_queue.as_ref(), app_config.as_ref(), settings.as_ref(), time.as_ref()); } -#[derive(Clone, Inspectable, ExtractResource)] +#[derive(Clone, ExtractResource, InspectorOptions, Reflect, Resource)] +#[reflect(InspectorOptions, Resource)] pub struct SimulationSettings { pub pause: bool, pub num_agents: u32, - #[inspectable(min = 0.1, max = 5.0)] + #[inspector(min = 0.1, max = 5.0)] pub agent_speed: f32, - #[inspectable(min = 0.0, max = 2.0, speed = 0.05)] + #[inspector(min = 0.0, max = 2.0, speed = 0.05)] pub agent_sense_angle_offset: f32, - #[inspectable(min = 0.0, max = 30.0)] + #[inspector(min = 0.0, max = 30.0)] pub agent_sense_distance: f32, pub agent_turn_speed: f32, - #[inspectable(min = 0.0, max = 2.0, speed = 0.05)] + #[inspector(min = 0.0, max = 2.0, speed = 0.05)] pub agent_turn_randomness: f32, pub color: Color, pub has_trails: bool, - #[inspectable(min = 0.0, max = 5.0, speed = 0.005)] + #[inspector(min = 0.0, max = 5.0, speed = 0.005)] pub fade_rate: f32, - #[inspectable(min = 0, max = 7)] + #[inspector(min = 0, max = 7)] pub blur_radius: u32, } -impl FromWorld for SimulationSettings { - fn from_world(_world: &mut World) -> Self { +impl Default for SimulationSettings { + fn default() -> Self { Self { pause: true, num_agents: 1000000, @@ -133,6 +131,7 @@ impl FromWorld for SimulationSettings { } } +#[derive(Resource)] pub struct PluginTime { pub delta_time: f32, pub time: f32, @@ -144,7 +143,7 @@ impl ExtractResource for PluginTime { fn extract_resource(source: &Self::Source) -> Self { Self { delta_time: source.delta_seconds_f64() as f32, - time: source.seconds_since_startup() as f32, + time: source.elapsed_seconds_f64() as f32, } } }