From b17f8a4bce5551b418654fffb1fe97ff0f9852f0 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Thu, 11 Mar 2021 00:27:30 +0000 Subject: [PATCH] format comments (#1612) Uses the new unstable comment formatting features added to rustfmt.toml. --- crates/bevy_app/src/app.rs | 17 +-- crates/bevy_app/src/app_builder.rs | 9 +- crates/bevy_app/src/event.rs | 49 +++++---- crates/bevy_app/src/lib.rs | 3 +- crates/bevy_app/src/plugin.rs | 3 +- crates/bevy_app/src/schedule_runner.rs | 3 +- crates/bevy_asset/src/asset_server.rs | 6 +- crates/bevy_asset/src/filesystem_watcher.rs | 3 +- crates/bevy_asset/src/handle.rs | 12 ++- crates/bevy_asset/src/lib.rs | 4 +- crates/bevy_core/src/bytes.rs | 4 +- crates/bevy_core/src/float_ord.rs | 6 +- crates/bevy_core/src/label.rs | 3 +- crates/bevy_core/src/lib.rs | 6 +- crates/bevy_core/src/task_pool_options.rs | 6 +- crates/bevy_core/src/time/fixed_timestep.rs | 4 +- crates/bevy_core/src/time/timer.rs | 3 +- crates/bevy_derive/src/lib.rs | 4 +- crates/bevy_ecs/src/archetype.rs | 8 +- crates/bevy_ecs/src/bundle.rs | 30 ++++-- crates/bevy_ecs/src/component/mod.rs | 6 +- crates/bevy_ecs/src/entity/mod.rs | 25 ++--- crates/bevy_ecs/src/query/access.rs | 3 +- crates/bevy_ecs/src/query/fetch.rs | 66 ++++++++---- crates/bevy_ecs/src/query/filter.rs | 59 +++++----- crates/bevy_ecs/src/query/state.rs | 12 +-- crates/bevy_ecs/src/reflect.rs | 6 +- crates/bevy_ecs/src/schedule/executor.rs | 4 +- .../src/schedule/executor_parallel.rs | 4 +- crates/bevy_ecs/src/schedule/stage.rs | 13 +-- crates/bevy_ecs/src/schedule/state.rs | 6 +- crates/bevy_ecs/src/storage/blob_vec.rs | 40 ++++--- crates/bevy_ecs/src/storage/sparse_set.rs | 17 +-- crates/bevy_ecs/src/storage/table.rs | 31 ++++-- crates/bevy_ecs/src/system/commands.rs | 19 +++- crates/bevy_ecs/src/system/into_system.rs | 3 +- crates/bevy_ecs/src/system/query.rs | 67 +++++++----- crates/bevy_ecs/src/system/system.rs | 7 +- crates/bevy_ecs/src/system/system_param.rs | 43 ++++---- crates/bevy_ecs/src/world/entity_ref.rs | 70 +++++++----- crates/bevy_ecs/src/world/mod.rs | 84 ++++++++------- crates/bevy_ecs/src/world/pointer.rs | 3 +- crates/bevy_ecs/src/world/spawn_batch.rs | 3 +- crates/bevy_ecs/src/world/world_cell.rs | 4 +- crates/bevy_input/src/mouse.rs | 3 +- .../bevy_pbr/src/render_graph/lights_node.rs | 3 +- crates/bevy_reflect/src/map.rs | 4 +- crates/bevy_reflect/src/reflect.rs | 12 ++- crates/bevy_reflect/src/type_registry.rs | 3 +- crates/bevy_render/src/camera/camera.rs | 6 +- .../src/camera/visible_entities.rs | 10 +- crates/bevy_render/src/color.rs | 3 +- crates/bevy_render/src/colorspace.rs | 6 +- crates/bevy_render/src/draw.rs | 3 +- crates/bevy_render/src/lib.rs | 6 +- crates/bevy_render/src/mesh/mesh.rs | 9 +- crates/bevy_render/src/mesh/shape/capsule.rs | 3 +- crates/bevy_render/src/pipeline/binding.rs | 4 +- .../src/pipeline/pipeline_compiler.rs | 5 +- .../src/pipeline/pipeline_layout.rs | 4 +- .../src/pipeline/render_pipelines.rs | 3 +- crates/bevy_render/src/render_graph/base.rs | 9 +- .../bevy_render/src/render_graph/command.rs | 3 +- crates/bevy_render/src/render_graph/node.rs | 6 +- .../src/render_graph/nodes/camera_node.rs | 4 +- .../nodes/render_resources_node.rs | 6 +- .../bevy_render/src/render_graph/schedule.rs | 17 +-- .../render_resource_bindings.rs | 14 ++- .../src/renderer/render_resource_context.rs | 11 +- crates/bevy_render/src/shader/shader_defs.rs | 3 +- crates/bevy_render/src/texture/texture.rs | 17 +-- .../src/texture/texture_dimension.rs | 3 +- crates/bevy_scene/src/scene_spawner.rs | 3 +- .../src/dynamic_texture_atlas_builder.rs | 4 +- crates/bevy_sprite/src/lib.rs | 3 +- crates/bevy_sprite/src/rect.rs | 3 +- crates/bevy_sprite/src/sprite.rs | 3 +- crates/bevy_tasks/src/countdown_event.rs | 3 +- crates/bevy_tasks/src/iter/mod.rs | 6 +- crates/bevy_tasks/src/task.rs | 3 +- crates/bevy_tasks/src/task_pool.rs | 22 ++-- crates/bevy_text/src/text2d.rs | 3 +- .../src/components/global_transform.rs | 3 +- .../bevy_transform/src/components/parent.rs | 4 +- .../src/components/transform.rs | 3 +- .../src/hierarchy/child_builder.rs | 10 +- .../bevy_transform/src/hierarchy/hierarchy.rs | 3 +- .../hierarchy/hierarchy_maintenance_system.rs | 4 +- crates/bevy_ui/src/focus.rs | 6 +- crates/bevy_ui/src/widget/text.rs | 3 +- .../src/renderer/wgpu_render_context.rs | 5 +- crates/bevy_wgpu/src/wgpu_resources.rs | 40 ++++--- crates/bevy_window/src/event.rs | 4 +- crates/bevy_window/src/window.rs | 10 +- crates/bevy_winit/src/lib.rs | 3 +- examples/2d/texture_atlas.rs | 3 +- examples/3d/msaa.rs | 7 +- examples/3d/parenting.rs | 4 +- examples/3d/spawner.rs | 7 +- examples/3d/z_sort_debug.rs | 3 +- examples/app/logs.rs | 3 +- examples/app/plugin_group.rs | 4 +- examples/asset/asset_loading.rs | 8 +- examples/asset/hot_asset_reloading.rs | 6 +- examples/diagnostics/custom_diagnostic.rs | 6 +- examples/ecs/ecs_guide.rs | 102 ++++++++++-------- examples/ecs/fixed_timestep.rs | 3 +- examples/ecs/hierarchy.rs | 6 +- examples/ecs/state.rs | 3 +- examples/ecs/system_chaining.rs | 3 +- examples/ecs/timers.rs | 4 +- examples/game/breakout.rs | 6 +- examples/reflection/reflection.rs | 28 ++--- examples/reflection/reflection_types.rs | 49 +++++---- examples/reflection/trait_reflection.rs | 24 +++-- examples/scene/scene.rs | 33 +++--- examples/shader/array_texture.rs | 10 +- examples/shader/hot_shader_reloading.rs | 6 +- examples/shader/mesh_custom_attribute.rs | 9 +- examples/shader/shader_custom_material.rs | 9 +- examples/shader/shader_defs.rs | 11 +- examples/ui/button.rs | 3 +- examples/ui/font_atlas_debug.rs | 3 +- src/lib.rs | 18 ++-- tools/ci/src/main.rs | 3 +- 125 files changed, 894 insertions(+), 599 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index fb56ad03ca..c7b850cff7 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -9,24 +9,25 @@ use bevy_utils::tracing::info_span; #[allow(clippy::needless_doctest_main)] /// Containers of app logic and data /// -/// App store the ECS World, Resources, Schedule, and Executor. They also store the "run" function of the App, which -/// by default executes the App schedule once. Apps are constructed using the builder pattern. +/// App store the ECS World, Resources, Schedule, and Executor. They also store the "run" function +/// of the App, which by default executes the App schedule once. Apps are constructed using the +/// builder pattern. /// /// ## Example /// Here is a simple "Hello World" Bevy app: /// ``` -///# use bevy_app::prelude::*; -///# use bevy_ecs::prelude::*; +/// # use bevy_app::prelude::*; +/// # use bevy_ecs::prelude::*; /// -///fn main() { +/// fn main() { /// App::build() /// .add_system(hello_world_system.system()) /// .run(); -///} +/// } /// -///fn hello_world_system() { +/// fn hello_world_system() { /// println!("hello world"); -///} +/// } /// ``` pub struct App { pub world: World, diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index 9b5c53ed0d..82a5aeaf1e 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -234,7 +234,8 @@ impl AppBuilder { .add_system_to_stage(CoreStage::First, Events::::update_system.system()) } - /// Inserts a resource to the current [App] and overwrites any resource previously added of the same type. + /// Inserts a resource to the current [App] and overwrites any resource previously added of the + /// same type. pub fn insert_resource(&mut self, resource: T) -> &mut Self where T: Component, @@ -255,9 +256,9 @@ impl AppBuilder { where R: FromWorld + Send + Sync + 'static, { - // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed not to - // modify the map. However, we would need to be borrowing resources both mutably and immutably, - // so we would need to be extremely certain this is correct + // PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed + // not to modify the map. However, we would need to be borrowing resources both + // mutably and immutably, so we would need to be extremely certain this is correct if !self.world_mut().contains_resource::() { let resource = R::from_world(self.world_mut()); self.insert_resource(resource); diff --git a/crates/bevy_app/src/event.rs b/crates/bevy_app/src/event.rs index d519b8e290..03dcf530f5 100644 --- a/crates/bevy_app/src/event.rs +++ b/crates/bevy_app/src/event.rs @@ -55,10 +55,12 @@ enum State { B, } -/// An event collection that represents the events that occurred within the last two [Events::update] calls. Events can be cheaply read using -/// an [EventReader]. This collection is meant to be paired with a system that calls [Events::update] exactly once per update/frame. [Events::update_system] -/// is a system that does this. [EventReader]s are expected to read events from this collection at least once per update/frame. If events are not handled -/// within one frame/update, they will be dropped. +/// An event collection that represents the events that occurred within the last two +/// [Events::update] calls. Events can be cheaply read using an [EventReader]. This collection is +/// meant to be paired with a system that calls [Events::update] exactly once per update/frame. +/// [Events::update_system] is a system that does this. [EventReader]s are expected to read events +/// from this collection at least once per update/frame. If events are not handled within one +/// frame/update, they will be dropped. /// /// # Example /// ``` @@ -89,14 +91,16 @@ enum State { /// /// # Details /// -/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and clears out the oldest buffer. -/// [EventReader]s that read at least once per update will never drop events. [EventReader]s that read once within two updates might -/// still receive some events. [EventReader]s that read after two updates are guaranteed to drop all events that occurred before those updates. +/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and +/// clears out the oldest buffer. [EventReader]s that read at least once per update will never drop +/// events. [EventReader]s that read once within two updates might still receive some events. +/// [EventReader]s that read after two updates are guaranteed to drop all events that occurred +/// before those updates. /// /// The buffers in [Events] will grow indefinitely if [Events::update] is never called. /// -/// An alternative call pattern would be to call [Events::update] manually across frames to control when events are cleared. However -/// this complicates consumption +/// An alternative call pattern would be to call [Events::update] manually across frames to control +/// when events are cleared. However this complicates consumption #[derive(Debug)] pub struct Events { events_a: Vec>, @@ -180,7 +184,8 @@ impl ManualEventReader { } } -/// Like [`iter_with_id`](EventReader::iter_with_id) except not emitting any traces for read messages. +/// Like [`iter_with_id`](EventReader::iter_with_id) except not emitting any traces for read +/// messages. fn internal_event_reader<'a, T>( last_event_count: &mut usize, events: &'a Events, @@ -232,7 +237,8 @@ fn internal_event_reader<'a, T>( impl<'a, T: Component> EventReader<'a, T> { /// Iterates over the events this EventReader has not seen yet. This updates the EventReader's - /// event counter, which means subsequent event reads will not include events that happened before now. + /// event counter, which means subsequent event reads will not include events that happened + /// before now. pub fn iter(&mut self) -> impl DoubleEndedIterator { self.iter_with_id().map(|(event, _id)| event) } @@ -247,7 +253,8 @@ impl<'a, T: Component> EventReader<'a, T> { } impl Events { - /// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read the event. + /// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read + /// the event. pub fn send(&mut self, event: T) { let event_id = EventId { id: self.event_count, @@ -273,7 +280,8 @@ impl Events { } } - /// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It will read all future events. + /// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It + /// will read all future events. pub fn get_reader_current(&self) -> ManualEventReader { ManualEventReader { last_event_count: self.event_count, @@ -281,7 +289,8 @@ impl Events { } } - /// Swaps the event buffers and clears the oldest event buffer. In general, this should be called once per frame/update. + /// Swaps the event buffers and clears the oldest event buffer. In general, this should be + /// called once per frame/update. pub fn update(&mut self) { match self.state { State::A => { @@ -335,10 +344,11 @@ impl Events { } /// Iterates over events that happened since the last "update" call. - /// WARNING: You probably don't want to use this call. In most cases you should use an `EventReader`. You should only use - /// this if you know you only need to consume events between the last `update()` call and your call to `iter_current_update_events`. - /// If events happen outside that window, they will not be handled. For example, any events that happen after this call and before - /// the next `update()` call will be dropped. + /// WARNING: You probably don't want to use this call. In most cases you should use an + /// `EventReader`. You should only use this if you know you only need to consume events + /// between the last `update()` call and your call to `iter_current_update_events`. + /// If events happen outside that window, they will not be handled. For example, any events that + /// happen after this call and before the next `update()` call will be dropped. pub fn iter_current_update_events(&self) -> impl DoubleEndedIterator { match self.state { State::A => self.events_a.iter().map(map_instance_event), @@ -363,7 +373,8 @@ mod tests { let event_1 = TestEvent { i: 1 }; let event_2 = TestEvent { i: 2 }; - // this reader will miss event_0 and event_1 because it wont read them over the course of two updates + // this reader will miss event_0 and event_1 because it wont read them over the course of + // two updates let mut reader_missed = events.get_reader(); let mut reader_a = events.get_reader(); diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index 13c3aacc22..1de98508ba 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -33,7 +33,8 @@ pub enum CoreStage { First, /// Name of app stage responsible for performing setup before an update. Runs before UPDATE. PreUpdate, - /// Name of app stage responsible for doing most app logic. Systems should be registered here by default. + /// Name of app stage responsible for doing most app logic. Systems should be registered here + /// by default. Update, /// Name of app stage responsible for processing the results of UPDATE. Runs after UPDATE. PostUpdate, diff --git a/crates/bevy_app/src/plugin.rs b/crates/bevy_app/src/plugin.rs index cbb49239ec..ea5ef0021a 100644 --- a/crates/bevy_app/src/plugin.rs +++ b/crates/bevy_app/src/plugin.rs @@ -3,7 +3,8 @@ use std::any::Any; /// A collection of Bevy App logic and configuration /// -/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers a plugin, the plugin's [Plugin::build] function is run. +/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers +/// a plugin, the plugin's [Plugin::build] function is run. pub trait Plugin: Any + Send + Sync { fn build(&self, app: &mut AppBuilder); fn name(&self) -> &str { diff --git a/crates/bevy_app/src/schedule_runner.rs b/crates/bevy_app/src/schedule_runner.rs index 69dde8e477..86b6dd1299 100644 --- a/crates/bevy_app/src/schedule_runner.rs +++ b/crates/bevy_app/src/schedule_runner.rs @@ -41,7 +41,8 @@ impl ScheduleRunnerSettings { } } -/// Configures an App to run its [Schedule](bevy_ecs::schedule::Schedule) according to a given [RunMode] +/// Configures an App to run its [Schedule](bevy_ecs::schedule::Schedule) according to a given +/// [RunMode] #[derive(Default)] pub struct ScheduleRunnerPlugin {} diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index 7d58a10a6f..3586a18ba4 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -226,7 +226,8 @@ impl AssetServer { let asset_loader = self.get_path_asset_loader(asset_path.path())?; let asset_path_id: AssetPathId = asset_path.get_id(); - // load metadata and update source info. this is done in a scope to ensure we release the locks before loading + // load metadata and update source info. this is done in a scope to ensure we release the + // locks before loading let version = { let mut asset_sources = self.server.asset_sources.write(); let source_info = match asset_sources.entry(asset_path_id.source_path_id()) { @@ -282,7 +283,8 @@ impl AssetServer { .await .map_err(AssetServerError::AssetLoaderError)?; - // if version has changed since we loaded and grabbed a lock, return. theres is a newer version being loaded + // if version has changed since we loaded and grabbed a lock, return. theres is a newer + // version being loaded let mut asset_sources = self.server.asset_sources.write(); let source_info = asset_sources .get_mut(&asset_path_id.source_path_id()) diff --git a/crates/bevy_asset/src/filesystem_watcher.rs b/crates/bevy_asset/src/filesystem_watcher.rs index 00a3487e59..004a2b24bf 100644 --- a/crates/bevy_asset/src/filesystem_watcher.rs +++ b/crates/bevy_asset/src/filesystem_watcher.rs @@ -2,7 +2,8 @@ use crossbeam_channel::Receiver; use notify::{Event, RecommendedWatcher, RecursiveMode, Result, Watcher}; use std::path::Path; -/// Watches for changes to assets on the filesystem. This is used by the `AssetServer` to reload them +/// Watches for changes to assets on the filesystem. This is used by the `AssetServer` to reload +/// them pub struct FilesystemWatcher { pub watcher: RecommendedWatcher, pub receiver: Receiver>, diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index c33fcce4f3..d02cfa71ea 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -56,7 +56,8 @@ impl HandleId { /// A handle into a specific Asset of type `T` /// -/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) collection. +/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) +/// collection. #[derive(Reflect)] #[reflect(Component)] pub struct Handle @@ -147,7 +148,8 @@ impl Drop for Handle { fn drop(&mut self) { match self.handle_type { HandleType::Strong(ref sender) => { - // ignore send errors because this means the channel is shut down / the game has stopped + // ignore send errors because this means the channel is shut down / the game has + // stopped let _ = sender.send(RefChange::Decrement(self.id)); } HandleType::Weak => {} @@ -233,7 +235,8 @@ unsafe impl Sync for Handle {} /// A non-generic version of [Handle] /// -/// This allows handles to be mingled in a cross asset context. For example, storing `Handle` and `Handle` in the same `HashSet`. +/// This allows handles to be mingled in a cross asset context. For example, storing `Handle` and +/// `Handle` in the same `HashSet`. #[derive(Debug)] pub struct HandleUntyped { pub id: HandleId, @@ -299,7 +302,8 @@ impl Drop for HandleUntyped { fn drop(&mut self) { match self.handle_type { HandleType::Strong(ref sender) => { - // ignore send errors because this means the channel is shut down / the game has stopped + // ignore send errors because this means the channel is shut down / the game has + // stopped let _ = sender.send(RefChange::Decrement(self.id)); } HandleType::Weak => {} diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 4b2214a5af..d023e66a7a 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -39,8 +39,8 @@ pub enum AssetStage { AssetEvents, } -/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources. -/// Examples of assets: textures, sounds, 3d models, maps, scenes +/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are +/// added as App Resources. Examples of assets: textures, sounds, 3d models, maps, scenes #[derive(Default)] pub struct AssetPlugin; diff --git a/crates/bevy_core/src/bytes.rs b/crates/bevy_core/src/bytes.rs index 495cc64c41..109c523eb4 100644 --- a/crates/bevy_core/src/bytes.rs +++ b/crates/bevy_core/src/bytes.rs @@ -101,8 +101,8 @@ unsafe impl Byteable for isize {} unsafe impl Byteable for f32 {} unsafe impl Byteable for f64 {} unsafe impl Byteable for Vec2 {} -// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually convenient because GLSL -// uniform buffer objects pad Vec3s to be 16 bytes. +// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually +// convenient because GLSL uniform buffer objects pad Vec3s to be 16 bytes. unsafe impl Byteable for Vec3 {} unsafe impl Byteable for Vec4 {} diff --git a/crates/bevy_core/src/float_ord.rs b/crates/bevy_core/src/float_ord.rs index 2958e83857..bf8f1cb32d 100644 --- a/crates/bevy_core/src/float_ord.rs +++ b/crates/bevy_core/src/float_ord.rs @@ -5,9 +5,9 @@ use std::{ ops::Neg, }; -/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float ordering" problem. -/// By using it, you acknowledge that sorting NaN is undefined according to spec. This implementation treats NaN as the -/// "smallest" float. +/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float +/// ordering" problem. By using it, you acknowledge that sorting NaN is undefined according to spec. +/// This implementation treats NaN as the "smallest" float. #[derive(Debug, Copy, Clone, PartialOrd)] pub struct FloatOrd(pub f32); diff --git a/crates/bevy_core/src/label.rs b/crates/bevy_core/src/label.rs index 9bd5aee9d4..ce7b676eb6 100644 --- a/crates/bevy_core/src/label.rs +++ b/crates/bevy_core/src/label.rs @@ -61,7 +61,8 @@ impl Labels { } } -/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity labels to [Entities](bevy_ecs::prelude::Entity). +/// Maintains a mapping from [Entity](bevy_ecs::prelude::Entity) ids to entity labels and entity +/// labels to [Entities](bevy_ecs::prelude::Entity). #[derive(Debug, Default)] pub struct EntityLabels { label_entities: HashMap, Vec>, diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index c887dad0bd..c0c824f10e 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -31,7 +31,8 @@ pub struct CorePlugin; #[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)] pub enum CoreSystem { - /// Updates the elapsed time. Any system that interacts with [Time] component should run after this. + /// Updates the elapsed time. Any system that interacts with [Time] component should run after + /// this. Time, } @@ -54,7 +55,8 @@ impl Plugin for CorePlugin { .register_type::() .register_type::>() .register_type::() - // time system is added as an "exclusive system" to ensure it runs before other systems in CoreStage::First + // time system is added as an "exclusive system" to ensure it runs before other systems + // in CoreStage::First .add_system_to_stage( CoreStage::First, time_system.exclusive_system().label(CoreSystem::Time), diff --git a/crates/bevy_core/src/task_pool_options.rs b/crates/bevy_core/src/task_pool_options.rs index ca8d0c8c97..80b9ad7f78 100644 --- a/crates/bevy_core/src/task_pool_options.rs +++ b/crates/bevy_core/src/task_pool_options.rs @@ -36,9 +36,11 @@ impl TaskPoolThreadAssignmentPolicy { /// this helper will do nothing. #[derive(Clone)] pub struct DefaultTaskPoolOptions { - /// If the number of physical cores is less than min_total_threads, force using min_total_threads + /// If the number of physical cores is less than min_total_threads, force using + /// min_total_threads pub min_total_threads: usize, - /// If the number of physical cores is grater than max_total_threads, force using max_total_threads + /// If the number of physical cores is grater than max_total_threads, force using + /// max_total_threads pub max_total_threads: usize, /// Used to determine number of IO threads to allocate diff --git a/crates/bevy_core/src/time/fixed_timestep.rs b/crates/bevy_core/src/time/fixed_timestep.rs index befd138892..ca5262721f 100644 --- a/crates/bevy_core/src/time/fixed_timestep.rs +++ b/crates/bevy_core/src/time/fixed_timestep.rs @@ -169,8 +169,8 @@ impl System for FixedTimestep { } unsafe fn run_unsafe(&mut self, _input: Self::In, world: &World) -> Self::Out { - // SAFE: this system inherits the internal system's component access and archetype component access, - // which means the caller has ensured running the internal system is safe + // SAFE: this system inherits the internal system's component access and archetype component + // access, which means the caller has ensured running the internal system is safe self.internal_system.run_unsafe((), world) } diff --git a/crates/bevy_core/src/time/timer.rs b/crates/bevy_core/src/time/timer.rs index bec4b29fbc..290d73e7c1 100644 --- a/crates/bevy_core/src/time/timer.rs +++ b/crates/bevy_core/src/time/timer.rs @@ -6,7 +6,8 @@ use bevy_utils::Duration; /// Tracks elapsed time. Enters the finished state once `duration` is reached. /// /// Non repeating timers will stop tracking and stay in the finished state until reset. -/// Repeating timers will only be in the finished state on each tick `duration` is reached or exceeded, and can still be reset at any given point. +/// Repeating timers will only be in the finished state on each tick `duration` is reached or +/// exceeded, and can still be reset at any given point. /// /// Paused timers will not have elapsed time increased. #[derive(Clone, Debug, Default, Reflect)] diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index a7b3d01cf7..8603625470 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -11,8 +11,8 @@ mod shader_defs; use proc_macro::TokenStream; -/// Derives the FromResources trait. Each field must also implement the FromResources trait or this will fail. FromResources is -/// automatically implemented for types that implement Default. +/// Derives the FromResources trait. Each field must also implement the FromResources trait or this +/// will fail. FromResources is automatically implemented for types that implement Default. #[proc_macro_derive(FromResources, attributes(as_crate))] pub fn derive_from_resources(input: TokenStream) -> TokenStream { resource::derive_from_resources(input) diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index ba9220d890..871d31e58a 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -264,7 +264,8 @@ impl Archetype { self.table_info.entity_rows.reserve(additional); } - /// Removes the entity at `index` by swapping it out. Returns the table row the entity is stored in. + /// Removes the entity at `index` by swapping it out. Returns the table row the entity is stored + /// in. pub(crate) fn swap_remove(&mut self, index: usize) -> ArchetypeSwapRemoveResult { let is_last = index == self.entities.len() - 1; self.entities.swap_remove(index); @@ -374,8 +375,8 @@ impl Default for Archetypes { }; archetypes.get_id_or_insert(TableId::empty(), Vec::new(), Vec::new()); - // adds the resource archetype. it is "special" in that it is inaccessible via a "hash", which prevents entities from - // being added to it + // adds the resource archetype. it is "special" in that it is inaccessible via a "hash", + // which prevents entities from being added to it archetypes.archetypes.push(Archetype::new( ArchetypeId::resource(), TableId::empty(), @@ -470,6 +471,7 @@ impl Archetypes { /// Gets the archetype id matching the given inputs or inserts a new one if it doesn't exist. /// `table_components` and `sparse_set_components` must be sorted + /// /// # Safety /// TableId must exist in tables pub(crate) fn get_id_or_insert( diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index e6b1012b4c..1c0e6a44ca 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -8,14 +8,15 @@ use crate::{ use bevy_ecs_macros::all_tuples; use std::{any::TypeId, collections::HashMap}; -/// An ordered collection of components, commonly used for spawning entities, and adding and removing components in bulk. +/// An ordered collection of components, commonly used for spawning entities, and adding and +/// removing components in bulk. /// /// You cannot query for a bundle, only individual components within it. /// /// Typically, you will simply use `#[derive(Bundle)]` when creating your own `Bundle`. /// The `Bundle` trait is automatically implemented for tuples of components: -/// `(ComponentA, ComponentB)` is a very convenient shorthand when working with one-off collections of components. -/// Note that both `()` and `(ComponentA, )` are valid tuples. +/// `(ComponentA, ComponentB)` is a very convenient shorthand when working with one-off collections +/// of components. Note that both `()` and `(ComponentA, )` are valid tuples. /// /// You can nest bundles like so: /// ``` @@ -34,23 +35,29 @@ use std::{any::TypeId, collections::HashMap}; /// z: String, /// } /// ``` +/// /// # Safety -/// [Bundle::type_info] must return the TypeInfo for each component type in the bundle, in the _exact_ -/// order that [Bundle::get_components] is called. -/// [Bundle::from_components] must call `func` exactly once for each [TypeInfo] returned by [Bundle::type_info] +/// [Bundle::type_info] must return the TypeInfo for each component type in the bundle, in the +/// _exact_ order that [Bundle::get_components] is called. +/// [Bundle::from_components] must call `func` exactly once for each [TypeInfo] returned by +/// [Bundle::type_info] pub unsafe trait Bundle: Send + Sync + 'static { /// Gets this [Bundle]'s components type info, in the order of this bundle's Components fn type_info() -> Vec; - /// Calls `func`, which should return data for each component in the bundle, in the order of this bundle's Components + /// Calls `func`, which should return data for each component in the bundle, in the order of + /// this bundle's Components + /// /// # Safety - /// Caller must return data for each component in the bundle, in the order of this bundle's Components + /// Caller must return data for each component in the bundle, in the order of this bundle's + /// Components unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self where Self: Sized; - /// Calls `func` on each value, in the order of this bundle's Components. This will "mem::forget" the bundle - /// fields, so callers are responsible for dropping the fields if that is desirable. + /// Calls `func` on each value, in the order of this bundle's Components. This will + /// "mem::forget" the bundle fields, so callers are responsible for dropping the fields if + /// that is desirable. fn get_components(self, func: impl FnMut(*mut u8)); } @@ -126,7 +133,8 @@ impl BundleInfo { bundle_flags: &[ComponentFlags], bundle: T, ) { - // NOTE: get_components calls this closure on each component in "bundle order". bundle_info.component_ids are also in "bundle order" + // NOTE: get_components calls this closure on each component in "bundle order". + // bundle_info.component_ids are also in "bundle order" let mut bundle_component = 0; bundle.get_components(|component_ptr| { // SAFE: component_id was initialized by get_dynamic_bundle_info diff --git a/crates/bevy_ecs/src/component/mod.rs b/crates/bevy_ecs/src/component/mod.rs index 914030eff4..7b101c4bcb 100644 --- a/crates/bevy_ecs/src/component/mod.rs +++ b/crates/bevy_ecs/src/component/mod.rs @@ -31,7 +31,8 @@ pub struct ComponentInfo { name: String, id: ComponentId, type_id: Option, - // SAFETY: This must remain private. It must only be set to "true" if this component is actually Send + Sync + // SAFETY: This must remain private. It must only be set to "true" if this component is + // actually Send + Sync is_send_and_sync: bool, layout: Layout, drop: unsafe fn(*mut u8), @@ -116,7 +117,8 @@ impl SparseSetIndex for ComponentId { pub struct ComponentDescriptor { name: String, storage_type: StorageType, - // SAFETY: This must remain private. It must only be set to "true" if this component is actually Send + Sync + // SAFETY: This must remain private. It must only be set to "true" if this component is + // actually Send + Sync is_send_and_sync: bool, type_id: Option, layout: Layout, diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 85d67e024f..1c03c9b784 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -56,9 +56,9 @@ impl Entity { self.id } - /// Returns the generation of this Entity's id. The generation is incremented each time an entity with - /// a given id is despawned. This serves as a "count" of the number of times a given id has been reused - /// (id, generation) pairs uniquely identify a given Entity. + /// Returns the generation of this Entity's id. The generation is incremented each time an + /// entity with a given id is despawned. This serves as a "count" of the number of times a + /// given id has been reused (id, generation) pairs uniquely identify a given Entity. #[inline] pub fn generation(self) -> u32 { self.generation @@ -121,16 +121,16 @@ pub struct Entities { /// The `pending` and `free_cursor` fields describe three sets of Entity IDs /// that have been freed or are in the process of being allocated: /// - /// - The `freelist` IDs, previously freed by `free()`. These IDs are available to any - /// of `alloc()`, `reserve_entity()` or `reserve_entities()`. Allocation will - /// always prefer these over brand new IDs. + /// - The `freelist` IDs, previously freed by `free()`. These IDs are available to any of + /// `alloc()`, `reserve_entity()` or `reserve_entities()`. Allocation will always prefer + /// these over brand new IDs. /// - /// - The `reserved` list of IDs that were once in the freelist, but got - /// reserved by `reserve_entities` or `reserve_entity()`. They are now waiting - /// for `flush()` to make them fully allocated. + /// - The `reserved` list of IDs that were once in the freelist, but got reserved by + /// `reserve_entities` or `reserve_entity()`. They are now waiting for `flush()` to make them + /// fully allocated. /// - /// - The count of new IDs that do not yet exist in `self.meta()`, but which - /// we have handed out and reserved. `flush()` will allocate room for them in `self.meta()`. + /// - The count of new IDs that do not yet exist in `self.meta()`, but which we have handed out + /// and reserved. `flush()` will allocate room for them in `self.meta()`. /// /// The contents of `pending` look like this: /// @@ -257,7 +257,8 @@ impl Entities { /// Allocate a specific entity ID, overwriting its generation /// - /// Returns the location of the entity currently using the given ID, if any. Location should be written immediately. + /// Returns the location of the entity currently using the given ID, if any. Location should be + /// written immediately. pub fn alloc_at(&mut self, entity: Entity) -> Option { self.verify_flushed(); diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index b6e805a2f4..2f2d625dde 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -171,7 +171,8 @@ impl FilteredAccessSet { } pub fn get_conflicts(&self, filtered_access: &FilteredAccess) -> Vec { - // if combined unfiltered access is incompatible, check each filtered access for compatibility + // if combined unfiltered access is incompatible, check each filtered access for + // compatibility if !filtered_access.access.is_compatible(&self.combined_access) { for current_filtered_access in self.filtered_accesses.iter() { if !current_filtered_access.is_compatible(&filtered_access) { diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 10f7f6b4ab..807030c1e9 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -22,44 +22,60 @@ pub trait Fetch<'w>: Sized { type State: FetchState; /// Creates a new instance of this fetch. + /// /// # Safety - /// `state` must have been initialized (via [FetchState::init]) using the same `world` passed in to this function. + /// `state` must have been initialized (via [FetchState::init]) using the same `world` passed in + /// to this function. unsafe fn init(world: &World, state: &Self::State) -> Self; - /// Returns true if (and only if) every table of every archetype matched by this Fetch contains all of the matched components. - /// This is used to select a more efficient "table iterator" for "dense" queries. - /// If this returns true, [Fetch::set_table] and [Fetch::table_fetch] will be called for iterators - /// If this returns false, [Fetch::set_archetype] and [Fetch::archetype_fetch] will be called for iterators + /// Returns true if (and only if) every table of every archetype matched by this Fetch contains + /// all of the matched components. This is used to select a more efficient "table iterator" + /// for "dense" queries. If this returns true, [Fetch::set_table] and [Fetch::table_fetch] + /// will be called for iterators If this returns false, [Fetch::set_archetype] and + /// [Fetch::archetype_fetch] will be called for iterators fn is_dense(&self) -> bool; - /// Adjusts internal state to account for the next [Archetype]. This will always be called on archetypes that match this [Fetch] + /// Adjusts internal state to account for the next [Archetype]. This will always be called on + /// archetypes that match this [Fetch] + /// /// # Safety - /// `archetype` and `tables` must be from the [World] [Fetch::init] was called on. `state` must be the [Self::State] this was initialized with. + /// `archetype` and `tables` must be from the [World] [Fetch::init] was called on. `state` must + /// be the [Self::State] this was initialized with. unsafe fn set_archetype(&mut self, state: &Self::State, archetype: &Archetype, tables: &Tables); - /// Adjusts internal state to account for the next [Table]. This will always be called on tables that match this [Fetch] + /// Adjusts internal state to account for the next [Table]. This will always be called on tables + /// that match this [Fetch] + /// /// # Safety - /// `table` must be from the [World] [Fetch::init] was called on. `state` must be the [Self::State] this was initialized with. + /// `table` must be from the [World] [Fetch::init] was called on. `state` must be the + /// [Self::State] this was initialized with. unsafe fn set_table(&mut self, state: &Self::State, table: &Table); - /// Fetch [Self::Item] for the given `archetype_index` in the current [Archetype]. This must always be called after [Fetch::set_archetype] with an `archetype_index` - /// in the range of the current [Archetype] + /// Fetch [Self::Item] for the given `archetype_index` in the current [Archetype]. This must + /// always be called after [Fetch::set_archetype] with an `archetype_index` in the range of + /// the current [Archetype] + /// /// # Safety - /// Must always be called _after_ [Fetch::set_archetype]. `archetype_index` must be in the range of the current archetype + /// Must always be called _after_ [Fetch::set_archetype]. `archetype_index` must be in the range + /// of the current archetype unsafe fn archetype_fetch(&mut self, archetype_index: usize) -> Self::Item; - /// Fetch [Self::Item] for the given `table_row` in the current [Table]. This must always be called after [Fetch::set_table] with a `table_row` - /// in the range of the current [Table] + /// Fetch [Self::Item] for the given `table_row` in the current [Table]. This must always be + /// called after [Fetch::set_table] with a `table_row` in the range of the current [Table] + /// /// # Safety - /// Must always be called _after_ [Fetch::set_table]. `table_row` must be in the range of the current table + /// Must always be called _after_ [Fetch::set_table]. `table_row` must be in the range of the + /// current table unsafe fn table_fetch(&mut self, table_row: usize) -> Self::Item; } -/// State used to construct a Fetch. This will be cached inside QueryState, so it is best to move as much data / -/// computation here as possible to reduce the cost of constructing Fetch. +/// State used to construct a Fetch. This will be cached inside QueryState, so it is best to move as +/// much data / computation here as possible to reduce the cost of constructing Fetch. /// SAFETY: -/// Implementor must ensure that [FetchState::update_component_access] and [FetchState::update_archetype_component_access] exactly -/// reflects the results of [FetchState::matches_archetype], [FetchState::matches_table], [Fetch::archetype_fetch], and [Fetch::table_fetch] +/// Implementor must ensure that [FetchState::update_component_access] and +/// [FetchState::update_archetype_component_access] exactly reflects the results of +/// [FetchState::matches_archetype], [FetchState::matches_table], [Fetch::archetype_fetch], and +/// [Fetch::table_fetch] pub unsafe trait FetchState: Send + Sync + Sized { fn init(world: &mut World) -> Self; fn update_component_access(&self, access: &mut FilteredAccess); @@ -167,7 +183,8 @@ pub struct ReadState { marker: PhantomData, } -// SAFE: component access and archetype component access are properly updated to reflect that T is read +// SAFE: component access and archetype component access are properly updated to reflect that T is +// read unsafe impl FetchState for ReadState { fn init(world: &mut World) -> Self { let component_info = world.components.get_or_insert_info::(); @@ -312,7 +329,8 @@ pub struct WriteState { marker: PhantomData, } -// SAFE: component access and archetype component access are properly updated to reflect that T is written +// SAFE: component access and archetype component access are properly updated to reflect that T is +// written unsafe impl FetchState for WriteState { fn init(world: &mut World) -> Self { let component_info = world.components.get_or_insert_info::(); @@ -457,7 +475,8 @@ pub struct OptionState { state: T, } -// SAFE: component access and archetype component access are properly updated according to the internal Fetch +// SAFE: component access and archetype component access are properly updated according to the +// internal Fetch unsafe impl FetchState for OptionState { fn init(world: &mut World) -> Self { Self { @@ -589,7 +608,8 @@ pub struct FlagsState { marker: PhantomData, } -// SAFE: component access and archetype component access are properly updated to reflect that T is read +// SAFE: component access and archetype component access are properly updated to reflect that T is +// read unsafe impl FetchState for FlagsState { fn init(world: &mut World) -> Self { let component_info = world.components.get_or_insert_info::(); diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index ff977445d3..60a45a2f76 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -10,8 +10,8 @@ use crate::{ use bevy_ecs_macros::all_tuples; use std::{marker::PhantomData, ptr}; -// TODO: uncomment this and use as shorthand (remove where F::Fetch: FilterFetch everywhere) when this bug is fixed in Rust 1.51: -// https://github.com/rust-lang/rust/pull/81671 +// TODO: uncomment this and use as shorthand (remove where F::Fetch: FilterFetch everywhere) when +// this bug is fixed in Rust 1.51: https://github.com/rust-lang/rust/pull/81671 // pub trait QueryFilter: WorldQuery // where // Self::Fetch: FilterFetch, @@ -21,14 +21,17 @@ use std::{marker::PhantomData, ptr}; // impl QueryFilter for T where T::Fetch: FilterFetch { // } -/// Fetch methods used by query filters. This trait exists to allow "short circuit" behaviors for relevant query filter fetches. +/// Fetch methods used by query filters. This trait exists to allow "short circuit" behaviors for +/// relevant query filter fetches. pub trait FilterFetch: for<'a> Fetch<'a> { /// # Safety - /// Must always be called _after_ [Fetch::set_archetype]. `archetype_index` must be in the range of the current archetype + /// Must always be called _after_ [Fetch::set_archetype]. `archetype_index` must be in the range + /// of the current archetype unsafe fn archetype_filter_fetch(&mut self, archetype_index: usize) -> bool; /// # Safety - /// Must always be called _after_ [Fetch::set_table]. `table_row` must be in the range of the current table + /// Must always be called _after_ [Fetch::set_table]. `table_row` must be in the range of the + /// current table unsafe fn table_filter_fetch(&mut self, table_row: usize) -> bool; } @@ -47,7 +50,8 @@ where } } -/// Filter that retrieves components of type `T` that have either been mutated or added since the start of the frame. +/// Filter that retrieves components of type `T` that have either been mutated or added since the +/// start of the frame. pub struct With(PhantomData); impl WorldQuery for With { @@ -137,7 +141,8 @@ impl<'a, T: Component> Fetch<'a> for WithFetch { } } -/// Filter that retrieves components of type `T` that have either been mutated or added since the start of the frame. +/// Filter that retrieves components of type `T` that have either been mutated or added since the +/// start of the frame. pub struct Without(PhantomData); impl WorldQuery for Without { @@ -573,13 +578,15 @@ macro_rules! impl_flag_filter { } impl_flag_filter!( - /// Filter that retrieves components of type `T` that have been added since the start of the frame + /// Filter that retrieves components of type `T` that have been added since the start of the + /// frame /// - /// This filter is useful as a performance optimization as it means that the query contains fewer items - /// for a system to iterate over. + /// This filter is useful as a performance optimization as it means that the query contains + /// fewer items for a system to iterate over. /// - /// Because the ordering of systems can change and this filter is only effective on changes before the query executes - /// you need to use explicit dependency ordering or ordered stages for these query filters to be useful. + /// Because the ordering of systems can change and this filter is only effective on changes + /// before the query executes you need to use explicit dependency ordering or ordered + /// stages for these query filters to be useful. /// /// /// Example: @@ -604,14 +611,15 @@ impl_flag_filter!( ); impl_flag_filter!( - /// Filter that retrieves components of type `T` that have been mutated since the start of the frame. - /// Added components do not count as mutated. + /// Filter that retrieves components of type `T` that have been mutated since the start of the + /// frame. Added components do not count as mutated. /// - /// This filter is useful as a performance optimization as it means that the query contains fewer items - /// for a system to iterate over. + /// This filter is useful as a performance optimization as it means that the query contains + /// fewer items for a system to iterate over. /// - /// Because the ordering of systems can change and this filter is only effective on changes before the query executes - /// you need to use explicit dependency ordering or ordered stages for these query filters to be useful. + /// Because the ordering of systems can change and this filter is only effective on changes + /// before the query executes you need to use explicit dependency ordering or ordered + /// stages for these query filters to be useful. /// /// Example: /// ``` @@ -635,15 +643,18 @@ impl_flag_filter!( ); impl_flag_filter!( - /// Filter that retrieves components of type `T` that have been added or mutated since the start of the frame + /// Filter that retrieves components of type `T` that have been added or mutated since the + /// start of the frame /// - /// This filter is useful as a performance optimization as it means that the query contains fewer items - /// for a system to iterate over. + /// This filter is useful as a performance optimization as it means that the query contains + /// fewer items for a system to iterate over. /// - /// Because the ordering of systems can change and this filter is only effective on changes before the query executes - /// you need to use explicit dependency ordering or ordered stages for these query filters to be useful. + /// Because the ordering of systems can change and this filter is only effective on changes + /// before the query executes you need to use explicit dependency ordering or ordered + /// stages for these query filters to be useful. /// - /// Also see the documentation for [`Mutated`] and [`Added`] as this filter is a logical OR of them. + /// Also see the documentation for [`Mutated`] and [`Added`] as this filter is a logical OR + /// of them. Changed, ChangedState, ChangedFetch, diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index b87fc7c637..93d4c29f44 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -199,8 +199,8 @@ where /// # Safety /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. - /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` with - /// a mismatched WorldId is unsafe. + /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` + /// with a mismatched WorldId is unsafe. #[inline] pub(crate) unsafe fn iter_unchecked_manual<'w, 's>( &'s self, @@ -296,8 +296,8 @@ where /// # Safety /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. - /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` with - /// a mismatched WorldId is unsafe. + /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` + /// with a mismatched WorldId is unsafe. pub(crate) unsafe fn for_each_unchecked_manual<'w, 's>( &'s self, world: &'w World, @@ -341,8 +341,8 @@ where /// # Safety /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. - /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` with - /// a mismatched WorldId is unsafe. + /// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world` + /// with a mismatched WorldId is unsafe. pub unsafe fn par_for_each_unchecked_manual<'w, 's>( &'s self, world: &'w World, diff --git a/crates/bevy_ecs/src/reflect.rs b/crates/bevy_ecs/src/reflect.rs index c2a462027f..ed5ab878db 100644 --- a/crates/bevy_ecs/src/reflect.rs +++ b/crates/bevy_ecs/src/reflect.rs @@ -43,8 +43,10 @@ impl ReflectComponent { } /// # Safety - /// This method does not prevent you from having two mutable pointers to the same data, violating Rust's aliasing rules. To avoid this: - /// * Only call this method in an exclusive system to avoid sharing across threads (or use a scheduler that enforces safe memory access). + /// This method does not prevent you from having two mutable pointers to the same data, + /// violating Rust's aliasing rules. To avoid this: + /// * Only call this method in an exclusive system to avoid sharing across threads (or use a + /// scheduler that enforces safe memory access). /// * Don't call this method more than once in the same scope for a given component. pub unsafe fn reflect_component_unchecked_mut<'a>( &self, diff --git a/crates/bevy_ecs/src/schedule/executor.rs b/crates/bevy_ecs/src/schedule/executor.rs index ba08d0d10f..6cef6b3ed3 100644 --- a/crates/bevy_ecs/src/schedule/executor.rs +++ b/crates/bevy_ecs/src/schedule/executor.rs @@ -38,8 +38,8 @@ impl ParallelSystemExecutor for SingleThreadedExecutor { } impl SingleThreadedExecutor { - /// Calls system.new_archetype() for each archetype added since the last call to [update_archetypes] and - /// updates cached archetype_component_access. + /// Calls system.new_archetype() for each archetype added since the last call to + /// [update_archetypes] and updates cached archetype_component_access. fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) { let archetypes = world.archetypes(); let old_generation = self.archetype_generation; diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index 49ae06b673..f24c43adad 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -148,8 +148,8 @@ impl ParallelSystemExecutor for ParallelExecutor { } impl ParallelExecutor { - /// Calls system.new_archetype() for each archetype added since the last call to [update_archetypes] and - /// updates cached archetype_component_access. + /// Calls system.new_archetype() for each archetype added since the last call to + /// [update_archetypes] and updates cached archetype_component_access. fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) { let archetypes = world.archetypes(); let old_generation = self.archetype_generation; diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 458ad71ab7..1d087ceffe 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -35,13 +35,14 @@ impl_downcast!(Stage); /// This occurs because, in the absence of explicit constraints, systems are executed in /// an unstable, arbitrary order within each stage that may vary between runs and frames. /// -/// Some ambiguities reported by the ambiguity checker may be warranted (to allow two systems to run without blocking each other) -/// or spurious, as the exact combination of archetypes used may prevent them from ever conflicting during actual gameplay. -/// You can resolve the warnings produced by the ambiguity checker by adding `.before` or `.after` to one of the conflicting systems +/// Some ambiguities reported by the ambiguity checker may be warranted (to allow two systems to run +/// without blocking each other) or spurious, as the exact combination of archetypes used may +/// prevent them from ever conflicting during actual gameplay. You can resolve the warnings produced +/// by the ambiguity checker by adding `.before` or `.after` to one of the conflicting systems /// referencing the other system to force a specific ordering. /// -/// The checker may report a system more times than the amount of constraints it would actually need to have -/// unambiguous order with regards to a group of already-constrained systems. +/// The checker may report a system more times than the amount of constraints it would actually need +/// to have unambiguous order with regards to a group of already-constrained systems. pub struct ReportExecutionOrderAmbiguities; struct VirtualSystemSet { @@ -523,7 +524,7 @@ fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec< for (index_a, relations) in all_relations.drain(..).enumerate() { // TODO: prove that `.take(index_a)` would be correct here, and uncomment it if so. for index_b in full_bitset.difference(&relations) - /*.take(index_a)*/ + // .take(index_a) { if !processed.contains(index_b) && all_ambiguity_sets[index_a].is_disjoint(&all_ambiguity_sets[index_b]) diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 0ffbb84069..a590910267 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -217,7 +217,8 @@ impl State { self.next.as_ref() } - /// Queue a state change. This will fail if there is already a state in the queue, or if the given `state` matches the current state + /// Queue a state change. This will fail if there is already a state in the queue, or if the + /// given `state` matches the current state pub fn set_next(&mut self, state: T) -> Result<(), StateError> { if std::mem::discriminant(&self.current) == std::mem::discriminant(&state) { return Err(StateError::AlreadyInState); @@ -231,7 +232,8 @@ impl State { Ok(()) } - /// Same as [Self::set_next], but if there is already a next state, it will be overwritten instead of failing + /// Same as [Self::set_next], but if there is already a next state, it will be overwritten + /// instead of failing pub fn overwrite_next(&mut self, state: T) -> Result<(), StateError> { if std::mem::discriminant(&self.current) == std::mem::discriminant(&state) { return Err(StateError::AlreadyInState); diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index 56e1026e13..b236d88827 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -98,7 +98,9 @@ impl BlobVec { std::ptr::copy_nonoverlapping(value, ptr, self.item_layout.size()); } - /// increases the length by one (and grows the vec if needed) with uninitialized memory and returns the index + /// increases the length by one (and grows the vec if needed) with uninitialized memory and + /// returns the index + /// /// # Safety /// the newly allocated space must be immediately populated with a valid value #[inline] @@ -110,17 +112,19 @@ impl BlobVec { } /// # Safety - /// len must be <= capacity. if length is decreased, "out of bounds" items must be dropped. Newly added items must be - /// immediately populated with valid values and length must be increased. For better unwind safety, call [BlobVec::set_len] - /// _after_ populating a new value. + /// len must be <= capacity. if length is decreased, "out of bounds" items must be dropped. + /// Newly added items must be immediately populated with valid values and length must be + /// increased. For better unwind safety, call [BlobVec::set_len] _after_ populating a new + /// value. pub unsafe fn set_len(&mut self, len: usize) { debug_assert!(len <= self.capacity()); self.len = len; } - /// Performs a "swap remove" at the given `index`, which removes the item at `index` and moves the last item - /// in the [BlobVec] to `index` (if `index` is not the last item). It is the caller's responsibility to - /// drop the returned pointer, if that is desirable. + /// Performs a "swap remove" at the given `index`, which removes the item at `index` and moves + /// the last item in the [BlobVec] to `index` (if `index` is not the last item). It is the + /// caller's responsibility to drop the returned pointer, if that is desirable. + /// /// # Safety /// It is the caller's responsibility to ensure that `index` is < self.len() /// Callers should _only_ access the returned pointer immediately after calling this function. @@ -161,6 +165,7 @@ impl BlobVec { } /// Gets a pointer to the start of the vec + /// /// # Safety /// must ensure rust mutability rules are not violated #[inline] @@ -170,13 +175,13 @@ impl BlobVec { pub fn clear(&mut self) { let len = self.len; - // We set len to 0 _before_ dropping elements for unwind safety. This ensures we don't accidentally - // drop elements twice in the event of a drop impl panicking. + // We set len to 0 _before_ dropping elements for unwind safety. This ensures we don't + // accidentally drop elements twice in the event of a drop impl panicking. self.len = 0; for i in 0..len { unsafe { - // NOTE: this doesn't use self.get_unchecked(i) because the debug_assert on index will - // panic here due to self.len being set to 0 + // NOTE: this doesn't use self.get_unchecked(i) because the debug_assert on index + // will panic here due to self.len being set to 0 let ptr = self.get_ptr().as_ptr().add(i * self.item_layout.size()); (self.drop)(ptr); } @@ -260,7 +265,8 @@ mod tests { use crate::component::TypeInfo; use std::{alloc::Layout, cell::RefCell, rc::Rc}; - /// # Safety: + /// # Safety + /// /// `blob_vec` must have a layout that matches Layout::new::() unsafe fn push(blob_vec: &mut BlobVec, mut value: T) { let index = blob_vec.push_uninit(); @@ -268,7 +274,8 @@ mod tests { std::mem::forget(value); } - /// # Safety: + /// # Safety + /// /// `blob_vec` must have a layout that matches Layout::new::() unsafe fn swap_remove(blob_vec: &mut BlobVec, index: usize) -> T { assert!(index < blob_vec.len()); @@ -276,9 +283,10 @@ mod tests { value.cast::().read() } - /// # Safety: - /// `blob_vec` must have a layout that matches Layout::new::(), it most store a valid T value at - /// the given `index` + /// # Safety + /// + /// `blob_vec` must have a layout that matches Layout::new::(), it most store a valid T value + /// at the given `index` unsafe fn get_mut(blob_vec: &mut BlobVec, index: usize) -> &mut T { assert!(index < blob_vec.len()); &mut *blob_vec.get_unchecked(index).cast::() diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index cf4ea2b3d4..67c3180cfd 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -113,10 +113,12 @@ impl ComponentSparseSet { } /// Inserts the `entity` key and component `value` pair into this sparse set. - /// The caller is responsible for ensuring the value is not dropped. This collection will drop the value when needed. + /// The caller is responsible for ensuring the value is not dropped. This collection will drop + /// the value when needed. + /// /// # Safety - /// The `value` pointer must point to a valid address that matches the `Layout` inside the `ComponentInfo` given - /// when constructing this sparse set. + /// The `value` pointer must point to a valid address that matches the `Layout` inside the + /// `ComponentInfo` given when constructing this sparse set. pub unsafe fn insert(&mut self, entity: Entity, value: *mut u8, flags: ComponentFlags) { let dense = &mut self.dense; let entities = &mut self.entities; @@ -175,8 +177,9 @@ impl ComponentSparseSet { }) } - /// Removes the `entity` from this sparse set and returns a pointer to the associated value (if it exists). - /// It is the caller's responsibility to drop the returned ptr (if Some is returned). + /// Removes the `entity` from this sparse set and returns a pointer to the associated value (if + /// it exists). It is the caller's responsibility to drop the returned ptr (if Some is + /// returned). pub fn remove_and_forget(&mut self, entity: Entity) -> Option<*mut u8> { self.sparse.remove(entity).map(|dense_index| { // SAFE: unique access to flags @@ -268,8 +271,8 @@ impl SparseSet { self.dense.push(value); } - // PERF: switch to this. it's faster but it has an invalid memory access on table_add_remove_many - // let dense = &mut self.dense; + // PERF: switch to this. it's faster but it has an invalid memory access on + // table_add_remove_many let dense = &mut self.dense; // let indices = &mut self.indices; // let dense_index = *self.sparse.get_or_insert_with(index.clone(), move || { // if dense.len() == dense.capacity() { diff --git a/crates/bevy_ecs/src/storage/table.rs b/crates/bevy_ecs/src/storage/table.rs index 45449ed58a..82a93c9d25 100644 --- a/crates/bevy_ecs/src/storage/table.rs +++ b/crates/bevy_ecs/src/storage/table.rs @@ -49,7 +49,8 @@ impl Column { /// # Safety /// Assumes data has already been allocated for the given row/column. - /// Allows aliased mutable accesses to the data at the given `row`. Caller must ensure that this does not happen. + /// Allows aliased mutable accesses to the data at the given `row`. Caller must ensure that this + /// does not happen. #[inline] pub unsafe fn set_unchecked(&self, row: usize, data: *mut u8) { self.data.set_unchecked(row, data); @@ -67,7 +68,8 @@ impl Column { /// # Safety /// Assumes data has already been allocated for the given row/column. - /// Allows aliased mutable accesses to the row's ComponentFlags. Caller must ensure that this does not happen. + /// Allows aliased mutable accesses to the row's ComponentFlags. Caller must ensure that this + /// does not happen. #[inline] #[allow(clippy::mut_from_ref)] pub unsafe fn get_flags_unchecked_mut(&self, row: usize) -> &mut ComponentFlags { @@ -193,7 +195,9 @@ impl Table { ) } - /// Removes the entity at the given row and returns the entity swapped in to replace it (if an entity was swapped in) + /// Removes the entity at the given row and returns the entity swapped in to replace it (if an + /// entity was swapped in) + /// /// # Safety /// `row` must be in-bounds pub unsafe fn swap_remove_unchecked(&mut self, row: usize) -> Option { @@ -209,9 +213,11 @@ impl Table { } } - /// Moves the `row` column values to `new_table`, for the columns shared between both tables. Returns the index of the - /// new row in `new_table` and the entity in this table swapped in to replace it (if an entity was swapped in). - /// missing columns will be "forgotten". It is the caller's responsibility to drop them + /// Moves the `row` column values to `new_table`, for the columns shared between both tables. + /// Returns the index of the new row in `new_table` and the entity in this table swapped in + /// to replace it (if an entity was swapped in). missing columns will be "forgotten". It is + /// the caller's responsibility to drop them + /// /// # Safety /// Row must be in-bounds pub unsafe fn move_to_and_forget_missing_unchecked( @@ -239,8 +245,10 @@ impl Table { } } - /// Moves the `row` column values to `new_table`, for the columns shared between both tables. Returns the index of the - /// new row in `new_table` and the entity in this table swapped in to replace it (if an entity was swapped in). + /// Moves the `row` column values to `new_table`, for the columns shared between both tables. + /// Returns the index of the new row in `new_table` and the entity in this table swapped in + /// to replace it (if an entity was swapped in). + /// /// # Safety /// row must be in-bounds pub unsafe fn move_to_and_drop_missing_unchecked( @@ -270,8 +278,10 @@ impl Table { } } - /// Moves the `row` column values to `new_table`, for the columns shared between both tables. Returns the index of the - /// new row in `new_table` and the entity in this table swapped in to replace it (if an entity was swapped in). + /// Moves the `row` column values to `new_table`, for the columns shared between both tables. + /// Returns the index of the new row in `new_table` and the entity in this table swapped in + /// to replace it (if an entity was swapped in). + /// /// # Safety /// `row` must be in-bounds. `new_table` must contain every component this table has pub unsafe fn move_to_superset_unchecked( @@ -326,6 +336,7 @@ impl Table { } /// Allocates space for a new entity + /// /// # Safety /// the allocated row must be written to immediately with valid values in each column pub unsafe fn allocate(&mut self, entity: Entity) -> usize { diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index 8b60b9ada1..9e2d0c31ca 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -49,7 +49,10 @@ impl<'a> Commands<'a> { /// Creates a new entity with the components contained in `bundle`. /// - /// Note that `bundle` is a [Bundle], which is a collection of components. [Bundle] is automatically implemented for tuples of components. You can also create your own bundle types by deriving [`derive@Bundle`]. If you would like to spawn an entity with a single component, consider wrapping the component in a tuple (which [Bundle] is implemented for). + /// Note that `bundle` is a [Bundle], which is a collection of components. [Bundle] is + /// automatically implemented for tuples of components. You can also create your own bundle + /// types by deriving [`derive@Bundle`]. If you would like to spawn an entity with a single + /// component, consider wrapping the component in a tuple (which [Bundle] is implemented for). /// /// See [`Self::set_current_entity`], [`Self::insert`]. /// @@ -88,7 +91,8 @@ impl<'a> Commands<'a> { self } - /// Equivalent to iterating `bundles_iter` and calling [`Self::spawn`] on each bundle, but slightly more performant. + /// Equivalent to iterating `bundles_iter` and calling [`Self::spawn`] on each bundle, but + /// slightly more performant. pub fn spawn_batch(&mut self, bundles_iter: I) -> &mut Self where I: IntoIterator + Send + Sync + 'static, @@ -167,7 +171,10 @@ impl<'a> Commands<'a> { /// /// # Warning /// - /// It's possible to call this with a bundle, but this is likely not intended and [`Self::with_bundle`] should be used instead. If `with` is called with a bundle, the bundle itself will be added as a component instead of the bundles' inner components each being added. + /// It's possible to call this with a bundle, but this is likely not intended and + /// [`Self::with_bundle`] should be used instead. If `with` is called with a bundle, the bundle + /// itself will be added as a component instead of the bundles' inner components each being + /// added. /// /// # Example /// @@ -207,7 +214,8 @@ impl<'a> Commands<'a> { self } - /// Adds a command directly to the command list. Prefer this to [`Self::add_command_boxed`] if the type of `command` is statically known. + /// Adds a command directly to the command list. Prefer this to [`Self::add_command_boxed`] if + /// the type of `command` is statically known. pub fn add_command(&mut self, command: C) -> &mut Self { self.queue.push(Box::new(command)); self @@ -344,7 +352,8 @@ where { fn write(self: Box, world: &mut World) { if let Some(mut entity_mut) = world.get_entity_mut(self.entity) { - // remove intersection to gracefully handle components that were removed before running this command + // remove intersection to gracefully handle components that were removed before running + // this command entity_mut.remove_bundle_intersection::(); } } diff --git a/crates/bevy_ecs/src/system/into_system.rs b/crates/bevy_ecs/src/system/into_system.rs index 3317fe8a99..ed9c707ae3 100644 --- a/crates/bevy_ecs/src/system/into_system.rs +++ b/crates/bevy_ecs/src/system/into_system.rs @@ -13,7 +13,8 @@ pub struct SystemState { pub(crate) name: Cow<'static, str>, pub(crate) component_access_set: FilteredAccessSet, pub(crate) archetype_component_access: Access, - // NOTE: this must be kept private. making a SystemState non-send is irreversible to prevent SystemParams from overriding each other + // NOTE: this must be kept private. making a SystemState non-send is irreversible to prevent + // SystemParams from overriding each other is_send: bool, } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index d19056b86c..0361d82122 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -24,8 +24,8 @@ where F::Fetch: FilterFetch, { /// # Safety - /// This will create a Query that could violate memory safety rules. Make sure that this is only called in - /// ways that ensure the Queries have unique mutable access. + /// This will create a Query that could violate memory safety rules. Make sure that this is only + /// called in ways that ensure the Queries have unique mutable access. #[inline] pub(crate) unsafe fn new(world: &'w World, state: &'w QueryState) -> Self { Self { world, state } @@ -37,41 +37,49 @@ where where Q::Fetch: ReadOnlyFetch, { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state.iter_unchecked_manual(self.world) } } /// Iterates over the query results #[inline] pub fn iter_mut(&mut self) -> QueryIter<'_, '_, Q, F> { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state.iter_unchecked_manual(self.world) } } /// Iterates over the query results + /// /// # Safety - /// This allows aliased mutability. You must make sure this call does not result in multiple mutable references to the same component + /// This allows aliased mutability. You must make sure this call does not result in multiple + /// mutable references to the same component #[inline] pub unsafe fn iter_unsafe(&self) -> QueryIter<'_, '_, Q, F> { - // SEMI-SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SEMI-SAFE: system runs without conflicts with other systems. same-system queries have + // runtime borrow checks when they conflict self.state.iter_unchecked_manual(self.world) } - /// Runs `f` on each query result. This is faster than the equivalent iter() method, but cannot be chained like a normal iterator. - /// This can only be called for read-only queries + /// Runs `f` on each query result. This is faster than the equivalent iter() method, but cannot + /// be chained like a normal iterator. This can only be called for read-only queries #[inline] pub fn for_each(&self, f: impl FnMut(>::Item)) where Q::Fetch: ReadOnlyFetch, { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state.for_each_unchecked_manual(self.world, f) }; } - /// Runs `f` on each query result. This is faster than the equivalent iter() method, but cannot be chained like a normal iterator. + /// Runs `f` on each query result. This is faster than the equivalent iter() method, but cannot + /// be chained like a normal iterator. #[inline] pub fn for_each_mut(&self, f: impl FnMut(>::Item)) { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state.for_each_unchecked_manual(self.world, f) }; } @@ -85,7 +93,8 @@ where ) where Q::Fetch: ReadOnlyFetch, { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state .par_for_each_unchecked_manual(self.world, task_pool, batch_size, f) @@ -100,7 +109,8 @@ where batch_size: usize, f: impl Fn(>::Item) + Send + Sync + Clone, ) { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state .par_for_each_unchecked_manual(self.world, task_pool, batch_size, f) @@ -113,7 +123,8 @@ where where Q::Fetch: ReadOnlyFetch, { - // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SAFE: system runs without conflicts with other systems. same-system queries have runtime + // borrow checks when they conflict unsafe { self.state.get_unchecked_manual(self.world, entity) } } @@ -123,24 +134,29 @@ where &mut self, entity: Entity, ) -> Result<::Item, QueryEntityError> { - // // SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // // SAFE: system runs without conflicts with other systems. same-system queries have + // runtime borrow checks when they conflict unsafe { self.state.get_unchecked_manual(self.world, entity) } } /// Gets the query result for the given `entity` + /// /// # Safety - /// This allows aliased mutability. You must make sure this call does not result in multiple mutable references to the same component + /// This allows aliased mutability. You must make sure this call does not result in multiple + /// mutable references to the same component #[inline] pub unsafe fn get_unchecked( &self, entity: Entity, ) -> Result<::Item, QueryEntityError> { - // SEMI-SAFE: system runs without conflicts with other systems. same-system queries have runtime borrow checks when they conflict + // SEMI-SAFE: system runs without conflicts with other systems. same-system queries have + // runtime borrow checks when they conflict self.state.get_unchecked_manual(self.world, entity) } - /// Gets a reference to the entity's component of the given type. This will fail if the entity does not have - /// the given component type or if the given component type does not match this query. + /// Gets a reference to the entity's component of the given type. This will fail if the entity + /// does not have the given component type or if the given component type does not match + /// this query. #[inline] pub fn get_component(&self, entity: Entity) -> Result<&T, QueryComponentError> { let world = self.world; @@ -168,8 +184,9 @@ where } } - /// Gets a mutable reference to the entity's component of the given type. This will fail if the entity does not have - /// the given component type or if the given component type does not match this query. + /// Gets a mutable reference to the entity's component of the given type. This will fail if the + /// entity does not have the given component type or if the given component type does not + /// match this query. #[inline] pub fn get_component_mut( &mut self, @@ -179,10 +196,12 @@ where unsafe { self.get_component_unchecked_mut(entity) } } - /// Gets a mutable reference to the entity's component of the given type. This will fail if the entity does not have - /// the given component type or the component does not match the query. + /// Gets a mutable reference to the entity's component of the given type. This will fail if the + /// entity does not have the given component type or the component does not match the query. + /// /// # Safety - /// This allows aliased mutability. You must make sure this call does not result in multiple mutable references to the same component + /// This allows aliased mutability. You must make sure this call does not result in multiple + /// mutable references to the same component #[inline] pub unsafe fn get_component_unchecked_mut( &self, diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index 5ddfa56e17..8d38ddfd5f 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -27,9 +27,10 @@ pub trait System: Send + Sync + 'static { fn archetype_component_access(&self) -> &Access; fn is_send(&self) -> bool; /// # Safety - /// This might access World and Resources in an unsafe manner. This should only be called in one of the following contexts: - /// 1. This system is the only system running on the given World across all threads - /// 2. This system only runs in parallel with other systems that do not conflict with the `archetype_component_access()` + /// This might access World and Resources in an unsafe manner. This should only be called in one + /// of the following contexts: 1. This system is the only system running on the given World + /// across all threads 2. This system only runs in parallel with other systems that do not + /// conflict with the `archetype_component_access()` unsafe fn run_unsafe(&mut self, input: Self::In, world: &World) -> Self::Out; fn run(&mut self, input: Self::In, world: &mut World) -> Self::Out { // SAFE: world and resources are exclusively borrowed diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 06878e67a5..8131a32760 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -38,8 +38,9 @@ pub trait SystemParam: Sized { /// # Safety /// it is the implementors responsibility to ensure `system_state` is populated with the _exact_ -/// [World] access used by the SystemParamState (and associated FetchSystemParam). Additionally, it is the -/// implementor's responsibility to ensure there is no conflicting access across all SystemParams. +/// [World] access used by the SystemParamState (and associated FetchSystemParam). Additionally, it +/// is the implementor's responsibility to ensure there is no conflicting access across all +/// SystemParams. pub unsafe trait SystemParamState: Send + Sync + 'static { type Config: Default + Send + Sync; fn init(world: &mut World, system_state: &mut SystemState, config: Self::Config) -> Self; @@ -52,8 +53,8 @@ pub unsafe trait SystemParamState: Send + Sync + 'static { pub trait SystemParamFetch<'a>: SystemParamState { type Item; /// # Safety - /// This call might access any of the input parameters in an unsafe way. Make sure the data access is safe in - /// the context of the system scheduler + /// This call might access any of the input parameters in an unsafe way. Make sure the data + /// access is safe in the context of the system scheduler unsafe fn get_param( state: &'a mut Self, system_state: &'a SystemState, @@ -70,8 +71,8 @@ where type Fetch = QueryState; } -// SAFE: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemState. If this QueryState conflicts -// with any prior access, a panic will occur. +// SAFE: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemState. If +// this QueryState conflicts with any prior access, a panic will occur. unsafe impl SystemParamState for QueryState where F::Fetch: FilterFetch, @@ -168,7 +169,8 @@ impl<'w, T: Component> Res<'w, T> { self.flags.contains(ComponentFlags::MUTATED) } - /// Returns true if (and only if) this resource been either mutated or added since the start of the frame. + /// Returns true if (and only if) this resource been either mutated or added since the start of + /// the frame. pub fn changed(&self) -> bool { self.flags .intersects(ComponentFlags::ADDED | ComponentFlags::MUTATED) @@ -192,8 +194,8 @@ impl<'a, T: Component> SystemParam for Res<'a, T> { type Fetch = ResState; } -// SAFE: Res ComponentId and ArchetypeComponentId access is applied to SystemState. If this Res conflicts -// with any prior access, a panic will occur. +// SAFE: Res ComponentId and ArchetypeComponentId access is applied to SystemState. If this Res +// conflicts with any prior access, a panic will occur. unsafe impl SystemParamState for ResState { type Config = (); @@ -293,7 +295,8 @@ impl<'w, T: Component> ResMut<'w, T> { self.flags.contains(ComponentFlags::MUTATED) } - /// Returns true if (and only if) this resource been either mutated or added since the start of the frame. + /// Returns true if (and only if) this resource been either mutated or added since the start of + /// the frame. pub fn changed(&self) -> bool { self.flags .intersects(ComponentFlags::ADDED | ComponentFlags::MUTATED) @@ -324,8 +327,8 @@ impl<'a, T: Component> SystemParam for ResMut<'a, T> { type Fetch = ResMutState; } -// SAFE: Res ComponentId and ArchetypeComponentId access is applied to SystemState. If this Res conflicts -// with any prior access, a panic will occur. +// SAFE: Res ComponentId and ArchetypeComponentId access is applied to SystemState. If this Res +// conflicts with any prior access, a panic will occur. unsafe impl SystemParamState for ResMutState { type Config = (); @@ -505,8 +508,8 @@ impl<'a, T: Component> SystemParam for RemovedComponents<'a, T> { type Fetch = RemovedComponentsState; } -// SAFE: no component access. removed component entity collections can be read in parallel and are never mutably borrowed -// during system execution +// SAFE: no component access. removed component entity collections can be read in parallel and are +// never mutably borrowed during system execution unsafe impl SystemParamState for RemovedComponentsState { type Config = (); @@ -557,8 +560,8 @@ impl<'a, T: 'static> SystemParam for NonSend<'a, T> { type Fetch = NonSendState; } -// SAFE: NonSendComponentId and ArchetypeComponentId access is applied to SystemState. If this NonSend conflicts -// with any prior access, a panic will occur. +// SAFE: NonSendComponentId and ArchetypeComponentId access is applied to SystemState. If this +// NonSend conflicts with any prior access, a panic will occur. unsafe impl SystemParamState for NonSendState { type Config = (); @@ -643,8 +646,8 @@ impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { type Fetch = NonSendMutState; } -// SAFE: NonSendMut ComponentId and ArchetypeComponentId access is applied to SystemState. If this NonSendMut conflicts -// with any prior access, a panic will occur. +// SAFE: NonSendMut ComponentId and ArchetypeComponentId access is applied to SystemState. If this +// NonSendMut conflicts with any prior access, a panic will occur. unsafe impl SystemParamState for NonSendMutState { type Config = (); @@ -858,6 +861,6 @@ macro_rules! impl_system_param_tuple { }; } -// TODO: consider creating a Config trait with a default() function, then implementing that for tuples. -// that would allow us to go past tuples of len 12 +// TODO: consider creating a Config trait with a default() function, then implementing that for +// tuples. that would allow us to go past tuples of len 12 all_tuples!(impl_system_param_tuple, 0, 12, P); diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 9313d0d833..379d560583 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -36,7 +36,8 @@ impl<'w> EntityRef<'w> { #[inline] pub fn archetype(&self) -> &Archetype { - // SAFE: EntityRefs always point to valid entities. Valid entities always have valid archetypes + // SAFE: EntityRefs always point to valid entities. Valid entities always have valid + // archetypes unsafe { self.world .archetypes @@ -76,7 +77,8 @@ impl<'w> EntityRef<'w> { } /// # Safety - /// This allows aliased mutability. You must make sure this call does not result in multiple mutable references to the same component + /// This allows aliased mutability. You must make sure this call does not result in multiple + /// mutable references to the same component #[inline] pub unsafe fn get_unchecked_mut(&self) -> Option> { get_component_and_flags_with_type(self.world, TypeId::of::(), self.entity, self.location) @@ -121,7 +123,8 @@ impl<'w> EntityMut<'w> { #[inline] pub fn archetype(&self) -> &Archetype { - // SAFE: EntityRefs always point to valid entities. Valid entities always have valid archetypes + // SAFE: EntityRefs always point to valid entities. Valid entities always have valid + // archetypes unsafe { self.world .archetypes @@ -157,7 +160,8 @@ impl<'w> EntityMut<'w> { #[inline] pub fn get_mut(&mut self) -> Option> { - // SAFE: world access is unique, entity location is valid, and returned component is of type T + // SAFE: world access is unique, entity location is valid, and returned component is of type + // T unsafe { get_component_and_flags_with_type( self.world, @@ -173,7 +177,8 @@ impl<'w> EntityMut<'w> { } /// # Safety - /// This allows aliased mutability. You must make sure this call does not result in multiple mutable references to the same component + /// This allows aliased mutability. You must make sure this call does not result in multiple + /// mutable references to the same component #[inline] pub unsafe fn get_unchecked_mut(&self) -> Option> { get_component_and_flags_with_type(self.world, TypeId::of::(), self.entity, self.location) @@ -227,7 +232,8 @@ impl<'w> EntityMut<'w> { let (old_table, new_table) = storages .tables .get_2_mut(old_table_id, new_archetype.table_id()); - // PERF: store "non bundle" components in edge, then just move those to avoid redundant copies + // PERF: store "non bundle" components in edge, then just move those to avoid + // redundant copies let move_result = old_table.move_to_superset_unchecked(old_table_row, new_table); @@ -235,7 +241,8 @@ impl<'w> EntityMut<'w> { // if an entity was moved into this entity's table spot, update its table row if let Some(swapped_entity) = move_result.swapped_entity { let swapped_location = entities.get(swapped_entity).unwrap(); - // SAFE: entity is live and is therefore contained in an archetype that exists + // SAFE: entity is live and is therefore contained in an archetype that + // exists archetypes .get_unchecked_mut(swapped_location.archetype_id) .set_entity_table_row(swapped_location.index, old_table_row); @@ -297,7 +304,8 @@ impl<'w> EntityMut<'w> { let old_archetype = unsafe { archetypes.get_unchecked_mut(old_location.archetype_id) }; let mut bundle_components = bundle_info.component_ids.iter().cloned(); let entity = self.entity; - // SAFE: bundle components are iterated in order, which guarantees that the component type matches + // SAFE: bundle components are iterated in order, which guarantees that the component type + // matches let result = unsafe { T::from_components(|| { let component_id = bundle_components.next().unwrap(); @@ -330,7 +338,8 @@ impl<'w> EntityMut<'w> { .tables .get_2_mut(old_table_id, new_archetype.table_id()); - // SAFE: table_row exists. All "missing" components have been extracted into the bundle above and the caller takes ownership + // SAFE: table_row exists. All "missing" components have been extracted into the bundle + // above and the caller takes ownership let move_result = unsafe { old_table.move_to_and_forget_missing_unchecked(old_table_row, new_table) }; @@ -505,22 +514,24 @@ impl<'w> EntityMut<'w> { /// # Safety /// Caller must not modify the world in a way that changes the current entity's location - /// If the caller _does_ do something that could change the location, self.update_location() must be - /// called before using any other methods in EntityMut + /// If the caller _does_ do something that could change the location, self.update_location() + /// must be called before using any other methods in EntityMut #[inline] pub unsafe fn world_mut(&mut self) -> &mut World { self.world } /// Updates the internal entity location to match the current location in the internal [World]. - /// This is only needed if the user called [EntityMut::world], which enables the location to change. + /// This is only needed if the user called [EntityMut::world], which enables the location to + /// change. pub fn update_location(&mut self) { self.location = self.world.entities().get(self.entity).unwrap(); } } /// # Safety -/// `entity_location` must be within bounds of the given archetype and `entity` must exist inside the archetype +/// `entity_location` must be within bounds of the given archetype and `entity` must exist inside +/// the archetype #[inline] unsafe fn get_component( world: &World, @@ -580,7 +591,8 @@ unsafe fn get_component_and_flags( } /// # Safety -// `entity_location` must be within bounds of the given archetype and `entity` must exist inside the archetype +// `entity_location` must be within bounds of the given archetype and `entity` must exist inside the +// archetype /// The relevant table row must be removed separately /// `component_id` must be valid #[inline] @@ -666,9 +678,10 @@ unsafe fn contains_component_with_id( .contains(component_id) } -/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the same [ArchetypeId], -/// in the event that adding the given bundle does not result in an Archetype change. Results are cached in the -/// Archetype Graph to avoid redundant work. +/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the same +/// [ArchetypeId], in the event that adding the given bundle does not result in an Archetype change. +/// Results are cached in the Archetype Graph to avoid redundant work. +/// /// # Safety /// `archetype_id` must exist and components in `bundle_info` must exist pub(crate) unsafe fn add_bundle_to_archetype( @@ -760,11 +773,13 @@ pub(crate) unsafe fn add_bundle_to_archetype( } } -/// Removes a bundle from the given archetype and returns the resulting archetype (or None if the removal was invalid). -/// in the event that adding the given bundle does not result in an Archetype change. Results are cached in the -/// Archetype Graph to avoid redundant work. -/// if `intersection` is false, attempting to remove a bundle with components _not_ contained in the current archetype will fail, -/// returning None. if `intersection` is true, components in the bundle but not in the current archetype will be ignored +/// Removes a bundle from the given archetype and returns the resulting archetype (or None if the +/// removal was invalid). in the event that adding the given bundle does not result in an Archetype +/// change. Results are cached in the Archetype Graph to avoid redundant work. +/// if `intersection` is false, attempting to remove a bundle with components _not_ contained in the +/// current archetype will fail, returning None. if `intersection` is true, components in the bundle +/// but not in the current archetype will be ignored +/// /// # Safety /// `archetype_id` must exist and components in `bundle_info` must exist unsafe fn remove_bundle_from_archetype( @@ -775,7 +790,8 @@ unsafe fn remove_bundle_from_archetype( bundle_info: &BundleInfo, intersection: bool, ) -> Option { - // check the archetype graph to see if the Bundle has been removed from this archetype in the past + // check the archetype graph to see if the Bundle has been removed from this archetype in the + // past let remove_bundle_result = { // SAFE: entity location is valid and therefore the archetype exists let current_archetype = archetypes.get_unchecked_mut(archetype_id); @@ -808,8 +824,9 @@ unsafe fn remove_bundle_from_archetype( StorageType::SparseSet => removed_sparse_set_components.push(component_id), } } else if !intersection { - // a component in the bundle was not present in the entity's archetype, so this removal is invalid - // cache the result in the archetype graph + // a component in the bundle was not present in the entity's archetype, so this + // removal is invalid cache the result in the archetype + // graph current_archetype .edges_mut() .set_remove_bundle(bundle_info.id, None); @@ -817,7 +834,8 @@ unsafe fn remove_bundle_from_archetype( } } - // sort removed components so we can do an efficient "sorted remove". archetype components are already sorted + // sort removed components so we can do an efficient "sorted remove". archetype + // components are already sorted removed_table_components.sort(); removed_sparse_set_components.sort(); next_table_components = current_archetype.table_components().to_vec(); diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 2a932d83d3..6c9cd7e619 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -30,9 +30,10 @@ impl Default for WorldId { } } -/// [World] stores and exposes operations on [entities](Entity), [components](Component), and their associated metadata. -/// Each [Entity] has a set of components. Each component can have up to one instance of each component type. -/// Entity components can be created, updated, removed, and queried using a given [World]. +/// [World] stores and exposes operations on [entities](Entity), [components](Component), and their +/// associated metadata. Each [Entity] has a set of components. Each component can have up to one +/// instance of each component type. Entity components can be created, updated, removed, and queried +/// using a given [World]. #[derive(Default)] pub struct World { id: WorldId, @@ -96,16 +97,17 @@ impl World { &self.bundles } - /// Retrieves a [WorldCell], which safely enables multiple mutable World accesses at the same time, - /// provided those accesses do not conflict with each other. + /// Retrieves a [WorldCell], which safely enables multiple mutable World accesses at the same + /// time, provided those accesses do not conflict with each other. #[inline] pub fn cell(&mut self) -> WorldCell<'_> { WorldCell::new(self) } - /// Registers a new component using the given [ComponentDescriptor]. Components do not need to be manually - /// registered. This just provides a way to override default configuration. Attempting to register a component - /// with a type that has already been used by [World] will result in an error. + /// Registers a new component using the given [ComponentDescriptor]. Components do not need to + /// be manually registered. This just provides a way to override default configuration. + /// Attempting to register a component with a type that has already been used by [World] + /// will result in an error. /// /// The default component storage type can be overridden like this: /// @@ -269,7 +271,8 @@ impl World { // PERF: consider avoiding allocating entities in the empty archetype unless needed // SAFE: archetype tables always exist let table = self.storages.tables.get_unchecked_mut(archetype.table_id()); - // SAFE: no components are allocated by archetype.allocate() because the archetype is empty + // SAFE: no components are allocated by archetype.allocate() because the archetype is + // empty let location = archetype.allocate(entity, table.allocate(entity)); // SAFE: entity index was just allocated self.entities @@ -347,9 +350,9 @@ impl World { self.get_entity_mut(entity)?.get_mut() } - /// Despawns the given `entity`, if it exists. This will also remove all of the entity's [Component]s. - /// Returns `true` if the `entity` is successfully despawned and `false` if the `entity` does not exist. - /// ``` + /// Despawns the given `entity`, if it exists. This will also remove all of the entity's + /// [Component]s. Returns `true` if the `entity` is successfully despawned and `false` if + /// the `entity` does not exist. ``` /// use bevy_ecs::world::World; /// /// struct Position { @@ -391,7 +394,6 @@ impl World { /// Returns [QueryState] for the given [WorldQuery], which is used to efficiently /// run queries on the [World]. /// ``` - /// /// use bevy_ecs::{entity::Entity, world::World}; /// /// #[derive(Debug, PartialEq)] @@ -450,7 +452,8 @@ impl World { QueryState::new(self) } - /// Returns an iterator of entities that had components of type `T` removed since the last call to [World::clear_trackers]. + /// Returns an iterator of entities that had components of type `T` removed since the last call + /// to [World::clear_trackers]. pub fn removed(&self) -> std::iter::Cloned> { if let Some(component_id) = self.components.get_id(TypeId::of::()) { self.removed_with_id(component_id) @@ -459,7 +462,8 @@ impl World { } } - /// Returns an iterator of entities that had components with the given `component_id` removed since the last call to [World::clear_trackers]. + /// Returns an iterator of entities that had components with the given `component_id` removed + /// since the last call to [World::clear_trackers]. pub fn removed_with_id( &self, component_id: ComponentId, @@ -501,8 +505,8 @@ impl World { if column.is_empty() { return None; } - // SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of the ptr value / drop is called when - // T is dropped + // SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of the + // ptr value / drop is called when T is dropped let (ptr, _) = unsafe { column.swap_remove_and_forget_unchecked(0) }; // SAFE: column is of type T Some(unsafe { ptr.cast::().read() }) @@ -528,8 +532,8 @@ impl World { unsafe { self.get_resource_with_id(component_id) } } - /// Gets a mutable reference to the resource of the given type, if it exists. Otherwise returns [None] - /// Resources are "unique" data of a given type. + /// Gets a mutable reference to the resource of the given type, if it exists. Otherwise returns + /// [None] Resources are "unique" data of a given type. #[inline] pub fn get_resource_mut(&mut self) -> Option> { // SAFE: unique world access @@ -537,7 +541,8 @@ impl World { } // PERF: optimize this to avoid redundant lookups - /// Gets a resource of type `T` if it exists, otherwise inserts the resource using the result of calling `func`. + /// Gets a resource of type `T` if it exists, otherwise inserts the resource using the result of + /// calling `func`. #[inline] pub fn get_resource_or_insert_with( &mut self, @@ -549,19 +554,20 @@ impl World { self.get_resource_mut().unwrap() } - /// Gets a mutable reference to the resource of the given type, if it exists. Otherwise returns [None] - /// Resources are "unique" data of a given type. + /// Gets a mutable reference to the resource of the given type, if it exists. Otherwise returns + /// [None] Resources are "unique" data of a given type. + /// /// # Safety - /// This will allow aliased mutable access to the given resource type. The caller must ensure that only - /// one mutable access exists at a time. + /// This will allow aliased mutable access to the given resource type. The caller must ensure + /// that only one mutable access exists at a time. #[inline] pub unsafe fn get_resource_unchecked_mut(&self) -> Option> { let component_id = self.components.get_resource_id(TypeId::of::())?; self.get_resource_unchecked_mut_with_id(component_id) } - /// Gets a reference to the non-send resource of the given type, if it exists. Otherwise returns [None] - /// Resources are "unique" data of a given type. + /// Gets a reference to the non-send resource of the given type, if it exists. Otherwise returns + /// [None] Resources are "unique" data of a given type. #[inline] pub fn get_non_send_resource(&self) -> Option<&T> { let component_id = self.components.get_resource_id(TypeId::of::())?; @@ -569,28 +575,29 @@ impl World { unsafe { self.get_non_send_with_id(component_id) } } - /// Gets a mutable reference to the non-send resource of the given type, if it exists. Otherwise returns [None] - /// Resources are "unique" data of a given type. + /// Gets a mutable reference to the non-send resource of the given type, if it exists. Otherwise + /// returns [None] Resources are "unique" data of a given type. #[inline] pub fn get_non_send_resource_mut(&mut self) -> Option> { // SAFE: unique world access unsafe { self.get_non_send_resource_unchecked_mut() } } - /// Gets a mutable reference to the non-send resource of the given type, if it exists. Otherwise returns [None] - /// Resources are "unique" data of a given type. + /// Gets a mutable reference to the non-send resource of the given type, if it exists. Otherwise + /// returns [None] Resources are "unique" data of a given type. + /// /// # Safety - /// This will allow aliased mutable access to the given non-send resource type. The caller must ensure that only - /// one mutable access exists at a time. + /// This will allow aliased mutable access to the given non-send resource type. The caller must + /// ensure that only one mutable access exists at a time. #[inline] pub unsafe fn get_non_send_resource_unchecked_mut(&self) -> Option> { let component_id = self.components.get_resource_id(TypeId::of::())?; self.get_non_send_unchecked_mut_with_id(component_id) } - /// Temporarily removes the requested resource from this [World], then re-adds it before returning. - /// This enables safe mutable access to a resource while still providing mutable world access - /// ``` + /// Temporarily removes the requested resource from this [World], then re-adds it before + /// returning. This enables safe mutable access to a resource while still providing mutable + /// world access ``` /// use bevy_ecs::world::{World, Mut}; /// struct A(u32); /// struct B(u32); @@ -621,8 +628,8 @@ impl World { if column.is_empty() { panic!("resource does not exist"); } - // SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of the ptr value / drop is called when - // T is dropped + // SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of + // the ptr value / drop is called when T is dropped unsafe { column.swap_remove_and_forget_unchecked(0) } }; // SAFE: pointer is of type T @@ -801,7 +808,8 @@ impl World { .get_unchecked_mut(empty_archetype.table_id()); // PERF: consider pre-allocating space for flushed entities self.entities.flush(|entity, location| { - // SAFE: no components are allocated by archetype.allocate() because the archetype is empty + // SAFE: no components are allocated by archetype.allocate() because the archetype + // is empty *location = empty_archetype.allocate(entity, table.allocate(entity)); }); } diff --git a/crates/bevy_ecs/src/world/pointer.rs b/crates/bevy_ecs/src/world/pointer.rs index c857f424a3..a0e270274f 100644 --- a/crates/bevy_ecs/src/world/pointer.rs +++ b/crates/bevy_ecs/src/world/pointer.rs @@ -41,7 +41,8 @@ impl<'w, T> Mut<'w, T> { self.flags.contains(ComponentFlags::MUTATED) } - /// Returns true if (and only if) this component been either mutated or added since the start of the frame. + /// Returns true if (and only if) this component been either mutated or added since the start of + /// the frame. pub fn changed(&self) -> bool { self.flags .intersects(ComponentFlags::ADDED | ComponentFlags::MUTATED) diff --git a/crates/bevy_ecs/src/world/spawn_batch.rs b/crates/bevy_ecs/src/world/spawn_batch.rs index 6eeab491b4..a008ed4093 100644 --- a/crates/bevy_ecs/src/world/spawn_batch.rs +++ b/crates/bevy_ecs/src/world/spawn_batch.rs @@ -88,7 +88,8 @@ where fn next(&mut self) -> Option { let bundle = self.inner.next()?; let entity = self.entities.alloc(); - // SAFE: component values are immediately written to relevant storages (which have been allocated) + // SAFE: component values are immediately written to relevant storages (which have been + // allocated) unsafe { let table_row = self.table.allocate(entity); let location = self.archetype.allocate(entity, table_row); diff --git a/crates/bevy_ecs/src/world/world_cell.rs b/crates/bevy_ecs/src/world/world_cell.rs index 762f7178c0..11aee9fd40 100644 --- a/crates/bevy_ecs/src/world/world_cell.rs +++ b/crates/bevy_ecs/src/world/world_cell.rs @@ -11,8 +11,8 @@ use std::{ rc::Rc, }; -/// Exposes safe mutable access to multiple resources at a time in a World. Attempting to access World in a way that violates -/// Rust's mutability rules will panic thanks to runtime checks. +/// Exposes safe mutable access to multiple resources at a time in a World. Attempting to access +/// World in a way that violates Rust's mutability rules will panic thanks to runtime checks. pub struct WorldCell<'w> { pub(crate) world: &'w mut World, pub(crate) access: Rc>, diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index 01a5afaecd..7b89e5c101 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -33,7 +33,8 @@ pub enum MouseScrollUnit { Pixel, } -/// A mouse scroll wheel event, where x represents horizontal scroll and y represents vertical scroll. +/// A mouse scroll wheel event, where x represents horizontal scroll and y represents vertical +/// scroll. #[derive(Debug, Clone)] pub struct MouseWheel { pub unit: MouseScrollUnit, diff --git a/crates/bevy_pbr/src/render_graph/lights_node.rs b/crates/bevy_pbr/src/render_graph/lights_node.rs index 776ef83524..795341d096 100644 --- a/crates/bevy_pbr/src/render_graph/lights_node.rs +++ b/crates/bevy_pbr/src/render_graph/lights_node.rs @@ -79,7 +79,8 @@ pub fn lights_node_system( mut state: Local, render_resource_context: Res>, ambient_light_resource: Res, - // TODO: this write on RenderResourceBindings will prevent this system from running in parallel with other systems that do the same + // TODO: this write on RenderResourceBindings will prevent this system from running in parallel + // with other systems that do the same mut render_resource_bindings: ResMut, query: Query<(&Light, &GlobalTransform)>, ) { diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index 218e70e8bd..ae72a9aa6f 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -4,8 +4,8 @@ use bevy_utils::HashMap; use crate::{serde::Serializable, Reflect, ReflectMut, ReflectRef}; -/// An ordered ReflectValue->ReflectValue mapping. ReflectValue Keys are assumed to return a non-None hash. -/// Ideally the ordering is stable across runs, but this is not required. +/// An ordered ReflectValue->ReflectValue mapping. ReflectValue Keys are assumed to return a +/// non-None hash. Ideally the ordering is stable across runs, but this is not required. /// This corresponds to types like [std::collections::HashMap]. pub trait Map: Reflect { fn get(&self, key: &dyn Reflect) -> Option<&dyn Reflect>; diff --git a/crates/bevy_reflect/src/reflect.rs b/crates/bevy_reflect/src/reflect.rs index 28ccf3e428..22c11b6c49 100644 --- a/crates/bevy_reflect/src/reflect.rs +++ b/crates/bevy_reflect/src/reflect.rs @@ -31,11 +31,14 @@ pub trait Reflect: Any + Send + Sync { fn reflect_ref(&self) -> ReflectRef; fn reflect_mut(&mut self) -> ReflectMut; fn clone_value(&self) -> Box; - /// Returns a hash of the value (which includes the type) if hashing is supported. Otherwise `None` will be returned. + /// Returns a hash of the value (which includes the type) if hashing is supported. Otherwise + /// `None` will be returned. fn reflect_hash(&self) -> Option; - /// Returns a "partial equal" comparison result if comparison is supported. Otherwise `None` will be returned. + /// Returns a "partial equal" comparison result if comparison is supported. Otherwise `None` + /// will be returned. fn reflect_partial_eq(&self, _value: &dyn Reflect) -> Option; - /// Returns a serializable value, if serialization is supported. Otherwise `None` will be returned. + /// Returns a serializable value, if serialization is supported. Otherwise `None` will be + /// returned. fn serializable(&self) -> Option; } @@ -47,7 +50,8 @@ impl Debug for dyn Reflect { impl dyn Reflect { pub fn downcast(self: Box) -> Result, Box> { - // SAFE?: Same approach used by std::any::Box::downcast. ReflectValue is always Any and type has been checked. + // SAFE?: Same approach used by std::any::Box::downcast. ReflectValue is always Any and type + // has been checked. if self.is::() { unsafe { let raw: *mut dyn Reflect = Box::into_raw(self); diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index b9fa42267b..6b6e39147b 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -13,7 +13,8 @@ pub struct TypeRegistry { ambiguous_names: HashSet, } -// TODO: remove this wrapper once we migrate to Atelier Assets and the Scene AssetLoader doesn't need a TypeRegistry ref +// TODO: remove this wrapper once we migrate to Atelier Assets and the Scene AssetLoader doesn't +// need a TypeRegistry ref #[derive(Clone, Default)] pub struct TypeRegistryArc { pub internal: Arc>, diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 34e7c515ce..d1b983e69f 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -73,7 +73,8 @@ pub fn camera_system( )>, ) { let mut changed_window_ids = Vec::new(); - // handle resize events. latest events are handled first because we only want to resize each window once + // handle resize events. latest events are handled first because we only want to resize each + // window once for event in window_resized_events.iter().rev() { if changed_window_ids.contains(&event.id) { continue; @@ -82,7 +83,8 @@ pub fn camera_system( changed_window_ids.push(event.id); } - // handle resize events. latest events are handled first because we only want to resize each window once + // handle resize events. latest events are handled first because we only want to resize each + // window once for event in window_created_events.iter().rev() { if changed_window_ids.contains(&event.id) { continue; diff --git a/crates/bevy_render/src/camera/visible_entities.rs b/crates/bevy_render/src/camera/visible_entities.rs index 689c8af162..f116c17f33 100644 --- a/crates/bevy_render/src/camera/visible_entities.rs +++ b/crates/bevy_render/src/camera/visible_entities.rs @@ -34,8 +34,8 @@ pub type Layer = u8; /// Cameras with this component will only render entities with intersecting /// layers. /// -/// There are 32 layers numbered `0` - [`TOTAL_LAYERS`](RenderLayers::TOTAL_LAYERS). Entities may belong to one or more -/// layers, or no layer at all. +/// There are 32 layers numbered `0` - [`TOTAL_LAYERS`](RenderLayers::TOTAL_LAYERS). Entities may +/// belong to one or more layers, or no layer at all. /// /// The [`Default`] instance of `RenderLayers` contains layer `0`, the first layer. /// @@ -228,7 +228,8 @@ pub fn visible_entities_system( let order = if let Ok(global_transform) = visible_transform_query.get(entity) { let position = global_transform.translation; - // smaller distances are sorted to lower indices by using the distance from the camera + // smaller distances are sorted to lower indices by using the distance from the + // camera FloatOrd(match camera.depth_calculation { DepthCalculation::ZDifference => camera_position.z - position.z, DepthCalculation::Distance => (camera_position - position).length_squared(), @@ -253,6 +254,7 @@ pub fn visible_entities_system( transparent_entities.sort_by_key(|e| -e.order); visible_entities.value.extend(transparent_entities); - // TODO: check for big changes in visible entities len() vs capacity() (ex: 2x) and resize to prevent holding unneeded memory + // TODO: check for big changes in visible entities len() vs capacity() (ex: 2x) and resize + // to prevent holding unneeded memory } } diff --git a/crates/bevy_render/src/color.rs b/crates/bevy_render/src/color.rs index 64dbbe7d0a..c953b997d8 100644 --- a/crates/bevy_render/src/color.rs +++ b/crates/bevy_render/src/color.rs @@ -13,7 +13,8 @@ use std::ops::{Add, AddAssign, Mul, MulAssign}; // TODO: Separate types for non-linear sRGB and linear sRGB, with conversions between // see comment on bevy issue #688 https://github.com/bevyengine/bevy/pull/688#issuecomment-711414011 -/// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear", "RGB", or "linear RGB"). +/// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear", "RGB", or +/// "linear RGB"). #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] #[reflect(PartialEq, Serialize, Deserialize)] diff --git a/crates/bevy_render/src/colorspace.rs b/crates/bevy_render/src/colorspace.rs index 28a1a5249f..53d99aa2dd 100644 --- a/crates/bevy_render/src/colorspace.rs +++ b/crates/bevy_render/src/colorspace.rs @@ -3,7 +3,7 @@ pub trait SrgbColorSpace { fn nonlinear_to_linear_srgb(self) -> Self; } -//source: https://entropymine.com/imageworsener/srgbformula/ +// source: https://entropymine.com/imageworsener/srgbformula/ impl SrgbColorSpace for f32 { fn linear_to_nonlinear_srgb(self) -> f32 { if self <= 0.0 { @@ -13,7 +13,7 @@ impl SrgbColorSpace for f32 { if self <= 0.0031308 { self * 12.92 // linear falloff in dark values } else { - (1.055 * self.powf(1.0 / 2.4)) - 0.055 //gamma curve in other area + (1.055 * self.powf(1.0 / 2.4)) - 0.055 // gamma curve in other area } } @@ -24,7 +24,7 @@ impl SrgbColorSpace for f32 { if self <= 0.04045 { self / 12.92 // linear falloff in dark values } else { - ((self + 0.055) / 1.055).powf(2.4) //gamma curve in other area + ((self + 0.055) / 1.055).powf(2.4) // gamma curve in other area } } } diff --git a/crates/bevy_render/src/draw.rs b/crates/bevy_render/src/draw.rs index 9bdbb5533d..1daf2de282 100644 --- a/crates/bevy_render/src/draw.rs +++ b/crates/bevy_render/src/draw.rs @@ -277,7 +277,8 @@ impl<'a> DrawContext<'a> { } } - // if none of the given RenderResourceBindings have the current bind group, try their assets + // if none of the given RenderResourceBindings have the current bind group, try their + // assets let asset_render_resource_bindings = if let Some(value) = asset_render_resource_bindings.as_mut() { value diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 98fea3a99b..2d93873708 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -68,7 +68,8 @@ pub enum RenderSystem { pub enum RenderStage { /// Stage where render resources are set up RenderResource, - /// Stage where Render Graph systems are run. In general you shouldn't add systems to this stage manually. + /// Stage where Render Graph systems are run. In general you shouldn't add systems to this + /// stage manually. RenderGraphSystems, // Stage where draw systems are executed. This is generally where Draw components are setup Draw, @@ -78,7 +79,8 @@ pub enum RenderStage { /// Adds core render types and systems to an App pub struct RenderPlugin { - /// configures the "base render graph". If this is not `None`, the "base render graph" will be added + /// configures the "base render graph". If this is not `None`, the "base render graph" will be + /// added pub base_render_graph_config: Option, } diff --git a/crates/bevy_render/src/mesh/mesh.rs b/crates/bevy_render/src/mesh/mesh.rs index 73ec6b3b77..68d42de2d7 100644 --- a/crates/bevy_render/src/mesh/mesh.rs +++ b/crates/bevy_render/src/mesh/mesh.rs @@ -208,7 +208,8 @@ impl From<&Indices> for IndexFormat { #[uuid = "8ecbac0f-f545-4473-ad43-e1f4243af51e"] pub struct Mesh { primitive_topology: PrimitiveTopology, - /// `bevy_utils::HashMap` with all defined vertex attributes (Positions, Normals, ...) for this mesh. Attribute name maps to attribute values. + /// `bevy_utils::HashMap` with all defined vertex attributes (Positions, Normals, ...) for this + /// mesh. Attribute name maps to attribute values. attributes: HashMap, VertexAttributeValues>, indices: Option, } @@ -233,7 +234,8 @@ pub struct Mesh { impl Mesh { /// Per vertex coloring. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_COLOR: &'static str = "Vertex_Color"; - /// The direction the vertex normal is facing in. Use in conjunction with [`Mesh::set_attribute`] + /// The direction the vertex normal is facing in. Use in conjunction with + /// [`Mesh::set_attribute`] pub const ATTRIBUTE_NORMAL: &'static str = "Vertex_Normal"; /// Where the vertex is located in space. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_POSITION: &'static str = "Vertex_Position"; @@ -279,7 +281,8 @@ impl Mesh { } /// Indices describe how triangles are constructed out of the vertex attributes. - /// They are only useful for the [`crate::pipeline::PrimitiveTopology`] variants that use triangles + /// They are only useful for the [`crate::pipeline::PrimitiveTopology`] variants that use + /// triangles pub fn set_indices(&mut self, indices: Option) { self.indices = indices; } diff --git a/crates/bevy_render/src/mesh/shape/capsule.rs b/crates/bevy_render/src/mesh/shape/capsule.rs index f2cbf866bb..63c4f3717a 100644 --- a/crates/bevy_render/src/mesh/shape/capsule.rs +++ b/crates/bevy_render/src/mesh/shape/capsule.rs @@ -39,7 +39,8 @@ pub enum CapsuleUvProfile { Aspect, /// Hemispheres get UV space according to the ratio of latitudes to rings. Uniform, - /// Upper third of the texture goes to the northern hemisphere, middle third to the cylinder and lower third to the southern one. + /// Upper third of the texture goes to the northern hemisphere, middle third to the cylinder + /// and lower third to the southern one. Fixed, } diff --git a/crates/bevy_render/src/pipeline/binding.rs b/crates/bevy_render/src/pipeline/binding.rs index 4ec2cae86f..55fbf9bda8 100644 --- a/crates/bevy_render/src/pipeline/binding.rs +++ b/crates/bevy_render/src/pipeline/binding.rs @@ -30,8 +30,8 @@ pub enum BindType { readonly: bool, }, Sampler { - /// The sampling result is produced based on more than a single color sample from a texture, - /// e.g. when bilinear interpolation is enabled. + /// The sampling result is produced based on more than a single color sample from a + /// texture, e.g. when bilinear interpolation is enabled. /// /// A filtering sampler can only be used with a filterable texture. filtering: bool, diff --git a/crates/bevy_render/src/pipeline/pipeline_compiler.rs b/crates/bevy_render/src/pipeline/pipeline_compiler.rs index ab031df61e..320a2dde7f 100644 --- a/crates/bevy_render/src/pipeline/pipeline_compiler.rs +++ b/crates/bevy_render/src/pipeline/pipeline_compiler.rs @@ -197,7 +197,8 @@ impl PipelineCompiler { } specialized_descriptor.layout = Some(layout); - // create a vertex layout that provides all attributes from either the specialized vertex buffers or a zero buffer + // create a vertex layout that provides all attributes from either the specialized vertex + // buffers or a zero buffer let mut pipeline_layout = specialized_descriptor.layout.as_mut().unwrap(); // the vertex buffer descriptor of the mesh let mesh_vertex_buffer_layout = &pipeline_specialization.vertex_buffer_layout; @@ -235,7 +236,7 @@ impl PipelineCompiler { } } - //TODO: add other buffers (like instancing) here + // TODO: add other buffers (like instancing) here let mut vertex_buffer_descriptors = Vec::::default(); if !pipeline_layout.vertex_buffer_descriptors.is_empty() { vertex_buffer_descriptors.push(compiled_vertex_buffer_descriptor); diff --git a/crates/bevy_render/src/pipeline/pipeline_layout.rs b/crates/bevy_render/src/pipeline/pipeline_layout.rs index 86702f4dad..5a1816ca1d 100644 --- a/crates/bevy_render/src/pipeline/pipeline_layout.rs +++ b/crates/bevy_render/src/pipeline/pipeline_layout.rs @@ -58,8 +58,8 @@ impl PipelineLayout { .map(|(_, value)| value) .collect::>(); - // NOTE: for some reason bind groups need to be sorted by index. this is likely an issue with bevy and not with wgpu - // TODO: try removing this + // NOTE: for some reason bind groups need to be sorted by index. this is likely an issue + // with bevy and not with wgpu TODO: try removing this bind_groups_result.sort_by(|a, b| a.index.partial_cmp(&b.index).unwrap()); PipelineLayout { diff --git a/crates/bevy_render/src/pipeline/render_pipelines.rs b/crates/bevy_render/src/pipeline/render_pipelines.rs index 8f0476024f..24a43e92a2 100644 --- a/crates/bevy_render/src/pipeline/render_pipelines.rs +++ b/crates/bevy_render/src/pipeline/render_pipelines.rs @@ -17,7 +17,8 @@ use bevy_utils::HashSet; pub struct RenderPipeline { pub pipeline: Handle, pub specialization: PipelineSpecialization, - /// used to track if PipelineSpecialization::dynamic_bindings is in sync with RenderResourceBindings + /// used to track if PipelineSpecialization::dynamic_bindings is in sync with + /// RenderResourceBindings pub dynamic_bindings_generation: usize, } diff --git a/crates/bevy_render/src/render_graph/base.rs b/crates/bevy_render/src/render_graph/base.rs index f145eb316c..bf7f349aaf 100644 --- a/crates/bevy_render/src/render_graph/base.rs +++ b/crates/bevy_render/src/render_graph/base.rs @@ -92,9 +92,9 @@ impl Default for BaseRenderGraphConfig { } } -/// The "base render graph" provides a core set of render graph nodes which can be used to build any graph. -/// By itself this graph doesn't do much, but it allows Render plugins to interop with each other by having a common -/// set of nodes. It can be customized using `BaseRenderGraphConfig`. +/// The "base render graph" provides a core set of render graph nodes which can be used to build any +/// graph. By itself this graph doesn't do much, but it allows Render plugins to interop with each +/// other by having a common set of nodes. It can be customized using `BaseRenderGraphConfig`. pub(crate) fn add_base_graph(config: &BaseRenderGraphConfig, world: &mut World) { let world = world.cell(); let mut graph = world.get_resource_mut::().unwrap(); @@ -124,7 +124,8 @@ pub(crate) fn add_base_graph(config: &BaseRenderGraphConfig, world: &mut World) mip_level_count: 1, sample_count: msaa.samples, dimension: TextureDimension::D2, - format: TextureFormat::Depth32Float, // PERF: vulkan docs recommend using 24 bit depth for better performance + format: TextureFormat::Depth32Float, /* PERF: vulkan docs recommend using 24 + * bit depth for better performance */ usage: TextureUsage::OUTPUT_ATTACHMENT, }, ), diff --git a/crates/bevy_render/src/render_graph/command.rs b/crates/bevy_render/src/render_graph/command.rs index b689ceead5..480cbbf3ba 100644 --- a/crates/bevy_render/src/render_graph/command.rs +++ b/crates/bevy_render/src/render_graph/command.rs @@ -47,7 +47,8 @@ pub enum Command { #[derive(Debug, Default, Clone)] pub struct CommandQueue { - // TODO: this shouldn't really need a mutex. it just needs to be shared on whatever thread it's scheduled on + // TODO: this shouldn't really need a mutex. it just needs to be shared on whatever thread it's + // scheduled on queue: Arc>>, } diff --git a/crates/bevy_render/src/render_graph/node.rs b/crates/bevy_render/src/render_graph/node.rs index 048533e900..c7d84079fa 100644 --- a/crates/bevy_render/src/render_graph/node.rs +++ b/crates/bevy_render/src/render_graph/node.rs @@ -28,10 +28,12 @@ pub trait Node: Downcast + Send + Sync + 'static { &[] } - /// Prepare the graph node with unique world access. This runs once per graph run before [Node::update] is called. + /// Prepare the graph node with unique world access. This runs once per graph run before + /// [Node::update] is called. fn prepare(&mut self, _world: &mut World) {} - /// Run the graph node logic. This runs once per graph run after [Node::prepare] has been called on all nodes. + /// Run the graph node logic. This runs once per graph run after [Node::prepare] has been called + /// on all nodes. fn update( &mut self, world: &World, diff --git a/crates/bevy_render/src/render_graph/nodes/camera_node.rs b/crates/bevy_render/src/render_graph/nodes/camera_node.rs index ed62fdd395..7b814304d9 100644 --- a/crates/bevy_render/src/render_graph/nodes/camera_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/camera_node.rs @@ -70,8 +70,8 @@ pub fn camera_node_system( mut state: Local, active_cameras: Res, render_resource_context: Res>, - // PERF: this write on RenderResourceAssignments will prevent this system from running in parallel - // with other systems that do the same + // PERF: this write on RenderResourceAssignments will prevent this system from running in + // parallel with other systems that do the same mut render_resource_bindings: ResMut, query: Query<(&Camera, &GlobalTransform)>, ) { 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 b6e3560383..23756aead2 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 @@ -182,7 +182,8 @@ where self.current_staging_buffer_offset = 0; } - /// Find a spot for the given RenderResources in each uniform's BufferArray and prepare space in the staging buffer + /// Find a spot for the given RenderResources in each uniform's BufferArray and prepare space in + /// the staging buffer fn prepare_uniform_buffers(&mut self, id: I, render_resources: &T) { for (i, render_resource) in render_resources.iter().enumerate() { if let Some(RenderResourceType::Buffer) = render_resource.resource_type() { @@ -497,7 +498,8 @@ fn render_resources_node_system( staging_buffer, 0..state.uniform_buffer_arrays.staging_buffer_size as u64, &mut |mut staging_buffer, _render_resource_context| { - // if the buffer array was resized, write all entities to the new buffer, otherwise only write changes + // if the buffer array was resized, write all entities to the new buffer, otherwise + // only write changes if resized { for (entity, uniforms, visible, mut render_pipelines) in queries.q1_mut().iter_mut() diff --git a/crates/bevy_render/src/render_graph/schedule.rs b/crates/bevy_render/src/render_graph/schedule.rs index b0ef997294..eb0c98077c 100644 --- a/crates/bevy_render/src/render_graph/schedule.rs +++ b/crates/bevy_render/src/render_graph/schedule.rs @@ -67,7 +67,8 @@ impl Stages { } pub fn borrow<'a>(&self, render_graph: &'a mut RenderGraph) -> Vec> { - // unfortunately borrowing render graph nodes in a specific order takes a little bit of gymnastics + // unfortunately borrowing render graph nodes in a specific order takes a little bit of + // gymnastics let mut stage_borrows = Vec::with_capacity(self.stages.len()); let mut node_borrows = Vec::new(); @@ -101,13 +102,15 @@ impl Stages { } } -/// Produces a collection of `Stages`, which are sets of OrderedJobs that must be run before moving on to the next stage +/// Produces a collection of `Stages`, which are sets of OrderedJobs that must be run before moving +/// on to the next stage pub trait RenderGraphStager { fn get_stages(&mut self, render_graph: &RenderGraph) -> Result; } // TODO: remove this -/// This scheduler ignores dependencies and puts everything in one stage. It shouldn't be used for anything :) +/// This scheduler ignores dependencies and puts everything in one stage. It shouldn't be used for +/// anything :) #[derive(Debug, Default)] pub struct LinearStager; @@ -229,8 +232,9 @@ fn stage_node( }) .count(); - // if the current node has more than one parent on the highest stage (aka requires synchronization), then move it to the next - // stage and start a new job on that stage + // if the current node has more than one parent on the highest stage (aka requires + // synchronization), then move it to the next stage and start a new job on that + // stage if max_stage_parent_count > 1 { stage_index = max_parent_stage + 1; } else { @@ -492,7 +496,8 @@ mod tests { assert_eq!(job.nodes.len(), 7, "expect exactly 7 nodes in the job"); - // its hard to test the exact order of this job's nodes because of hashing, so instead we'll test the constraints that must hold true + // its hard to test the exact order of this job's nodes because of hashing, so instead we'll + // test the constraints that must hold true let index = |node_id: NodeId| -> usize { job.nodes.iter().position(|id| *id == node_id).unwrap() }; diff --git a/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs b/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs index ecb0e8b2c2..f44982fd4c 100644 --- a/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs +++ b/crates/bevy_render/src/renderer/render_resource/render_resource_bindings.rs @@ -61,13 +61,15 @@ pub enum BindGroupStatus { NoMatch, } -// PERF: if the bindings are scoped to a specific pipeline layout, then names could be replaced with indices here for a perf boost +// PERF: if the bindings are scoped to a specific pipeline layout, then names could be replaced with +// indices here for a perf boost #[derive(Eq, PartialEq, Debug, Default, Clone)] pub struct RenderResourceBindings { pub bindings: HashMap, /// A Buffer that contains all attributes a mesh has defined pub vertex_attribute_buffer: Option, - /// A Buffer that is filled with zeros that will be used for attributes required by the shader, but undefined by the mesh. + /// A Buffer that is filled with zeros that will be used for attributes required by the shader, + /// but undefined by the mesh. pub vertex_fallback_buffer: Option, pub index_buffer: Option<(BufferId, IndexFormat)>, assets: HashSet<(HandleUntyped, TypeId)>, @@ -87,7 +89,8 @@ impl RenderResourceBindings { self.bindings.insert(name.to_string(), binding); } - /// The current "generation" of dynamic bindings. This number increments every time a dynamic binding changes + /// The current "generation" of dynamic bindings. This number increments every time a dynamic + /// binding changes pub fn dynamic_bindings_generation(&self) -> usize { self.dynamic_bindings_generation } @@ -182,8 +185,9 @@ impl RenderResourceBindings { Some(bind_group) } BindGroupStatus::Unchanged(id) => { - // PERF: this is only required because RenderResourceContext::remove_stale_bind_groups doesn't inform RenderResourceBindings - // when a stale bind group has been removed + // PERF: this is only required because + // RenderResourceContext::remove_stale_bind_groups doesn't inform + // RenderResourceBindings when a stale bind group has been removed let bind_group = self .get_bind_group(id) .expect("`RenderResourceSet` was just changed, so it should exist."); diff --git a/crates/bevy_render/src/renderer/render_resource_context.rs b/crates/bevy_render/src/renderer/render_resource_context.rs index 87d3e21a06..9afa958aa8 100644 --- a/crates/bevy_render/src/renderer/render_resource_context.rs +++ b/crates/bevy_render/src/renderer/render_resource_context.rs @@ -77,13 +77,16 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static { fn remove_stale_bind_groups(&self); /// Reflects the pipeline layout from its shaders. /// - /// If `bevy_conventions` is true, it will be assumed that the shader follows "bevy shader conventions". These allow - /// richer reflection, such as inferred Vertex Buffer names and inferred instancing. + /// If `bevy_conventions` is true, it will be assumed that the shader follows "bevy shader + /// conventions". These allow richer reflection, such as inferred Vertex Buffer names and + /// inferred instancing. /// - /// If `dynamic_bindings` has values, shader uniforms will be set to "dynamic" if there is a matching binding in the list + /// If `dynamic_bindings` has values, shader uniforms will be set to "dynamic" if there is a + /// matching binding in the list /// /// If `vertex_buffer_descriptors` is set, the pipeline's vertex buffers - /// will inherit their layouts from global descriptors, otherwise the layout will be assumed to be complete / local. + /// will inherit their layouts from global descriptors, otherwise the layout will be assumed to + /// be complete / local. fn reflect_pipeline_layout( &self, shaders: &Assets, diff --git a/crates/bevy_render/src/shader/shader_defs.rs b/crates/bevy_render/src/shader/shader_defs.rs index 3076183c9d..db862dc1d5 100644 --- a/crates/bevy_render/src/shader/shader_defs.rs +++ b/crates/bevy_render/src/shader/shader_defs.rs @@ -4,7 +4,8 @@ use crate::{pipeline::RenderPipelines, Texture}; pub use bevy_derive::ShaderDefs; use bevy_ecs::system::{Query, Res}; -/// Something that can either be "defined" or "not defined". This is used to determine if a "shader def" should be considered "defined" +/// Something that can either be "defined" or "not defined". This is used to determine if a "shader +/// def" should be considered "defined" pub trait ShaderDef { fn is_defined(&self) -> bool; } diff --git a/crates/bevy_render/src/texture/texture.rs b/crates/bevy_render/src/texture/texture.rs index f7d6ea6ba2..54f1e4a380 100644 --- a/crates/bevy_render/src/texture/texture.rs +++ b/crates/bevy_render/src/texture/texture.rs @@ -101,7 +101,8 @@ impl Texture { .resize(size.volume() * self.format.pixel_size(), 0); } - /// Changes the `size`, asserting that the total number of data elements (pixels) remains the same. + /// Changes the `size`, asserting that the total number of data elements (pixels) remains the + /// same. pub fn reinterpret_size(&mut self, new_size: Extent3d) { assert!( new_size.volume() == self.size.volume(), @@ -113,9 +114,9 @@ impl Texture { self.size = new_size; } - /// Takes a 2D texture containing vertically stacked images of the same size, and reinterprets it as a 2D array texture, - /// where each of the stacked images becomes one layer of the array. This is primarily for use with the `texture2DArray` - /// shader uniform type. + /// Takes a 2D texture containing vertically stacked images of the same size, and reinterprets + /// it as a 2D array texture, where each of the stacked images becomes one layer of the + /// array. This is primarily for use with the `texture2DArray` shader uniform type. pub fn reinterpret_stacked_2d_as_array(&mut self, layers: u32) { // Must be a stacked image, and the height must be divisible by layers. assert!(self.dimension == TextureDimension::D2); @@ -171,8 +172,9 @@ impl Texture { } AssetEvent::Removed { handle } => { Self::remove_current_texture_resources(render_resource_context, handle); - // if texture was modified and removed in the same update, ignore the modification - // events are ordered so future modification events are ok + // if texture was modified and removed in the same update, ignore the + // modification events are ordered so future modification + // events are ok changed_textures.remove(handle); } } @@ -217,7 +219,8 @@ impl Texture { } } - /// Load a bytes buffer in a [`Texture`], according to type `image_type`, using the `image` crate` + /// Load a bytes buffer in a [`Texture`], according to type `image_type`, using the `image` + /// crate` pub fn from_buffer(buffer: &[u8], image_type: ImageType) -> Result { let format = match image_type { ImageType::MimeType(mime_type) => match mime_type { diff --git a/crates/bevy_render/src/texture/texture_dimension.rs b/crates/bevy_render/src/texture/texture_dimension.rs index c5b8e8552f..3ed2c66970 100644 --- a/crates/bevy_render/src/texture/texture_dimension.rs +++ b/crates/bevy_render/src/texture/texture_dimension.rs @@ -95,7 +95,8 @@ pub struct PixelInfo { /// Underlying texture data format. /// /// If there is a conversion in the format (such as srgb -> linear), The conversion listed is for -/// loading from texture in a shader. When writing to the texture, the opposite conversion takes place. +/// loading from texture in a shader. When writing to the texture, the opposite conversion takes +/// place. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)] pub enum TextureFormat { // Normal 8 bit formats diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index 244d6548fa..ccb3a1c6a3 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -81,7 +81,8 @@ impl SceneSpawner { for instance_id in instance_ids { if let Some(instance) = self.spawned_instances.get(&instance_id) { for entity in instance.entity_map.values() { - let _ = world.despawn(entity); // Ignore the result, despawn only cares if it exists. + let _ = world.despawn(entity); // Ignore the result, despawn only cares if + // it exists. } } } diff --git a/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs b/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs index 8fc4827523..0353bb1ea9 100644 --- a/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs @@ -51,8 +51,8 @@ impl DynamicTextureAtlasBuilder { // let change_list = self.atlas_allocator.resize_and_rearrange(new_size2); // for change in change_list.changes { - // if let Some(changed_texture_handle) = self.allocation_textures.remove(&change.old.id) { - // let changed_texture = textures.get(&changed_texture_handle).unwrap(); + // if let Some(changed_texture_handle) = self.allocation_textures.remove(&change.old.id) + // { let changed_texture = textures.get(&changed_texture_handle).unwrap(); // self.place_texture(change.new, changed_texture_handle, changed_texture); // } // } diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index 1301229281..2081f5ede1 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -68,7 +68,8 @@ impl Plugin for SpritePlugin { color_materials.set_untracked(Handle::::default(), ColorMaterial::default()); meshes.set_untracked( QUAD_HANDLE, - // Use a flipped quad because the camera is facing "forward" but quads should face backward + // Use a flipped quad because the camera is facing "forward" but quads should face + // backward Mesh::from(shape::Quad::new(Vec2::new(1.0, 1.0))), ) } diff --git a/crates/bevy_sprite/src/rect.rs b/crates/bevy_sprite/src/rect.rs index 5a2254efff..befb82f20e 100644 --- a/crates/bevy_sprite/src/rect.rs +++ b/crates/bevy_sprite/src/rect.rs @@ -1,7 +1,8 @@ use bevy_core::Byteable; use bevy_math::Vec2; -/// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere (top-left, bottom-left, etc) +/// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere +/// (top-left, bottom-left, etc) #[repr(C)] #[derive(Default, Clone, Copy, Debug)] pub struct Rect { diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index 794efd4e2c..555048970c 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -86,7 +86,8 @@ pub fn sprite_system( if let Some(ref texture_handle) = material.texture { if let Some(texture) = textures.get(texture_handle) { let texture_size = texture.size.as_vec3().truncate(); - // only set sprite size if it has changed (this check prevents change detection from triggering) + // only set sprite size if it has changed (this check prevents change + // detection from triggering) if sprite.size != texture_size { sprite.size = texture_size; } diff --git a/crates/bevy_tasks/src/countdown_event.rs b/crates/bevy_tasks/src/countdown_event.rs index 4a89823ec3..35bb03bc28 100644 --- a/crates/bevy_tasks/src/countdown_event.rs +++ b/crates/bevy_tasks/src/countdown_event.rs @@ -114,7 +114,8 @@ pub fn event_resets_if_listeners_are_cleared() { event.notify(std::usize::MAX); futures_lite::future::block_on(listener1); - // If all listeners are notified, the structure should now be cleared. We're free to listen again + // If all listeners are notified, the structure should now be cleared. We're free to listen + // again let listener2 = event.listen(); let listener3 = event.listen(); diff --git a/crates/bevy_tasks/src/iter/mod.rs b/crates/bevy_tasks/src/iter/mod.rs index 2cd8cf9576..91147fceb1 100644 --- a/crates/bevy_tasks/src/iter/mod.rs +++ b/crates/bevy_tasks/src/iter/mod.rs @@ -381,7 +381,8 @@ where .max_by_key(f) } - /// Returns the item that gives the maximum value with respect to the specified comparison function. + /// Returns the item that gives the maximum value with respect to the specified comparison + /// function. /// /// See [`Iterator::max_by()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.max_by) fn max_by(mut self, pool: &TaskPool, f: F) -> Option @@ -420,7 +421,8 @@ where .min_by_key(f) } - /// Returns the item that gives the minimum value with respect to the specified comparison function. + /// Returns the item that gives the minimum value with respect to the specified comparison + /// function. /// /// See [`Iterator::min_by()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.min_by) fn min_by(mut self, pool: &TaskPool, f: F) -> Option diff --git a/crates/bevy_tasks/src/task.rs b/crates/bevy_tasks/src/task.rs index 2704682735..461ed36e0e 100644 --- a/crates/bevy_tasks/src/task.rs +++ b/crates/bevy_tasks/src/task.rs @@ -22,7 +22,8 @@ impl Task { Self(task) } - /// Detaches the task to let it keep running in the background. See `async_executor::Task::detach` + /// Detaches the task to let it keep running in the background. See + /// `async_executor::Task::detach` pub fn detach(self) { self.0.detach(); } diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index db98543b17..aa708ec0dd 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -86,8 +86,8 @@ pub struct TaskPool { /// The executor for the pool /// /// This has to be separate from TaskPoolInner because we have to create an Arc to - /// pass into the worker threads, and we must create the worker threads before we can create the - /// Vec> contained within TaskPoolInner + /// pass into the worker threads, and we must create the worker threads before we can create + /// the Vec> contained within TaskPoolInner executor: Arc>, /// Inner state of the pool @@ -200,17 +200,18 @@ impl TaskPool { // Pin the futures on the stack. pin!(fut); - // SAFETY: This function blocks until all futures complete, so we do not read/write the - // data from futures outside of the 'scope lifetime. However, rust has no way of knowing - // this so we must convert to 'static here to appease the compiler as it is unable to - // validate safety. + // SAFETY: This function blocks until all futures complete, so we do not read/write + // the data from futures outside of the 'scope lifetime. However, + // rust has no way of knowing this so we must convert to 'static + // here to appease the compiler as it is unable to validate safety. let fut: Pin<&mut (dyn Future>)> = fut; let fut: Pin<&'static mut (dyn Future> + 'static)> = unsafe { mem::transmute(fut) }; - // The thread that calls scope() will participate in driving tasks in the pool forward - // until the tasks that are spawned by this scope() call complete. (If the caller of scope() - // happens to be a thread in this thread pool, and we only have one thread in the pool, then + // The thread that calls scope() will participate in driving tasks in the pool + // forward until the tasks that are spawned by this scope() call + // complete. (If the caller of scope() happens to be a thread in + // this thread pool, and we only have one thread in the pool, then // simply calling future::block_on(spawned) would deadlock.) let mut spawned = local_executor.spawn(fut); loop { @@ -376,7 +377,8 @@ mod tests { scope.spawn_local(async move { inner_count_clone.fetch_add(1, Ordering::Release); if std::thread::current().id() != spawner { - // NOTE: This check is using an atomic rather than simply panicing the thread to avoid deadlocking the barrier on failure + // NOTE: This check is using an atomic rather than simply panicing the + // thread to avoid deadlocking the barrier on failure inner_thread_check_failed.store(true, Ordering::Release); } }); diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index a821ee1a76..4cb2714720 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -171,7 +171,8 @@ pub fn text2d_system( &mut *textures, ) { Err(TextError::NoSuchFont) => { - // There was an error processing the text layout, let's add this entity to the queue for further processing + // There was an error processing the text layout, let's add this entity to the + // queue for further processing new_queue.push(entity); } Err(e @ TextError::FailedToAddGlyph(_)) => { diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index bc8d556d93..345e51d632 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -63,7 +63,8 @@ impl GlobalTransform { } } - /// Returns transform with the same translation and scale, but rotation so that transform.forward() points at target + /// Returns transform with the same translation and scale, but rotation so that + /// transform.forward() points at target #[inline] pub fn looking_at(mut self, target: Vec3, up: Vec3) -> Self { self.look_at(target, up); diff --git a/crates/bevy_transform/src/components/parent.rs b/crates/bevy_transform/src/components/parent.rs index f26dfba1dd..8f65d3a81d 100644 --- a/crates/bevy_transform/src/components/parent.rs +++ b/crates/bevy_transform/src/components/parent.rs @@ -12,8 +12,8 @@ pub struct Parent(pub Entity); // TODO: We need to impl either FromWorld or Default so Parent can be registered as Properties. // This is because Properties deserialize by creating an instance and apply a patch on top. -// However Parent should only ever be set with a real user-defined entity. Its worth looking into better -// ways to handle cases like this. +// However Parent should only ever be set with a real user-defined entity. Its worth looking into +// better ways to handle cases like this. impl FromWorld for Parent { fn from_world(_world: &mut World) -> Self { Parent(Entity::new(u32::MAX)) diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 781c71377a..21975861d4 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -63,7 +63,8 @@ impl Transform { } } - /// Returns transform with the same translation and scale, but rotation so that transform.forward() points at target + /// Returns transform with the same translation and scale, but rotation so that + /// transform.forward() points at target #[inline] pub fn looking_at(mut self, target: Vec3, up: Vec3) -> Self { self.look_at(target, up); diff --git a/crates/bevy_transform/src/hierarchy/child_builder.rs b/crates/bevy_transform/src/hierarchy/child_builder.rs index 8298049dc6..66e042d338 100644 --- a/crates/bevy_transform/src/hierarchy/child_builder.rs +++ b/crates/bevy_transform/src/hierarchy/child_builder.rs @@ -29,7 +29,8 @@ impl Command for InsertChildren { added = true; } - // NOTE: ideally this is just an else statement, but currently that _incorrectly_ fails borrow-checking + // NOTE: ideally this is just an else statement, but currently that _incorrectly_ fails + // borrow-checking if !added { world .entity_mut(self.parent) @@ -64,7 +65,8 @@ impl Command for PushChildren { added = true; } - // NOTE: ideally this is just an else statement, but currently that _incorrectly_ fails borrow-checking + // NOTE: ideally this is just an else statement, but currently that _incorrectly_ fails + // borrow-checking if !added { world .entity_mut(self.parent) @@ -270,8 +272,8 @@ impl<'w> BuildWorldChildren for EntityMut<'w> { let mut builder = WorldChildBuilder { current_entity: None, parent_entities: vec![entity], - // SAFE: self.update_location() is called below. It is impossible to make EntityMut function calls on `self` - // within the scope defined here + // SAFE: self.update_location() is called below. It is impossible to make EntityMut + // function calls on `self` within the scope defined here world: unsafe { self.world_mut() }, }; diff --git a/crates/bevy_transform/src/hierarchy/hierarchy.rs b/crates/bevy_transform/src/hierarchy/hierarchy.rs index 47f8db14b3..455a88f202 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy.rs @@ -106,7 +106,8 @@ mod tests { { let mut commands = Commands::new(&mut queue, &world); commands.despawn_recursive(parent_entity); - commands.despawn_recursive(parent_entity); // despawning the same entity twice should not panic + commands.despawn_recursive(parent_entity); // despawning the same entity twice should + // not panic } queue.apply(&mut world); diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index 19f408d210..62ddec77b3 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -10,8 +10,8 @@ use smallvec::SmallVec; pub fn parent_update_system( mut commands: Commands, removed_parent_query: Query<(Entity, &PreviousParent), Without>, - // The next query could be run with a Changed filter. However, this would mean that modifications later in the frame are lost. - // See issue 891: https://github.com/bevyengine/bevy/issues/891 + // The next query could be run with a Changed filter. However, this would mean that + // modifications later in the frame are lost. See issue 891: https://github.com/bevyengine/bevy/issues/891 mut parent_query: Query<(Entity, &Parent, Option<&mut PreviousParent>)>, mut children_query: Query<&mut Children>, ) { diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 0924e4e530..df99b53869 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -93,7 +93,8 @@ pub fn ui_focus_system( let extents = node.size / 2.0; let min = ui_position - extents; let max = ui_position + extents; - // if the current cursor position is within the bounds of the node, consider it for clicking + // if the current cursor position is within the bounds of the node, consider it for + // clicking if (min.x..max.x).contains(&cursor_position.x) && (min.y..max.y).contains(&cursor_position.y) { @@ -120,7 +121,8 @@ pub fn ui_focus_system( // only consider nodes with Interaction "clickable" if *interaction != Interaction::Clicked { *interaction = Interaction::Clicked; - // if the mouse was simultaneously released, reset this Interaction in the next frame + // if the mouse was simultaneously released, reset this Interaction in the next + // frame if mouse_released { state.entities_to_reset.push(entity); } diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index a5643177bd..f92e54ebe7 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -105,7 +105,8 @@ pub fn text_system( &mut *textures, ) { Err(TextError::NoSuchFont) => { - // There was an error processing the text layout, let's add this entity to the queue for further processing + // There was an error processing the text layout, let's add this entity to the + // queue for further processing new_queue.push(entity); } Err(e @ TextError::FailedToAddGlyph(_)) => { diff --git a/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs b/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs index 6bed9a3095..4f5b465052 100644 --- a/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs +++ b/crates/bevy_wgpu/src/renderer/wgpu_render_context.rs @@ -66,8 +66,9 @@ impl WgpuRenderContext { } } - /// Consume this context, finalize the current CommandEncoder (if it exists), and take the current WgpuResources. - /// This is intended to be called from a worker thread right before synchronizing with the main thread. + /// Consume this context, finalize the current CommandEncoder (if it exists), and take the + /// current WgpuResources. This is intended to be called from a worker thread right before + /// synchronizing with the main thread. pub fn finish(&mut self) -> Option { self.command_encoder.take().map(|encoder| encoder.finish()) } diff --git a/crates/bevy_wgpu/src/wgpu_resources.rs b/crates/bevy_wgpu/src/wgpu_resources.rs index aa3e76c6be..b3cb93c9fd 100644 --- a/crates/bevy_wgpu/src/wgpu_resources.rs +++ b/crates/bevy_wgpu/src/wgpu_resources.rs @@ -17,27 +17,32 @@ pub struct WgpuBindGroupInfo { } /// Grabs a read lock on all wgpu resources. When paired with WgpuResourceRefs, this allows -/// you to pass in wgpu resources to wgpu::RenderPass<'a> with the appropriate lifetime. This is accomplished by -/// grabbing a WgpuResourcesReadLock _before_ creating a wgpu::RenderPass, getting a WgpuResourcesRefs, and storing that -/// in the pass. +/// you to pass in wgpu resources to wgpu::RenderPass<'a> with the appropriate lifetime. This is +/// accomplished by grabbing a WgpuResourcesReadLock _before_ creating a wgpu::RenderPass, getting a +/// WgpuResourcesRefs, and storing that in the pass. /// -/// This is only a problem because RwLockReadGuard.read() erases the guard's lifetime and creates a new anonymous lifetime. If -/// you call RwLockReadGuard.read() during a pass, the reference will have an anonymous lifetime that lives for less than the -/// pass, which violates the lifetime constraints in place. +/// This is only a problem because RwLockReadGuard.read() erases the guard's lifetime and creates a +/// new anonymous lifetime. If you call RwLockReadGuard.read() during a pass, the reference will +/// have an anonymous lifetime that lives for less than the pass, which violates the lifetime +/// constraints in place. /// -/// The biggest implication of this design (other than the additional boilerplate here) is that beginning a render pass -/// blocks writes to these resources. This means that if the pass attempts to write any resource, a deadlock will occur. WgpuResourceRefs -/// only has immutable references, so the only way to make a deadlock happen is to access WgpuResources directly in the pass. It also means -/// that other threads attempting to write resources will need to wait for pass encoding to finish. Almost all writes should occur before -/// passes start, so this hopefully won't be a problem. +/// The biggest implication of this design (other than the additional boilerplate here) is that +/// beginning a render pass blocks writes to these resources. This means that if the pass attempts +/// to write any resource, a deadlock will occur. WgpuResourceRefs only has immutable references, so +/// the only way to make a deadlock happen is to access WgpuResources directly in the pass. It also +/// means that other threads attempting to write resources will need to wait for pass encoding to +/// finish. Almost all writes should occur before passes start, so this hopefully won't be a +/// problem. /// -/// It is worth comparing the performance of this to transactional / copy-based approaches. This lock based design guarantees -/// consistency, doesn't perform redundant allocations, and only blocks when a write is occurring. A copy based approach would -/// never block, but would require more allocations / state-synchronization, which I expect will be more expensive. It would also be +/// It is worth comparing the performance of this to transactional / copy-based approaches. This +/// lock based design guarantees consistency, doesn't perform redundant allocations, and only blocks +/// when a write is occurring. A copy based approach would never block, but would require more +/// allocations / state-synchronization, which I expect will be more expensive. It would also be /// "eventually consistent" instead of "strongly consistent". /// -/// Single threaded implementations don't need to worry about these lifetimes constraints at all. RenderPasses can use a RenderContext's -/// WgpuResources directly. RenderContext already has a lifetime greater than the RenderPass. +/// Single threaded implementations don't need to worry about these lifetimes constraints at all. +/// RenderPasses can use a RenderContext's WgpuResources directly. RenderContext already has a +/// lifetime greater than the RenderPass. #[derive(Debug)] pub struct WgpuResourcesReadLock<'a> { pub buffers: RwLockReadGuard<'a, HashMap>>, @@ -62,7 +67,8 @@ impl<'a> WgpuResourcesReadLock<'a> { } } -/// Stores read only references to WgpuResource collections. See WgpuResourcesReadLock docs for context on why this exists +/// Stores read only references to WgpuResource collections. See WgpuResourcesReadLock docs for +/// context on why this exists #[derive(Debug)] pub struct WgpuResourceRefs<'a> { pub buffers: &'a HashMap>, diff --git a/crates/bevy_window/src/event.rs b/crates/bevy_window/src/event.rs index 2498d66d73..9feb54c4ed 100644 --- a/crates/bevy_window/src/event.rs +++ b/crates/bevy_window/src/event.rs @@ -30,8 +30,8 @@ pub struct WindowCreated { pub id: WindowId, } -/// An event that is sent whenever a close was requested for a window. For example: when the "close" button -/// is pressed on a window. +/// An event that is sent whenever a close was requested for a window. For example: when the "close" +/// button is pressed on a window. #[derive(Debug, Clone)] pub struct WindowCloseRequested { pub id: WindowId, diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index a6db393515..2501ddf47a 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -304,13 +304,15 @@ impl Window { /// Modifies the position of the window in physical pixels. /// - /// Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, - /// the top-left hand corner of the desktop is the top-left hand corner of the monitor at the top-left of the desktop. This automatically un-maximizes - /// the window if it's maximized. + /// Note that the top-left hand corner of the desktop is not necessarily the same as the screen. + /// If the user uses a desktop with multiple monitors, the top-left hand corner of the + /// desktop is the top-left hand corner of the monitor at the top-left of the desktop. This + /// automatically un-maximizes the window if it's maximized. /// /// # Platform-specific /// - /// - iOS: Can only be called on the main thread. Sets the top left coordinates of the window in the screen space coordinate system. + /// - iOS: Can only be called on the main thread. Sets the top left coordinates of the window in + /// the screen space coordinate system. /// - Web: Sets the top-left coordinates relative to the viewport. /// - Android / Wayland: Unsupported. #[inline] diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 35add30746..978009f4e4 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -365,7 +365,8 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) { let winit_window = winit_windows.get_window(window_id).unwrap(); let mut location = touch.location.to_logical(winit_window.scale_factor()); - // On a mobile window, the start is from the top while on PC/Linux/OSX from bottom + // On a mobile window, the start is from the top while on PC/Linux/OSX from + // bottom if cfg!(target_os = "android") || cfg!(target_os = "ios") { let window_height = windows.get_primary().unwrap().height(); location.y = window_height - location.y; diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 6220f0722e..b5460f2aa8 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -1,6 +1,7 @@ use bevy::{asset::LoadState, prelude::*, sprite::TextureAtlasBuilder}; -/// In this example we generate a new texture atlas (sprite sheet) from a folder containing individual sprites +/// In this example we generate a new texture atlas (sprite sheet) from a folder containing +/// individual sprites fn main() { App::build() .init_resource::() diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index 61180e2597..e233c3c996 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -1,8 +1,9 @@ use bevy::prelude::*; -/// This example shows how to configure Multi-Sample Anti-Aliasing. Setting the sample count higher will result in smoother edges, -/// but it will also increase the cost to render those edges. The range should generally be somewhere between 1 (no multi sampling, -/// but cheap) to 8 (crisp but expensive) +/// This example shows how to configure Multi-Sample Anti-Aliasing. Setting the sample count higher +/// will result in smoother edges, but it will also increase the cost to render those edges. The +/// range should generally be somewhere between 1 (no multi sampling, but cheap) to 8 (crisp but +/// expensive) fn main() { App::build() .insert_resource(Msaa { samples: 4 }) diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 3f170c54fe..6fcedc6648 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; -/// This example illustrates how to create parent->child relationships between entities how parent transforms -/// are propagated to their descendants +/// This example illustrates how to create parent->child relationships between entities how parent +/// transforms are propagated to their descendants fn main() { App::build() .insert_resource(Msaa { samples: 4 }) diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 4bce18b3ea..7b72d2f892 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -5,9 +5,10 @@ use bevy::{ use rand::{rngs::StdRng, Rng, SeedableRng}; /// This example spawns a large number of cubes, each with its own changing position and material -/// This is intended to be a stress test of bevy's ability to render many objects with different properties -/// For the best results, run it in release mode: ```cargo run --example spawner --release -/// NOTE: Bevy still has a number of optimizations to do in this area. Expect the performance here to go way up in the future +/// This is intended to be a stress test of bevy's ability to render many objects with different +/// properties For the best results, run it in release mode: ```cargo run --example spawner +/// --release NOTE: Bevy still has a number of optimizations to do in this area. Expect the +/// performance here to go way up in the future fn main() { App::build() .add_plugins(DefaultPlugins) diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index c870925e61..973760c7e3 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -6,7 +6,8 @@ use bevy::{ }, }; -/// This example visualizes camera z-ordering by setting the material of rotating cubes to their distance from the camera +/// This example visualizes camera z-ordering by setting the material of rotating cubes to their +/// distance from the camera fn main() { App::build() .add_plugins(DefaultPlugins) diff --git a/examples/app/logs.rs b/examples/app/logs.rs index 5b68265a6b..103d34787e 100644 --- a/examples/app/logs.rs +++ b/examples/app/logs.rs @@ -14,7 +14,8 @@ fn main() { } fn log_system() { - // here is how you write new logs at each "log level" (in "least important" to "most important" order) + // here is how you write new logs at each "log level" (in "least important" to "most important" + // order) trace!("very noisy"); debug!("helpful for debugging"); info!("helpful information that is worth printing by default"); diff --git a/examples/app/plugin_group.rs b/examples/app/plugin_group.rs index 7e0be8143b..b7ad942f3a 100644 --- a/examples/app/plugin_group.rs +++ b/examples/app/plugin_group.rs @@ -11,8 +11,8 @@ fn main() { // .add_plugins_with(HelloWorldPlugins, |group| { // group // .disable::() - // .add_before::(bevy::diagnostic::LogDiagnosticsPlugin::default()) - // }) + // .add_before::(bevy::diagnostic::LogDiagnosticsPlugin::default()) }) .run(); } diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index 519052f2f2..019430a211 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -22,14 +22,16 @@ fn setup( // All assets end up in their Assets collection once they are done loading: if let Some(sphere) = meshes.get(&sphere_handle) { - // You might notice that this doesn't run! This is because assets load in parallel without blocking. - // When an asset has loaded, it will appear in relevant Assets collection. + // You might notice that this doesn't run! This is because assets load in parallel without + // blocking. When an asset has loaded, it will appear in relevant Assets + // collection. println!("{:?}", sphere.primitive_topology()); } else { println!("sphere hasn't loaded yet"); } - // You can load all assets in a folder like this. They will be loaded in parallel without blocking + // You can load all assets in a folder like this. They will be loaded in parallel without + // blocking let _scenes: Vec = asset_server.load_folder("models/monkey").unwrap(); // Then any asset in the folder can be accessed like this: diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index bb9148c8f5..503d416a49 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -1,8 +1,8 @@ use bevy::prelude::*; -/// Hot reloading allows you to modify assets on disk and they will be "live reloaded" while your game is running. -/// This lets you immediately see the results of your changes without restarting the game. -/// This example illustrates hot reloading mesh changes. +/// Hot reloading allows you to modify assets on disk and they will be "live reloaded" while your +/// game is running. This lets you immediately see the results of your changes without restarting +/// the game. This example illustrates hot reloading mesh changes. fn main() { App::build() .add_plugins(DefaultPlugins) diff --git a/examples/diagnostics/custom_diagnostic.rs b/examples/diagnostics/custom_diagnostic.rs index ea2eb59123..6169ac9284 100644 --- a/examples/diagnostics/custom_diagnostic.rs +++ b/examples/diagnostics/custom_diagnostic.rs @@ -7,14 +7,16 @@ use bevy::{ fn main() { App::build() .add_plugins(DefaultPlugins) - // The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the console + // The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the + // console .add_plugin(LogDiagnosticsPlugin::default()) .add_startup_system(setup_diagnostic_system.system()) .add_system(my_system.system()) .run(); } -// All diagnostics should have a unique DiagnosticId. for each new diagnostic, generate a new random number +// All diagnostics should have a unique DiagnosticId. for each new diagnostic, generate a new random +// number pub const SYSTEM_ITERATION_COUNT: DiagnosticId = DiagnosticId::from_u128(337040787172757619024841343456040760896); diff --git a/examples/ecs/ecs_guide.rs b/examples/ecs/ecs_guide.rs index ac1ee132d6..7e284dca2b 100644 --- a/examples/ecs/ecs_guide.rs +++ b/examples/ecs/ecs_guide.rs @@ -20,7 +20,8 @@ use rand::random; /// Examples: position, velocity, health, color, name /// /// Entity: a collection of components with a unique id -/// Examples: Entity1 { Name("Alice"), Position(0, 0) }, Entity2 { Name("Bill"), Position(10, 5) } +/// Examples: Entity1 { Name("Alice"), Position(0, 0) }, Entity2 { Name("Bill"), Position(10, 5) +/// } /// Resource: a shared global piece of data /// Examples: asset_storage, events, system state @@ -31,7 +32,6 @@ use rand::random; /// Now that you know a little bit about ECS, lets look at some Bevy code! /// We will now make a simple "game" to illustrate what Bevy's ECS looks like in practice. -// // COMPONENTS: Pieces of functionality we add to entities. These are just normal Rust data types // @@ -45,7 +45,6 @@ struct Score { value: usize, } -// // RESOURCES: "Global" state accessible by systems. These are also just normal Rust data types! // @@ -64,8 +63,8 @@ struct GameRules { max_players: usize, } -// -// SYSTEMS: Logic that runs on entities, components, and resources. These generally run once each time the app updates. +// SYSTEMS: Logic that runs on entities, components, and resources. These generally run once each +// time the app updates. // // This is the simplest type of system. It just prints "This game is fun!" on each run: @@ -119,8 +118,9 @@ fn score_check_system( } } -// This system ends the game if we meet the right conditions. This fires an AppExit event, which tells our -// App to quit. Check out the "event.rs" example if you want to learn more about using events. +// This system ends the game if we meet the right conditions. This fires an AppExit event, which +// tells our App to quit. Check out the "event.rs" example if you want to learn more about using +// events. fn game_over_system( game_rules: Res, game_state: Res, @@ -137,10 +137,10 @@ fn game_over_system( println!(); } -// This is a "startup" system that runs exactly once when the app starts up. Startup systems are generally used to create -// the initial "state" of our game. The only thing that distinguishes a "startup" system from a "normal" system is how it is registered: -// Startup: app.add_startup_system(startup_system) -// Normal: app.add_system(normal_system) +// This is a "startup" system that runs exactly once when the app starts up. Startup systems are +// generally used to create the initial "state" of our game. The only thing that distinguishes a +// "startup" system from a "normal" system is how it is registered: Startup: +// app.add_startup_system(startup_system) Normal: app.add_system(normal_system) fn startup_system(mut commands: Commands, mut game_state: ResMut) { // Create our game rules resource commands.insert_resource(GameRules { @@ -149,7 +149,8 @@ fn startup_system(mut commands: Commands, mut game_state: ResMut) { max_players: 4, }); - // Add some players to our world. Players start with a score of 0 ... we want our game to be fair! + // Add some players to our world. Players start with a score of 0 ... we want our game to be + // fair! commands.spawn_batch(vec![ ( Player { @@ -169,10 +170,11 @@ fn startup_system(mut commands: Commands, mut game_state: ResMut) { game_state.total_players = 2; } -// This system uses a command buffer to (potentially) add a new player to our game on each iteration. -// Normal systems cannot safely access the World instance directly because they run in parallel. -// Our World contains all of our components, so mutating arbitrary parts of it in parallel is not thread safe. -// Command buffers give us the ability to queue up changes to our World without directly accessing it +// This system uses a command buffer to (potentially) add a new player to our game on each +// iteration. Normal systems cannot safely access the World instance directly because they run in +// parallel. Our World contains all of our components, so mutating arbitrary parts of it in parallel +// is not thread safe. Command buffers give us the ability to queue up changes to our World without +// directly accessing it fn new_player_system( mut commands: Commands, game_rules: Res, @@ -193,10 +195,10 @@ fn new_player_system( } } -// If you really need full, immediate read/write access to the world or resources, you can use a "thread local system". -// These run on the main app thread (hence the name "thread local") -// WARNING: These will block all parallel execution of other systems until they finish, so they should generally be avoided if you -// care about performance +// If you really need full, immediate read/write access to the world or resources, you can use a +// "thread local system". These run on the main app thread (hence the name "thread local") +// WARNING: These will block all parallel execution of other systems until they finish, so they +// should generally be avoided if you care about performance #[allow(dead_code)] fn thread_local_system(world: &mut World) { // this does the same thing as "new_player_system" @@ -220,13 +222,14 @@ fn thread_local_system(world: &mut World) { } } -// Sometimes systems need their own unique "local" state. Bevy's ECS provides Local resources for this case. -// Local resources are unique to their system and are automatically initialized on your behalf (if they don't already exist). -// If you have a system's id, you can also access local resources directly in the Resources collection using `Resources::get_local()`. -// In general you should only need this feature in the following cases: -// 1. You have multiple instances of the same system and they each need their own unique state -// 2. You already have a global version of a resource that you don't want to overwrite for your current system -// 3. You are too lazy to register the system's resource as a global resource +// Sometimes systems need their own unique "local" state. Bevy's ECS provides Local resources for +// this case. Local resources are unique to their system and are automatically initialized on +// your behalf (if they don't already exist). If you have a system's id, you can also access local +// resources directly in the Resources collection using `Resources::get_local()`. In general you +// should only need this feature in the following cases: 1. You have multiple instances of the same +// system and they each need their own unique state 2. You already have a global version of a +// resource that you don't want to overwrite for your current system 3. You are too lazy to +// register the system's resource as a global resource #[derive(Default)] struct State { @@ -256,15 +259,17 @@ enum MyLabels { // Our Bevy app's entry point fn main() { - // Bevy apps are created using the builder pattern. We use the builder to add systems, resources, and plugins to our app + // Bevy apps are created using the builder pattern. We use the builder to add systems, + // resources, and plugins to our app App::build() // Resources can be added to our app like this .insert_resource(State { counter: 0 }) // Some systems are configured by adding their settings as a resource .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs(5))) // Plugins are just a grouped set of app builder calls (just like we're doing here). - // We could easily turn our game into a plugin, but you can check out the plugin example for that :) - // The plugin below runs our app's "system schedule" once every 5 seconds (configured above). + // We could easily turn our game into a plugin, but you can check out the plugin example for + // that :) The plugin below runs our app's "system schedule" once every 5 seconds + // (configured above). .add_plugin(ScheduleRunnerPlugin::default()) // Resources that implement the Default or FromResources trait can be added like this: .init_resource::() @@ -273,22 +278,24 @@ fn main() { .add_startup_system(startup_system.system()) // my_system calls converts normal rust functions into ECS systems: .add_system(print_message_system.system()) - // // SYSTEM EXECUTION ORDER // - // Each system belongs to a `Stage`, which controls the execution strategy and broad order of the systems within each tick. - // Startup stages (which startup systems are registered in) will always complete before ordinary stages begin, + // Each system belongs to a `Stage`, which controls the execution strategy and broad order + // of the systems within each tick. Startup stages (which startup systems are + // registered in) will always complete before ordinary stages begin, // and every system in a stage must complete before the next stage advances. // Once every stage has concluded, the main loop is complete and begins again. // - // By default, all systems run in parallel, except when they require mutable access to a piece of data. - // This is efficient, but sometimes order matters. - // For example, we want our "game over" system to execute after all other systems to ensure we don't - // accidentally run the game for an extra round. + // By default, all systems run in parallel, except when they require mutable access to a + // piece of data. This is efficient, but sometimes order matters. + // For example, we want our "game over" system to execute after all other systems to ensure + // we don't accidentally run the game for an extra round. // - // Rather than splitting each of your systems into separate stages, you should force an explicit ordering between them - // by giving the relevant systems a label with `.label`, then using the `.before` or `.after` methods. - // Systems will not be scheduled until all of the systems that they have an "ordering dependency" on have completed. + // Rather than splitting each of your systems into separate stages, you should force an + // explicit ordering between them by giving the relevant systems a label with + // `.label`, then using the `.before` or `.after` methods. Systems will not be + // scheduled until all of the systems that they have an "ordering dependency" on have + // completed. // // Doing that will, in just about all cases, lead to better performance compared to // splitting systems between stages, because it gives the scheduling algorithm more @@ -300,7 +307,8 @@ fn main() { // adding or removing resources, etc. // // add_system(system) adds systems to the UPDATE stage by default - // However we can manually specify the stage if we want to. The following is equivalent to add_system(score_system) + // However we can manually specify the stage if we want to. The following is equivalent to + // add_system(score_system) .add_system_to_stage(CoreStage::Update, score_system.system()) // We can also create new stages. Here is what our games stage order will look like: // "before_round": new_player_system, new_round_system @@ -318,8 +326,8 @@ fn main() { ) .add_system_to_stage(MyStage::BeforeRound, new_round_system.system()) .add_system_to_stage(MyStage::BeforeRound, new_player_system.system()) - // We can ensure that game_over system runs after score_check_system using explicit ordering constraints - // First, we label the system we want to refer to using `.label` + // We can ensure that game_over system runs after score_check_system using explicit ordering + // constraints First, we label the system we want to refer to using `.label` // Then, we use either `.before` or `.after` to describe the order we want the relationship .add_system_to_stage( MyStage::AfterRound, @@ -329,10 +337,10 @@ fn main() { MyStage::AfterRound, game_over_system.system().after(MyLabels::ScoreCheck), ) - // We can check our systems for execution order ambiguities by examining the output produced in the console - // by adding the following Resource to our App :) - // Be aware that not everything reported by this checker is a potential problem, you'll have to make - // that judgement yourself. + // We can check our systems for execution order ambiguities by examining the output produced + // in the console by adding the following Resource to our App :) + // Be aware that not everything reported by this checker is a potential problem, you'll have + // to make that judgement yourself. .insert_resource(ReportExecutionOrderAmbiguities) // This call to run() starts the app we just built! .run(); diff --git a/examples/ecs/fixed_timestep.rs b/examples/ecs/fixed_timestep.rs index beef7ad70a..6dd6a28ed5 100644 --- a/examples/ecs/fixed_timestep.rs +++ b/examples/ecs/fixed_timestep.rs @@ -20,7 +20,8 @@ fn main() { SystemStage::parallel() .with_run_criteria( FixedTimestep::step(2.0) - // labels are optional. they provide a way to access the current FixedTimestep state from within a system + // labels are optional. they provide a way to access the current + // FixedTimestep state from within a system .with_label(LABEL), ) .with_system(fixed_update.system()), diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index 48edf2cda5..1a6cdbc9b8 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -48,7 +48,8 @@ fn setup( // Another way to create a hierarchy is to add a Parent component to an entity, // which would be added automatically to parents with other methods. - // Similarly, adding a Parent component will automatically add a Children component to the parent. + // Similarly, adding a Parent component will automatically add a Children component to the + // parent. commands .spawn(SpriteBundle { transform: Transform { @@ -108,7 +109,8 @@ fn rotate( } } - // To demonstrate removing children, we'll start to remove the children after a couple of seconds + // To demonstrate removing children, we'll start to remove the children after a couple of + // seconds if time.seconds_since_startup() >= 2.0 && children.len() == 3 { let child = children.last().copied().unwrap(); commands.despawn(child); diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index 2a7dec07b6..30e05b3ad2 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -1,6 +1,7 @@ use bevy::prelude::*; -/// This example illustrates how to use States to control transitioning from a Menu state to an InGame state. +/// This example illustrates how to use States to control transitioning from a Menu state to an +/// InGame state. fn main() { App::build() .add_plugins(DefaultPlugins) diff --git a/examples/ecs/system_chaining.rs b/examples/ecs/system_chaining.rs index 4bbcd6822b..2dd14437e1 100644 --- a/examples/ecs/system_chaining.rs +++ b/examples/ecs/system_chaining.rs @@ -16,7 +16,8 @@ fn parse_message_system(message: Res) -> Result { } // This system takes a Result input and either prints the parsed value or the error message -// Try changing the Message resource to something that isn't an integer. You should see the error message printed. +// Try changing the Message resource to something that isn't an integer. You should see the error +// message printed. fn handler_system(In(result): In>) { match result { Ok(value) => println!("parsed message: {}", value), diff --git a/examples/ecs/timers.rs b/examples/ecs/timers.rs index 3a8094e1bf..8ac872fd1d 100644 --- a/examples/ecs/timers.rs +++ b/examples/ecs/timers.rs @@ -51,8 +51,8 @@ fn countdown_system(time: Res