From cc0f6a8db43581755bd84302072c7b97ea51bc0f Mon Sep 17 00:00:00 2001 From: Christian Hughes <9044780+ItsDoot@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:43:05 -0600 Subject: [PATCH] Remove deprecated ECS items (#16853) # Objective - Cleanup deprecated code ## Solution - Removed `#[deprecated]` items which were marked as such in 0.15 or prior versions. ## Migration Guide - The following deprecated items were removed: `Events::get_reader`, `Events::get_reader_current`, `ManualEventReader`, `Condition::and_then`, `Condition::or_else`, `World::,many_entities`, `World::many_entities_mut`, `World::get_many_entities`, `World::get_many_entities_dynamic`, `World::get_many_entities_mut`, `World::get_many_entities_dynamic_mut`, `World::get_many_entities_from_set_mut` --- crates/bevy_ecs/src/event/collections.rs | 22 -- crates/bevy_ecs/src/event/event_cursor.rs | 11 - crates/bevy_ecs/src/lib.rs | 2 +- crates/bevy_ecs/src/schedule/condition.rs | 115 +------- crates/bevy_ecs/src/schedule/executor/mod.rs | 5 +- crates/bevy_ecs/src/world/mod.rs | 269 +------------------ 6 files changed, 22 insertions(+), 402 deletions(-) diff --git a/crates/bevy_ecs/src/event/collections.rs b/crates/bevy_ecs/src/event/collections.rs index 1354509107777..caa7c8e5b4c24 100644 --- a/crates/bevy_ecs/src/event/collections.rs +++ b/crates/bevy_ecs/src/event/collections.rs @@ -192,28 +192,6 @@ impl Events { } } - #[deprecated( - since = "0.14.0", - note = "`get_reader` has been deprecated. Please use `get_cursor` instead." - )] - /// Gets a new [`EventCursor`]. This will include all events already in the event buffers. - pub fn get_reader(&self) -> EventCursor { - EventCursor::default() - } - - #[deprecated( - since = "0.14.0", - note = "`get_reader_current` has been replaced. Please use `get_cursor_current` instead." - )] - /// Gets a new [`EventCursor`]. This will ignore all events already in the event buffers. - /// It will read all future events. - pub fn get_reader_current(&self) -> EventCursor { - EventCursor { - last_event_count: self.event_count, - ..Default::default() - } - } - /// Swaps the event buffers and clears the oldest event buffer. In general, this should be /// called once per frame/update. /// diff --git a/crates/bevy_ecs/src/event/event_cursor.rs b/crates/bevy_ecs/src/event/event_cursor.rs index 8fdcea8d244c5..ca1be152e5caa 100644 --- a/crates/bevy_ecs/src/event/event_cursor.rs +++ b/crates/bevy_ecs/src/event/event_cursor.rs @@ -6,17 +6,6 @@ use bevy_ecs::event::{ use bevy_ecs::event::{EventMutParIter, EventParIter}; use core::marker::PhantomData; -// Deprecated in favor of `EventCursor`, there is no nice way to deprecate this -// because generic constraints are not allowed in type aliases, so this will always -// 'dead code'. Hence the `#[allow(dead_code)]`. -#[deprecated( - since = "0.14.0", - note = "`ManualEventReader` has been replaced. Please use `EventCursor` instead." -)] -#[doc(alias = "EventCursor")] -#[allow(dead_code)] -pub type ManualEventReader = EventCursor; - /// Stores the state for an [`EventReader`] or [`EventMutator`]. /// /// Access to the [`Events`] resource is required to read any incoming events. diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index aa28a10df7bda..ccc2aa702f43e 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -50,7 +50,7 @@ pub use bevy_ptr as ptr; /// /// This includes the most common types in this crate, re-exported for your convenience. pub mod prelude { - #[allow(deprecated)] + #[expect(deprecated)] #[doc(hidden)] pub use crate::{ bundle::Bundle, diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 6956d2715069f..9b9d642a2ee7e 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -123,57 +123,6 @@ pub trait Condition: sealed::Condition CombinatorSystem::new(a, b, Cow::Owned(name)) } - /// Returns a new run condition that only returns `true` - /// if both this one and the passed `and_then` return `true`. - /// - /// The returned run condition is short-circuiting, meaning - /// `and_then` will only be invoked if `self` returns `true`. - /// - /// # Examples - /// - /// ``` - /// use bevy_ecs::prelude::*; - /// - /// #[derive(Resource, PartialEq)] - /// struct R(u32); - /// - /// # let mut app = Schedule::default(); - /// # let mut world = World::new(); - /// # fn my_system() {} - /// app.add_systems( - /// // The `resource_equals` run condition will fail since we don't initialize `R`, - /// // just like if we used `Res` in a system. - /// my_system.run_if(resource_equals(R(0))), - /// ); - /// # app.run(&mut world); - /// ``` - /// - /// Use `.and_then()` to avoid checking the condition. - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # #[derive(Resource, PartialEq)] - /// # struct R(u32); - /// # let mut app = Schedule::default(); - /// # let mut world = World::new(); - /// # fn my_system() {} - /// app.add_systems( - /// // `resource_equals` will only get run if the resource `R` exists. - /// my_system.run_if(resource_exists::.and_then(resource_equals(R(0)))), - /// ); - /// # app.run(&mut world); - /// ``` - /// - /// Note that in this case, it's better to just use the run condition [`resource_exists_and_equals`]. - /// - /// [`resource_exists_and_equals`]: common_conditions::resource_exists_and_equals - #[deprecated( - note = "Users should use the `.and(condition)` method in lieu of `.and_then(condition)`" - )] - fn and_then>(self, and_then: C) -> And { - self.and(and_then) - } - /// Returns a new run condition that only returns `false` /// if both this one and the passed `nand` return `true`. /// @@ -325,53 +274,6 @@ pub trait Condition: sealed::Condition CombinatorSystem::new(a, b, Cow::Owned(name)) } - /// Returns a new run condition that returns `true` - /// if either this one or the passed `or` return `true`. - /// - /// The returned run condition is short-circuiting, meaning - /// `or` will only be invoked if `self` returns `false`. - /// - /// # Examples - /// - /// ``` - /// use bevy_ecs::prelude::*; - /// - /// #[derive(Resource, PartialEq)] - /// struct A(u32); - /// - /// #[derive(Resource, PartialEq)] - /// struct B(u32); - /// - /// # let mut app = Schedule::default(); - /// # let mut world = World::new(); - /// # #[derive(Resource)] struct C(bool); - /// # fn my_system(mut c: ResMut) { c.0 = true; } - /// app.add_systems( - /// // Only run the system if either `A` or `B` exist. - /// my_system.run_if(resource_exists::.or(resource_exists::)), - /// ); - /// # - /// # world.insert_resource(C(false)); - /// # app.run(&mut world); - /// # assert!(!world.resource::().0); - /// # - /// # world.insert_resource(A(0)); - /// # app.run(&mut world); - /// # assert!(world.resource::().0); - /// # - /// # world.remove_resource::(); - /// # world.insert_resource(B(0)); - /// # world.insert_resource(C(false)); - /// # app.run(&mut world); - /// # assert!(world.resource::().0); - /// ``` - #[deprecated( - note = "Users should use the `.or(condition)` method in lieu of `.or_else(condition)`" - )] - fn or_else>(self, or_else: C) -> Or { - self.or(or_else) - } - /// Returns a new run condition that only returns `true` /// if `self` and `xnor` **both** return `false` or **both** return `true`. /// @@ -1406,7 +1308,6 @@ mod tests { } #[test] - #[allow(deprecated)] fn run_condition_combinators() { let mut world = World::new(); world.init_resource::(); @@ -1415,23 +1316,21 @@ mod tests { schedule.add_systems( ( increment_counter.run_if(every_other_time.and(|| true)), // Run every odd cycle. - increment_counter.run_if(every_other_time.and_then(|| true)), // Run every odd cycle. - increment_counter.run_if(every_other_time.nand(|| false)), // Always run. - double_counter.run_if(every_other_time.nor(|| false)), // Run every even cycle. - increment_counter.run_if(every_other_time.or(|| true)), // Always run. - increment_counter.run_if(every_other_time.or_else(|| true)), // Always run. + increment_counter.run_if(every_other_time.nand(|| false)), // Always run. + double_counter.run_if(every_other_time.nor(|| false)), // Run every even cycle. + increment_counter.run_if(every_other_time.or(|| true)), // Always run. increment_counter.run_if(every_other_time.xnor(|| true)), // Run every odd cycle. - double_counter.run_if(every_other_time.xnor(|| false)), // Run every even cycle. + double_counter.run_if(every_other_time.xnor(|| false)), // Run every even cycle. increment_counter.run_if(every_other_time.xor(|| false)), // Run every odd cycle. - double_counter.run_if(every_other_time.xor(|| true)), // Run every even cycle. + double_counter.run_if(every_other_time.xor(|| true)), // Run every even cycle. ) .chain(), ); schedule.run(&mut world); - assert_eq!(world.resource::().0, 7); + assert_eq!(world.resource::().0, 5); schedule.run(&mut world); - assert_eq!(world.resource::().0, 72); + assert_eq!(world.resource::().0, 52); } #[test] diff --git a/crates/bevy_ecs/src/schedule/executor/mod.rs b/crates/bevy_ecs/src/schedule/executor/mod.rs index d0231bb2f0c5b..a9267bb77f76a 100644 --- a/crates/bevy_ecs/src/schedule/executor/mod.rs +++ b/crates/bevy_ecs/src/schedule/executor/mod.rs @@ -108,7 +108,10 @@ impl SystemSchedule { } /// See [`ApplyDeferred`]. -#[deprecated = "Use `ApplyDeferred` instead. This was previously a function but is now a marker struct System."] +#[deprecated( + since = "0.16.0", + note = "Use `ApplyDeferred` instead. This was previously a function but is now a marker struct System." +)] #[expect(non_upper_case_globals)] pub const apply_deferred: ApplyDeferred = ApplyDeferred; diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 63d6ea725accf..3efb57f0e0856 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -38,10 +38,10 @@ use crate::{ ComponentInfo, ComponentTicks, Components, Mutable, RequiredComponents, RequiredComponentsError, Tick, }, - entity::{AllocAtWithoutReplacement, Entities, Entity, EntityHashSet, EntityLocation}, + entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation}, event::{Event, EventId, Events, SendBatchIds}, observer::Observers, - query::{DebugCheckedUnwrap, QueryData, QueryEntityError, QueryFilter, QueryState}, + query::{DebugCheckedUnwrap, QueryData, QueryFilter, QueryState}, removal_detection::RemovedComponentEvents, schedule::{Schedule, ScheduleLabel, Schedules}, storage::{ResourceData, Storages}, @@ -697,6 +697,8 @@ impl World { /// assert_eq!(eref.get::().unwrap().y, 1.0); /// } /// ``` + /// + /// [`EntityHashSet`]: crate::entity::EntityHashSet #[inline] #[track_caller] pub fn entity(&self, entities: F) -> F::Ref<'_> { @@ -833,6 +835,8 @@ impl World { /// assert_eq!(pos.y, 2.0); /// } /// ``` + /// + /// [`EntityHashSet`]: crate::entity::EntityHashSet #[inline] #[track_caller] pub fn entity_mut(&mut self, entities: F) -> F::Mut<'_> { @@ -849,76 +853,6 @@ impl World { } } - /// Gets an [`EntityRef`] for multiple entities at once. - /// - /// # Panics - /// - /// If any entity does not exist in the world. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Getting multiple entities. - /// let [entity1, entity2] = world.many_entities([id1, id2]); - /// ``` - /// - /// ```should_panic - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Trying to get a despawned entity will fail. - /// world.despawn(id2); - /// world.many_entities([id1, id2]); - /// ``` - #[deprecated(since = "0.15.0", note = "Use `World::entity::<[Entity; N]>` instead")] - pub fn many_entities(&mut self, entities: [Entity; N]) -> [EntityRef<'_>; N] { - self.entity(entities) - } - - /// Gets mutable access to multiple entities at once. - /// - /// # Panics - /// - /// If any entities do not exist in the world, - /// or if the same entity is specified multiple times. - /// - /// # Examples - /// - /// Disjoint mutable access. - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Disjoint mutable access. - /// let [entity1, entity2] = world.many_entities_mut([id1, id2]); - /// ``` - /// - /// Trying to access the same entity multiple times will fail. - /// - /// ```should_panic - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id = world.spawn_empty().id(); - /// world.many_entities_mut([id, id]); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::entity_mut::<[Entity; N]>` instead" - )] - pub fn many_entities_mut( - &mut self, - entities: [Entity; N], - ) -> [EntityMut<'_>; N] { - self.entity_mut(entities) - } - /// Returns the components of an [`Entity`] through [`ComponentInfo`]. #[inline] pub fn inspect_entity(&self, entity: Entity) -> impl Iterator { @@ -1005,6 +939,8 @@ impl World { /// # Examples /// /// For examples, see [`World::entity`]. + /// + /// [`EntityHashSet`]: crate::entity::EntityHashSet #[inline] pub fn get_entity(&self, entities: F) -> Result, Entity> { let cell = self.as_unsafe_world_cell_readonly(); @@ -1012,70 +948,6 @@ impl World { unsafe { entities.fetch_ref(cell) } } - /// Gets an [`EntityRef`] for multiple entities at once. - /// - /// # Errors - /// - /// If any entity does not exist in the world. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Getting multiple entities. - /// let [entity1, entity2] = world.get_many_entities([id1, id2]).unwrap(); - /// - /// // Trying to get a despawned entity will fail. - /// world.despawn(id2); - /// assert!(world.get_many_entities([id1, id2]).is_err()); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::get_entity::<[Entity; N]>` instead" - )] - pub fn get_many_entities( - &self, - entities: [Entity; N], - ) -> Result<[EntityRef<'_>; N], Entity> { - self.get_entity(entities) - } - - /// Gets an [`EntityRef`] for multiple entities at once, whose number is determined at runtime. - /// - /// # Errors - /// - /// If any entity does not exist in the world. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Getting multiple entities. - /// let entities = world.get_many_entities_dynamic(&[id1, id2]).unwrap(); - /// let entity1 = entities.get(0).unwrap(); - /// let entity2 = entities.get(1).unwrap(); - /// - /// // Trying to get a despawned entity will fail. - /// world.despawn(id2); - /// assert!(world.get_many_entities_dynamic(&[id1, id2]).is_err()); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::get_entity::<&[Entity]>` instead" - )] - pub fn get_many_entities_dynamic<'w>( - &'w self, - entities: &[Entity], - ) -> Result>, Entity> { - self.get_entity(entities) - } - /// Returns [`EntityMut`]s that expose read and write operations for the /// given `entities`, returning [`Err`] if any of the given entities do not /// exist. Instead of immediately unwrapping the value returned from this @@ -1105,6 +977,8 @@ impl World { /// # Examples /// /// For examples, see [`World::entity_mut`]. + /// + /// [`EntityHashSet`]: crate::entity::EntityHashSet #[inline] pub fn get_entity_mut( &mut self, @@ -1173,129 +1047,6 @@ impl World { }) } - /// Gets mutable access to multiple entities. - /// - /// # Errors - /// - /// If any entities do not exist in the world, - /// or if the same entity is specified multiple times. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Disjoint mutable access. - /// let [entity1, entity2] = world.get_many_entities_mut([id1, id2]).unwrap(); - /// - /// // Trying to access the same entity multiple times will fail. - /// assert!(world.get_many_entities_mut([id1, id1]).is_err()); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::get_entity_mut::<[Entity; N]>` instead" - )] - pub fn get_many_entities_mut( - &mut self, - entities: [Entity; N], - ) -> Result<[EntityMut<'_>; N], QueryEntityError<'_>> { - self.get_entity_mut(entities).map_err(|e| match e { - EntityFetchError::NoSuchEntity(entity, world) => { - QueryEntityError::NoSuchEntity(entity, world) - } - EntityFetchError::AliasedMutability(entity) => { - QueryEntityError::AliasedMutability(entity) - } - }) - } - - /// Gets mutable access to multiple entities, whose number is determined at runtime. - /// - /// # Errors - /// - /// If any entities do not exist in the world, - /// or if the same entity is specified multiple times. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// // Disjoint mutable access. - /// let mut entities = world.get_many_entities_dynamic_mut(&[id1, id2]).unwrap(); - /// let entity1 = entities.get_mut(0).unwrap(); - /// - /// // Trying to access the same entity multiple times will fail. - /// assert!(world.get_many_entities_dynamic_mut(&[id1, id1]).is_err()); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::get_entity_mut::<&[Entity]>` instead" - )] - pub fn get_many_entities_dynamic_mut<'w>( - &'w mut self, - entities: &[Entity], - ) -> Result>, QueryEntityError<'w>> { - self.get_entity_mut(entities).map_err(|e| match e { - EntityFetchError::NoSuchEntity(entity, world) => { - QueryEntityError::NoSuchEntity(entity, world) - } - EntityFetchError::AliasedMutability(entity) => { - QueryEntityError::AliasedMutability(entity) - } - }) - } - - /// Gets mutable access to multiple entities, contained in a [`EntityHashSet`]. - /// The uniqueness of items in a [`EntityHashSet`] allows us to avoid checking for duplicates. - /// - /// # Errors - /// - /// If any entities do not exist in the world. - /// - /// # Examples - /// - /// ``` - /// # use bevy_ecs::prelude::*; - /// # use bevy_ecs::entity::EntityHash; - /// # use bevy_ecs::entity::EntityHashSet; - /// # use bevy_utils::HashSet; - /// # let mut world = World::new(); - /// # let id1 = world.spawn_empty().id(); - /// # let id2 = world.spawn_empty().id(); - /// let s = EntityHash::default(); - /// let mut set = EntityHashSet::with_hasher(s); - /// set.insert(id1); - /// set.insert(id2); - /// - /// // Disjoint mutable access. - /// let mut entities = world.get_many_entities_from_set_mut(&set).unwrap(); - /// let entity1 = entities.get_mut(0).unwrap(); - /// ``` - #[deprecated( - since = "0.15.0", - note = "Use `World::get_entity_mut::<&EntityHashSet>` instead." - )] - pub fn get_many_entities_from_set_mut<'w>( - &'w mut self, - entities: &EntityHashSet, - ) -> Result>, QueryEntityError<'w>> { - self.get_entity_mut(entities) - .map(|fetched| fetched.into_values().collect()) - .map_err(|e| match e { - EntityFetchError::NoSuchEntity(entity, world) => { - QueryEntityError::NoSuchEntity(entity, world) - } - EntityFetchError::AliasedMutability(entity) => { - QueryEntityError::AliasedMutability(entity) - } - }) - } - /// Spawns a new [`Entity`] and returns a corresponding [`EntityWorldMut`], which can be used /// to add components to the entity or retrieve its id. ///