mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Remove with bundle filter (#2623)
# Objective Fixes #2620 ## Solution Remove WithBundle filter and temporarily remove example for query_bundle.
This commit is contained in:
parent
336583a86b
commit
49038d03f5
6 changed files with 1 additions and 159 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct WithBundle<T: Bundle>(PhantomData<T>);
|
||||
|
||||
impl<T: Bundle> WorldQuery for WithBundle<T> {
|
||||
type Fetch = WithBundleFetch<T>;
|
||||
type State = WithBundleState<T>;
|
||||
}
|
||||
|
||||
pub struct WithBundleFetch<T: Bundle> {
|
||||
is_dense: bool,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
pub struct WithBundleState<T: Bundle> {
|
||||
component_ids: Vec<ComponentId>,
|
||||
is_dense: bool,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
// SAFETY: no component access or archetype component access
|
||||
unsafe impl<T: Bundle> FetchState for WithBundleState<T> {
|
||||
fn init(world: &mut World) -> Self {
|
||||
let bundle_info = world.bundles.init_info::<T>(&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<ComponentId>) {
|
||||
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<ArchetypeComponentId>,
|
||||
) {
|
||||
}
|
||||
|
||||
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<T> {
|
||||
type Item = bool;
|
||||
type State = WithBundleState<T>;
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<PersonBundle>>) {
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue