From 09388527f5423974c3db7f01b40624bab13c50fc Mon Sep 17 00:00:00 2001 From: Jerome Humbert Date: Sat, 22 Jun 2024 20:54:18 +0200 Subject: [PATCH] Run cargo fmt with nightly flags (#346) --- examples/2d.rs | 3 +- examples/activate.rs | 3 +- examples/billboard.rs | 3 +- examples/circle.rs | 3 +- examples/expr.rs | 3 +- examples/firework.rs | 3 +- examples/force_field.rs | 3 +- examples/gradient.rs | 6 +- examples/init.rs | 3 +- examples/instancing.rs | 3 +- examples/lifetime.rs | 3 +- examples/multicam.rs | 3 +- examples/ordering.rs | 1 - examples/portal.rs | 3 +- examples/random.rs | 3 +- examples/ribbon.rs | 1 - examples/spawn.rs | 3 +- examples/spawn_on_command.rs | 3 +- examples/visibility.rs | 3 +- examples/worms.rs | 3 +- gpu_tests/empty_effect.rs | 1 - src/asset.rs | 6 +- src/attributes.rs | 14 ++-- src/bundle.rs | 3 +- src/gradient.rs | 6 +- src/graph/expr.rs | 36 +++++----- src/graph/mod.rs | 7 +- src/graph/node.rs | 3 +- src/lib.rs | 116 +++++++++++++++---------------- src/modifier/accel.rs | 3 +- src/modifier/force.rs | 3 +- src/modifier/kill.rs | 3 +- src/modifier/mod.rs | 12 ++-- src/modifier/output.rs | 40 ++++++----- src/properties.rs | 10 +-- src/render/aligned_buffer_vec.rs | 6 +- src/render/batch.rs | 8 +-- src/render/buffer_table.rs | 11 +-- src/render/effect_cache.rs | 19 +++-- src/render/mod.rs | 21 +++--- src/spawn.rs | 3 +- src/test_utils.rs | 8 +-- src/time.rs | 6 +- 43 files changed, 195 insertions(+), 209 deletions(-) diff --git a/examples/2d.rs b/examples/2d.rs index e22621f9..c8a4ba74 100644 --- a/examples/2d.rs +++ b/examples/2d.rs @@ -12,11 +12,10 @@ use bevy::{ }, sprite::{MaterialMesh2dBundle, Mesh2dHandle}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/activate.rs b/examples/activate.rs index d58950f7..0ad7bfe1 100644 --- a/examples/activate.rs +++ b/examples/activate.rs @@ -18,11 +18,10 @@ use bevy::{ camera::ScalingMode, render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin, }, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/billboard.rs b/examples/billboard.rs index 4432333a..83fdd245 100644 --- a/examples/billboard.rs +++ b/examples/billboard.rs @@ -37,11 +37,10 @@ use bevy::{ camera::Projection, render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin, }, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/circle.rs b/examples/circle.rs index 11f8a008..92b481e1 100644 --- a/examples/circle.rs +++ b/examples/circle.rs @@ -11,11 +11,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - mod texutils; use texutils::make_anim_img; diff --git a/examples/expr.rs b/examples/expr.rs index e64408ba..192ed063 100644 --- a/examples/expr.rs +++ b/examples/expr.rs @@ -12,11 +12,10 @@ use bevy::{ log::LogPlugin, prelude::*, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut app = App::default(); app.add_plugins( diff --git a/examples/firework.rs b/examples/firework.rs index 194e61ca..5213a179 100644 --- a/examples/firework.rs +++ b/examples/firework.rs @@ -23,11 +23,10 @@ use bevy::{ log::LogPlugin, prelude::*, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut app = App::default(); app.add_plugins( diff --git a/examples/force_field.rs b/examples/force_field.rs index edf001d3..9c7e2c13 100644 --- a/examples/force_field.rs +++ b/examples/force_field.rs @@ -20,11 +20,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/gradient.rs b/examples/gradient.rs index a0347379..61a45db8 100644 --- a/examples/gradient.rs +++ b/examples/gradient.rs @@ -1,3 +1,5 @@ +use std::f32::consts::PI; + use bevy::{ core_pipeline::tonemapping::Tonemapping, log::LogPlugin, @@ -6,11 +8,9 @@ use bevy::{ render_resource::WgpuFeatures, settings::WgpuSettings, view::RenderLayers, RenderPlugin, }, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use std::f32::consts::PI; - -use bevy_hanabi::prelude::*; fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); diff --git a/examples/init.rs b/examples/init.rs index c69ab4cd..b7b95f20 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -13,11 +13,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - #[derive(Component)] struct RotateSpeed(pub f32); diff --git a/examples/instancing.rs b/examples/instancing.rs index e2c1b73a..8cbf824c 100644 --- a/examples/instancing.rs +++ b/examples/instancing.rs @@ -10,12 +10,11 @@ #![allow(dead_code)] use bevy::{core_pipeline::tonemapping::Tonemapping, log::LogPlugin, prelude::*}; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; use rand::Rng; -use bevy_hanabi::prelude::*; - #[derive(Default, Resource)] struct InstanceManager { effect: Handle, diff --git a/examples/lifetime.rs b/examples/lifetime.rs index 0d59afd2..c04fc4d0 100644 --- a/examples/lifetime.rs +++ b/examples/lifetime.rs @@ -17,11 +17,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/multicam.rs b/examples/multicam.rs index d83ac894..f89f5251 100644 --- a/examples/multicam.rs +++ b/examples/multicam.rs @@ -8,11 +8,10 @@ use bevy::{ render::{camera::Viewport, view::RenderLayers}, window::WindowResized, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() { let mut app = App::default(); app.add_plugins( diff --git a/examples/ordering.rs b/examples/ordering.rs index 1713c9aa..8c71bcf3 100644 --- a/examples/ordering.rs +++ b/examples/ordering.rs @@ -14,7 +14,6 @@ use bevy::{ log::LogPlugin, prelude::*, }; - use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; diff --git a/examples/portal.rs b/examples/portal.rs index 930d93c0..45615c01 100644 --- a/examples/portal.rs +++ b/examples/portal.rs @@ -16,11 +16,10 @@ use bevy::{ log::LogPlugin, prelude::*, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut app = App::default(); app.add_plugins( diff --git a/examples/random.rs b/examples/random.rs index 41b81ffb..10a04488 100644 --- a/examples/random.rs +++ b/examples/random.rs @@ -7,11 +7,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/ribbon.rs b/examples/ribbon.rs index 26c1ad85..56a39886 100644 --- a/examples/ribbon.rs +++ b/examples/ribbon.rs @@ -7,7 +7,6 @@ use bevy::{ math::vec3, }; use bevy_hanabi::prelude::*; - #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; diff --git a/examples/spawn.rs b/examples/spawn.rs index 701105e4..cc4aabf0 100644 --- a/examples/spawn.rs +++ b/examples/spawn.rs @@ -7,11 +7,10 @@ use bevy::{ RenderPlugin, }, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - /// Set this to `true` to enable WGPU downlevel constraints. This is disabled by /// default to prevent the example from failing to start on devices with a /// monitor resolution larger than the maximum resolution imposed by the diff --git a/examples/spawn_on_command.rs b/examples/spawn_on_command.rs index 8283d50e..67dd12f7 100644 --- a/examples/spawn_on_command.rs +++ b/examples/spawn_on_command.rs @@ -17,11 +17,10 @@ use bevy::{ RenderPlugin, }, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/visibility.rs b/examples/visibility.rs index db67b74c..54dc4cc4 100644 --- a/examples/visibility.rs +++ b/examples/visibility.rs @@ -18,11 +18,10 @@ use bevy::{ prelude::*, render::{render_resource::WgpuFeatures, settings::WgpuSettings, RenderPlugin}, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() -> Result<(), Box> { let mut wgpu_settings = WgpuSettings::default(); wgpu_settings diff --git a/examples/worms.rs b/examples/worms.rs index 46cce9aa..893285c3 100644 --- a/examples/worms.rs +++ b/examples/worms.rs @@ -10,11 +10,10 @@ use bevy::{ math::{vec3, vec4}, prelude::*, }; +use bevy_hanabi::prelude::*; #[cfg(feature = "examples_world_inspector")] use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_hanabi::prelude::*; - fn main() { let mut app = App::default(); app.add_plugins( diff --git a/gpu_tests/empty_effect.rs b/gpu_tests/empty_effect.rs index c3ba13d4..88d350aa 100644 --- a/gpu_tests/empty_effect.rs +++ b/gpu_tests/empty_effect.rs @@ -1,7 +1,6 @@ //! Test that an empty (invalid) bundle doesn't produce any error. use bevy::{app::AppExit, core_pipeline::tonemapping::Tonemapping, log::LogPlugin, prelude::*}; - use bevy_hanabi::prelude::*; #[derive(Default, Resource)] diff --git a/src/asset.rs b/src/asset.rs index 5a9ef8c8..526849e4 100644 --- a/src/asset.rs +++ b/src/asset.rs @@ -1,10 +1,11 @@ +use std::ops::Deref; + use bevy::{ asset::{io::Reader, Asset, AssetLoader, AsyncReadExt, LoadContext}, reflect::Reflect, utils::{default, thiserror::Error, BoxedFuture, HashSet}, }; use serde::{Deserialize, Serialize}; -use std::ops::Deref; use crate::{ modifier::{Modifier, RenderModifier}, @@ -720,9 +721,8 @@ impl AssetLoader for EffectAssetLoader { mod tests { use ron::ser::PrettyConfig; - use crate::*; - use super::*; + use crate::*; #[test] fn add_modifiers() { diff --git a/src/attributes.rs b/src/attributes.rs index a26aa2d5..ac594be9 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -486,7 +486,7 @@ impl std::hash::Hash for AttributeInner { } macro_rules! declare_custom_attr_inner { - ($t: ident, $T: ty, $name: literal, $new_fn: ident) => { + ($t:ident, $T:ty, $name:literal, $new_fn:ident) => { pub const $t: &'static AttributeInner = &AttributeInner::new( Cow::Borrowed($name), Value::Vector(VectorValue::$new_fn(<$T>::ZERO)), @@ -1289,9 +1289,7 @@ impl ParticleLayoutBuilder { /// /// ``` /// # use bevy_hanabi::*; - /// let layout = ParticleLayout::new() - /// .append(Attribute::POSITION) - /// .build(); + /// let layout = ParticleLayout::new().append(Attribute::POSITION).build(); /// ``` pub fn build(mut self) -> ParticleLayout { // Remove duplicates @@ -1575,9 +1573,7 @@ impl ParticleLayout { /// /// ``` /// # use bevy_hanabi::*; - /// let layout = ParticleLayout::new() - /// .append(Attribute::SIZE) - /// .build(); + /// let layout = ParticleLayout::new().append(Attribute::SIZE).build(); /// let has_size = layout.contains(Attribute::SIZE); /// assert!(has_size); /// ``` @@ -1610,11 +1606,11 @@ impl ParticleLayout { #[cfg(test)] mod tests { - use super::*; - use bevy::reflect::TypeRegistration; use naga::{front::wgsl::Frontend, proc::Layouter}; + use super::*; + // Ensure the size and alignment of all types conforms to the WGSL spec by // querying naga as a reference. #[test] diff --git a/src/bundle.rs b/src/bundle.rs index 1a3e4415..50b5846f 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -1,6 +1,7 @@ -use crate::{CompiledParticleEffect, EffectAsset, EffectProperties, ParticleEffect}; use bevy::prelude::*; +use crate::{CompiledParticleEffect, EffectAsset, EffectProperties, ParticleEffect}; + /// A component bundle for a particle effect. /// /// This bundle contains all necessary components for a [`ParticleEffect`] to diff --git a/src/gradient.rs b/src/gradient.rs index d1a32efc..afa99828 100644 --- a/src/gradient.rs +++ b/src/gradient.rs @@ -1,10 +1,11 @@ +use std::hash::{Hash, Hasher}; + use bevy::{ math::{Quat, Vec2, Vec3, Vec3A, Vec4}, reflect::{FromReflect, Reflect}, utils::FloatOrd, }; use serde::{Deserialize, Serialize}; -use std::hash::{Hash, Hasher}; /// Describes a type that can be linearly interpolated between two keys. /// @@ -484,9 +485,8 @@ mod tests { use bevy::reflect::{ReflectRef, Struct}; use rand::{distributions::Standard, prelude::Distribution, rngs::ThreadRng, thread_rng, Rng}; - use crate::test_utils::*; - use super::*; + use crate::test_utils::*; const RED: Vec4 = Vec4::new(1., 0., 0., 1.); const BLUE: Vec4 = Vec4::new(0., 0., 1., 1.); diff --git a/src/graph/expr.rs b/src/graph/expr.rs index 27a07810..752cc8c1 100644 --- a/src/graph/expr.rs +++ b/src/graph/expr.rs @@ -107,13 +107,12 @@ use std::{cell::RefCell, num::NonZeroU32, rc::Rc}; use bevy::{reflect::Reflect, utils::thiserror::Error}; use serde::{Deserialize, Serialize}; +use super::Value; use crate::{ Attribute, ModifierContext, ParticleLayout, Property, PropertyLayout, ScalarType, ToWgslString, ValueType, }; -use super::Value; - /// A one-based ID into a collection of a [`Module`]. type Id = NonZeroU32; @@ -857,7 +856,10 @@ impl Expr { /// # use bevy_hanabi::*; /// // Literal expressions always have a constant, build-time value type. /// let expr = Expr::Literal(LiteralExpr::new(1.)); - /// assert_eq!(expr.value_type(), Some(ValueType::Scalar(ScalarType::Float))); + /// assert_eq!( + /// expr.value_type(), + /// Some(ValueType::Scalar(ScalarType::Float)) + /// ); /// ``` /// /// [`eval()`]: crate::graph::Expr::eval @@ -1910,8 +1912,8 @@ impl ToWgslString for TernaryOperator { /// let init_modifier = SetAttributeModifier::new(Attribute::LIFETIME, expr); /// /// // Create an EffectAsset with the modifier and the Module from the writer -/// let effect = EffectAsset::new(vec![1024], Spawner::rate(32_f32.into()), w.finish()) -/// .init(init_modifier); +/// let effect = +/// EffectAsset::new(vec![1024], Spawner::rate(32_f32.into()), w.finish()).init(init_modifier); /// ``` /// /// [`finish()`]: ExprWriter::finish @@ -2141,7 +2143,9 @@ impl ExprWriter { /// let my_prop = w.add_property("my_prop", 3.0.into()); /// /// // x = max(-3.5 + 1., properties.my_prop) * 0.5 - particle.position; -/// let x = (w.lit(-3.5) + w.lit(1.)).max(w.prop(my_prop)).mul(w.lit(0.5)) +/// let x = (w.lit(-3.5) + w.lit(1.)) +/// .max(w.prop(my_prop)) +/// .mul(w.lit(0.5)) /// .sub(w.attr(Attribute::POSITION)); /// /// let handle: ExprHandle = x.expr(); @@ -2818,8 +2822,8 @@ impl WriterExpr { /// /// // The sum of both vectors `z = x + y;`. /// let z = x.add(y); // == vec2(4., 3.) - /// // -OR- - /// // let z = x + y; + /// // -OR- + /// // let z = x + y; /// ``` #[allow(clippy::should_implement_trait)] #[inline] @@ -2926,8 +2930,8 @@ impl WriterExpr { /// /// // The quotient of both vectors `z = x / y;`. /// let z = x.div(y); // == vec2(3., -0.4) - /// // -OR- - /// // let z = x / y; + /// // -OR- + /// // let z = x / y; /// ``` #[allow(clippy::should_implement_trait)] #[inline] @@ -3111,8 +3115,8 @@ impl WriterExpr { /// /// // The product of both vectors `z = x * y;`. /// let z = x.mul(y); // == vec2(3., -10.) - /// // -OR- - /// // let z = x * y; + /// // -OR- + /// // let z = x * y; /// ``` #[allow(clippy::should_implement_trait)] #[inline] @@ -3195,8 +3199,8 @@ impl WriterExpr { /// /// // The difference of both vectors `z = x - y;`. /// let z = x.sub(y); // == vec2(2., -7.) - /// // -OR- - /// // let z = x - y; + /// // -OR- + /// // let z = x - y; /// ``` #[allow(clippy::should_implement_trait)] #[inline] @@ -3435,10 +3439,10 @@ impl std::ops::Rem for WriterExpr { #[cfg(test)] mod tests { - use crate::{MatrixType, ScalarValue, ShaderWriter, VectorType}; + use bevy::{prelude::*, utils::HashSet}; use super::*; - use bevy::{prelude::*, utils::HashSet}; + use crate::{MatrixType, ScalarValue, ShaderWriter, VectorType}; #[test] fn module() { diff --git a/src/graph/mod.rs b/src/graph/mod.rs index 61c127ad..e4fa1ed4 100644 --- a/src/graph/mod.rs +++ b/src/graph/mod.rs @@ -1619,7 +1619,7 @@ impl From for Value { } macro_rules! impl_scalar_value { - ($t: ty, $sv: ident) => { + ($t:ty, $sv:ident) => { impl From<$t> for Value { fn from(value: $t) -> Self { Self::Scalar(value.into()) @@ -1663,7 +1663,7 @@ impl_scalar_value!(i32, Int); impl_scalar_value!(u32, Uint); macro_rules! impl_vec_value { - ($t: ty, $vt: ident, $cast: tt) => { + ($t:ty, $vt:ident, $cast:tt) => { impl From<$t> for Value { fn from(value: $t) -> Self { Self::Vector(value.into()) @@ -1718,12 +1718,13 @@ impl_vec_value!(UVec4, VEC4U, as_uvec4); #[cfg(test)] mod tests { - use super::*; use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, }; + use super::*; + #[test] fn as_bytes() { // let v = Value::Scalar(true.into()); diff --git a/src/graph/node.rs b/src/graph/node.rs index 503d8ba8..bbf4151c 100644 --- a/src/graph/node.rs +++ b/src/graph/node.rs @@ -773,9 +773,8 @@ equal to one." mod tests { use bevy::prelude::*; - use crate::{EvalContext, ModifierContext, ParticleLayout, PropertyLayout, ShaderWriter}; - use super::*; + use crate::{EvalContext, ModifierContext, ParticleLayout, PropertyLayout, ShaderWriter}; #[test] fn add() { diff --git a/src/lib.rs b/src/lib.rs index ba6b2f08..cb89330a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,61 +64,60 @@ //! # use bevy::prelude::*; //! # use bevy_hanabi::prelude::*; //! fn setup(mut effects: ResMut>) { -//! // Define a color gradient from red to transparent black -//! let mut gradient = Gradient::new(); -//! gradient.add_key(0.0, Vec4::new(1., 0., 0., 1.)); -//! gradient.add_key(1.0, Vec4::splat(0.)); +//! // Define a color gradient from red to transparent black +//! let mut gradient = Gradient::new(); +//! gradient.add_key(0.0, Vec4::new(1., 0., 0., 1.)); +//! gradient.add_key(1.0, Vec4::splat(0.)); //! -//! // Create a new expression module -//! let mut module = Module::default(); +//! // Create a new expression module +//! let mut module = Module::default(); //! -//! // On spawn, randomly initialize the position of the particle -//! // to be over the surface of a sphere of radius 2 units. -//! let init_pos = SetPositionSphereModifier { -//! center: module.lit(Vec3::ZERO), -//! radius: module.lit(0.05), -//! dimension: ShapeDimension::Surface, -//! }; +//! // On spawn, randomly initialize the position of the particle +//! // to be over the surface of a sphere of radius 2 units. +//! let init_pos = SetPositionSphereModifier { +//! center: module.lit(Vec3::ZERO), +//! radius: module.lit(0.05), +//! dimension: ShapeDimension::Surface, +//! }; //! -//! // Also initialize a radial initial velocity to 6 units/sec -//! // away from the (same) sphere center. -//! let init_vel = SetVelocitySphereModifier { -//! center: module.lit(Vec3::ZERO), -//! speed: module.lit(6.), -//! }; +//! // Also initialize a radial initial velocity to 6 units/sec +//! // away from the (same) sphere center. +//! let init_vel = SetVelocitySphereModifier { +//! center: module.lit(Vec3::ZERO), +//! speed: module.lit(6.), +//! }; //! -//! // Initialize the total lifetime of the particle, that is -//! // the time for which it's simulated and rendered. This modifier -//! // is almost always required, otherwise the particles won't show. -//! let lifetime = module.lit(10.); // literal value "10.0" -//! let init_lifetime = SetAttributeModifier::new( -//! Attribute::LIFETIME, lifetime); +//! // Initialize the total lifetime of the particle, that is +//! // the time for which it's simulated and rendered. This modifier +//! // is almost always required, otherwise the particles won't show. +//! let lifetime = module.lit(10.); // literal value "10.0" +//! let init_lifetime = SetAttributeModifier::new(Attribute::LIFETIME, lifetime); //! -//! // Every frame, add a gravity-like acceleration downward -//! let accel = module.lit(Vec3::new(0., -3., 0.)); -//! let update_accel = AccelModifier::new(accel); +//! // Every frame, add a gravity-like acceleration downward +//! let accel = module.lit(Vec3::new(0., -3., 0.)); +//! let update_accel = AccelModifier::new(accel); //! -//! // Create the effect asset -//! let effect = EffectAsset::new( -//! // Maximum number of particles alive at a time -//! vec![32768], -//! // Spawn at a rate of 5 particles per second -//! Spawner::rate(5.0.into()), -//! // Move the expression module into the asset -//! module -//! ) -//! .with_name("MyEffect") -//! .init(init_pos) -//! .init(init_vel) -//! .init(init_lifetime) -//! .update(update_accel) -//! // Render the particles with a color gradient over their -//! // lifetime. This maps the gradient key 0 to the particle spawn -//! // time, and the gradient key 1 to the particle death (10s). -//! .render(ColorOverLifetimeModifier { gradient }); +//! // Create the effect asset +//! let effect = EffectAsset::new( +//! // Maximum number of particles alive at a time +//! vec![32768], +//! // Spawn at a rate of 5 particles per second +//! Spawner::rate(5.0.into()), +//! // Move the expression module into the asset +//! module, +//! ) +//! .with_name("MyEffect") +//! .init(init_pos) +//! .init(init_vel) +//! .init(init_lifetime) +//! .update(update_accel) +//! // Render the particles with a color gradient over their +//! // lifetime. This maps the gradient key 0 to the particle spawn +//! // time, and the gradient key 1 to the particle death (10s). +//! .render(ColorOverLifetimeModifier { gradient }); //! -//! // Insert into the asset system -//! let effect_asset = effects.add(effect); +//! // Insert into the asset system +//! let effect_asset = effects.add(effect); //! } //! ``` //! @@ -132,13 +131,11 @@ //! # use bevy_hanabi::prelude::*; //! # fn spawn_effect(mut commands: Commands) { //! # let effect_asset = Handle::::default(); -//! commands.spawn( -//! ParticleEffectBundle { -//! effect: ParticleEffect::new(effect_asset), -//! transform: Transform::from_translation(Vec3::Y), -//! ..Default::default() -//! }, -//! ); +//! commands.spawn(ParticleEffectBundle { +//! effect: ParticleEffect::new(effect_asset), +//! transform: Transform::from_translation(Vec3::Y), +//! ..Default::default() +//! }); //! # } //! ``` //! @@ -168,6 +165,8 @@ //! some moderate CPU-side control over the simulation and rendering of the //! effect, without having to destroy the effect and re-create a new one. +use std::fmt::Write as _; + #[cfg(feature = "2d")] use bevy::utils::FloatOrd; use bevy::{ @@ -175,7 +174,6 @@ use bevy::{ utils::{thiserror::Error, HashSet}, }; use serde::{Deserialize, Serialize}; -use std::fmt::Write as _; // import without risk of name clashing mod asset; pub mod attributes; @@ -1484,9 +1482,8 @@ mod tests { }; use naga_oil::compose::{Composer, NagaModuleDescriptor, ShaderDefValue}; - use crate::spawn::new_rng; - use super::*; + use crate::spawn::new_rng; const INTS: &[usize] = &[1, 2, 4, 8, 9, 15, 16, 17, 23, 24, 31, 32, 33]; const INTS_POW2: &[usize] = &[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]; @@ -1901,7 +1898,8 @@ else { return c1; } assert_eq!(entity, effect_entity); assert_eq!(particle_effect.handle, Handle::::default()); - // `compile_effects()` cannot update the CompiledParticleEffect because the asset is invalid + // `compile_effects()` cannot update the CompiledParticleEffect because the + // asset is invalid assert_eq!( compiled_particle_effect.asset, Handle::::default() diff --git a/src/modifier/accel.rs b/src/modifier/accel.rs index a6c28fe4..bf8f2bb7 100644 --- a/src/modifier/accel.rs +++ b/src/modifier/accel.rs @@ -312,9 +312,8 @@ impl Modifier for TangentAccelModifier { #[cfg(test)] mod tests { - use crate::{ParticleLayout, Property, PropertyLayout, ToWgslString}; - use super::*; + use crate::{ParticleLayout, Property, PropertyLayout, ToWgslString}; #[test] fn mod_accel() { diff --git a/src/modifier/force.rs b/src/modifier/force.rs index feca2c70..30382aaf 100644 --- a/src/modifier/force.rs +++ b/src/modifier/force.rs @@ -301,9 +301,8 @@ impl Modifier for LinearDragModifier { #[cfg(test)] mod tests { - use crate::{ParticleLayout, PropertyLayout}; - use super::*; + use crate::{ParticleLayout, PropertyLayout}; #[test] fn mod_drag() { diff --git a/src/modifier/kill.rs b/src/modifier/kill.rs index 71a50293..9ad75bde 100644 --- a/src/modifier/kill.rs +++ b/src/modifier/kill.rs @@ -185,9 +185,8 @@ impl Modifier for KillAabbModifier { #[cfg(test)] mod tests { - use crate::{ParticleLayout, PropertyLayout}; - use super::*; + use crate::{ParticleLayout, PropertyLayout}; #[test] fn mod_kill_aabb() { diff --git a/src/modifier/mod.rs b/src/modifier/mod.rs index ed4486aa..88dce25d 100644 --- a/src/modifier/mod.rs +++ b/src/modifier/mod.rs @@ -20,6 +20,11 @@ //! attribute on spawning, or to assign a value to that attribute each frame //! during simulation (update). +use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, +}; + use bevy::{ asset::Handle, math::{UVec2, Vec2, Vec4}, @@ -29,10 +34,6 @@ use bevy::{ }; use bitflags::bitflags; use serde::{Deserialize, Serialize}; -use std::{ - collections::hash_map::DefaultHasher, - hash::{Hash, Hasher}, -}; pub mod accel; pub mod attr; @@ -598,9 +599,8 @@ mod tests { use bevy::prelude::*; use naga::front::wgsl::Frontend; - use crate::{BuiltInOperator, ExprWriter, ScalarType}; - use super::*; + use crate::{BuiltInOperator, ExprWriter, ScalarType}; fn make_test_modifier() -> SetPositionSphereModifier { // We use a dummy module here because we don't care about the values and won't diff --git a/src/modifier/output.rs b/src/modifier/output.rs index 6d8c9e26..094aeefd 100644 --- a/src/modifier/output.rs +++ b/src/modifier/output.rs @@ -1,8 +1,9 @@ //! Modifiers to influence the output (rendering) of each particle. +use std::hash::Hash; + use bevy::prelude::*; use serde::{Deserialize, Serialize}; -use std::hash::Hash; use crate::{ impl_mod_render, Attribute, BoxedModifier, CpuValue, EvalContext, ExprError, ExprHandle, @@ -499,21 +500,29 @@ axis_z = cross(axis_x, axis_y); /// let init_age = SetAttributeModifier::new(Attribute::AGE, age); /// /// // sprite_index = i32(particle.age) % 4; -/// let sprite_index = writer.attr(Attribute::AGE).cast(ScalarType::Int).rem(writer.lit(4i32)).expr(); +/// let sprite_index = writer +/// .attr(Attribute::AGE) +/// .cast(ScalarType::Int) +/// .rem(writer.lit(4i32)) +/// .expr(); /// let update_sprite_index = SetAttributeModifier::new(Attribute::SPRITE_INDEX, sprite_index); /// -/// let asset = EffectAsset::new(vec![32768], Spawner::once(32.0.into(), true), writer.finish()) -/// .with_name("flipbook") -/// .init(init_age) -/// .init(init_lifetime) -/// .update(update_sprite_index) -/// .render(ParticleTextureModifier { -/// texture, -/// sample_mapping: ImageSampleMapping::ModulateOpacityFromR, -/// }) -/// .render(FlipbookModifier { -/// sprite_grid_size: UVec2::new(2, 2), // 4 frames -/// }); +/// let asset = EffectAsset::new( +/// vec![32768], +/// Spawner::once(32.0.into(), true), +/// writer.finish(), +/// ) +/// .with_name("flipbook") +/// .init(init_age) +/// .init(init_lifetime) +/// .update(update_sprite_index) +/// .render(ParticleTextureModifier { +/// texture, +/// sample_mapping: ImageSampleMapping::ModulateOpacityFromR, +/// }) +/// .render(FlipbookModifier { +/// sprite_grid_size: UVec2::new(2, 2), // 4 frames +/// }); /// ``` /// /// # Attributes @@ -697,9 +706,8 @@ impl RoundModifier { #[cfg(test)] mod tests { - use crate::*; - use super::*; + use crate::*; #[test] fn mod_particle_texture() { diff --git a/src/properties.rs b/src/properties.rs index 951070ca..e86b7ef2 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -78,11 +78,11 @@ //! # use bevy_hanabi::*; //! # use bevy::prelude::*; //! fn change_property(mut query: Query<&mut EffectProperties>) { -//! let mut effect_properties = query.single_mut(); -//! let color = Color::RED.as_rgba_u32(); -//! // If the current color is not already Color::RED, it will be updated, and -//! // the properties will be re-uploaded to the GPU. -//! EffectProperties::set_if_changed(effect_properties, "my_color", color.into()); +//! let mut effect_properties = query.single_mut(); +//! let color = Color::RED.as_rgba_u32(); +//! // If the current color is not already Color::RED, it will be updated, and +//! // the properties will be re-uploaded to the GPU. +//! EffectProperties::set_if_changed(effect_properties, "my_color", color.into()); //! } //! ``` //! diff --git a/src/render/aligned_buffer_vec.rs b/src/render/aligned_buffer_vec.rs index 77a92c48..34c08aef 100644 --- a/src/render/aligned_buffer_vec.rs +++ b/src/render/aligned_buffer_vec.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroU64; + use bevy::{ core::{cast_slice, Pod}, log::trace, @@ -9,7 +11,6 @@ use bevy::{ }, }; use copyless::VecHelper; -use std::num::NonZeroU64; use crate::next_multiple_of; @@ -348,9 +349,10 @@ mod tests { #[cfg(all(test, feature = "gpu_tests"))] mod gpu_tests { + use tests::*; + use super::*; use crate::test_utils::MockRenderer; - use tests::*; #[test] fn abv_write() { diff --git a/src/render/batch.rs b/src/render/batch.rs index 73946548..93a056d6 100644 --- a/src/render/batch.rs +++ b/src/render/batch.rs @@ -1,19 +1,17 @@ use std::ops::{Index, Range}; +#[cfg(feature = "2d")] +use bevy::utils::FloatOrd; use bevy::{ prelude::*, render::render_resource::{Buffer, CachedComputePipelineId}, }; -#[cfg(feature = "2d")] -use bevy::utils::FloatOrd; - -use crate::{EffectAsset, EffectShader, ParticleLayout, PropertyLayout}; - use super::{ effect_cache::{DispatchBufferIndices, EffectSlices}, EffectCacheId, GpuCompressedTransform, LayoutFlags, }; +use crate::{EffectAsset, EffectShader, ParticleLayout, PropertyLayout}; /// Data needed to render all batches pertaining to a specific effect. #[derive(Debug, Component)] diff --git a/src/render/buffer_table.rs b/src/render/buffer_table.rs index b5949027..ebd7afd2 100644 --- a/src/render/buffer_table.rs +++ b/src/render/buffer_table.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroU64; + use bevy::{ core::{cast_slice, Pod}, log::trace, @@ -10,7 +12,6 @@ use bevy::{ }, }; use copyless::VecHelper; -use std::num::NonZeroU64; use crate::next_multiple_of; @@ -638,13 +639,15 @@ mod tests { #[cfg(all(test, feature = "gpu_tests"))] mod gpu_tests { - use super::*; - use crate::test_utils::MockRenderer; - use bevy::render::render_resource::BufferSlice; use std::fmt::Write; + + use bevy::render::render_resource::BufferSlice; use tests::*; use wgpu::{BufferView, CommandBuffer}; + use super::*; + use crate::test_utils::MockRenderer; + /// Read data from GPU back into CPU memory. /// /// This call blocks until the data is available on CPU. Used for testing diff --git a/src/render/effect_cache.rs b/src/render/effect_cache.rs index 1049b62f..db1a9a6a 100644 --- a/src/render/effect_cache.rs +++ b/src/render/effect_cache.rs @@ -1,3 +1,10 @@ +use std::{ + cmp::Ordering, + num::NonZeroU64, + ops::Range, + sync::atomic::{AtomicU64, Ordering as AtomicOrdering}, +}; + use bevy::{ asset::Handle, ecs::system::Resource, @@ -6,13 +13,8 @@ use bevy::{ utils::HashMap, }; use bytemuck::cast_slice_mut; -use std::{ - cmp::Ordering, - num::NonZeroU64, - ops::Range, - sync::atomic::{AtomicU64, Ordering as AtomicOrdering}, -}; +use super::buffer_table::BufferTableId; use crate::{ asset::EffectAsset, render::{ @@ -21,8 +23,6 @@ use crate::{ ParticleLayout, PropertyLayout, }; -use super::buffer_table::BufferTableId; - /// Describes all particle groups' slices of particles in the particle buffer /// for a single effect. #[derive(Debug, Clone, PartialEq, Eq)] @@ -901,14 +901,13 @@ mod gpu_tests { use bevy::math::Vec4; + use super::*; use crate::{ graph::{Value, VectorValue}, test_utils::MockRenderer, Attribute, AttributeInner, }; - use super::*; - #[test] fn effect_slice_ord() { let particle_layout = ParticleLayout::new().append(Attribute::POSITION).build(); diff --git a/src/render/mod.rs b/src/render/mod.rs index d34ce12b..7dd7765b 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,3 +1,13 @@ +use std::{ + borrow::Cow, + num::{NonZeroU32, NonZeroU64}, +}; +use std::{iter, marker::PhantomData}; + +#[cfg(feature = "2d")] +use bevy::core_pipeline::core_2d::Transparent2d; +#[cfg(feature = "3d")] +use bevy::core_pipeline::core_3d::{AlphaMask3d, Transparent3d}; #[cfg(feature = "2d")] use bevy::utils::FloatOrd; use bevy::{ @@ -27,16 +37,6 @@ use bitflags::bitflags; use fixedbitset::FixedBitSet; use naga_oil::compose::{Composer, NagaModuleDescriptor}; use rand::random; -use std::{ - borrow::Cow, - num::{NonZeroU32, NonZeroU64}, -}; -use std::{iter, marker::PhantomData}; - -#[cfg(feature = "2d")] -use bevy::core_pipeline::core_2d::Transparent2d; -#[cfg(feature = "3d")] -use bevy::core_pipeline::core_3d::{AlphaMask3d, Transparent3d}; use crate::{ asset::EffectAsset, @@ -59,7 +59,6 @@ mod shader_cache; use aligned_buffer_vec::AlignedBufferVec; use buffer_table::{BufferTable, BufferTableId}; pub(crate) use effect_cache::{EffectCache, EffectCacheId}; - pub use shader_cache::ShaderCache; use self::batch::EffectBatches; diff --git a/src/spawn.rs b/src/spawn.rs index e91d1f09..9943a476 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -685,9 +685,8 @@ mod test { tasks::{IoTaskPool, TaskPoolBuilder}, }; - use crate::Module; - use super::*; + use crate::Module; /// Make an `EffectSpawner` wrapping a `Spawner`. fn make_effect_spawner(spawner: Spawner) -> EffectSpawner { diff --git a/src/test_utils.rs b/src/test_utils.rs index 8fbf1e66..24ff8006 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,8 +1,8 @@ -#[cfg(feature = "gpu_tests")] -use bevy::render::renderer::{RenderDevice, RenderQueue}; +use std::ops::Sub; use bevy::prelude::{Quat, Vec2, Vec3, Vec4}; -use std::ops::Sub; +#[cfg(feature = "gpu_tests")] +use bevy::render::renderer::{RenderDevice, RenderQueue}; /// Utility trait to compare floating-point values with a tolerance. pub(crate) trait AbsDiffEq { @@ -90,7 +90,7 @@ impl AbsDiffEq for Quat { /// /// ``` /// let x = 3.500009; -/// assert_approx_eq!(x, 3.5); // default tolerance 1e-5 +/// assert_approx_eq!(x, 3.5); // default tolerance 1e-5 /// /// let x = 3.509; /// assert_approx_eq!(x, 3.5, 0.01); // explicit tolerance diff --git a/src/time.rs b/src/time.rs index 4844601d..b1cafa5f 100644 --- a/src/time.rs +++ b/src/time.rs @@ -183,10 +183,12 @@ pub(crate) fn effect_simulation_time_system( #[cfg(test)] mod tests { - use super::*; - use bevy::time::{virtual_time_system, TimePlugin, TimeSystem}; use std::{thread::sleep, time::Duration}; + use bevy::time::{virtual_time_system, TimePlugin, TimeSystem}; + + use super::*; + fn make_test_app() -> App { let mut app = App::new();