From 003765a878ec4d9685b48440772783312ca91348 Mon Sep 17 00:00:00 2001 From: Lixou <82600264+DasLixou@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:57:22 +0100 Subject: [PATCH 01/79] Remove unnecessary if statement in scheduler (#10446) # Objective There is an if statement checking if a node is present in a graph moments after it explicitly being added. Unless the edge function has super weird side effects and the tests don't pass, this is unnecessary. ## Solution Removed it --- crates/bevy_ecs/src/schedule/schedule.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 82732b1a7e052..8d65f61119e61 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -859,10 +859,6 @@ impl ScheduleGraph { self.dependency.graph.add_node(set); } - if !self.dependency.graph.contains_node(id) { - self.dependency.graph.add_node(id); - } - for (kind, set) in dependencies .into_iter() .map(|Dependency { kind, set }| (kind, self.system_set_ids[&set])) From f91f69e88f62d79c23886668f6696b35238feaa8 Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Thu, 9 Nov 2023 03:10:22 +0100 Subject: [PATCH 02/79] Reexport `wgpu::Maintain` (#10461) # Objective Calling `RenderDevice::poll` requires an instance of `wgpu::Maintain`, but the type was not reexported by bevy. Working around it requires adding a dependency on `wgpu`, since bevy does not reexport the `wgpu` crate as a whole anywhere. ## Solution Reexport `wgpu::Maintain` in `render_resource`, where the other wgpu types are reexported. --- crates/bevy_render/src/render_resource/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/src/render_resource/mod.rs b/crates/bevy_render/src/render_resource/mod.rs index b7d245b0bdbc9..5ccf34bf85344 100644 --- a/crates/bevy_render/src/render_resource/mod.rs +++ b/crates/bevy_render/src/render_resource/mod.rs @@ -38,9 +38,9 @@ pub use wgpu::{ ComputePipelineDescriptor as RawComputePipelineDescriptor, DepthBiasState, DepthStencilState, Extent3d, Face, Features as WgpuFeatures, FilterMode, FragmentState as RawFragmentState, FrontFace, ImageCopyBuffer, ImageCopyBufferBase, ImageCopyTexture, ImageCopyTextureBase, - ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits as WgpuLimits, LoadOp, MapMode, - MultisampleState, Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor, PolygonMode, - PrimitiveState, PrimitiveTopology, PushConstantRange, RenderPassColorAttachment, + ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits as WgpuLimits, LoadOp, Maintain, + MapMode, MultisampleState, Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor, + PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipelineDescriptor as RawRenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor, ShaderModule, ShaderModuleDescriptor, ShaderSource, ShaderStages, StencilFaceState, From 13d46a528ac6e8c2e08e8b9ba436abb9baaefefc Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:07:48 +0100 Subject: [PATCH 03/79] Don't `.unwrap()` in `AssetPath::try_parse` (#10452) # Objective - The docs on `AssetPath::try_parse` say that it will return an error when the string is malformed, but it actually just `.unwrap()`s the result. ## Solution - Use `?` instead of unwrapping the result. --- crates/bevy_asset/src/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index fccc0783f6249..db2c48fb88b0d 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -115,7 +115,7 @@ impl<'a> AssetPath<'a> { /// /// This will return a [`ParseAssetPathError`] if `asset_path` is in an invalid format. pub fn try_parse(asset_path: &'a str) -> Result, ParseAssetPathError> { - let (source, path, label) = Self::parse_internal(asset_path).unwrap(); + let (source, path, label) = Self::parse_internal(asset_path)?; Ok(Self { source: match source { Some(source) => AssetSourceId::Name(CowArc::Borrowed(source)), From e75c2f8b1633904658175a2f8d3e21789a55c47d Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Thu, 9 Nov 2023 20:32:33 +0100 Subject: [PATCH 04/79] Remove a ptr-to-int cast in `CommandQueue::apply` (#10475) # Objective - `CommandQueue::apply` calculates the address of the end of the internal buffer as a `usize` rather than as a pointer, requiring two casts of `cursor` to `usize`. Casting pointers to integers is generally discouraged and may also prevent optimizations. It's also unnecessary here. ## Solution - Calculate the end address as a pointer rather than a `usize`. Small note: A trivial translation of the old code to use pointers would have computed `end_addr` as `cursor.add(self.bytes.len())`, which is not wrong but is an additional `unsafe` operation that also needs to be properly documented and proven correct. However this operation is already implemented in the form of the safe `as_mut_ptr_range`, so I just used that. --- crates/bevy_ecs/src/system/commands/command_queue.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/command_queue.rs b/crates/bevy_ecs/src/system/commands/command_queue.rs index b32ff7a8134e5..86a4e160e1370 100644 --- a/crates/bevy_ecs/src/system/commands/command_queue.rs +++ b/crates/bevy_ecs/src/system/commands/command_queue.rs @@ -97,18 +97,18 @@ impl CommandQueue { // flush the previously queued entities world.flush(); - // Pointer that will iterate over the entries of the buffer. - let mut cursor = self.bytes.as_mut_ptr(); + // The range of pointers of the filled portion of `self.bytes`. + let bytes_range = self.bytes.as_mut_ptr_range(); - // The address of the end of the buffer. - let end_addr = cursor as usize + self.bytes.len(); + // Pointer that will iterate over the entries of the buffer. + let mut cursor = bytes_range.start; // Reset the buffer, so it can be reused after this function ends. // In the loop below, ownership of each command will be transferred into user code. // SAFETY: `set_len(0)` is always valid. unsafe { self.bytes.set_len(0) }; - while (cursor as usize) < end_addr { + while cursor < bytes_range.end { // SAFETY: The cursor is either at the start of the buffer, or just after the previous command. // Since we know that the cursor is in bounds, it must point to the start of a new command. let meta = unsafe { cursor.cast::().read_unaligned() }; From cbadc31d19e1d40841969ac503d49b3fff030f57 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 9 Nov 2023 15:05:32 -0700 Subject: [PATCH 05/79] Use a consistent scale factor and resolution in stress tests (#10474) # Objective Related to #10472. Not having a hardcoded scale factor makes comparing results from these stress tests difficult. Contributors using high dpi screens may be rendering 4x as many pixels as others (or more). Stress tests may have different behavior when moved from one monitor in a dual setup to another. At very high resolutions, different parts of the engine / hardware are being stressed. 1080p is also a far more common resolution for gaming. ## Solution Use a consistent 1080p with `scale_factor_override: 1.0` everywhere. In #9903, this sort of change was added specifically to `bevymark` and `many_cubes` but it makes sense to do it everywhere. ## Discussion - Maybe we should have a command line option, environment variable, or `CI_TESTING_CONFIG` option for 1080p / 1440p / 4k. - Will these look odd (small text?) when screenshotted and shown in the example showcase? The aspect ratio is the same, but they will be downscaled from 1080p instead of ~720p. - Maybe there are other window properties that should be consistent across stress tests. e.g. `resizable: false`. - Should we add a `stress_test_window(title)` helper or something? - Bevymark (pre-10472) was intentionally 800x600 to match "bunnymark", I believe. I don't personally think this is very important. --- examples/stress_tests/many_animated_sprites.rs | 4 +++- examples/stress_tests/many_buttons.rs | 3 ++- examples/stress_tests/many_foxes.rs | 4 +++- examples/stress_tests/many_gizmos.rs | 3 ++- examples/stress_tests/many_glyphs.rs | 3 ++- examples/stress_tests/many_lights.rs | 5 +++-- examples/stress_tests/many_sprites.rs | 4 +++- examples/stress_tests/text_pipeline.rs | 4 +++- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/examples/stress_tests/many_animated_sprites.rs b/examples/stress_tests/many_animated_sprites.rs index 9e8962473036d..ec5b3d7953905 100644 --- a/examples/stress_tests/many_animated_sprites.rs +++ b/examples/stress_tests/many_animated_sprites.rs @@ -10,7 +10,7 @@ use bevy::{ math::Quat, prelude::*, render::camera::Camera, - window::PresentMode, + window::{PresentMode, WindowResolution}, }; use rand::Rng; @@ -26,6 +26,8 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0) + .with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/many_buttons.rs b/examples/stress_tests/many_buttons.rs index d7c8533c37a07..3521a92f7d183 100644 --- a/examples/stress_tests/many_buttons.rs +++ b/examples/stress_tests/many_buttons.rs @@ -3,7 +3,7 @@ use argh::FromArgs; use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; const FONT_SIZE: f32 = 7.0; @@ -49,6 +49,7 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/many_foxes.rs b/examples/stress_tests/many_foxes.rs index 367b437cfbbe7..bef3cab8a2f0f 100644 --- a/examples/stress_tests/many_foxes.rs +++ b/examples/stress_tests/many_foxes.rs @@ -9,7 +9,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, pbr::CascadeShadowConfigBuilder, prelude::*, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; #[derive(FromArgs, Resource)] @@ -41,6 +41,8 @@ fn main() { primary_window: Some(Window { title: "🦊🦊🦊 Many Foxes! 🦊🦊🦊".into(), present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0) + .with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/many_gizmos.rs b/examples/stress_tests/many_gizmos.rs index f0a72f451e2db..018423991595d 100644 --- a/examples/stress_tests/many_gizmos.rs +++ b/examples/stress_tests/many_gizmos.rs @@ -3,7 +3,7 @@ use std::f32::consts::TAU; use bevy::{ diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, prelude::*, - window::PresentMode, + window::{PresentMode, WindowResolution}, }; const SYSTEM_COUNT: u32 = 10; @@ -15,6 +15,7 @@ fn main() { primary_window: Some(Window { title: "Many Debug Lines".to_string(), present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/many_glyphs.rs b/examples/stress_tests/many_glyphs.rs index d4b18507cd1a9..f0427ee79133e 100644 --- a/examples/stress_tests/many_glyphs.rs +++ b/examples/stress_tests/many_glyphs.rs @@ -9,7 +9,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, text::{BreakLineOn, Text2dBounds}, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; fn main() { @@ -18,6 +18,7 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/many_lights.rs b/examples/stress_tests/many_lights.rs index b42d1b42cc9c5..a64680a25b3f6 100644 --- a/examples/stress_tests/many_lights.rs +++ b/examples/stress_tests/many_lights.rs @@ -9,7 +9,7 @@ use bevy::{ pbr::{ExtractedPointLight, GlobalLightMeta}, prelude::*, render::{camera::ScalingMode, Render, RenderApp, RenderSet}, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; use rand::{thread_rng, Rng}; @@ -18,7 +18,8 @@ fn main() { .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - resolution: (1024.0, 768.0).into(), + resolution: WindowResolution::new(1920.0, 1080.0) + .with_scale_factor_override(1.0), title: "many_lights".into(), present_mode: PresentMode::AutoNoVsync, ..default() diff --git a/examples/stress_tests/many_sprites.rs b/examples/stress_tests/many_sprites.rs index ab539af1b9c95..a357fbba057e2 100644 --- a/examples/stress_tests/many_sprites.rs +++ b/examples/stress_tests/many_sprites.rs @@ -10,7 +10,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; use rand::Rng; @@ -34,6 +34,8 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0) + .with_scale_factor_override(1.0), ..default() }), ..default() diff --git a/examples/stress_tests/text_pipeline.rs b/examples/stress_tests/text_pipeline.rs index da31326005486..c4781294a4dab 100644 --- a/examples/stress_tests/text_pipeline.rs +++ b/examples/stress_tests/text_pipeline.rs @@ -6,7 +6,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, text::{BreakLineOn, Text2dBounds}, - window::{PresentMode, WindowPlugin}, + window::{PresentMode, WindowPlugin, WindowResolution}, }; fn main() { @@ -15,6 +15,8 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { present_mode: PresentMode::AutoNoVsync, + resolution: WindowResolution::new(1920.0, 1080.0) + .with_scale_factor_override(1.0), ..default() }), ..default() From 2a036b658f31e830a903c8ab9d0f437b0bab069b Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 10 Nov 2023 16:38:46 -0500 Subject: [PATCH 06/79] feat: `Debug` implemented for `AssetMode` (#10494) # Objective - Implements Debug for AssetMode Closes #10473 Co-authored-by: Sebastian Hamel --- crates/bevy_asset/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 9f9cd44c77b0d..cc914e47c1fae 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -74,6 +74,7 @@ pub struct AssetPlugin { pub mode: AssetMode, } +#[derive(Debug)] pub enum AssetMode { /// Loads assets from their [`AssetSource`]'s default [`AssetReader`] without any "preprocessing". /// From c50561035833943876672a6f15e3cda2752ce11a Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:26:41 +0100 Subject: [PATCH 07/79] `#[derive(Reflect)]` on `GizmoConfig` (#10483) --- crates/bevy_gizmos/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 446605b43e4f8..333d8e2e9bbc7 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -37,7 +37,7 @@ use bevy_ecs::{ component::Component, entity::Entity, query::{ROQueryItem, Without}, - reflect::ReflectComponent, + reflect::{ReflectComponent, ReflectResource}, schedule::IntoSystemConfigs, system::{ lifetimeless::{Read, SRes}, @@ -77,7 +77,9 @@ impl Plugin for GizmoPlugin { fn build(&self, app: &mut bevy_app::App) { load_internal_asset!(app, LINE_SHADER_HANDLE, "lines.wgsl", Shader::from_wgsl); - app.add_plugins(UniformComponentPlugin::::default()) + app.register_type::() + .register_type::() + .add_plugins(UniformComponentPlugin::::default()) .init_asset::() .add_plugins(RenderAssetPlugin::::default()) .init_resource::() @@ -135,7 +137,8 @@ impl Plugin for GizmoPlugin { } /// A [`Resource`] that stores configuration for gizmos. -#[derive(Resource, Clone)] +#[derive(Resource, Clone, Reflect)] +#[reflect(Resource)] pub struct GizmoConfig { /// Set to `false` to stop drawing gizmos. /// @@ -188,7 +191,7 @@ impl Default for GizmoConfig { } /// Configuration for drawing the [`Aabb`] component on entities. -#[derive(Clone, Default)] +#[derive(Clone, Default, Reflect)] pub struct AabbGizmoConfig { /// Draws all bounding boxes in the scene when set to `true`. /// From 0eeb8f95fbb05ffbf705d8da4bd3f1b104065645 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Sat, 11 Nov 2023 15:01:08 -0800 Subject: [PATCH 08/79] Fix shader import hot reloading on windows (#10502) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Hot reloading shader imports on windows is currently broken due to inconsistent `/` and `\` usage ('/` is used in the user facing APIs and `\` is produced by notify-rs (and likely other OS apis). Fixes #10500 ## Solution Standardize import paths when loading a `Shader`. The correct long term fix is to standardize AssetPath on `/`-only, but this is the right scope of fix for a patch release. --------- Co-authored-by: François --- .../bevy_render/src/render_resource/shader.rs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 465fbb193d35a..7b10677784c8f 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -259,30 +259,24 @@ impl AssetLoader for ShaderLoader { ) -> BoxedFuture<'a, Result> { Box::pin(async move { let ext = load_context.path().extension().unwrap().to_str().unwrap(); - + let path = load_context.asset_path().to_string(); + // On windows, the path will inconsistently use \ or /. + // TODO: remove this once AssetPath forces cross-platform "slash" consistency. See #10511 + let path = path.replace(std::path::MAIN_SEPARATOR, "/"); let mut bytes = Vec::new(); reader.read_to_end(&mut bytes).await?; let mut shader = match ext { "spv" => Shader::from_spirv(bytes, load_context.path().to_string_lossy()), - "wgsl" => Shader::from_wgsl( - String::from_utf8(bytes)?, - load_context.path().to_string_lossy(), - ), - "vert" => Shader::from_glsl( - String::from_utf8(bytes)?, - naga::ShaderStage::Vertex, - load_context.path().to_string_lossy(), - ), - "frag" => Shader::from_glsl( - String::from_utf8(bytes)?, - naga::ShaderStage::Fragment, - load_context.path().to_string_lossy(), - ), - "comp" => Shader::from_glsl( - String::from_utf8(bytes)?, - naga::ShaderStage::Compute, - load_context.path().to_string_lossy(), - ), + "wgsl" => Shader::from_wgsl(String::from_utf8(bytes)?, path), + "vert" => { + Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Vertex, path) + } + "frag" => { + Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Fragment, path) + } + "comp" => { + Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Compute, path) + } _ => panic!("unhandled extension: {ext}"), }; From 51180f81a22683e4aa6f271e73900d85e79abfca Mon Sep 17 00:00:00 2001 From: Connor King Date: Sun, 12 Nov 2023 09:51:35 -0500 Subject: [PATCH 09/79] Remove rogue : from embedded_asset! docs (#10516) # Objective - Fix a random typo I noticed in the docs of `embedded_asset` ## Solution - fixed the typo --- crates/bevy_asset/src/io/embedded/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/io/embedded/mod.rs b/crates/bevy_asset/src/io/embedded/mod.rs index e5470cd3d5c3f..a0d95c9744f5a 100644 --- a/crates/bevy_asset/src/io/embedded/mod.rs +++ b/crates/bevy_asset/src/io/embedded/mod.rs @@ -156,7 +156,7 @@ macro_rules! embedded_path { /// ``` /// /// Some things to note in the path: -/// 1. The non-default `embedded:://` [`AssetSource`] +/// 1. The non-default `embedded://` [`AssetSource`] /// 2. `src` is trimmed from the path /// /// The default behavior also works for cargo workspaces. Pretend the `bevy_rock` crate now exists in a larger workspace in From 39c8998257b2767f23877508cd8a0dd752c92425 Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Sun, 12 Nov 2023 18:07:15 +0100 Subject: [PATCH 10/79] Register `WireframeColor` (#10486) This makes it usable via reflection by adding its data to the `TypeRegistry`. --- crates/bevy_pbr/src/wireframe.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index 2d533e7e52f5c..dc1075090c891 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -36,6 +36,7 @@ impl Plugin for WireframePlugin { app.register_type::() .register_type::() .register_type::() + .register_type::() .init_resource::() .add_plugins(MaterialPlugin::::default()) .add_systems(Startup, setup_global_wireframe_material) From bf4f4e42da3da07b0e84a4d6e40077f7398aea8b Mon Sep 17 00:00:00 2001 From: Connor King Date: Sun, 12 Nov 2023 12:11:26 -0500 Subject: [PATCH 11/79] use `tree` syntax to explain bevy_rock file structure (#10523) # Objective The current way it's written is just kinda hard to read ![image](https://github.com/bevyengine/bevy/assets/14184826/3102f50a-9220-4f86-99e0-41ea23822ea7) ## Solution the box-drawing characters stolen from `tree` ![image](https://github.com/bevyengine/bevy/assets/14184826/e66c027b-ed69-469d-a0ee-1d73e2c7be18) --- would've added this to my previous PR but i woke up this morning and it was merged --- crates/bevy_asset/src/io/embedded/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/bevy_asset/src/io/embedded/mod.rs b/crates/bevy_asset/src/io/embedded/mod.rs index a0d95c9744f5a..f6620b3e69cec 100644 --- a/crates/bevy_asset/src/io/embedded/mod.rs +++ b/crates/bevy_asset/src/io/embedded/mod.rs @@ -131,13 +131,15 @@ macro_rules! embedded_path { /// For example, consider the following file structure in the theoretical `bevy_rock` crate, which provides a Bevy [`Plugin`](bevy_app::Plugin) /// that renders fancy rocks for scenes. /// -/// * `bevy_rock` -/// * `src` -/// * `render` -/// * `rock.wgsl` -/// * `mod.rs` -/// * `lib.rs` -/// * `Cargo.toml` +/// ```text +/// bevy_rock +/// ├── src +/// │   ├── render +/// │  │ ├── rock.wgsl +/// │  │ └── mod.rs +/// │   └── lib.rs +/// └── Cargo.toml +/// ``` /// /// `rock.wgsl` is a WGSL shader asset that the `bevy_rock` plugin author wants to bundle with their crate. They invoke the following /// in `bevy_rock/src/render/mod.rs`: From 54b7cabc7b73737298bffbfd4639f36bceb54fbf Mon Sep 17 00:00:00 2001 From: mamekoro <86554319+mamekoro@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:36:46 +0000 Subject: [PATCH 12/79] Rename `Time::::overstep_percentage()` and `Time::::overstep_percentage_f64()` (#10448) # Objective This is similar to #10439. `Time::::overstep_percentage()` and `Time::::overstep_percentage_f64()` returns values from 0.0 to 1.0, but their names use the word "percentage". These function names make it easy to misunderstand that they return values from 0.0 to 100.0. To avoid confusion, these functions should be renamed to "`overstep_fraction(_f64)`". ## Solution Rename them. --- ## Changelog ### Changed - Renamed `Time::::overstep_percentage()` to `Time::::overstep_fraction()` - Renamed `Time::::overstep_percentage_f64()` to `Time::::overstep_fraction_f64()` ## Migration Guide - `Time::::overstep_percentage()` has been renamed to `Time::::overstep_fraction()` - `Time::::overstep_percentage_f64()` has been renamed to `Time::::overstep_fraction_f64()` --- crates/bevy_time/src/fixed.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/bevy_time/src/fixed.rs b/crates/bevy_time/src/fixed.rs index 60270172aaa22..ced8e821ce9fe 100644 --- a/crates/bevy_time/src/fixed.rs +++ b/crates/bevy_time/src/fixed.rs @@ -178,14 +178,14 @@ impl Time { /// Returns the amount of overstep time accumulated toward new steps, as an /// [`f32`] fraction of the timestep. #[inline] - pub fn overstep_percentage(&self) -> f32 { + pub fn overstep_fraction(&self) -> f32 { self.context().overstep.as_secs_f32() / self.context().timestep.as_secs_f32() } /// Returns the amount of overstep time accumulated toward new steps, as an /// [`f64`] fraction of the timestep. #[inline] - pub fn overstep_percentage_f64(&self) -> f64 { + pub fn overstep_fraction_f64(&self) -> f64 { self.context().overstep.as_secs_f64() / self.context().timestep.as_secs_f64() } @@ -265,56 +265,56 @@ mod test { assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); time.accumulate(Duration::from_secs(1)); assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(2)); - assert_eq!(time.overstep_percentage(), 1.0); - assert_eq!(time.overstep_percentage_f64(), 1.0); + assert_eq!(time.overstep_fraction(), 1.0); + assert_eq!(time.overstep_fraction_f64(), 1.0); assert!(time.expend()); // true assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::ZERO); - assert_eq!(time.overstep_percentage(), 0.0); - assert_eq!(time.overstep_percentage_f64(), 0.0); + assert_eq!(time.overstep_fraction(), 0.0); + assert_eq!(time.overstep_fraction_f64(), 0.0); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::ZERO); - assert_eq!(time.overstep_percentage(), 0.0); - assert_eq!(time.overstep_percentage_f64(), 0.0); + assert_eq!(time.overstep_fraction(), 0.0); + assert_eq!(time.overstep_fraction_f64(), 0.0); time.accumulate(Duration::from_secs(1)); assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); } #[test] From 18d001d27ce475388743d9825f2833ce51f5b20d Mon Sep 17 00:00:00 2001 From: mamekoro <86554319+mamekoro@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:59:42 +0000 Subject: [PATCH 13/79] Rename `Timer::{percent,percent_left}` to `Timer::{fraction,fraction_remaining}` (#10442) # Objective Fixes #10439 `Timer::percent()` and `Timer::percent_left()` return values in the range of 0.0 to 1.0, even though their names contain "percent". These functions should be renamed for clarity. ## Solution - Rename `Timer::percent()` to `Timer::fraction()` - Rename `Timer::percent_left()` to `Timer::fraction_remaining()` --- ## Changelog ### Changed - Renamed `Timer::percent()` to `Timer::fraction()` - Renamed `Timer::percent_left()` to `Timer::fraction_remaining()` ## Migration Guide - `Timer::percent()` has been renamed to `Timer::fraction()` - `Timer::percent_left()` has been renamed to `Timer::fraction_remaining()` --- crates/bevy_time/src/timer.rs | 50 +++++++++++++++++------------------ examples/time/timers.rs | 2 +- examples/ui/ui_scaling.rs | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/bevy_time/src/timer.rs b/crates/bevy_time/src/timer.rs index e7152978ee561..8383843571919 100644 --- a/crates/bevy_time/src/timer.rs +++ b/crates/bevy_time/src/timer.rs @@ -334,7 +334,7 @@ impl Timer { self.times_finished_this_tick = 0; } - /// Returns the percentage of the timer elapsed time (goes from 0.0 to 1.0). + /// Returns the fraction of the timer elapsed time (goes from 0.0 to 1.0). /// /// # Examples /// ``` @@ -342,10 +342,10 @@ impl Timer { /// use std::time::Duration; /// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); /// timer.tick(Duration::from_secs_f32(0.5)); - /// assert_eq!(timer.percent(), 0.25); + /// assert_eq!(timer.fraction(), 0.25); /// ``` #[inline] - pub fn percent(&self) -> f32 { + pub fn fraction(&self) -> f32 { if self.duration == Duration::ZERO { 1.0 } else { @@ -353,7 +353,7 @@ impl Timer { } } - /// Returns the percentage of the timer remaining time (goes from 1.0 to 0.0). + /// Returns the fraction of the timer remaining time (goes from 1.0 to 0.0). /// /// # Examples /// ``` @@ -361,11 +361,11 @@ impl Timer { /// use std::time::Duration; /// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); /// timer.tick(Duration::from_secs_f32(0.5)); - /// assert_eq!(timer.percent_left(), 0.75); + /// assert_eq!(timer.fraction_remaining(), 0.75); /// ``` #[inline] - pub fn percent_left(&self) -> f32 { - 1.0 - self.percent() + pub fn fraction_remaining(&self) -> f32 { + 1.0 - self.fraction() } /// Returns the remaining time in seconds @@ -452,8 +452,8 @@ mod tests { assert!(!t.just_finished()); assert_eq!(t.times_finished_this_tick(), 0); assert_eq!(t.mode(), TimerMode::Once); - assert_eq!(t.percent(), 0.025); - assert_eq!(t.percent_left(), 0.975); + assert_eq!(t.fraction(), 0.025); + assert_eq!(t.fraction_remaining(), 0.975); // Ticking while paused changes nothing t.pause(); t.tick(Duration::from_secs_f32(500.0)); @@ -463,8 +463,8 @@ mod tests { assert!(!t.just_finished()); assert_eq!(t.times_finished_this_tick(), 0); assert_eq!(t.mode(), TimerMode::Once); - assert_eq!(t.percent(), 0.025); - assert_eq!(t.percent_left(), 0.975); + assert_eq!(t.fraction(), 0.025); + assert_eq!(t.fraction_remaining(), 0.975); // Tick past the end and make sure elapsed doesn't go past 0.0 and other things update t.unpause(); t.tick(Duration::from_secs_f32(500.0)); @@ -472,16 +472,16 @@ mod tests { assert!(t.finished()); assert!(t.just_finished()); assert_eq!(t.times_finished_this_tick(), 1); - assert_eq!(t.percent(), 1.0); - assert_eq!(t.percent_left(), 0.0); + assert_eq!(t.fraction(), 1.0); + assert_eq!(t.fraction_remaining(), 0.0); // Continuing to tick when finished should only change just_finished t.tick(Duration::from_secs_f32(1.0)); assert_eq!(t.elapsed_secs(), 10.0); assert!(t.finished()); assert!(!t.just_finished()); assert_eq!(t.times_finished_this_tick(), 0); - assert_eq!(t.percent(), 1.0); - assert_eq!(t.percent_left(), 0.0); + assert_eq!(t.fraction(), 1.0); + assert_eq!(t.fraction_remaining(), 0.0); } #[test] @@ -495,24 +495,24 @@ mod tests { assert!(!t.just_finished()); assert_eq!(t.times_finished_this_tick(), 0); assert_eq!(t.mode(), TimerMode::Repeating); - assert_eq!(t.percent(), 0.375); - assert_eq!(t.percent_left(), 0.625); + assert_eq!(t.fraction(), 0.375); + assert_eq!(t.fraction_remaining(), 0.625); // Tick past the end and make sure elapsed wraps t.tick(Duration::from_secs_f32(1.5)); assert_eq!(t.elapsed_secs(), 0.25); assert!(t.finished()); assert!(t.just_finished()); assert_eq!(t.times_finished_this_tick(), 1); - assert_eq!(t.percent(), 0.125); - assert_eq!(t.percent_left(), 0.875); + assert_eq!(t.fraction(), 0.125); + assert_eq!(t.fraction_remaining(), 0.875); // Continuing to tick should turn off both finished & just_finished for repeating timers t.tick(Duration::from_secs_f32(1.0)); assert_eq!(t.elapsed_secs(), 1.25); assert!(!t.finished()); assert!(!t.just_finished()); assert_eq!(t.times_finished_this_tick(), 0); - assert_eq!(t.percent(), 0.625); - assert_eq!(t.percent_left(), 0.375); + assert_eq!(t.fraction(), 0.625); + assert_eq!(t.fraction_remaining(), 0.375); } #[test] @@ -543,19 +543,19 @@ mod tests { let mut t = Timer::from_seconds(0.0, TimerMode::Repeating); assert_eq!(t.times_finished_this_tick(), 0); assert_eq!(t.elapsed(), Duration::ZERO); - assert_eq!(t.percent(), 1.0); + assert_eq!(t.fraction(), 1.0); t.tick(Duration::from_secs(1)); assert_eq!(t.times_finished_this_tick(), u32::MAX); assert_eq!(t.elapsed(), Duration::ZERO); - assert_eq!(t.percent(), 1.0); + assert_eq!(t.fraction(), 1.0); t.tick(Duration::from_secs(2)); assert_eq!(t.times_finished_this_tick(), u32::MAX); assert_eq!(t.elapsed(), Duration::ZERO); - assert_eq!(t.percent(), 1.0); + assert_eq!(t.fraction(), 1.0); t.reset(); assert_eq!(t.times_finished_this_tick(), 0); assert_eq!(t.elapsed(), Duration::ZERO); - assert_eq!(t.percent(), 1.0); + assert_eq!(t.fraction(), 1.0); } #[test] diff --git a/examples/time/timers.rs b/examples/time/timers.rs index 7f20f080ff771..67abe1081efb3 100644 --- a/examples/time/timers.rs +++ b/examples/time/timers.rs @@ -66,7 +66,7 @@ fn countdown(time: Res