From cf36a87074bf2fe5e2414d6372fb4e7a3c6672fb Mon Sep 17 00:00:00 2001 From: Patrick Dobbs Date: Sat, 7 Dec 2024 01:07:54 +0000 Subject: [PATCH] Update to Bevy 0.15 (#74) Co-authored-by: Hennadii Chernyshchyk --- Cargo.toml | 9 ++++--- README.md | 1 + deny.toml | 19 ++++++++------ examples/basic.rs | 2 +- examples/cycle.rs | 56 ++++++++++++++++++----------------------- examples/detection.rs | 2 +- examples/gradient.rs | 6 +---- examples/models.rs | 6 +---- examples/nishita.rs | 6 +---- examples/settings.rs | 10 +------- examples/splitscreen.rs | 52 +++++++++++++++++--------------------- macros/Cargo.toml | 4 +-- macros/src/model.rs | 1 + src/lib.rs | 2 +- src/pipeline.rs | 21 ++++++++-------- src/plugin.rs | 15 +++-------- src/system_param.rs | 6 ++--- 17 files changed, 92 insertions(+), 126 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a46983d..7cbdff3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,17 +11,18 @@ repository = "https://github.com/JonahPlusPlus/bevy_atmosphere" exclude = ["/assets/", "/examples/", "/.github/"] [dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "bevy_asset", "bevy_render", "bevy_pbr", + "png", # Enable temporary due to 0.15 bug: https://github.com/bevyengine/bevy/issues/16563 ] } -bevy_atmosphere_macros = { path = "macros", version = "0.6" } +bevy_atmosphere_macros = { path = "macros", version = "0.7" } cfg-if = "1.0" [dev-dependencies] -bevy_spectator = "0.6" -bevy = { version = "0.14", features = ["bevy_core_pipeline", "x11"] } +bevy_spectator = "0.7" +bevy = { version = "0.15", features = ["bevy_core_pipeline", "x11"] } [features] default = ["basic", "all_models"] diff --git a/README.md b/README.md index a8d4215..72e309d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ For more information on the technicalities, you can check out the [technical doc | bevy | bevy_atmosphere | |------|-----------------| +| 0.15 | 0.11 | | 0.14 | 0.10 | | 0.13 | 0.9 | | 0.12 | 0.8 | diff --git a/deny.toml b/deny.toml index 0c89c3f..b529b5a 100644 --- a/deny.toml +++ b/deny.toml @@ -1,11 +1,16 @@ -[advisories] -unmaintained = "deny" -yanked = "deny" -notice = "deny" - [licenses] -copyleft = "deny" -allow-osi-fsf-free = "either" +allow = [ + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "BSL-1.0", + "CC0-1.0", + "ISC", + "MIT-0", + "MIT", + "Unicode-3.0", + "Zlib", +] [[licenses.clarify]] name = "stretch" diff --git a/examples/basic.rs b/examples/basic.rs index 32999fe..6028b18 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -10,5 +10,5 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn((Camera3dBundle::default(), AtmosphereCamera::default())); + commands.spawn((Camera3d::default(), AtmosphereCamera::default())); } diff --git a/examples/cycle.rs b/examples/cycle.rs index c93449f..ad7b328 100644 --- a/examples/cycle.rs +++ b/examples/cycle.rs @@ -4,7 +4,6 @@ use bevy_spectator::{Spectator, SpectatorPlugin}; fn main() { App::new() - .insert_resource(Msaa::Sample4) .insert_resource(AtmosphereModel::default()) // Default Atmosphere material, we can edit it to simulate another planet .insert_resource(CycleTimer(Timer::new( bevy::utils::Duration::from_millis(50), // Update our atmosphere every 50ms (in a real game, this would be much slower, but for the sake of an example we use a faster update) @@ -38,7 +37,7 @@ fn daylight_cycle( timer.0.tick(time.delta()); if timer.0.finished() { - let t = time.elapsed_seconds_wrapped() / 2.0; + let t = time.elapsed_secs_wrapped() / 2.0; atmosphere.sun_position = Vec3::new(0., t.sin(), t.cos()); if let Some((mut light_trans, mut directional)) = query.single_mut().into() { @@ -56,49 +55,42 @@ fn setup_environment( ) { // Our Sun commands.spawn(( - DirectionalLightBundle { - ..Default::default() - }, + DirectionalLight::default(), Sun, // Marks the light as Sun )); // Simple transform shape just for reference - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::default()), - material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.8, 0.8))), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::default())), + MeshMaterial3d(materials.add(StandardMaterial::from(Color::srgb(0.8, 0.8, 0.8)))), + )); // X axis - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.0, 0.0))), - transform: Transform::from_xyz(1., 0., 0.), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))), + MeshMaterial3d(materials.add(StandardMaterial::from(Color::srgb(0.8, 0.0, 0.0)))), + Transform::from_xyz(1., 0., 0.), + )); // Y axis - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::srgb(0.0, 0.8, 0.0))), - transform: Transform::from_xyz(0., 1., 0.), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))), + MeshMaterial3d(materials.add(StandardMaterial::from(Color::srgb(0.0, 0.8, 0.0)))), + Transform::from_xyz(0., 1., 0.), + )); // Z axis - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)), - material: materials.add(StandardMaterial::from(Color::srgb(0.0, 0.0, 0.8))), - transform: Transform::from_xyz(0., 0., 1.), - ..Default::default() - }); + commands.spawn(( + Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))), + MeshMaterial3d(materials.add(StandardMaterial::from(Color::srgb(0.0, 0.0, 0.8)))), + Transform::from_xyz(0., 0., 1.), + )); // Spawn our camera commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(5., 0., 5.), - ..default() - }, + Camera3d::default(), + Transform::from_xyz(5., 0., 5.), + Msaa::Sample4, AtmosphereCamera::default(), // Marks camera as having a skybox, by default it doesn't specify the render layers the skybox can be seen on Spectator, // Marks camera as spectator (specific to bevy_spectator) )); diff --git a/examples/detection.rs b/examples/detection.rs index 18b858c..f9d076a 100644 --- a/examples/detection.rs +++ b/examples/detection.rs @@ -14,7 +14,7 @@ fn main() { struct PrimaryCamera; fn setup(mut commands: Commands) { - commands.spawn((Camera3dBundle::default(), PrimaryCamera)); + commands.spawn((Camera3d::default(), PrimaryCamera)); } fn update( diff --git a/examples/gradient.rs b/examples/gradient.rs index 6b6ba34..4addfd7 100644 --- a/examples/gradient.rs +++ b/examples/gradient.rs @@ -14,11 +14,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn(( - Camera3dBundle::default(), - AtmosphereCamera::default(), - Spectator, - )); + commands.spawn((Camera3d::default(), AtmosphereCamera::default(), Spectator)); } fn change_gradient(mut commands: Commands, keys: Res>) { diff --git a/examples/models.rs b/examples/models.rs index 6ec35d1..4e0fab5 100644 --- a/examples/models.rs +++ b/examples/models.rs @@ -13,11 +13,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn(( - Camera3dBundle::default(), - AtmosphereCamera::default(), - Spectator, - )); + commands.spawn((Camera3d::default(), AtmosphereCamera::default(), Spectator)); } fn change_model(mut commands: Commands, keys: Res>) { diff --git a/examples/nishita.rs b/examples/nishita.rs index eb41bdb..1e4b4bb 100644 --- a/examples/nishita.rs +++ b/examples/nishita.rs @@ -12,11 +12,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn(( - Camera3dBundle::default(), - AtmosphereCamera::default(), - Spectator, - )); + commands.spawn((Camera3d::default(), AtmosphereCamera::default(), Spectator)); } fn change_nishita(mut commands: Commands, keys: Res>) { diff --git a/examples/settings.rs b/examples/settings.rs index 36e049b..5876b30 100644 --- a/examples/settings.rs +++ b/examples/settings.rs @@ -16,11 +16,7 @@ fn main() { } fn setup(mut commands: Commands) { - commands.spawn(( - Camera3dBundle::default(), - AtmosphereCamera::default(), - Spectator, - )); + commands.spawn((Camera3d::default(), AtmosphereCamera::default(), Spectator)); } // Change the resolution when the user presses a number key @@ -30,8 +26,6 @@ fn change_resolution( keys: Res>, ) { if keys.just_pressed(KeyCode::Space) { - #[cfg(feature = "bevy/trace")] - // enabling "bevy/trace" (via "bevy/trace_chrome" or "bevy/trace_tracy") allows you to debug bevy_atmosphere let _change_dithering_executed_span = info_span!("executed", name = "settings::change_dithering").entered(); if let Some(mut settings) = settings { @@ -69,8 +63,6 @@ fn change_resolution( // A separate `change` fn makes it easier to debug in tracy. fn change(mut commands: Commands, settings: Option>, resolution: u32) { - #[cfg(feature = "bevy/trace")] - // enabling "bevy/trace" (via "bevy/trace_chrome" or "bevy/trace_tracy") allows you to debug bevy_atmosphere let _change_resolution_executed_span = info_span!("executed", name = "settings::change_resolution").entered(); if let Some(mut settings) = settings { diff --git a/examples/splitscreen.rs b/examples/splitscreen.rs index 052c412..41d797d 100644 --- a/examples/splitscreen.rs +++ b/examples/splitscreen.rs @@ -12,7 +12,6 @@ use bevy_spectator::{Spectator, SpectatorPlugin, SpectatorSettings}; fn main() { println!("Demonstrates using `AtmosphereCamera.render_layers` to have multiple skyboxes in the scene at once\n\t- E: Switch camera"); App::new() - .insert_resource(Msaa::Sample4) .insert_resource(AtmosphereModel::new(Nishita { rayleigh_coefficient: Vec3::new(22.4e-6, 5.5e-6, 13.0e-6), // Change rayleigh coefficient to change color ..default() @@ -36,34 +35,31 @@ fn setup( mut settings: ResMut, ) { // Plane - commands.spawn(PbrBundle { - mesh: meshes.add(Plane3d::default().mesh().size(100.0, 100.0)), - material: materials.add(Color::srgb(0.3, 0.5, 0.3)), - ..default() - }); + commands.spawn(( + Mesh3d(meshes.add(Plane3d::default().mesh().size(100.0, 100.0))), + MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), + )); // Light - commands.spawn(DirectionalLightBundle { - transform: Transform::from_rotation(Quat::from_euler( + commands.spawn(( + DirectionalLight { + shadows_enabled: true, + ..default() + }, + Transform::from_rotation(Quat::from_euler( EulerRot::ZYX, 0.0, 1.0, -std::f32::consts::FRAC_PI_4, )), - directional_light: DirectionalLight { - shadows_enabled: true, - ..default() - }, - ..default() - }); + )); // Spawn left screen camera and make it the default spectator let left = commands .spawn(( - Camera3dBundle { - transform: Transform::from_xyz(0.0, 25.0, -100.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }, + Camera3d::default(), + Transform::from_xyz(0.0, 25.0, -100.0).looking_at(Vec3::ZERO, Vec3::Y), + Msaa::Sample4, RenderLayers::from_layers(&[0, 1]), // To prevent each player from seeing the other skybox, we put each one on a separate render layer (you could also use this render layer for other player specific effects) AtmosphereCamera { render_layers: Some(RenderLayers::layer(1)), @@ -77,19 +73,17 @@ fn setup( // Spawn right screen camera commands.spawn(( - Camera3dBundle { - transform: Transform::from_xyz(100.0, 50.0, 150.0).looking_at(Vec3::ZERO, Vec3::Y), - camera: Camera { - // Renders the right camera after the left camera, which has a default priority of 0 - order: 1, - // Don't clear on the second camera because the first camera already cleared the window - clear_color: ClearColorConfig::None, - ..default() - }, - camera_3d: Camera3d::default(), + Camera { + // Renders the right camera after the left camera, which has a default priority of 0 + order: 1, + // Don't clear on the second camera because the first camera already cleared the window + clear_color: ClearColorConfig::None, ..default() }, - RenderLayers::from_layers(&[0, 2]), + Camera3d::default(), + Transform::from_xyz(100.0, 50.0, 150.0).looking_at(Vec3::ZERO, Vec3::Y), + Msaa::Sample4, + RenderLayers::from_layers(&[0, 2]), // To prevent each player from seeing the other skybox, we put each one on a separate render layer (you could also use this render layer for other player specific effects) AtmosphereCamera { render_layers: Some(RenderLayers::layer(2)), }, diff --git a/macros/Cargo.toml b/macros/Cargo.toml index a900cab..495dd95 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_atmosphere_macros" description = "Proc macros for bevy_atmosphere" -version = "0.6.0" +version = "0.7.0" edition = "2021" authors = ["JonahPlusPlus <33059163+JonahPlusPlus@users.noreply.github.com>"] license = "MIT OR Apache-2.0" @@ -15,7 +15,7 @@ proc-macro = true [dependencies] proc-macro-crate = "3.1" -bevy_macro_utils = "0.14" +bevy_macro_utils = "0.15" syn = "2.0" proc-macro2 = "1.0" diff --git a/macros/src/model.rs b/macros/src/model.rs index c95ffac..0116449 100644 --- a/macros/src/model.rs +++ b/macros/src/model.rs @@ -467,6 +467,7 @@ pub fn derive_atmospheric(ast: syn::DeriveInput) -> Result { shader: handle, shader_defs: vec![], entry_point: Cow::from("main"), + zero_initialize_workgroup_memory: true, }); let id = TypeId::of::(); diff --git a/src/lib.rs b/src/lib.rs index b5e249a..8962e95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! } //! //! fn setup(mut commands: Commands) { -//! commands.spawn((Camera3dBundle::default(), AtmosphereCamera::default())); +//! commands.spawn((Camera3d::default(), AtmosphereCamera::default())); //! } //! ``` //! diff --git a/src/pipeline.rs b/src/pipeline.rs index 84cfad5..c18eeee 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -165,7 +165,6 @@ fn atmosphere_settings_changed( ) { if let Some(settings) = settings { if settings.is_changed() { - #[cfg(feature = "bevy/trace")] let _atmosphere_settings_changed_executed_span = info_span!( "executed", name = "bevy_atmosphere::pipeline::atmosphere_settings_changed" @@ -186,14 +185,12 @@ fn atmosphere_settings_changed( skybox_material.dithering = settings.dithering; } atmosphere_image.array_view = None; // drop the previous texture view - #[cfg(feature = "bevy/trace")] trace!("Resized image to {:?}", size); } } *settings_existed = true; } else { if *settings_existed { - #[cfg(feature = "bevy/trace")] let _atmosphere_settings_changed_executed_span = info_span!( "executed", name = "bevy_atmosphere::pipeline::atmosphere_settings_changed" @@ -212,7 +209,6 @@ fn atmosphere_settings_changed( image.resize(size); let _ = material_assets.get_mut(&material.0); // `get_mut` tells the material to update atmosphere_image.array_view = None; // drop the previous texture view - #[cfg(feature = "bevy/trace")] trace!("Resized image to {:?}", size); } } @@ -330,7 +326,6 @@ fn prepare_atmosphere_resources( let mut update = || update_events.send(AtmosphereUpdateEvent); if atmosphere_image.array_view.is_none() { - #[cfg(feature = "bevy/trace")] let _prepare_atmosphere_assets_executed_span = info_span!( "executed", name = "bevy_atmosphere::pipeline::prepare_atmosphere_assets" @@ -340,11 +335,17 @@ fn prepare_atmosphere_resources( let view = texture.create_view(&ATMOSPHERE_ARRAY_TEXTURE_VIEW_DESCRIPTOR); atmosphere_image.array_view = Some(view); update(); - #[cfg(feature = "bevy/trace")] - trace!( - "Created new 2D array texture view from atmosphere texture of size {:?}", - &gpu_images[&atmosphere_image.handle].size - ); + if let Some(image) = gpu_images.get(&atmosphere_image.handle) { + trace!( + "Created new 2D array texture view from atmosphere texture of size {:?}", + image.size + ); + } else { + trace!( + "Failed to find gpu_image for {:?}", + &atmosphere_image.handle + ); + } } if atmosphere.is_changed() { diff --git a/src/plugin.rs b/src/plugin.rs index 0e07260..c7c5242 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -105,21 +105,14 @@ fn atmosphere_insert( atmosphere_cameras: Query<(Entity, &Projection, &AtmosphereCamera), Added>, ) { for (camera, projection, atmosphere_camera) in &atmosphere_cameras { - #[cfg(feature = "bevy/trace")] trace!("Adding skybox to camera entity (ID:{:?})", camera); commands .entity(camera) - .insert(VisibilityBundle { - visibility: Visibility::Visible, - ..default() - }) + .insert(Visibility::Visible) .with_children(|c| { let mut child = c.spawn(( - MaterialMeshBundle { - mesh: mesh_assets.add(crate::skybox::mesh(projection.far())), - material: material.0.clone(), - ..default() - }, + Mesh3d(mesh_assets.add(crate::skybox::mesh(projection.far()))), + MeshMaterial3d(material.0.clone()), AtmosphereSkyBox, NotShadowCaster, NotShadowReceiver, @@ -144,7 +137,6 @@ fn atmosphere_remove( mut atmosphere_cameras: RemovedComponents, ) { for camera in &mut atmosphere_cameras.read() { - #[cfg(feature = "bevy/trace")] trace!("Removing skybox from camera entity (ID:{:?})", camera); let Ok(children) = parents.get(camera) else { error!("Failed to get skybox children entities from camera entity."); @@ -153,7 +145,6 @@ fn atmosphere_remove( for child in children { let Ok(skybox_entity) = atmosphere_skyboxes.get(*child) else { - #[cfg(feature = "bevy/trace")] trace!("Child wasn't found in skybox entities."); continue; }; diff --git a/src/system_param.rs b/src/system_param.rs index 5faa99b..f69ef9d 100644 --- a/src/system_param.rs +++ b/src/system_param.rs @@ -21,7 +21,7 @@ pub struct Atmosphere<'w, T: Atmospheric> { // SAFETY: Res only reads a single World resource unsafe impl ReadOnlySystemParam for Atmosphere<'_, T> {} -impl<'w, T: Atmospheric> Deref for Atmosphere<'w, T> { +impl Deref for Atmosphere<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -63,7 +63,7 @@ pub struct AtmosphereMut<'w, T: Atmospheric> { value: &'w mut T, } -impl<'w, T: Atmospheric> Deref for AtmosphereMut<'w, T> { +impl Deref for AtmosphereMut<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -71,7 +71,7 @@ impl<'w, T: Atmospheric> Deref for AtmosphereMut<'w, T> { } } -impl<'w, T: Atmospheric> DerefMut for AtmosphereMut<'w, T> { +impl DerefMut for AtmosphereMut<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { self.value }