-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add simple Disabled marker #17514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple Disabled marker #17514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ use crate::{ | |
RequiredComponentsError, Tick, | ||
}, | ||
entity::{AllocAtWithoutReplacement, Entities, Entity, EntityLocation}, | ||
entity_disabling::{DefaultQueryFilters, Disabled}, | ||
event::{Event, EventId, Events, SendBatchIds}, | ||
observer::Observers, | ||
query::{DebugCheckedUnwrap, QueryData, QueryFilter, QueryState}, | ||
|
@@ -159,6 +160,11 @@ impl World { | |
|
||
let on_despawn = OnDespawn::register_component_id(self); | ||
assert_eq!(ON_DESPAWN, on_despawn); | ||
|
||
let disabled = self.register_component::<Disabled>(); | ||
let mut filters = DefaultQueryFilters::default(); | ||
filters.set_disabled(disabled); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried that users might do a and lose the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.insert_resource(filters); | ||
} | ||
/// Creates a new empty [`World`]. | ||
/// | ||
|
@@ -3268,6 +3274,7 @@ impl World { | |
/// # struct B(u32); | ||
/// # | ||
/// # let mut world = World::new(); | ||
/// # world.remove_resource::<bevy_ecs::entity_disabling::DefaultQueryFilters>(); | ||
/// # world.insert_resource(A(1)); | ||
/// # world.insert_resource(B(2)); | ||
/// let mut total = 0; | ||
|
@@ -3766,6 +3773,7 @@ mod tests { | |
change_detection::DetectChangesMut, | ||
component::{ComponentDescriptor, ComponentInfo, StorageType}, | ||
entity::hash_set::EntityHashSet, | ||
entity_disabling::{DefaultQueryFilters, Disabled}, | ||
ptr::OwningPtr, | ||
resource::Resource, | ||
world::error::EntityFetchError, | ||
|
@@ -3955,6 +3963,8 @@ mod tests { | |
#[test] | ||
fn iter_resources() { | ||
let mut world = World::new(); | ||
// Remove DefaultQueryFilters so it doesn't show up in the iterator | ||
world.remove_resource::<DefaultQueryFilters>(); | ||
world.insert_resource(TestResource(42)); | ||
world.insert_resource(TestResource2("Hello, world!".to_string())); | ||
world.insert_resource(TestResource3); | ||
|
@@ -3981,6 +3991,8 @@ mod tests { | |
#[test] | ||
fn iter_resources_mut() { | ||
let mut world = World::new(); | ||
// Remove DefaultQueryFilters so it doesn't show up in the iterator | ||
world.remove_resource::<DefaultQueryFilters>(); | ||
world.insert_resource(TestResource(42)); | ||
world.insert_resource(TestResource2("Hello, world!".to_string())); | ||
world.insert_resource(TestResource3); | ||
|
@@ -4447,4 +4459,16 @@ mod tests { | |
None | ||
); | ||
} | ||
|
||
#[test] | ||
fn new_world_has_disabling() { | ||
let mut world = World::new(); | ||
world.spawn(Foo); | ||
world.spawn((Foo, Disabled)); | ||
assert_eq!(1, world.query::<&Foo>().iter(&world).count()); | ||
|
||
// If we explicitly remove the resource, no entities should be filtered anymore | ||
world.remove_resource::<DefaultQueryFilters>(); | ||
assert_eq!(2, world.query::<&Foo>().iter(&world).count()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
use core::any::TypeId; | ||
|
||
use crate::{DynamicEntity, DynamicScene, SceneFilter}; | ||
use alloc::collections::BTreeMap; | ||
use bevy_ecs::{ | ||
component::{Component, ComponentId}, | ||
entity_disabling::DefaultQueryFilters, | ||
prelude::Entity, | ||
reflect::{AppTypeRegistry, ReflectComponent, ReflectResource}, | ||
resource::Resource, | ||
|
@@ -348,9 +351,17 @@ impl<'w> DynamicSceneBuilder<'w> { | |
/// [`deny_resource`]: Self::deny_resource | ||
#[must_use] | ||
pub fn extract_resources(mut self) -> Self { | ||
let original_world_dqf_id = self | ||
.original_world | ||
.components() | ||
.get_resource_id(TypeId::of::<DefaultQueryFilters>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be nice when resources-as-components lets us use default query filters to exclude the default query filters resource from our resource query :). |
||
|
||
let type_registry = self.original_world.resource::<AppTypeRegistry>().read(); | ||
|
||
for (component_id, _) in self.original_world.storages().resources.iter() { | ||
if Some(component_id) == original_world_dqf_id { | ||
continue; | ||
} | ||
let mut extract_and_push = || { | ||
let type_id = self | ||
.original_world | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the module docs to mention that the
Disabled
component is disabled in the defaultDefaultQueryFilters
? Right now they talk about it as a hypothetical.