From c563dd094f604ee68e11c777b857707b8d20b0a5 Mon Sep 17 00:00:00 2001 From: bilsen <40690317+bilsen@users.noreply.github.com> Date: Tue, 31 Aug 2021 20:09:38 +0000 Subject: [PATCH 01/25] Fix comment typos (#2737) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix some typos in system_param.rs Co-authored-by: Ïvar Källström --- crates/bevy_ecs/src/system/system_param.rs | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 2b496e9e63355..2e350c05f3eb1 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -259,7 +259,7 @@ impl<'w, T: Component> AsRef for Res<'w, T> { } } -/// The [`SystemParamState`] of [`Res`]. +/// The [`SystemParamState`] of [`Res`]. pub struct ResState { component_id: ComponentId, marker: PhantomData, @@ -328,7 +328,8 @@ impl<'w, 's, T: Component> SystemParamFetch<'w, 's> for ResState { } } -/// The [`SystemParamState`] of `Option>`. +/// The [`SystemParamState`] of [`Option>`]. +/// See: [`Res`] pub struct OptionResState(ResState); impl<'a, T: Component> SystemParam for Option> { @@ -369,7 +370,7 @@ impl<'w, 's, T: Component> SystemParamFetch<'w, 's> for OptionResState { } } -/// The [`SystemParamState`] of [`ResMut`]. +/// The [`SystemParamState`] of [`ResMut`]. pub struct ResMutState { component_id: ComponentId, marker: PhantomData, @@ -444,7 +445,8 @@ impl<'w, 's, T: Component> SystemParamFetch<'w, 's> for ResMutState { } } -/// The [`SystemParamState`] of `Option>`. +/// The [`SystemParamState`] of [`Option>`]. +/// See: [`ResMut`] pub struct OptionResMutState(ResMutState); impl<'a, T: Component> SystemParam for Option> { @@ -576,7 +578,7 @@ impl<'a, T: Component> DerefMut for Local<'a, T> { } } -/// The [`SystemParamState`] of [`Local`]. +/// The [`SystemParamState`] of [`Local`]. pub struct LocalState(T); impl<'a, T: Component + FromWorld> SystemParam for Local<'a, T> { @@ -644,7 +646,7 @@ impl<'a, T> RemovedComponents<'a, T> { // SAFE: Only reads World components unsafe impl ReadOnlySystemParamFetch for RemovedComponentsState {} -/// The [`SystemParamState`] of [`RemovedComponents`]. +/// The [`SystemParamState`] of [`RemovedComponents`]. pub struct RemovedComponentsState { component_id: ComponentId, marker: PhantomData, @@ -741,7 +743,7 @@ impl<'w, T: 'static> Deref for NonSend<'w, T> { } } -/// The [`SystemParamState`] of [`NonSend`]. +/// The [`SystemParamState`] of [`NonSend`]. pub struct NonSendState { component_id: ComponentId, marker: PhantomData T>, @@ -814,7 +816,8 @@ impl<'w, 's, T: 'static> SystemParamFetch<'w, 's> for NonSendState { } } -/// The [`SystemParamState`] of `Option>`. +/// The [`SystemParamState`] of [`Option>`]. +/// See: [`NonSend`] pub struct OptionNonSendState(NonSendState); impl<'w, T: Component> SystemParam for Option> { @@ -856,7 +859,7 @@ impl<'w, 's, T: 'static> SystemParamFetch<'w, 's> for OptionNonSendState { } } -/// The [`SystemParamState`] of [`NonSendMut`]. +/// The [`SystemParamState`] of [`NonSendMut`]. pub struct NonSendMutState { component_id: ComponentId, marker: PhantomData T>, @@ -934,7 +937,8 @@ impl<'w, 's, T: 'static> SystemParamFetch<'w, 's> for NonSendMutState { } } -/// The [`SystemParamState`] of `Option>`. +/// The [`SystemParamState`] of [`Option>`]. +/// See: [`NonSendMut`] pub struct OptionNonSendMutState(NonSendMutState); impl<'a, T: 'static> SystemParam for Option> { @@ -1128,7 +1132,7 @@ impl SystemParam for SystemChangeTick { type Fetch = SystemChangeTickState; } -/// The [`SystemParamState`] of [`SystemChangeTickState`]. +/// The [`SystemParamState`] of [`SystemChangeTick`]. pub struct SystemChangeTickState {} unsafe impl SystemParamState for SystemChangeTickState { From 35979922df9de488e67dfdf5d8a7c857527cb2a7 Mon Sep 17 00:00:00 2001 From: bilsen <40690317+bilsen@users.noreply.github.com> Date: Tue, 31 Aug 2021 20:52:21 +0000 Subject: [PATCH 02/25] Fix Option> and Option> (#2757) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Fix `Option>` to work when T isn't `Send` Fix `Option>` to work when T isnt in the world. ## Solution Simple two row fix, properly initialize T in `OptionNonSendState` and remove `T: Component` bound for `Option>` also added a rudimentary test Co-authored-by: Ïvar Källström --- crates/bevy_ecs/src/system/mod.rs | 46 +++++++++++++++++++++- crates/bevy_ecs/src/system/system_param.rs | 4 +- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 8f0172af97a59..d4fd0ad79909c 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -27,8 +27,8 @@ mod tests { query::{Added, Changed, Or, QueryState, With, Without}, schedule::{Schedule, Stage, SystemStage}, system::{ - ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet, - RemovedComponents, Res, ResMut, System, SystemState, + ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend, NonSendMut, Query, + QuerySet, RemovedComponents, Res, ResMut, System, SystemState, }, world::{FromWorld, World}, }; @@ -331,6 +331,48 @@ mod tests { assert!(*world.get_resource::().unwrap()); } + #[test] + fn non_send_option_system() { + let mut world = World::default(); + + world.insert_resource(false); + struct NotSend1(std::rc::Rc); + struct NotSend2(std::rc::Rc); + world.insert_non_send(NotSend1(std::rc::Rc::new(0))); + + fn sys( + op: Option>, + mut _op2: Option>, + mut run: ResMut, + ) { + op.expect("NonSend should exist"); + *run = true; + } + + run_system(&mut world, sys); + // ensure the system actually ran + assert!(*world.get_resource::().unwrap()); + } + + #[test] + fn non_send_system() { + let mut world = World::default(); + + world.insert_resource(false); + struct NotSend1(std::rc::Rc); + struct NotSend2(std::rc::Rc); + + world.insert_non_send(NotSend1(std::rc::Rc::new(1))); + world.insert_non_send(NotSend2(std::rc::Rc::new(2))); + + fn sys(_op: NonSend, mut _op2: NonSendMut, mut run: ResMut) { + *run = true; + } + + run_system(&mut world, sys); + assert!(*world.get_resource::().unwrap()); + } + #[test] fn remove_tracking() { let mut world = World::new(); diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 2e350c05f3eb1..6f3e731ad3f22 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -820,7 +820,7 @@ impl<'w, 's, T: 'static> SystemParamFetch<'w, 's> for NonSendState { /// See: [`NonSend`] pub struct OptionNonSendState(NonSendState); -impl<'w, T: Component> SystemParam for Option> { +impl<'w, T: 'static> SystemParam for Option> { type Fetch = OptionNonSendState; } @@ -877,7 +877,7 @@ unsafe impl SystemParamState for NonSendMutState { fn init(world: &mut World, system_meta: &mut SystemMeta, _config: Self::Config) -> Self { system_meta.set_non_send(); - let component_id = world.components.get_or_insert_non_send_resource_id::(); + let component_id = world.initialize_non_send_resource::(); let combined_access = system_meta.component_access_set.combined_access_mut(); if combined_access.has_write(component_id) { panic!( From af20cad83058842687c79dd3f9aaf5b45dbce9c7 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 1 Sep 2021 20:59:25 +0000 Subject: [PATCH 03/25] Add error messages for the spooky insertions (#2581) # Objective Sometimes, the unwraps in `entity_mut` could fail here, if the entity was despawned *before* this command was applied. The simplest case involves two command buffers: ```rust use bevy::prelude::*; fn b(mut commands1: Commands, mut commands2: Commands) { let id = commands2.spawn().insert_bundle(()).id(); commands1.entity(id).despawn(); } fn main() { App::build().add_system(b.system()).run(); } ``` However, a more complicated version arises in the case of ambiguity: ```rust use std::time::Duration; use bevy::{app::ScheduleRunnerPlugin, prelude::*}; use rand::Rng; fn cleanup(mut e: ResMut>) { *e = None; } fn sleep_randomly() { let mut rng = rand::thread_rng(); std::thread::sleep(Duration::from_millis(rng.gen_range(0..50))); } fn spawn(mut commands: Commands, mut e: ResMut>) { *e = Some(commands.spawn().insert_bundle(()).id()); } fn despawn(mut commands: Commands, e: Res>) { let mut rng = rand::thread_rng(); std::thread::sleep(Duration::from_millis(rng.gen_range(0..50))); if let Some(e) = *e { commands.entity(e).despawn(); } } fn main() { App::build() .add_system(cleanup.system().label("cleanup")) .add_system(sleep_randomly.system().label("before_despawn")) .add_system(despawn.system().after("cleanup").after("before_despawn")) .add_system(sleep_randomly.system().label("before_spawn")) .add_system(spawn.system().after("cleanup").after("before_spawn")) .insert_resource(None::) .add_plugin(ScheduleRunnerPlugin::default()) .run(); } ``` In the cases where this example crashes, it's because `despawn` was ordered before `spawn` in the topological ordering of systems (which determines when buffers are applied). However, `despawn` actually ran *after* `spawn`, because these systems are ambiguous, so the jiggles in the sleeping time triggered a case where this works. ## Solution - Give a better error message --- crates/bevy_ecs/src/entity/mod.rs | 49 ++++++++++------------ crates/bevy_ecs/src/system/commands/mod.rs | 28 +++++++++++-- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 350d83d86c699..4f4681757d3cb 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -173,6 +173,7 @@ pub struct Entities { /// Once `flush()` is done, `free_cursor` will equal `pending.len()`. pending: Vec, free_cursor: AtomicI64, + /// Stores the number of free entities for [`len`](Entities::len) len: u32, } @@ -369,12 +370,12 @@ impl Entities { } } + /// Returns true if the [`Entities`] contains [`entity`](Entity). + // This will return false for entities which have been freed, even if + // not reallocated since the generation is incremented in `free` pub fn contains(&self, entity: Entity) -> bool { - // Note that out-of-range IDs are considered to be "contained" because - // they must be reserved IDs that we haven't flushed yet. - self.meta - .get(entity.id as usize) - .map_or(true, |meta| meta.generation == entity.generation) + self.resolve_from_id(entity.id()) + .map_or(false, |e| e.generation() == entity.generation) } pub fn clear(&mut self) { @@ -399,31 +400,23 @@ impl Entities { } } - /// Panics if the given id would represent an index outside of `meta`. + /// Get the [`Entity`] with a given id, if it exists in this [`Entities`] collection + /// Returns `None` if this [`Entity`] is outside of the range of currently reserved Entities /// - /// # Safety - /// - /// Must only be called for currently allocated `id`s. - pub unsafe fn resolve_unknown_gen(&self, id: u32) -> Entity { - let meta_len = self.meta.len(); - - if meta_len > id as usize { - let meta = &self.meta[id as usize]; - Entity { - generation: meta.generation, - id, - } + /// Note: This method may return [`Entities`](Entity) which are currently free + /// Note that [`contains`](Entities::contains) will correctly return false for freed + /// entities, since it checks the generation + pub fn resolve_from_id(&self, id: u32) -> Option { + let idu = id as usize; + if let Some(&EntityMeta { generation, .. }) = self.meta.get(idu) { + Some(Entity { generation, id }) } else { - // See if it's pending, but not yet flushed. + // `id` is outside of the meta list - check whether it is reserved but not yet flushed. let free_cursor = self.free_cursor.load(Ordering::Relaxed); - let num_pending = std::cmp::max(-free_cursor, 0) as usize; - - if meta_len + num_pending > id as usize { - // Pending entities will have generation 0. - Entity { generation: 0, id } - } else { - panic!("entity id is out of range"); - } + // If this entity was manually created, then free_cursor might be positive + // Returning None handles that case correctly + let num_pending = usize::try_from(-free_cursor).ok()?; + (idu < self.meta.len() + num_pending).then(|| Entity { generation: 0, id }) } } @@ -508,7 +501,7 @@ impl EntityMeta { generation: 0, location: EntityLocation { archetype_id: ArchetypeId::INVALID, - index: usize::max_value(), // dummy value, to be filled in + index: usize::MAX, // dummy value, to be filled in }, }; } diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 5e2873a29a39a..fc875f383c6bb 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -6,7 +6,7 @@ use crate::{ entity::{Entities, Entity}, world::World, }; -use bevy_utils::tracing::{debug, error}; +use bevy_utils::tracing::{error, warn}; pub use command_queue::CommandQueue; use std::marker::PhantomData; @@ -144,7 +144,13 @@ impl<'w, 's> Commands<'w, 's> { /// } /// # example_system.system(); /// ``` + #[track_caller] pub fn entity<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> { + assert!( + self.entities.contains(entity), + "Attempting to create an EntityCommands for entity {:?}, which doesn't exist.", + entity + ); EntityCommands { entity, commands: self, @@ -371,7 +377,9 @@ pub struct Despawn { impl Command for Despawn { fn write(self, world: &mut World) { if !world.despawn(self.entity) { - debug!("Failed to despawn non-existent entity {:?}", self.entity); + warn!("Could not despawn entity {:?} because it doesn't exist in this World.\n\ + If this command was added to a newly spawned entity, ensure that you have not despawned that entity within the same stage.\n\ + This may have occurred due to system order ambiguity, or if the spawning system has multiple command buffers", self.entity); } } } @@ -386,7 +394,13 @@ where T: Bundle + 'static, { fn write(self, world: &mut World) { - world.entity_mut(self.entity).insert_bundle(self.bundle); + if let Some(mut entity) = world.get_entity_mut(self.entity) { + entity.insert_bundle(self.bundle); + } else { + panic!("Could not insert a bundle (of type `{}`) for entity {:?} because it doesn't exist in this World.\n\ + If this command was added to a newly spawned entity, ensure that you have not despawned that entity within the same stage.\n\ + This may have occurred due to system order ambiguity, or if the spawning system has multiple command buffers", std::any::type_name::(), self.entity); + } } } @@ -401,7 +415,13 @@ where T: Component, { fn write(self, world: &mut World) { - world.entity_mut(self.entity).insert(self.component); + if let Some(mut entity) = world.get_entity_mut(self.entity) { + entity.insert(self.component); + } else { + panic!("Could not add a component (of type `{}`) to entity {:?} because it doesn't exist in this World.\n\ + If this command was added to a newly spawned entity, ensure that you have not despawned that entity within the same stage.\n\ + This may have occurred due to system order ambiguity, or if the spawning system has multiple command buffers", std::any::type_name::(), self.entity); + } } } From 321d998615606c1fe5528eb57ead32026bff0530 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 1 Sep 2021 21:21:41 +0000 Subject: [PATCH 04/25] Add convenience methods for checking a set of inputs (#2760) # Objective Make it easier to check if some set of inputs matches a key, such as if you want to allow all of space or up or w for jumping. Currently, this requires: ```rust if keyboard.pressed(KeyCode::Space) || keyboard.pressed(KeyCode::Up) || keyboard.pressed(KeyCode::W) { // ... ``` ## Solution Add an implementation of the helper methods, which very simply iterate through the items, used as: ```rust if keyboard.any_pressed([KeyCode::Space, KeyCode::Up, KeyCode::W]) { ``` --- crates/bevy_input/src/input.rs | 15 +++++++++++++++ examples/input/keyboard_modifiers.rs | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/bevy_input/src/input.rs b/crates/bevy_input/src/input.rs index c1bea3f77b88a..09aeea7b88d97 100644 --- a/crates/bevy_input/src/input.rs +++ b/crates/bevy_input/src/input.rs @@ -63,6 +63,11 @@ where self.pressed.contains(&input) } + /// Check if any item in `inputs` has been pressed. + pub fn any_pressed(&self, inputs: impl IntoIterator) -> bool { + inputs.into_iter().any(|it| self.pressed(it)) + } + /// Register a release for input `input`. pub fn release(&mut self, input: T) { self.pressed.remove(&input); @@ -74,6 +79,11 @@ where self.just_pressed.contains(&input) } + /// Check if any item in `inputs` has just been pressed. + pub fn any_just_pressed(&self, inputs: impl IntoIterator) -> bool { + inputs.into_iter().any(|it| self.just_pressed(it)) + } + /// Clear the "just pressed" state of `input`. Future calls to [`Input::just_pressed`] for the /// given input will return false until a new press event occurs. /// Returns true if `input` is currently "just pressed" @@ -86,6 +96,11 @@ where self.just_released.contains(&input) } + /// Check if any item in `inputs` has just been released. + pub fn any_just_released(&self, inputs: impl IntoIterator) -> bool { + inputs.into_iter().any(|it| self.just_released(it)) + } + /// Clear the "just released" state of `input`. Future calls to [`Input::just_released`] for the /// given input will return false until a new release event occurs. /// Returns true if `input` is currently "just released" diff --git a/examples/input/keyboard_modifiers.rs b/examples/input/keyboard_modifiers.rs index a22275bb0a2ee..5b6ebfa3afce2 100644 --- a/examples/input/keyboard_modifiers.rs +++ b/examples/input/keyboard_modifiers.rs @@ -12,8 +12,8 @@ fn main() { /// This system prints when Ctrl + Shift + A is pressed fn keyboard_input_system(input: Res>) { - let shift = input.pressed(KeyCode::LShift) || input.pressed(KeyCode::RShift); - let ctrl = input.pressed(KeyCode::LControl) || input.pressed(KeyCode::RControl); + let shift = input.any_pressed([KeyCode::LShift, KeyCode::RShift]); + let ctrl = input.any_pressed([KeyCode::LControl, KeyCode::RControl]); if ctrl && shift && input.just_pressed(KeyCode::A) { info!("Just pressed Ctrl + Shift + A!"); From ca54478569ad45aea5464055499f7e0e3a46cc25 Mon Sep 17 00:00:00 2001 From: Caleb Boylan Date: Sat, 4 Sep 2021 18:52:10 +0000 Subject: [PATCH 05/25] Fix breakout example scoreboard (#2770) # Objective - The breakout scoreboard was not using the correct text section to display the score integer. ## Solution - This updates the code to use the correct text section. --- examples/game/breakout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 26ef9bdcbe0c7..700c6b386925a 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -211,7 +211,7 @@ fn ball_movement_system(mut ball_query: Query<(&Ball, &mut Transform)>) { fn scoreboard_system(scoreboard: Res, mut query: Query<&mut Text>) { let mut text = query.single_mut().unwrap(); - text.sections[0].value = format!("Score: {}", scoreboard.score); + text.sections[1].value = format!("{}", scoreboard.score); } fn ball_collision_system( From 391d6c6cb2adb85a960567f4579ddca4512b772f Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Sat, 4 Sep 2021 19:05:23 +0000 Subject: [PATCH 06/25] Label PRs for all target branches (#2701) # Objective - All new PRs should get the "S-Needs-Triage" label. But at the moment we for example are getting quite a few PRs to the new renderer branch that do not get the label. ## Solution - Remove the required target "main" from the workflow - Also removed configuration for not needed functionality of the labeler action (see [docs](https://github.com/actions/labeler#inputs)) --- .github/workflows/label.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 9168873cc73f6..24f2c637e16c3 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -1,8 +1,6 @@ name: PR-Labeler -on: +on: pull_request_target: - branches: - - main types: - opened @@ -15,4 +13,3 @@ jobs: with: repo-token: "${{ secrets.GITHUB_TOKEN }}" configuration-path: .github/label-config.yml - sync-labels: true From edd822a2bb8d95472b945908f632d595994fae9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Sep 2021 18:49:40 +0000 Subject: [PATCH 07/25] Update glam requirement from 0.17.3 to 0.18.0 (#2748) Updates the requirements on [glam](https://github.com/bitshifter/glam-rs) to permit the latest version.
Changelog

Sourced from glam's changelog.

[0.18.0] - 2021-08-26

Breaking changes

  • Minimum Supported Version of Rust bumped to 1.51.0 for wasm-bindgen-test and rustdoc alias support.

Added

  • Added wasm32 SIMD intrinsics support.
  • Added optional support for the rkyv serialization crate.
  • Added Rem and RemAssign implementations for all vector types.
  • Added quaternion xyz() method for returning the vector part of the quaternion.
  • Added From((Scalar, Vector3)) for 4D vector types.

Changed

  • Deprecated as_f32(), as_f64(), as_i32() and as_u32() methods in favor of more specific methods such as as_vec2(), as_dvec2(), as_ivec2() and as_uvec2() and so on.

[0.17.3] - 2021-07-18

Fixed

  • Fix alignment unit tests on non x86 platforms.

[0.17.2] - 2021-07-15

Fixed

  • Fix alignment unit tests on i686 and S390x.

[0.17.1] - 2021-06-29

Added

  • Added serde support for Affine2, DAffine2, Affine3A and DAffine3.

[0.17.0] - 2021-06-26

Breaking changes

  • The addition of Add and Sub implementations of scalar values for vector types may create ambiguities with existing calls to add and sub.
  • Removed From<Mat3> implementation for Mat2 and From<DMat3> for DMat2. These have been replaced by Mat2::from_mat3() and DMat2::from_mat3().
  • Removed From<Mat4> implementation for Mat3 and From<DMat4> for DMat3. These have been replaced by Mat3::from_mat4() and DMat3::from_mat4().

... (truncated)

Commits
  • 1b70351 Merge pull request #231 from bitshifter/prepare-0.18.0
  • 935ad5c Prepare 0.18.0 release.
  • 8d79d8e Still managed to mess up the tarpaulin config...
  • 78c30fc Fix syntax error in tarpaulin config.
  • 0258ce7 Can use rustdoc alias after msrv bump to 1.51.0.
  • f9f7f24 Tidy up tarpaulin exlcudes.
  • 95dab21 Make some dev deps wasm only on not wasm.
  • 342176d Merge pull request #230 from DJMcNab/bytemuck-spirv
  • 837e5eb Bytemuck now compiles on spirv
  • bb35b1a Merge pull request #228 from bitshifter/wasm32-simd
  • Additional commits viewable in compare view

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- crates/bevy_math/Cargo.toml | 2 +- crates/bevy_reflect/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index b5636faa43438..5d6de28efb67f 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -9,5 +9,5 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [dependencies] -glam = { version = "0.17.3", features = ["serde", "bytemuck"] } +glam = { version = "0.18.0", features = ["serde", "bytemuck"] } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] } diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index e13d286cf9d53..263b0ade6b37f 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -24,7 +24,7 @@ parking_lot = "0.11.0" thiserror = "1.0" serde = "1" smallvec = { version = "1.6", features = ["serde", "union", "const_generics"], optional = true } -glam = { version = "0.17.3", features = ["serde"], optional = true } +glam = { version = "0.18.0", features = ["serde"], optional = true } [dev-dependencies] ron = "0.6.2" From 18c08dd86022397a371326ed84499ed44998aefa Mon Sep 17 00:00:00 2001 From: Patrick Greene Date: Mon, 6 Sep 2021 19:16:08 +0000 Subject: [PATCH 08/25] add get_history function to Diagnostic (#2772) # Objective - Allow access to diagnostic history value. - Fixes #2771. ## Solution - Add Diagnostic::get_history function. --- crates/bevy_diagnostic/src/diagnostic.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/bevy_diagnostic/src/diagnostic.rs b/crates/bevy_diagnostic/src/diagnostic.rs index 4256d72e98bef..7d8cfaebcacd7 100644 --- a/crates/bevy_diagnostic/src/diagnostic.rs +++ b/crates/bevy_diagnostic/src/diagnostic.rs @@ -119,6 +119,14 @@ impl Diagnostic { pub fn get_max_history_length(&self) -> usize { self.max_history_length } + + pub fn values(&self) -> impl Iterator { + self.history.iter().map(|x| &x.value) + } + + pub fn measurements(&self) -> impl Iterator { + self.history.iter() + } } /// A collection of [Diagnostic]s From e3170586776b165f40e446780fc4f9a4ed04187d Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Mon, 6 Sep 2021 19:16:09 +0000 Subject: [PATCH 09/25] Docs/more nixos instructions (#2775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Expand the documentation for NixOS setups (as discussed in Discord) ## Solution Added more info to `linux_dependencies.md` about NixOS. This is based off my own experience (as documented in [this blog post](https://blog.thomasheartman.com/posts/bevy-getting-started-on-nixos)), so I can't confirm that it'll work for everyone. However, if there are further tweaks necessary, then I think that this should nevertheless work as a good starting point and should give future users an idea of what they may need to change or update. Feedback and tweaks are very welcome 😄 --- docs/linux_dependencies.md | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/linux_dependencies.md b/docs/linux_dependencies.md index 2c46fad42e4c2..9c1b955d212ab 100644 --- a/docs/linux_dependencies.md +++ b/docs/linux_dependencies.md @@ -98,6 +98,49 @@ And enter it by just running `nix-shell`. You should be able compile bevy programms using `cargo` within this nix-shell. +### Fast compilation + +According to the Bevy getting started guide (for v0.5), you can enable fast compilation by add a Cargo config file and by adding `lld` and `clang`. As long as you add `clang` and `lld` to your environment, it should mostly work, but you'll still need to modify the Cargo config file so that it doesn't point to `/usr/bin/clang` anymore. + +Working off the above files, let's make the necessary changes. + +For `.cargo/config.toml`, change the path to the linker from `/usr/bin/clang` to `clang`: + +``` diff + [target.x86_64-unknown-linux-gnu] +- linker = "/usr/bin/clang" ++ linker = "clang" + rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"] +``` + +In `shell.nix`, add `lld` and `clang`: + +``` diff + buildInputs = [ + cargo + pkgconfig udev alsaLib lutris + x11 xorg.libXcursor xorg.libXrandr xorg.libXi + vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers ++ clang lld + ]; +``` + +### Building apps and using the GPU + +If you run into issues with building basic apps or activating the GPU ('thread 'main' panicked at 'Unable to find a GPU!'), then you may need to update your environment's `LD_LIBRARY_PATH`. To solve issues relating to missing `libudev.so.1` files, `alsa` drivers, and being unable to find a GPU, try updating the environment variable in your `shell.nix` by creating a `shellHook`: + +``` diff + { pkgs ? import { } }: + with pkgs; + mkShell { ++ shellHook = ''export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [ ++ pkgs.alsaLib ++ pkgs.udev ++ pkgs.vulkan-loader ++ ]}"''; + buildInputs = [ +``` + ## Opensuse Tumbleweed ```bash From 2f6c464f4be2f3abf6244800a08b614fa3b35c7f Mon Sep 17 00:00:00 2001 From: Matthias Seiffert Date: Thu, 9 Sep 2021 00:46:39 +0000 Subject: [PATCH 10/25] Add builder methods to Transform (#2778) # Objective Make it easier to construct transforms. E.g. ```rs Transform::from_xyz(0.0, 0.0, 10.0).with_scale(Vec3::splat(2.0)) ``` I found myself writing an extension method to do this so I don't have to write: ```rs Transform { translation: Vec3::new(0.0, 0.0, 10.0), scale: Vec3::splat(2.0), ..Default::default() } ``` ## Solution Add *builder style* methods to `Transform`. Methods: - `with_translation` - `with_rotation` - `with_scale` I also added these methods to `GlobalTransform`. But they are probably less useful there. --- .../src/components/global_transform.rs | 21 +++++++++++++++++++ .../src/components/transform.rs | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index ceca829bc74f6..8d29c7cd35b27 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -105,6 +105,27 @@ impl GlobalTransform { self } + #[doc(hidden)] + #[inline] + pub fn with_translation(mut self, translation: Vec3) -> Self { + self.translation = translation; + self + } + + #[doc(hidden)] + #[inline] + pub fn with_rotation(mut self, rotation: Quat) -> Self { + self.rotation = rotation; + self + } + + #[doc(hidden)] + #[inline] + pub fn with_scale(mut self, scale: Vec3) -> Self { + self.scale = scale; + self + } + /// Returns the 3d affine transformation matrix from this transforms translation, /// rotation, and scale. #[inline] diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index f4a538d30ecb8..9799f45df2699 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -117,6 +117,27 @@ impl Transform { self } + /// Returns this [`Transform`] with a new translation. + #[inline] + pub fn with_translation(mut self, translation: Vec3) -> Self { + self.translation = translation; + self + } + + /// Returns this [`Transform`] with a new rotation. + #[inline] + pub fn with_rotation(mut self, rotation: Quat) -> Self { + self.rotation = rotation; + self + } + + /// Returns this [`Transform`] with a new scale. + #[inline] + pub fn with_scale(mut self, scale: Vec3) -> Self { + self.scale = scale; + self + } + /// Returns the 3d affine transformation matrix from this transforms translation, /// rotation, and scale. #[inline] From cbe9e56d851c5dbcc735aa974925503f1a949e36 Mon Sep 17 00:00:00 2001 From: willolisp Date: Thu, 9 Sep 2021 12:26:43 +0000 Subject: [PATCH 11/25] Fixes to `World`'s documentation (#2790) # Objective Fixes #2787. ## Solution Fixed doc syntax for `World`'s `get` and `get_mut` methods. --- crates/bevy_ecs/src/world/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 121951dddaa02..f4a542b7f13a6 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -383,6 +383,7 @@ impl World { /// .id(); /// let position = world.get::(entity).unwrap(); /// assert_eq!(position.x, 0.0); + /// ``` #[inline] pub fn get(&self, entity: Entity) -> Option<&T> { self.get_entity(entity)?.get() @@ -404,6 +405,7 @@ impl World { /// .id(); /// let mut position = world.get_mut::(entity).unwrap(); /// position.x = 1.0; + /// ``` #[inline] pub fn get_mut(&mut self, entity: Entity) -> Option> { self.get_entity_mut(entity)?.get_mut() From 4c3c4b5e401717abbf57c56ef00a2e68ef7bce0d Mon Sep 17 00:00:00 2001 From: sark Date: Thu, 9 Sep 2021 16:41:21 +0000 Subject: [PATCH 12/25] Nightly clippy fixes (#2702) A few minor changes to fix warnings emitted from clippy on the nightly toolchain, including redundant_allocation, unwrap_or_else_default, and collapsible_match, fixes #2698 --- crates/bevy_asset/src/asset_server.rs | 11 ++++------- crates/bevy_core/src/lib.rs | 2 +- crates/bevy_reflect/bevy_reflect_derive/src/lib.rs | 4 +--- crates/bevy_wgpu/src/lib.rs | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index f46b96ed7bf8f..9847e242541d9 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -53,7 +53,7 @@ pub struct AssetServerInternal { pub(crate) asset_ref_counter: AssetRefCounter, pub(crate) asset_sources: Arc>>, pub(crate) asset_lifecycles: Arc>>>, - loaders: RwLock>>>, + loaders: RwLock>>, extension_to_loader_index: RwLock>, handle_to_path: Arc>>>, task_pool: TaskPool, @@ -112,7 +112,7 @@ impl AssetServer { .write() .insert(extension.to_string(), loader_index); } - loaders.push(Arc::new(Box::new(loader))); + loaders.push(Arc::new(loader)); } pub fn watch_for_changes(&self) -> Result<(), AssetServerError> { @@ -130,10 +130,7 @@ impl AssetServer { HandleUntyped::strong(id.into(), sender) } - fn get_asset_loader( - &self, - extension: &str, - ) -> Result>, AssetServerError> { + fn get_asset_loader(&self, extension: &str) -> Result, AssetServerError> { let index = { // scope map to drop lock as soon as possible let map = self.server.extension_to_loader_index.read(); @@ -149,7 +146,7 @@ impl AssetServer { fn get_path_asset_loader>( &self, path: P, - ) -> Result>, AssetServerError> { + ) -> Result, AssetServerError> { let s = path .as_ref() .file_name() diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 5af6bc88f297e..2e8066d62f66a 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -43,7 +43,7 @@ impl Plugin for CorePlugin { app.world .get_resource::() .cloned() - .unwrap_or_else(DefaultTaskPoolOptions::default) + .unwrap_or_default() .create_default_pools(&mut app.world); app.init_resource::