diff --git a/Cargo.toml b/Cargo.toml index d71a7ae476..a59b69cc50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -318,10 +318,6 @@ path = "examples/ecs/system_sets.rs" name = "timers" path = "examples/ecs/timers.rs" -[[example]] -name = "query_bundle" -path = "examples/ecs/query_bundle.rs" - # Games [[example]] name = "alien_cake_addict" diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 2c38e249fb..b911b89eba 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -12,8 +12,6 @@ use std::{any::TypeId, collections::HashMap}; /// An ordered collection of components, commonly used for spawning entities, and adding and /// removing components in bulk. /// -/// In order to query for components in a bundle use [crate::query::WithBundle]. -/// /// 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 diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 988d020aaa..cd474009a0 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -22,7 +22,7 @@ pub mod prelude { change_detection::DetectChanges, entity::Entity, event::{EventReader, EventWriter}, - query::{Added, ChangeTrackers, Changed, Or, QueryState, With, WithBundle, Without}, + query::{Added, ChangeTrackers, Changed, Or, QueryState, With, Without}, schedule::{ AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, RunCriteriaPiping, diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index 9a46035c62..69dd298cd3 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -1,6 +1,5 @@ use crate::{ archetype::{Archetype, ArchetypeComponentId}, - bundle::Bundle, component::{Component, ComponentId, ComponentTicks, StorageType}, entity::Entity, query::{Access, Fetch, FetchState, FilteredAccess, WorldQuery}, @@ -282,106 +281,6 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutFetch { } } -pub struct WithBundle(PhantomData); - -impl WorldQuery for WithBundle { - type Fetch = WithBundleFetch; - type State = WithBundleState; -} - -pub struct WithBundleFetch { - is_dense: bool, - marker: PhantomData, -} - -pub struct WithBundleState { - component_ids: Vec, - is_dense: bool, - marker: PhantomData, -} - -// SAFETY: no component access or archetype component access -unsafe impl FetchState for WithBundleState { - fn init(world: &mut World) -> Self { - let bundle_info = world.bundles.init_info::(&mut world.components); - let components = &world.components; - Self { - component_ids: bundle_info.component_ids.clone(), - is_dense: !bundle_info.component_ids.iter().any(|id| unsafe { - components.get_info_unchecked(*id).storage_type() != StorageType::Table - }), - marker: PhantomData, - } - } - - #[inline] - fn update_component_access(&self, access: &mut FilteredAccess) { - for component_id in self.component_ids.iter().cloned() { - access.add_with(component_id); - } - } - - #[inline] - fn update_archetype_component_access( - &self, - _archetype: &Archetype, - _access: &mut Access, - ) { - } - - fn matches_archetype(&self, archetype: &Archetype) -> bool { - self.component_ids.iter().all(|id| archetype.contains(*id)) - } - - fn matches_table(&self, table: &Table) -> bool { - self.component_ids.iter().all(|id| table.has_column(*id)) - } -} - -impl<'w, 's, T: Bundle> Fetch<'w, 's> for WithBundleFetch { - type Item = bool; - type State = WithBundleState; - - unsafe fn init( - _world: &World, - state: &Self::State, - _last_change_tick: u32, - _change_tick: u32, - ) -> Self { - Self { - is_dense: state.is_dense, - marker: PhantomData, - } - } - - #[inline] - fn is_dense(&self) -> bool { - self.is_dense - } - - #[inline] - unsafe fn set_table(&mut self, _state: &Self::State, _table: &Table) {} - - #[inline] - unsafe fn set_archetype( - &mut self, - _state: &Self::State, - _archetype: &Archetype, - _tables: &Tables, - ) { - } - - #[inline] - unsafe fn archetype_fetch(&mut self, _archetype_index: usize) -> bool { - true - } - - #[inline] - unsafe fn table_fetch(&mut self, _table_row: usize) -> bool { - true - } -} - /// A filter that tests if any of the given filters apply. /// /// This is useful for example if a system with multiple components in a query only wants to run diff --git a/examples/README.md b/examples/README.md index 37b76a3a34..7796afdb16 100644 --- a/examples/README.md +++ b/examples/README.md @@ -162,7 +162,6 @@ Example | File | Description `hierarchy` | [`ecs/hierarchy.rs`](./ecs/hierarchy.rs) | Creates a hierarchy of parents and children entities `iter_combinations` | [`ecs/iter_combinations.rs`](./ecs/iter_combinations.rs) | Shows how to iterate over combinations of query results. `parallel_query` | [`ecs/parallel_query.rs`](./ecs/parallel_query.rs) | Illustrates parallel queries with `ParallelIterator` -`query_bundle` | [`ecs/query_bundle.rs`](./ecs/query_bundle.rs) | Shows how to query entities that contain components in a `Bundle` `removal_detection` | [`ecs/removal_detection.rs`](./ecs/removal_detection.rs) | Query for entities that had a specific component removed in a previous stage during the current frame. `startup_system` | [`ecs/startup_system.rs`](./ecs/startup_system.rs) | Demonstrates a startup system (one that runs once when the app starts up) `state` | [`ecs/state.rs`](./ecs/state.rs) | Illustrates how to use States to control transitioning from a Menu state to an InGame state diff --git a/examples/ecs/query_bundle.rs b/examples/ecs/query_bundle.rs deleted file mode 100644 index 8d9f158f8d..0000000000 --- a/examples/ecs/query_bundle.rs +++ /dev/null @@ -1,50 +0,0 @@ -use bevy::{log::LogPlugin, prelude::*}; - -fn main() { - App::new() - .add_plugin(LogPlugin) - .add_startup_system(setup) - .add_system(log_names.label(LogNamesSystem)) - .add_system(log_person_bundles.after(LogNamesSystem)) - .run(); -} - -#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)] -struct LogNamesSystem; - -#[derive(Debug)] -struct Name(String); - -#[derive(Debug)] -struct Age(usize); - -#[derive(Debug, Bundle)] -struct PersonBundle { - name: Name, - age: Age, -} - -/// Sets up two entities, one with a [Name] component as part of a bundle, -/// and one entity with [Name] only. -fn setup(mut commands: Commands) { - commands.spawn().insert(Name("Steve".to_string())); - commands.spawn().insert_bundle(PersonBundle { - name: Name("Bob".to_string()), - age: Age(40), - }); -} - -fn log_names(query: Query<&Name>) { - info!("Log all entities with `Name` component"); - // this will necessarily have to print both components. - for name in query.iter() { - info!("{:?}", name); - } -} -fn log_person_bundles(query: Query<&Name, WithBundle>) { - info!("Log `Name` components from entities that have all components in `PersonBundle`."); - // this should only print `Name("Bob")`. - for name in query.iter() { - info!("{:?}", name); - } -}