-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 2 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); | ||
|
Contributor
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
Contributor
Author
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`]. | ||
| /// | ||
|
|
@@ -3217,6 +3223,15 @@ impl World { | |
| } | ||
|
|
||
| impl World { | ||
| /// Returns true if the type id is used internally, components and resources used internally | ||
| /// most likely should not be affected by things like saving and loading | ||
| pub fn is_internal_type(type_id: TypeId) -> bool { | ||
| if type_id == TypeId::of::<DefaultQueryFilters>() { | ||
| return true; | ||
| } | ||
| false | ||
| } | ||
NiseVoid marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Gets a pointer to the resource with the id [`ComponentId`] if it exists. | ||
| /// The returned pointer must not be used to modify the resource, and must not be | ||
| /// dereferenced after the immutable borrow of the [`World`] ends. | ||
|
|
@@ -3268,6 +3283,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 +3782,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 +3972,7 @@ mod tests { | |
| #[test] | ||
| fn iter_resources() { | ||
| let mut world = World::new(); | ||
| world.remove_resource::<DefaultQueryFilters>(); | ||
| world.insert_resource(TestResource(42)); | ||
| world.insert_resource(TestResource2("Hello, world!".to_string())); | ||
| world.insert_resource(TestResource3); | ||
|
|
@@ -3981,6 +3999,7 @@ mod tests { | |
| #[test] | ||
| fn iter_resources_mut() { | ||
| let mut world = World::new(); | ||
| world.remove_resource::<DefaultQueryFilters>(); | ||
| world.insert_resource(TestResource(42)); | ||
| world.insert_resource(TestResource2("Hello, world!".to_string())); | ||
| world.insert_resource(TestResource3); | ||
|
|
@@ -4447,4 +4466,15 @@ 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()); | ||
|
|
||
| world.remove_resource::<DefaultQueryFilters>(); | ||
| assert_eq!(2, world.query::<&Foo>().iter(&world).count()); | ||
| } | ||
| } | ||
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
Disabledcomponent is disabled in the defaultDefaultQueryFilters? Right now they talk about it as a hypothetical.