From 7212b70478c8465b178611794d5738703eb9f6f1 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 28 Jul 2020 14:24:03 -0700 Subject: [PATCH] rustfmt changes --- crates/bevy_asset/src/load_request.rs | 1 + crates/bevy_audio/src/audio_source.rs | 1 + crates/bevy_core/src/bytes.rs | 3 ++ crates/bevy_core/src/float_ord.rs | 1 + crates/bevy_core/src/time/timer.rs | 1 + crates/bevy_ecs/hecs/src/borrow.rs | 2 + crates/bevy_ecs/hecs/src/query.rs | 25 +++++++++- crates/bevy_ecs/hecs/src/world.rs | 2 + .../bevy_ecs/src/resource/resource_query.rs | 6 +++ .../src/schedule/parallel_executor.rs | 1 + crates/bevy_ecs/src/system/into_system.rs | 1 + crates/bevy_gltf/src/loader.rs | 1 + crates/bevy_math/src/geometry.rs | 22 ++++++--- .../bevy_property/src/dynamic_properties.rs | 5 ++ .../src/impl_property/impl_property_std.rs | 10 ++++ crates/bevy_property/src/properties.rs | 2 + crates/bevy_property/src/property_serde.rs | 8 ++++ crates/bevy_render/src/camera/projection.rs | 2 + crates/bevy_render/src/color.rs | 14 ++++-- crates/bevy_render/src/draw.rs | 3 ++ crates/bevy_render/src/mesh/mesh.rs | 2 +- crates/bevy_render/src/render_graph/graph.rs | 1 + .../bevy_render/src/render_graph/node_slot.rs | 1 + .../nodes/render_resources_node.rs | 1 + .../nodes/window_swapchain_node.rs | 1 + .../render_graph/nodes/window_texture_node.rs | 1 + .../bevy_render/src/render_graph/schedule.rs | 1 + .../headless_render_resource_context.rs | 23 +++++++++ .../render_resource/render_resource.rs | 7 +++ .../src/renderer/render_resource_context.rs | 2 + crates/bevy_render/src/shader/shader.rs | 1 + crates/bevy_render/src/shader/shader_defs.rs | 1 + .../src/texture/hdr_texture_loader.rs | 1 + .../src/texture/image_texture_loader.rs | 1 + crates/bevy_render/src/texture/texture.rs | 6 +++ crates/bevy_scene/src/loaded_scenes.rs | 1 + crates/bevy_scene/src/serde.rs | 6 +++ crates/bevy_text/src/font_loader.rs | 1 + .../bevy_transform/src/components/children.rs | 1 + .../src/components/local_transform.rs | 1 + .../src/components/non_uniform_scale.rs | 1 + .../bevy_transform/src/components/parent.rs | 1 + .../bevy_transform/src/components/rotation.rs | 1 + crates/bevy_transform/src/components/scale.rs | 1 + .../src/components/translation.rs | 1 + .../src/hierarchy/child_builder.rs | 3 ++ crates/bevy_ui/src/anchors.rs | 24 +++++----- crates/bevy_ui/src/entity.rs | 5 +- crates/bevy_ui/src/node.rs | 7 +-- crates/bevy_ui/src/widget/mod.rs | 4 +- .../wgpu_resource_diagnostics_plugin.rs | 47 +++++++------------ .../src/renderer/wgpu_render_context.rs | 1 + .../renderer/wgpu_render_resource_context.rs | 3 ++ examples/2d/texture_atlas.rs | 3 +- examples/scene/properties.rs | 2 +- examples/ui/font_atlas_debug.rs | 2 +- examples/window/multiple_windows.rs | 2 +- rustfmt.toml | 4 +- 58 files changed, 216 insertions(+), 67 deletions(-) diff --git a/crates/bevy_asset/src/load_request.rs b/crates/bevy_asset/src/load_request.rs index faffb2fcc8..2054654086 100644 --- a/crates/bevy_asset/src/load_request.rs +++ b/crates/bevy_asset/src/load_request.rs @@ -61,6 +61,7 @@ where .send(asset_result) .expect("loaded asset should have been sent"); } + fn extensions(&self) -> &[&str] { self.loader.extensions() } diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 8a7060def4..b3d4a20d03 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -22,6 +22,7 @@ impl AssetLoader for Mp3Loader { bytes: Arc::new(bytes), }) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["mp3"]; EXTENSIONS diff --git a/crates/bevy_core/src/bytes.rs b/crates/bevy_core/src/bytes.rs index 0fdb6a38f7..f77d8128ec 100644 --- a/crates/bevy_core/src/bytes.rs +++ b/crates/bevy_core/src/bytes.rs @@ -102,6 +102,7 @@ impl Bytes for Mat4 { let array = self.to_cols_array(); array.write_bytes(buffer); } + fn byte_len(&self) -> usize { std::mem::size_of::() } @@ -123,6 +124,7 @@ where val.write_bytes(buffer) } } + fn byte_len(&self) -> usize { self.as_ref().map_or(0, |val| val.byte_len()) } @@ -149,6 +151,7 @@ where let bytes = self.as_slice().as_bytes(); buffer[0..self.byte_len()].copy_from_slice(bytes) } + fn byte_len(&self) -> usize { self.as_slice().as_bytes().len() } diff --git a/crates/bevy_core/src/float_ord.rs b/crates/bevy_core/src/float_ord.rs index ed75780c87..46d6042c01 100644 --- a/crates/bevy_core/src/float_ord.rs +++ b/crates/bevy_core/src/float_ord.rs @@ -43,6 +43,7 @@ impl Hash for FloatOrd { impl Neg for FloatOrd { type Output = FloatOrd; + fn neg(self) -> Self::Output { FloatOrd(-self.0) } diff --git a/crates/bevy_core/src/time/timer.rs b/crates/bevy_core/src/time/timer.rs index 2e0fff520d..fc5efc576e 100644 --- a/crates/bevy_core/src/time/timer.rs +++ b/crates/bevy_core/src/time/timer.rs @@ -17,6 +17,7 @@ impl Timer { ..Default::default() } } + pub fn new(duration: Duration) -> Self { Timer { duration: duration.as_secs_f32(), diff --git a/crates/bevy_ecs/hecs/src/borrow.rs b/crates/bevy_ecs/hecs/src/borrow.rs index 9220324123..41b1cc4966 100644 --- a/crates/bevy_ecs/hecs/src/borrow.rs +++ b/crates/bevy_ecs/hecs/src/borrow.rs @@ -97,6 +97,7 @@ impl<'a, T: Component> Drop for Ref<'a, T> { impl<'a, T: Component> Deref for Ref<'a, T> { type Target = T; + fn deref(&self) -> &T { unsafe { self.target.as_ref() } } @@ -153,6 +154,7 @@ impl<'a, T: Component> Drop for RefMut<'a, T> { impl<'a, T: Component> Deref for RefMut<'a, T> { type Target = T; + fn deref(&self) -> &T { unsafe { self.target.as_ref() } } diff --git a/crates/bevy_ecs/hecs/src/query.rs b/crates/bevy_ecs/hecs/src/query.rs index e0edf0241c..4734928b91 100644 --- a/crates/bevy_ecs/hecs/src/query.rs +++ b/crates/bevy_ecs/hecs/src/query.rs @@ -81,18 +81,22 @@ impl Query for Entity { impl<'a> Fetch<'a> for EntityFetch { type Item = Entity; + #[inline] fn access(_archetype: &Archetype) -> Option { Some(Access::Iterate) } + #[inline] fn borrow(_archetype: &Archetype) {} + #[inline] unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { Some(EntityFetch(NonNull::new_unchecked( archetype.entities().as_ptr().add(offset), ))) } + #[inline] fn release(_archetype: &Archetype) {} @@ -125,11 +129,13 @@ impl<'a, T: Component> Fetch<'a> for FetchRead { fn borrow(archetype: &Archetype) { archetype.borrow::(); } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { archetype .get::() .map(|x| Self(NonNull::new_unchecked(x.as_ptr().add(offset)))) } + fn release(archetype: &Archetype) { archetype.release::(); } @@ -161,6 +167,7 @@ unsafe impl Sync for Mut<'_, T> {} impl<'a, T: Component> Deref for Mut<'a, T> { type Target = T; + #[inline] fn deref(&self) -> &T { self.value @@ -195,6 +202,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut { fn borrow(archetype: &Archetype) { archetype.borrow_mut::(); } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { archetype .get_with_mutated::() @@ -205,6 +213,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut { ) }) } + fn release(archetype: &Archetype) { archetype.release_mut::(); } @@ -229,6 +238,7 @@ pub struct Mutated<'a, T> { impl<'a, T: Component> Deref for Mutated<'a, T> { type Target = T; + #[inline] fn deref(&self) -> &T { self.value @@ -256,6 +266,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated { fn borrow(archetype: &Archetype) { archetype.borrow::(); } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { archetype .get_with_mutated::() @@ -266,6 +277,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated { ) }) } + fn release(archetype: &Archetype) { archetype.release::(); } @@ -291,6 +303,7 @@ pub struct Added<'a, T> { impl<'a, T: Component> Deref for Added<'a, T> { type Target = T; + #[inline] fn deref(&self) -> &T { self.value @@ -318,6 +331,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded { fn borrow(archetype: &Archetype) { archetype.borrow::(); } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { archetype.get_with_added::().map(|(components, added)| { Self( @@ -326,6 +340,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded { ) }) } + fn release(archetype: &Archetype) { archetype.release::(); } @@ -351,6 +366,7 @@ pub struct Changed<'a, T> { impl<'a, T: Component> Deref for Changed<'a, T> { type Target = T; + #[inline] fn deref(&self) -> &T { self.value @@ -390,6 +406,7 @@ impl<'a, T: Component> Fetch<'a> for FetchChanged { ) }) } + fn release(archetype: &Archetype) { archetype.release::(); } @@ -422,9 +439,11 @@ impl<'a, T: Fetch<'a>> Fetch<'a> for TryFetch { fn borrow(archetype: &Archetype) { T::borrow(archetype) } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { Some(Self(T::get(archetype, offset))) } + fn release(archetype: &Archetype) { T::release(archetype) } @@ -478,12 +497,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWithout { fn borrow(archetype: &Archetype) { F::borrow(archetype) } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { if archetype.has::() { return None; } Some(Self(F::get(archetype, offset)?, PhantomData)) } + fn release(archetype: &Archetype) { F::release(archetype) } @@ -539,12 +560,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWith { fn borrow(archetype: &Archetype) { F::borrow(archetype) } + unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option { if !archetype.has::() { return None; } Some(Self(F::get(archetype, offset)?, PhantomData)) } + fn release(archetype: &Archetype) { F::release(archetype) } @@ -693,8 +716,8 @@ impl<'w, Q: Query> Drop for QueryBorrow<'w, Q> { } impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q> { - type Item = >::Item; type IntoIter = QueryIter<'q, 'w, Q>; + type Item = >::Item; fn into_iter(self) -> Self::IntoIter { self.iter() diff --git a/crates/bevy_ecs/hecs/src/world.rs b/crates/bevy_ecs/hecs/src/world.rs index 27eb1c925f..eb5ed6e01f 100644 --- a/crates/bevy_ecs/hecs/src/world.rs +++ b/crates/bevy_ecs/hecs/src/world.rs @@ -622,6 +622,7 @@ impl Default for World { impl<'a> IntoIterator for &'a World { type IntoIter = Iter<'a>; type Item = (Entity, EntityRef<'a>); + fn into_iter(self) -> Iter<'a> { self.iter() } @@ -700,6 +701,7 @@ unsafe impl Sync for Iter<'_> {} impl<'a> Iterator for Iter<'a> { type Item = (Entity, EntityRef<'a>); + fn next(&mut self) -> Option { loop { match self.current { diff --git a/crates/bevy_ecs/src/resource/resource_query.rs b/crates/bevy_ecs/src/resource/resource_query.rs index 12b633bf10..acecb6047e 100644 --- a/crates/bevy_ecs/src/resource/resource_query.rs +++ b/crates/bevy_ecs/src/resource/resource_query.rs @@ -39,6 +39,7 @@ unsafe impl Sync for Res<'_, T> {} impl<'a, T: Component> Deref for Res<'a, T> { type Target = T; + fn deref(&self) -> &T { self.value } @@ -64,6 +65,7 @@ unsafe impl Sync for ResMut<'_, T> {} impl<'a, T: Component> Deref for ResMut<'a, T> { type Target = T; + fn deref(&self) -> &T { unsafe { &*self.value } } @@ -100,6 +102,7 @@ impl<'a, T: Component + FromResources> UnsafeClone for Local<'a, T> { impl<'a, T: Component + FromResources> Deref for Local<'a, T> { type Target = T; + fn deref(&self) -> &T { unsafe { &*self.value } } @@ -142,6 +145,7 @@ pub struct FetchResourceRead(NonNull); impl<'a, T: Component> FetchResource<'a> for FetchResourceRead { type Item = Res<'a, T>; + unsafe fn get(resources: &'a Resources, _system_id: Option) -> Self::Item { Res::new(resources.get_unsafe_ref::(ResourceIndex::Global)) } @@ -169,6 +173,7 @@ pub struct FetchResourceWrite(NonNull); impl<'a, T: Component> FetchResource<'a> for FetchResourceWrite { type Item = ResMut<'a, T>; + unsafe fn get(resources: &'a Resources, _system_id: Option) -> Self::Item { ResMut::new(resources.get_unsafe_ref::(ResourceIndex::Global)) } @@ -202,6 +207,7 @@ pub struct FetchResourceLocalMut(NonNull); impl<'a, T: Component + FromResources> FetchResource<'a> for FetchResourceLocalMut { type Item = Local<'a, T>; + unsafe fn get(resources: &'a Resources, system_id: Option) -> Self::Item { let id = system_id.expect("Local resources can only be used by systems"); Local { diff --git a/crates/bevy_ecs/src/schedule/parallel_executor.rs b/crates/bevy_ecs/src/schedule/parallel_executor.rs index 5402b87be1..a29d6b96dd 100644 --- a/crates/bevy_ecs/src/schedule/parallel_executor.rs +++ b/crates/bevy_ecs/src/schedule/parallel_executor.rs @@ -32,6 +32,7 @@ impl ParallelExecutor { ..Default::default() } } + pub fn prepare(&mut self, schedule: &mut Schedule, world: &World) { let schedule_generation = schedule.generation(); let schedule_changed = schedule_generation != self.last_schedule_generation; diff --git a/crates/bevy_ecs/src/system/into_system.rs b/crates/bevy_ecs/src/system/into_system.rs index 78a8427f1f..167b8f58f3 100644 --- a/crates/bevy_ecs/src/system/into_system.rs +++ b/crates/bevy_ecs/src/system/into_system.rs @@ -70,6 +70,7 @@ where fn initialize(&mut self, resources: &mut Resources) { (self.init_func)(resources); } + fn id(&self) -> SystemId { self.id } diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5e19efb7b3..7f586dbfa9 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -17,6 +17,7 @@ impl AssetLoader for GltfLoader { let mesh = load_gltf(asset_path, bytes)?; Ok(mesh) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["gltf"]; EXTENSIONS diff --git a/crates/bevy_math/src/geometry.rs b/crates/bevy_math/src/geometry.rs index 45fa658e82..d16ea2ae68 100644 --- a/crates/bevy_math/src/geometry.rs +++ b/crates/bevy_math/src/geometry.rs @@ -1,8 +1,8 @@ -use std::ops::{Add, AddAssign}; use glam::Vec2; +use std::ops::{Add, AddAssign}; #[derive(Copy, Clone, PartialEq, Debug)] -pub struct Size { +pub struct Size { pub width: T, pub height: T, } @@ -31,7 +31,10 @@ pub struct Rect { } impl Rect { - pub fn all(value: T) -> Self where T: Clone{ + pub fn all(value: T) -> Self + where + T: Clone, + { Rect { left: value.clone(), right: value.clone(), @@ -52,8 +55,12 @@ impl Default for Rect { } } -impl Add for Size where T: Add { +impl Add for Size +where + T: Add, +{ type Output = Size; + fn add(self, rhs: Vec2) -> Self::Output { Self { width: self.width + rhs.x(), @@ -62,9 +69,12 @@ impl Add for Size where T: Add { } } -impl AddAssign for Size where T: AddAssign { +impl AddAssign for Size +where + T: AddAssign, +{ fn add_assign(&mut self, rhs: Vec2) { self.width += rhs.x(); self.height += rhs.y(); } -} \ No newline at end of file +} diff --git a/crates/bevy_property/src/dynamic_properties.rs b/crates/bevy_property/src/dynamic_properties.rs index 7ca8e8b44f..52fdd89164 100644 --- a/crates/bevy_property/src/dynamic_properties.rs +++ b/crates/bevy_property/src/dynamic_properties.rs @@ -43,6 +43,7 @@ impl DynamicProperties { self.prop_indices.insert(cow_name, self.props.len() - 1); } } + pub fn set(&mut self, name: &str, prop: T) { // TODO: validate map / seq operations if let Some(index) = self.prop_indices.get(name) { @@ -51,6 +52,7 @@ impl DynamicProperties { self.push(Box::new(prop), Some(name)); } } + pub fn set_box(&mut self, name: &str, prop: Box) { // TODO: validate map / seq operations if let Some(index) = self.prop_indices.get(name) { @@ -122,14 +124,17 @@ impl Property for DynamicProperties { fn any(&self) -> &dyn Any { self } + #[inline] fn any_mut(&mut self) -> &mut dyn Any { self } + #[inline] fn clone_prop(&self) -> Box { Box::new(self.to_dynamic()) } + #[inline] fn set(&mut self, value: &dyn Property) { if let Some(properties) = value.as_properties() { diff --git a/crates/bevy_property/src/impl_property/impl_property_std.rs b/crates/bevy_property/src/impl_property/impl_property_std.rs index e0add3773f..9db4849835 100644 --- a/crates/bevy_property/src/impl_property/impl_property_std.rs +++ b/crates/bevy_property/src/impl_property/impl_property_std.rs @@ -18,21 +18,27 @@ where fn prop(&self, _name: &str) -> Option<&dyn Property> { None } + fn prop_mut(&mut self, _name: &str) -> Option<&mut dyn Property> { None } + fn prop_with_index(&self, index: usize) -> Option<&dyn Property> { Some(&self[index]) } + fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Property> { Some(&mut self[index]) } + fn prop_name(&self, _index: usize) -> Option<&str> { None } + fn prop_len(&self) -> usize { self.len() } + fn iter_props(&self) -> PropertyIter { PropertyIter::new(self) } @@ -45,9 +51,11 @@ where fn type_name(&self) -> &str { std::any::type_name::() } + fn any(&self) -> &dyn Any { self } + fn any_mut(&mut self) -> &mut dyn Any { self } @@ -55,6 +63,7 @@ where fn clone_prop(&self) -> Box { Box::new(self.clone()) } + fn set(&mut self, value: &dyn Property) { if let Some(properties) = value.as_properties() { if properties.property_type() != self.property_type() { @@ -71,6 +80,7 @@ where panic!("attempted to apply non-Properties type to Properties type"); } } + fn apply(&mut self, value: &dyn Property) { self.set(value); } diff --git a/crates/bevy_property/src/properties.rs b/crates/bevy_property/src/properties.rs index a59cd094e6..66b08c973e 100644 --- a/crates/bevy_property/src/properties.rs +++ b/crates/bevy_property/src/properties.rs @@ -55,6 +55,7 @@ impl<'a> PropertyIter<'a> { impl<'a> Iterator for PropertyIter<'a> { type Item = &'a dyn Property; + fn next(&mut self) -> Option { if self.index < self.props.prop_len() { let prop = self.props.prop_with_index(self.index).unwrap(); @@ -79,6 +80,7 @@ where fn prop_val(&self, name: &str) -> Option<&T> { self.prop(name).and_then(|p| p.any().downcast_ref::()) } + #[inline] fn set_prop_val(&mut self, name: &str, value: T) { if let Some(prop) = self.prop_mut(name) { diff --git a/crates/bevy_property/src/property_serde.rs b/crates/bevy_property/src/property_serde.rs index 42581cc1a9..c78340d301 100644 --- a/crates/bevy_property/src/property_serde.rs +++ b/crates/bevy_property/src/property_serde.rs @@ -223,6 +223,7 @@ impl<'a> DynamicPropertiesDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for DynamicPropertiesDeserializer<'a> { type Value = DynamicProperties; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -239,6 +240,7 @@ struct DynamicPropertiesVisiter<'a> { impl<'a, 'de> Visitor<'de> for DynamicPropertiesVisiter<'a> { type Value = DynamicProperties; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("dynamic property") } @@ -261,6 +263,7 @@ pub struct PropertyDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for PropertyDeserializer<'a> { type Value = Box; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -283,6 +286,7 @@ pub struct SeqPropertyDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for SeqPropertyDeserializer<'a> { type Value = DynamicProperties; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -299,6 +303,7 @@ pub struct SeqPropertyVisiter<'a> { impl<'a, 'de> Visitor<'de> for SeqPropertyVisiter<'a> { type Value = DynamicProperties; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("property value") } @@ -330,6 +335,7 @@ impl<'a> MapPropertyDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for MapPropertyDeserializer<'a> { type Value = DynamicProperties; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -346,6 +352,7 @@ struct MapPropertyVisiter<'a> { impl<'a, 'de> Visitor<'de> for MapPropertyVisiter<'a> { type Value = DynamicProperties; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("map value") } @@ -373,6 +380,7 @@ struct AnyPropVisiter<'a> { impl<'a, 'de> Visitor<'de> for AnyPropVisiter<'a> { type Value = Box; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("property value") } diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index e3e53adc0b..1c596f42dd 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -19,6 +19,7 @@ impl CameraProjection for PerspectiveProjection { fn get_projection_matrix(&self) -> Mat4 { Mat4::perspective_rh(self.fov, self.aspect_ratio, self.near, self.far) } + fn update(&mut self, width: usize, height: usize) { self.aspect_ratio = width as f32 / height as f32; } @@ -64,6 +65,7 @@ impl CameraProjection for OrthographicProjection { self.far, ) } + fn update(&mut self, width: usize, height: usize) { match self.window_origin { WindowOrigin::Center => { diff --git a/crates/bevy_render/src/color.rs b/crates/bevy_render/src/color.rs index 1bbad6e1c7..b94fb7e204 100644 --- a/crates/bevy_render/src/color.rs +++ b/crates/bevy_render/src/color.rs @@ -22,12 +22,12 @@ pub struct Color { unsafe impl Byteable for Color {} impl Color { - pub const WHITE: Color = Color::rgb(1.0, 1.0, 1.0); pub const BLACK: Color = Color::rgb(0.0, 0.0, 0.0); - pub const RED: Color = Color::rgb(1.0, 0.0, 0.0); - pub const GREEN: Color = Color::rgb(0.0, 1.0, 0.0); pub const BLUE: Color = Color::rgb(0.0, 0.0, 1.0); + pub const GREEN: Color = Color::rgb(0.0, 1.0, 0.0); pub const NONE: Color = Color::rgba(0.0, 0.0, 0.0, 0.0); + pub const RED: Color = Color::rgb(1.0, 0.0, 0.0); + pub const WHITE: Color = Color::rgb(1.0, 1.0, 1.0); pub const fn rgb(r: f32, g: f32, b: f32) -> Color { Color { r, g, b, a: 1.0 } @@ -57,6 +57,7 @@ impl AddAssign for Color { impl Add for Color { type Output = Color; + fn add(self, rhs: Color) -> Self::Output { Color { r: self.r + rhs.r, @@ -69,6 +70,7 @@ impl Add for Color { impl Add for Color { type Output = Color; + fn add(self, rhs: Vec4) -> Self::Output { Color { r: self.r + rhs.x(), @@ -97,6 +99,7 @@ impl Into<[f32; 4]> for Color { } impl Mul for Color { type Output = Color; + fn mul(self, rhs: f32) -> Self::Output { Color { r: self.r * rhs, @@ -118,6 +121,7 @@ impl MulAssign for Color { impl Mul for Color { type Output = Color; + fn mul(self, rhs: Vec4) -> Self::Output { Color { r: self.r * rhs.x(), @@ -139,12 +143,13 @@ impl MulAssign for Color { impl Mul for Color { type Output = Color; + fn mul(self, rhs: Vec3) -> Self::Output { Color { r: self.r * rhs.x(), g: self.g * rhs.y(), b: self.b * rhs.z(), - a: self.a + a: self.a, } } } @@ -164,6 +169,7 @@ impl Bytes for ColorSource { ColorSource::Texture(_) => {} // Texture is not a uniform } } + fn byte_len(&self) -> usize { match *self { ColorSource::Color(ref color) => color.byte_len(), diff --git a/crates/bevy_render/src/draw.rs b/crates/bevy_render/src/draw.rs index c31f34cecc..fbad394441 100644 --- a/crates/bevy_render/src/draw.rs +++ b/crates/bevy_render/src/draw.rs @@ -150,6 +150,7 @@ pub struct FetchDrawContext; // TODO: derive this impl impl<'a> FetchResource<'a> for FetchDrawContext { type Item = DrawContext<'a>; + fn borrow(resources: &Resources) { resources.borrow_mut::>(); resources.borrow_mut::>(); @@ -158,6 +159,7 @@ impl<'a> FetchResource<'a> for FetchDrawContext { resources.borrow::(); resources.borrow::(); } + fn release(resources: &Resources) { resources.release_mut::>(); resources.release_mut::>(); @@ -166,6 +168,7 @@ impl<'a> FetchResource<'a> for FetchDrawContext { resources.release::(); resources.release::(); } + unsafe fn get(resources: &'a Resources, _system_id: Option) -> Self::Item { DrawContext { pipelines: ResMut::new( diff --git a/crates/bevy_render/src/mesh/mesh.rs b/crates/bevy_render/src/mesh/mesh.rs index e3bc164afe..2dbed5a000 100644 --- a/crates/bevy_render/src/mesh/mesh.rs +++ b/crates/bevy_render/src/mesh/mesh.rs @@ -63,8 +63,8 @@ pub struct VertexAttribute { } impl VertexAttribute { - pub const POSITION: &'static str = "Vertex_Position"; pub const NORMAL: &'static str = "Vertex_Normal"; + pub const POSITION: &'static str = "Vertex_Position"; pub const UV: &'static str = "Vertex_Uv"; pub fn position(positions: Vec<[f32; 3]>) -> Self { diff --git a/crates/bevy_render/src/render_graph/graph.rs b/crates/bevy_render/src/render_graph/graph.rs index 2e6062391c..2dfc07b7d8 100644 --- a/crates/bevy_render/src/render_graph/graph.rs +++ b/crates/bevy_render/src/render_graph/graph.rs @@ -335,6 +335,7 @@ mod tests { fn output(&self) -> &[ResourceSlotInfo] { &self.outputs } + fn update( &mut self, _: &World, diff --git a/crates/bevy_render/src/render_graph/node_slot.rs b/crates/bevy_render/src/render_graph/node_slot.rs index 9e67395a3c..b0629c50f5 100644 --- a/crates/bevy_render/src/render_graph/node_slot.rs +++ b/crates/bevy_render/src/render_graph/node_slot.rs @@ -86,6 +86,7 @@ impl ResourceSlots { .ok_or_else(|| RenderGraphError::InvalidNodeSlot(label)), } } + pub fn iter(&self) -> impl Iterator { self.slots.iter() } diff --git a/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs b/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs index 6f408c5106..a99a7ae467 100644 --- a/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs @@ -186,6 +186,7 @@ where buffer_array_status.buffer = Some(buffer); } } + fn update_staging_buffer(&mut self, render_resource_context: &dyn RenderResourceContext) { let mut size = 0; for dynamic_buffer_array_status in self.uniform_arrays.iter_mut() { diff --git a/crates/bevy_render/src/render_graph/nodes/window_swapchain_node.rs b/crates/bevy_render/src/render_graph/nodes/window_swapchain_node.rs index ee7b621151..a1401e5a68 100644 --- a/crates/bevy_render/src/render_graph/nodes/window_swapchain_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/window_swapchain_node.rs @@ -15,6 +15,7 @@ pub struct WindowSwapChainNode { impl WindowSwapChainNode { pub const OUT_TEXTURE: &'static str = "texture"; + pub fn new(window_id: WindowId) -> Self { WindowSwapChainNode { window_id, diff --git a/crates/bevy_render/src/render_graph/nodes/window_texture_node.rs b/crates/bevy_render/src/render_graph/nodes/window_texture_node.rs index 6d1bb9d2c9..ba0ae467ff 100644 --- a/crates/bevy_render/src/render_graph/nodes/window_texture_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/window_texture_node.rs @@ -17,6 +17,7 @@ pub struct WindowTextureNode { impl WindowTextureNode { pub const OUT_TEXTURE: &'static str = "texture"; + pub fn new(window_id: WindowId, descriptor: TextureDescriptor) -> Self { WindowTextureNode { window_id, diff --git a/crates/bevy_render/src/render_graph/schedule.rs b/crates/bevy_render/src/render_graph/schedule.rs index bc68d0ec38..f5bb4cdbed 100644 --- a/crates/bevy_render/src/render_graph/schedule.rs +++ b/crates/bevy_render/src/render_graph/schedule.rs @@ -300,6 +300,7 @@ mod tests { fn output(&self) -> &[ResourceSlotInfo] { &self.outputs } + fn update( &mut self, _: &World, diff --git a/crates/bevy_render/src/renderer/headless_render_resource_context.rs b/crates/bevy_render/src/renderer/headless_render_resource_context.rs index a18488c101..133cbadb82 100644 --- a/crates/bevy_render/src/renderer/headless_render_resource_context.rs +++ b/crates/bevy_render/src/renderer/headless_render_resource_context.rs @@ -35,24 +35,31 @@ impl HeadlessRenderResourceContext { impl RenderResourceContext for HeadlessRenderResourceContext { fn create_swap_chain(&self, _window: &Window) {} + fn next_swap_chain_texture(&self, _window: &Window) -> TextureId { TextureId::new() } + fn drop_swap_chain_texture(&self, _render_resource: TextureId) {} + fn drop_all_swap_chain_textures(&self) {} + fn create_sampler(&self, _sampler_descriptor: &SamplerDescriptor) -> SamplerId { SamplerId::new() } + fn create_texture(&self, texture_descriptor: TextureDescriptor) -> TextureId { let texture = TextureId::new(); self.add_texture_descriptor(texture, texture_descriptor); texture } + fn create_buffer(&self, buffer_info: BufferInfo) -> BufferId { let buffer = BufferId::new(); self.add_buffer_info(buffer, buffer_info); buffer } + fn write_mapped_buffer( &self, id: BufferId, @@ -63,21 +70,29 @@ impl RenderResourceContext for HeadlessRenderResourceContext { let mut buffer = vec![0; size]; write(&mut buffer, self); } + fn map_buffer(&self, _id: BufferId) {} + fn unmap_buffer(&self, _id: BufferId) {} + fn create_buffer_with_data(&self, buffer_info: BufferInfo, _data: &[u8]) -> BufferId { let buffer = BufferId::new(); self.add_buffer_info(buffer, buffer_info); buffer } + fn create_shader_module(&self, _shader_handle: Handle, _shaders: &Assets) {} + fn remove_buffer(&self, buffer: BufferId) { self.buffer_info.write().unwrap().remove(&buffer); } + fn remove_texture(&self, texture: TextureId) { self.texture_descriptors.write().unwrap().remove(&texture); } + fn remove_sampler(&self, _sampler: SamplerId) {} + fn set_asset_resource_untyped( &self, handle: HandleUntyped, @@ -89,6 +104,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext { .unwrap() .insert((handle, index), render_resource); } + fn get_asset_resource_untyped( &self, handle: HandleUntyped, @@ -100,6 +116,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext { .get(&(handle, index)) .cloned() } + fn create_render_pipeline( &self, _pipeline_handle: Handle, @@ -107,23 +124,29 @@ impl RenderResourceContext for HeadlessRenderResourceContext { _shaders: &Assets, ) { } + fn create_bind_group( &self, _bind_group_descriptor_id: BindGroupDescriptorId, _bind_group: &BindGroup, ) { } + fn create_shader_module_from_source(&self, _shader_handle: Handle, _shader: &Shader) {} + fn remove_asset_resource_untyped(&self, handle: HandleUntyped, index: usize) { self.asset_resources .write() .unwrap() .remove(&(handle, index)); } + fn clear_bind_groups(&self) {} + fn get_buffer_info(&self, buffer: BufferId) -> Option { self.buffer_info.read().unwrap().get(&buffer).cloned() } + fn bind_group_descriptor_exists( &self, _bind_group_descriptor_id: BindGroupDescriptorId, diff --git a/crates/bevy_render/src/renderer/render_resource/render_resource.rs b/crates/bevy_render/src/renderer/render_resource/render_resource.rs index 14c1729860..11d17d19f1 100644 --- a/crates/bevy_render/src/renderer/render_resource/render_resource.rs +++ b/crates/bevy_render/src/renderer/render_resource/render_resource.rs @@ -104,6 +104,7 @@ impl<'a> RenderResourceIterator<'a> { } impl<'a> Iterator for RenderResourceIterator<'a> { type Item = &'a dyn RenderResource; + fn next(&mut self) -> Option { if self.index == self.render_resources.render_resources_len() { None @@ -125,12 +126,15 @@ macro_rules! impl_render_resource_bytes { fn resource_type(&self) -> Option { Some(RenderResourceType::Buffer) } + fn write_buffer_bytes(&self, buffer: &mut [u8]) { self.write_bytes(buffer); } + fn buffer_byte_len(&self) -> Option { Some(self.byte_len()) } + fn texture(&self) -> Option> { None } @@ -161,12 +165,15 @@ where fn resource_type(&self) -> Option { Some(RenderResourceType::Buffer) } + fn write_buffer_bytes(&self, buffer: &mut [u8]) { self.write_bytes(buffer); } + fn buffer_byte_len(&self) -> Option { Some(self.byte_len()) } + fn texture(&self) -> Option> { None } diff --git a/crates/bevy_render/src/renderer/render_resource_context.rs b/crates/bevy_render/src/renderer/render_resource_context.rs index a68b74ef1e..95e1f21329 100644 --- a/crates/bevy_render/src/renderer/render_resource_context.rs +++ b/crates/bevy_render/src/renderer/render_resource_context.rs @@ -69,12 +69,14 @@ impl dyn RenderResourceContext { { self.set_asset_resource_untyped(handle.into(), resource, index); } + pub fn get_asset_resource(&self, handle: Handle, index: usize) -> Option where T: 'static, { self.get_asset_resource_untyped(handle.into(), index) } + pub fn remove_asset_resource(&self, handle: Handle, index: usize) where T: 'static, diff --git a/crates/bevy_render/src/shader/shader.rs b/crates/bevy_render/src/shader/shader.rs index b93a9ed5a3..29e008e544 100644 --- a/crates/bevy_render/src/shader/shader.rs +++ b/crates/bevy_render/src/shader/shader.rs @@ -64,6 +64,7 @@ impl Shader { pub fn new(stage: ShaderStage, source: ShaderSource) -> Shader { Shader { stage, source } } + pub fn from_glsl(stage: ShaderStage, glsl: &str) -> Shader { Shader { source: ShaderSource::Glsl(glsl.to_string()), diff --git a/crates/bevy_render/src/shader/shader_defs.rs b/crates/bevy_render/src/shader/shader_defs.rs index 509f39cdc1..900713fab1 100644 --- a/crates/bevy_render/src/shader/shader_defs.rs +++ b/crates/bevy_render/src/shader/shader_defs.rs @@ -29,6 +29,7 @@ impl<'a> ShaderDefIterator<'a> { } impl<'a> Iterator for ShaderDefIterator<'a> { type Item = &'a str; + fn next(&mut self) -> Option { loop { if self.index == self.shader_defs.shader_defs_len() { diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index 160d74a79e..70f9dc126e 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -36,6 +36,7 @@ impl AssetLoader for HdrTextureLoader { format, )) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["hdr"]; EXTENSIONS diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index 0937a3741d..e06266afd1 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -148,6 +148,7 @@ impl AssetLoader for ImageTextureLoader { format, )) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["png"]; EXTENSIONS diff --git a/crates/bevy_render/src/texture/texture.rs b/crates/bevy_render/src/texture/texture.rs index 6a4ffbe2c1..bbcdc29eeb 100644 --- a/crates/bevy_render/src/texture/texture.rs +++ b/crates/bevy_render/src/texture/texture.rs @@ -147,10 +147,13 @@ impl RenderResource for Option> { fn resource_type(&self) -> Option { self.map(|_texture| RenderResourceType::Texture) } + fn write_buffer_bytes(&self, _buffer: &mut [u8]) {} + fn buffer_byte_len(&self) -> Option { None } + fn texture(&self) -> Option> { self.clone() } @@ -160,10 +163,13 @@ impl RenderResource for Handle { fn resource_type(&self) -> Option { Some(RenderResourceType::Texture) } + fn write_buffer_bytes(&self, _buffer: &mut [u8]) {} + fn buffer_byte_len(&self) -> Option { None } + fn texture(&self) -> Option> { Some(self.clone()) } diff --git a/crates/bevy_scene/src/loaded_scenes.rs b/crates/bevy_scene/src/loaded_scenes.rs index 4ad5127dfb..6162535b97 100644 --- a/crates/bevy_scene/src/loaded_scenes.rs +++ b/crates/bevy_scene/src/loaded_scenes.rs @@ -33,6 +33,7 @@ impl AssetLoader for SceneLoader { let scene = scene_deserializer.deserialize(&mut deserializer)?; Ok(scene) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["scn"]; EXTENSIONS diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 86d70cd66e..9d9e4b7c9b 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -87,6 +87,7 @@ pub struct SceneDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for SceneDeserializer<'a> { type Value = Scene; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -106,6 +107,7 @@ struct SceneEntitySeqVisiter<'a> { impl<'a, 'de> Visitor<'de> for SceneEntitySeqVisiter<'a> { type Value = Vec; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("list of entities") } @@ -131,6 +133,7 @@ pub struct SceneEntityDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for SceneEntityDeserializer<'a> { type Value = Entity; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -162,6 +165,7 @@ struct SceneEntityVisiter<'a> { impl<'a, 'de> Visitor<'de> for SceneEntityVisiter<'a> { type Value = Entity; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("entities") } @@ -212,6 +216,7 @@ pub struct ComponentVecDeserializer<'a> { impl<'a, 'de> DeserializeSeed<'de> for ComponentVecDeserializer<'a> { type Value = Vec; + fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -228,6 +233,7 @@ struct ComponentSeqVisiter<'a> { impl<'a, 'de> Visitor<'de> for ComponentSeqVisiter<'a> { type Value = Vec; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("list of components") } diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index 985e6995cf..c1e8db7d9f 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -10,6 +10,7 @@ impl AssetLoader for FontLoader { fn from_bytes(&self, _asset_path: &Path, bytes: Vec) -> Result { Ok(Font::try_from_bytes(bytes)?) } + fn extensions(&self) -> &[&str] { static EXTENSIONS: &[&str] = &["ttf"]; EXTENSIONS diff --git a/crates/bevy_transform/src/components/children.rs b/crates/bevy_transform/src/components/children.rs index 47a9f1402b..9868bbf9cf 100644 --- a/crates/bevy_transform/src/components/children.rs +++ b/crates/bevy_transform/src/components/children.rs @@ -14,6 +14,7 @@ impl Children { impl Deref for Children { type Target = SmallVec<[Entity; 8]>; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/local_transform.rs b/crates/bevy_transform/src/components/local_transform.rs index 1ae79197d7..887e5186df 100644 --- a/crates/bevy_transform/src/components/local_transform.rs +++ b/crates/bevy_transform/src/components/local_transform.rs @@ -28,6 +28,7 @@ impl fmt::Display for LocalTransform { impl Deref for LocalTransform { type Target = Mat4; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/non_uniform_scale.rs b/crates/bevy_transform/src/components/non_uniform_scale.rs index 00f77d3c1f..76dd716598 100644 --- a/crates/bevy_transform/src/components/non_uniform_scale.rs +++ b/crates/bevy_transform/src/components/non_uniform_scale.rs @@ -47,6 +47,7 @@ impl fmt::Display for NonUniformScale { impl Deref for NonUniformScale { type Target = Vec3; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/parent.rs b/crates/bevy_transform/src/components/parent.rs index d6d59840f1..73020fe759 100644 --- a/crates/bevy_transform/src/components/parent.rs +++ b/crates/bevy_transform/src/components/parent.rs @@ -20,6 +20,7 @@ pub struct PreviousParent(pub Option); impl Deref for Parent { type Target = Entity; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/rotation.rs b/crates/bevy_transform/src/components/rotation.rs index e97b6a64bc..5d7811397e 100644 --- a/crates/bevy_transform/src/components/rotation.rs +++ b/crates/bevy_transform/src/components/rotation.rs @@ -25,6 +25,7 @@ impl From for Rotation { impl Deref for Rotation { type Target = Quat; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/scale.rs b/crates/bevy_transform/src/components/scale.rs index 80ace74766..f9a118a55a 100644 --- a/crates/bevy_transform/src/components/scale.rs +++ b/crates/bevy_transform/src/components/scale.rs @@ -35,6 +35,7 @@ impl fmt::Display for Scale { impl Deref for Scale { type Target = f32; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/components/translation.rs b/crates/bevy_transform/src/components/translation.rs index b4211f93b5..f676e2c2a0 100644 --- a/crates/bevy_transform/src/components/translation.rs +++ b/crates/bevy_transform/src/components/translation.rs @@ -31,6 +31,7 @@ impl From for Translation { impl Deref for Translation { type Target = Vec3; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/bevy_transform/src/hierarchy/child_builder.rs b/crates/bevy_transform/src/hierarchy/child_builder.rs index 81c5fbec1c..51b462516f 100644 --- a/crates/bevy_transform/src/hierarchy/child_builder.rs +++ b/crates/bevy_transform/src/hierarchy/child_builder.rs @@ -147,6 +147,7 @@ impl BuildChildren for Commands { } self } + fn push_children(&mut self, parent: Entity, children: &[Entity]) -> &mut Self { { let mut commands = self.commands.lock().unwrap(); @@ -157,6 +158,7 @@ impl BuildChildren for Commands { } self } + fn insert_children(&mut self, parent: Entity, index: usize, children: &[Entity]) -> &mut Self { { let mut commands = self.commands.lock().unwrap(); @@ -199,6 +201,7 @@ impl<'a> BuildChildren for ChildBuilder<'a> { }); self } + fn insert_children(&mut self, parent: Entity, index: usize, children: &[Entity]) -> &mut Self { self.commands.write_world(InsertChildren { children: SmallVec::from(children), diff --git a/crates/bevy_ui/src/anchors.rs b/crates/bevy_ui/src/anchors.rs index 848acb9806..0e3c5c5274 100644 --- a/crates/bevy_ui/src/anchors.rs +++ b/crates/bevy_ui/src/anchors.rs @@ -7,22 +7,22 @@ pub struct Anchors { } impl Anchors { - pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5); - pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5); - pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5); - pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0); - pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0); - pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0); - pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5); - pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0); - pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0); - pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0); pub const BOTTOM_FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 0.0); pub const BOTTOM_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.0, 0.0); pub const BOTTOM_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.0, 0.0); - pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0); - pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0); + pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5); + pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0); + pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5); + pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0); + pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5); + pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5); + pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0); pub const FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 1.0); + pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0); + pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0); + pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0); + pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0); + pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0); pub const fn new(left: f32, right: f32, bottom: f32, top: f32) -> Self { Anchors { diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index 399c8aa061..6c857f339d 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -1,8 +1,8 @@ use super::Node; use crate::{ render::UI_PIPELINE_HANDLE, - widget::{Button, Text, Image}, - FocusPolicy, Interaction, Style, CalculatedSize, + widget::{Button, Image, Text}, + CalculatedSize, FocusPolicy, Interaction, Style, }; use bevy_asset::Handle; use bevy_ecs::Bundle; @@ -110,7 +110,6 @@ impl Default for ImageComponents { } } - #[derive(Bundle)] pub struct TextComponents { pub node: Node, diff --git a/crates/bevy_ui/src/node.rs b/crates/bevy_ui/src/node.rs index ecc42fc0b7..10fcdd8346 100644 --- a/crates/bevy_ui/src/node.rs +++ b/crates/bevy_ui/src/node.rs @@ -1,6 +1,6 @@ use bevy_math::{Rect, Size, Vec2}; use bevy_render::renderer::RenderResources; -use std::ops::{AddAssign, Add}; +use std::ops::{Add, AddAssign}; #[derive(Debug, Clone, Default, RenderResources)] pub struct Node { @@ -23,6 +23,7 @@ impl Default for Val { impl Add for Val { type Output = Val; + fn add(self, rhs: f32) -> Self::Output { match self { Val::Undefined => Val::Undefined, @@ -36,7 +37,7 @@ impl Add for Val { impl AddAssign for Val { fn add_assign(&mut self, rhs: f32) { match self { - Val::Undefined | Val::Auto => {}, + Val::Undefined | Val::Auto => {} Val::Px(value) => *value += rhs, Val::Percent(value) => *value += rhs, } @@ -238,4 +239,4 @@ impl Default for FlexWrap { fn default() -> FlexWrap { FlexWrap::NoWrap } -} \ No newline at end of file +} diff --git a/crates/bevy_ui/src/widget/mod.rs b/crates/bevy_ui/src/widget/mod.rs index 678775a070..1a85f97580 100644 --- a/crates/bevy_ui/src/widget/mod.rs +++ b/crates/bevy_ui/src/widget/mod.rs @@ -1,7 +1,7 @@ mod button; -mod text; mod image; +mod text; pub use button::*; -pub use text::*; pub use image::*; +pub use text::*; diff --git a/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs b/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs index ebb67096f3..21a11a7e1e 100644 --- a/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs +++ b/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs @@ -15,41 +15,30 @@ impl AppPlugin for WgpuResourceDiagnosticsPlugin { } impl WgpuResourceDiagnosticsPlugin { - pub const WINDOW_SURFACES: DiagnosticId = - DiagnosticId::from_u128(108237028251680341878766034324149135605); - - pub const SWAP_CHAINS: DiagnosticId = - DiagnosticId::from_u128(199253035828743332241465305105689014605); - - pub const SWAP_CHAIN_OUTPUTS: DiagnosticId = - DiagnosticId::from_u128(112048874168736161226721327099863374234); - - pub const BUFFERS: DiagnosticId = - DiagnosticId::from_u128(133146619577893994787249934474491530491); - - pub const TEXTURES: DiagnosticId = - DiagnosticId::from_u128(305955424195390184883220102469231911115); - - pub const TEXTURE_VIEWS: DiagnosticId = - DiagnosticId::from_u128(257307432866562594739240898780307437578); - - pub const SAMPLERS: DiagnosticId = - DiagnosticId::from_u128(305855369913076220671125671543184691267); - - pub const BIND_GROUP_IDS: DiagnosticId = - DiagnosticId::from_u128(283571569334075937453357861280307923122); - pub const BIND_GROUPS: DiagnosticId = DiagnosticId::from_u128(21302464753369276741568507794995836890); - + pub const BIND_GROUP_IDS: DiagnosticId = + DiagnosticId::from_u128(283571569334075937453357861280307923122); pub const BIND_GROUP_LAYOUTS: DiagnosticId = DiagnosticId::from_u128(96406067032931216377076410852598331304); - - pub const SHADER_MODULES: DiagnosticId = - DiagnosticId::from_u128(287681470908132753275843248383768232237); - + pub const BUFFERS: DiagnosticId = + DiagnosticId::from_u128(133146619577893994787249934474491530491); pub const RENDER_PIPELINES: DiagnosticId = DiagnosticId::from_u128(278527620040377353875091478462209885377); + pub const SAMPLERS: DiagnosticId = + DiagnosticId::from_u128(305855369913076220671125671543184691267); + pub const SHADER_MODULES: DiagnosticId = + DiagnosticId::from_u128(287681470908132753275843248383768232237); + pub const SWAP_CHAINS: DiagnosticId = + DiagnosticId::from_u128(199253035828743332241465305105689014605); + pub const SWAP_CHAIN_OUTPUTS: DiagnosticId = + DiagnosticId::from_u128(112048874168736161226721327099863374234); + pub const TEXTURES: DiagnosticId = + DiagnosticId::from_u128(305955424195390184883220102469231911115); + pub const TEXTURE_VIEWS: DiagnosticId = + DiagnosticId::from_u128(257307432866562594739240898780307437578); + pub const WINDOW_SURFACES: DiagnosticId = + DiagnosticId::from_u128(108237028251680341878766034324149135605); pub fn setup_system(mut diagnostics: ResMut) { diagnostics.add(Diagnostic::new( diff --git a/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs b/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs index 9a4be9b529..309804d3e4 100644 --- a/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs +++ b/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs @@ -116,6 +116,7 @@ impl RenderContext for WgpuRenderContext { fn resources(&self) -> &dyn RenderResourceContext { &self.render_resource_context } + fn resources_mut(&mut self) -> &mut dyn RenderResourceContext { &mut self.render_resource_context } diff --git a/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs b/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs index 975bfe8c71..f5970f17ce 100644 --- a/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs +++ b/crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs @@ -496,6 +496,7 @@ impl RenderResourceContext for WgpuRenderResourceContext { fn clear_bind_groups(&self) { self.resources.bind_groups.write().unwrap().clear(); } + fn get_buffer_info(&self, buffer: BufferId) -> Option { self.resources .buffer_infos @@ -504,6 +505,7 @@ impl RenderResourceContext for WgpuRenderResourceContext { .get(&buffer) .cloned() } + fn write_mapped_buffer( &self, id: BufferId, @@ -529,6 +531,7 @@ impl RenderResourceContext for WgpuRenderResourceContext { panic!("failed to map buffer to host"); } } + fn unmap_buffer(&self, id: BufferId) { let buffers = self.resources.buffers.read().unwrap(); let buffer = buffers.get(&id).unwrap(); diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 9dec91e324..6776c35fd8 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -28,8 +28,7 @@ fn setup( rpg_sprite_handles.handles = asset_server .load_asset_folder("assets/textures/rpg") .unwrap(); - commands - .spawn(Camera2dComponents::default()); + commands.spawn(Camera2dComponents::default()); } fn load_atlas( diff --git a/examples/scene/properties.rs b/examples/scene/properties.rs index 3b81eae410..5bd1ca7348 100644 --- a/examples/scene/properties.rs +++ b/examples/scene/properties.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; /// This example illustrates how Properties work. Properties provide a way to dynamically interact with Rust struct fields using /// their names. Properties are a core part of Bevy and enable a number of interesting scenarios (like scenes). If you are -/// familiar with "reflection" in other languages, Properties are very similar to that concept. +/// familiar with "reflection" in other languages, Properties are very similar to that concept. fn main() { App::build() .add_default_plugins() diff --git a/examples/ui/font_atlas_debug.rs b/examples/ui/font_atlas_debug.rs index 436959d509..1a60b3c556 100644 --- a/examples/ui/font_atlas_debug.rs +++ b/examples/ui/font_atlas_debug.rs @@ -1,6 +1,6 @@ use bevy::{prelude::*, text::FontAtlasSet}; -/// This example illustrates how FontAtlases are populated. Bevy uses FontAtlases under the hood to optimize text rendering. +/// This example illustrates how FontAtlases are populated. Bevy uses FontAtlases under the hood to optimize text rendering. fn main() { App::build() .init_resource::() diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index 9cb2700043..4211e96bab 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -9,7 +9,7 @@ use bevy::{ window::{CreateWindow, WindowDescriptor, WindowId}, }; -/// This example creates a second window and draws a mesh from two different cameras. +/// This example creates a second window and draws a mesh from two different cameras. fn main() { App::build() .add_default_plugins() diff --git a/rustfmt.toml b/rustfmt.toml index 718513f7ce..ffdf397ed2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,4 @@ merge_imports = true -use_field_init_shorthand = true \ No newline at end of file +use_field_init_shorthand = true +reorder_impl_items = true +newline_style = "Unix" \ No newline at end of file