-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Store Resources as components on singleton entities #20934
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
Open
Trashtalk217
wants to merge
114
commits into
bevyengine:main
Choose a base branch
from
Trashtalk217:resource-as-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,245
−1,010
Open
Changes from 98 commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
042337f
add back all changes
Trashtalk217 47c20a5
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 64eac9a
cargo fmt
Trashtalk217 956c1a6
cargo clippy
Trashtalk217 073df4b
add entities with resources, auto disabled IsResource
Trashtalk217 6c8281d
fixed and tests
Trashtalk217 f9dc9f1
fixed more tests
Trashtalk217 07723ac
fixed moore tests
Trashtalk217 1ba7af2
fix ci
Trashtalk217 b89c042
fix mooore tests (benches)
Trashtalk217 9b33933
fix docs
Trashtalk217 c7b4f1d
add migration guide
Trashtalk217 96aef45
fixed spelling errors to prove I'm not AI
Trashtalk217 e3ccd1b
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 5758134
addressed comments
Trashtalk217 9824c3a
testing robustness
Trashtalk217 9acf43f
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 da1d203
merge upstream
Trashtalk217 4d4e914
cleanup
Trashtalk217 78a0672
fix more stuff
Trashtalk217 4a2416d
update migration guides
Trashtalk217 3942c56
spelling
Trashtalk217 511e0b9
update resource macros to implement Component
Trashtalk217 d4c98eb
fix tests
Trashtalk217 724a4c4
merge
Trashtalk217 f442ff6
fix imports
Trashtalk217 acb539e
second attempt at fixing a test
Trashtalk217 a0d76c3
merge
Trashtalk217 c99df9c
Merge branch 'resource_entity_lookup' of github.com:trashtalk217/bevy…
Trashtalk217 12383a3
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 34570e8
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 f43905d
removed send resources from Storages
Trashtalk217 36e8191
fixed more tests
Trashtalk217 d1b9b56
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 bfb2829
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 011b068
cleanup
Trashtalk217 a12ec78
partly fixed bevy_scene
Trashtalk217 2261f8b
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 7f224be
address comments
Trashtalk217 4b0c77b
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 6fdf25e
fixed try_resource_scope in part
Trashtalk217 2b1a5b5
fixed require() statement for AmbientLight
Trashtalk217 e8c67cc
change location of resource_entities
Trashtalk217 a01dc7d
changed scene serialization
Trashtalk217 9aecdf3
removed ResourceEntity, redid bevy_scene, require ReflectComponent for
Trashtalk217 3ddf8bf
fixed final tests
Trashtalk217 f0e973a
cargo clippy fixes
Trashtalk217 02c2b5f
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 8c1c818
removed dead code
Trashtalk217 1383efd
typo
Trashtalk217 2f9990a
more clippy
Trashtalk217 678da53
fixed get_resources_mut and unsoundness Res and ResMut
Trashtalk217 67810f4
updated docs
Trashtalk217 af03cec
improve docs and name
Trashtalk217 25b49d0
cargo clippy
Trashtalk217 1117cfa
typos
Trashtalk217 e3b12c2
fixed bevy_render bug
Trashtalk217 33bd43d
fixed bevy_remove
Trashtalk217 18c7664
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 c75da2c
added ReflectComponent to debug_overlay
Trashtalk217 0e4d5c2
fixed docs
Trashtalk217 0eef31b
addressed comments
Trashtalk217 e68d5c2
fixed a bug with try_resource_scope
Trashtalk217 44c526b
typos
Trashtalk217 fb01522
clippy
Trashtalk217 d70a178
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 8afc908
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 44927a5
remove all unnecessary resourceComponent
Trashtalk217 e953fa1
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 4cbdaa5
remove entity_ref
Trashtalk217 2ec2182
further cleanup
Trashtalk217 ea36fec
more cleanup
Trashtalk217 1203662
more more cleanup
Trashtalk217 e751f15
removed a test and made IsResource automatically disabled (temporary)
Trashtalk217 2fa538e
rewrite resource component derive
Trashtalk217 740752d
change the hooks to be public under the Resource trait
Trashtalk217 737f04c
fixed compile problems, goto v2 implementation with hooks
Trashtalk217 8a1727b
deprecate dyanamic (send) resources
Trashtalk217 ff0e195
made ReflectResource deref to ReflectComponent
Trashtalk217 c9f7ec5
made resource entity stable, fixed bevy_scene
Trashtalk217 86962a8
fixed bevy_remote, added logging to hooks
Trashtalk217 3989f2e
remove pointless printing
Trashtalk217 d7d647e
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 6ceed0d
fixed ci
Trashtalk217 b2b2248
fix ci some more
Trashtalk217 5028619
updated example asset
Trashtalk217 039cd0b
fix ci some more
Trashtalk217 1014aad
fix ci some more
Trashtalk217 9fd6129
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 485c03a
revert to previous Res/ResMut implementation
Trashtalk217 8c67aa3
change doc comments
Trashtalk217 fe921d2
revert a weird bevy_render thing
Trashtalk217 75069d8
revert bevy_scene changes
Trashtalk217 da3f903
space
Trashtalk217 2453314
remove dead code
Trashtalk217 c9c0f95
cargo fmt
Trashtalk217 a4234fb
documentation
Trashtalk217 779b668
markdown fix
Trashtalk217 c919a69
fixed access bug
Trashtalk217 5438039
make is_resource not a dfq
Trashtalk217 4be1ccf
fix a broad query for animation conflicting with a resource
Trashtalk217 aa4d563
review comments
Trashtalk217 28ca0ac
fix
Trashtalk217 411a681
address review comments
Trashtalk217 a570cc3
forgot to make a change
Trashtalk217 e72f38e
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 a5e9612
spelling
Trashtalk217 73a9293
fixed tests
Trashtalk217 a3bef34
oops forgot to save
Trashtalk217 57ca7d6
rename non-send resources to non-send data
Trashtalk217 3e36aba
misc changes based on review
Trashtalk217 31530f6
docs
Trashtalk217 89c5622
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 f3153da
reflect dependency
Trashtalk217 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,21 +138,6 @@ impl<'w> ComponentsRegistrator<'w> { | |
| registrator.register(self); | ||
| } | ||
|
|
||
| // resources | ||
| while let Some(registrator) = { | ||
| let queued = self | ||
| .components | ||
| .queued | ||
| .get_mut() | ||
| .unwrap_or_else(PoisonError::into_inner); | ||
| queued.resources.keys().next().copied().map(|type_id| { | ||
| // SAFETY: the id just came from a valid iterator. | ||
| unsafe { queued.resources.remove(&type_id).debug_checked_unwrap() } | ||
| }) | ||
| } { | ||
| registrator.register(self); | ||
| } | ||
|
|
||
| // dynamic | ||
| let queued = &mut self | ||
| .components | ||
|
|
@@ -286,15 +271,9 @@ impl<'w> ComponentsRegistrator<'w> { | |
| /// # See also | ||
| /// | ||
| /// * [`Components::resource_id()`] | ||
| /// * [`ComponentsRegistrator::register_resource_with_descriptor()`] | ||
| #[inline] | ||
| pub fn register_resource<T: Resource>(&mut self) -> ComponentId { | ||
| // SAFETY: The [`ComponentDescriptor`] matches the [`TypeId`] | ||
| unsafe { | ||
| self.register_resource_with(TypeId::of::<T>(), || { | ||
| ComponentDescriptor::new_resource::<T>() | ||
| }) | ||
| } | ||
| self.register_component::<T>() | ||
| } | ||
|
|
||
| /// Registers a [non-send resource](crate::system::NonSend) of type `T` with this instance. | ||
|
|
@@ -304,24 +283,24 @@ impl<'w> ComponentsRegistrator<'w> { | |
| pub fn register_non_send<T: Any>(&mut self) -> ComponentId { | ||
| // SAFETY: The [`ComponentDescriptor`] matches the [`TypeId`] | ||
| unsafe { | ||
| self.register_resource_with(TypeId::of::<T>(), || { | ||
| self.register_non_send_with(TypeId::of::<T>(), || { | ||
| ComponentDescriptor::new_non_send::<T>(StorageType::default()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// Same as [`Components::register_resource_unchecked`] but handles safety. | ||
| /// Same as [`Components::register_non_send_unchecked`] but handles safety. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The [`ComponentDescriptor`] must match the [`TypeId`]. | ||
| #[inline] | ||
| unsafe fn register_resource_with( | ||
| unsafe fn register_non_send_with( | ||
| &mut self, | ||
| type_id: TypeId, | ||
| descriptor: impl FnOnce() -> ComponentDescriptor, | ||
| ) -> ComponentId { | ||
| if let Some(id) = self.resource_indices.get(&type_id) { | ||
| if let Some(id) = self.indices.get(&type_id) { | ||
| return *id; | ||
| } | ||
|
|
||
|
|
@@ -330,7 +309,7 @@ impl<'w> ComponentsRegistrator<'w> { | |
| .queued | ||
| .get_mut() | ||
| .unwrap_or_else(PoisonError::into_inner) | ||
| .resources | ||
| .components | ||
| .remove(&type_id) | ||
| { | ||
| // If we are trying to register something that has already been queued, we respect the queue. | ||
|
|
@@ -342,12 +321,12 @@ impl<'w> ComponentsRegistrator<'w> { | |
| // SAFETY: The resource is not currently registered, the id is fresh, and the [`ComponentDescriptor`] matches the [`TypeId`] | ||
| unsafe { | ||
| self.components | ||
| .register_resource_unchecked(type_id, id, descriptor()); | ||
| .register_non_send_unchecked(type_id, id, descriptor()); | ||
| } | ||
| id | ||
| } | ||
|
|
||
| /// Registers a [`Resource`] described by `descriptor`. | ||
| /// Registers a non-send resource described by `descriptor`. | ||
| /// | ||
| /// # Note | ||
| /// | ||
|
|
@@ -357,9 +336,9 @@ impl<'w> ComponentsRegistrator<'w> { | |
| /// # See also | ||
| /// | ||
| /// * [`Components::resource_id()`] | ||
| /// * [`ComponentsRegistrator::register_resource()`] | ||
| /// * [`ComponentsRegistrator::register_non_send()`] | ||
| #[inline] | ||
| pub fn register_resource_with_descriptor( | ||
| pub fn register_non_send_with_descriptor( | ||
|
Member
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. This is redundant with |
||
| &mut self, | ||
| descriptor: ComponentDescriptor, | ||
| ) -> ComponentId { | ||
|
|
@@ -419,7 +398,6 @@ impl QueuedRegistration { | |
| #[derive(Default)] | ||
| pub struct QueuedComponents { | ||
| pub(super) components: TypeIdMap<QueuedRegistration>, | ||
| pub(super) resources: TypeIdMap<QueuedRegistration>, | ||
| pub(super) dynamic_registrations: Vec<QueuedRegistration>, | ||
| } | ||
|
|
||
|
|
@@ -430,17 +408,15 @@ impl Debug for QueuedComponents { | |
| .iter() | ||
| .map(|(type_id, queued)| (type_id, queued.id)) | ||
| .collect::<Vec<_>>(); | ||
| let resources = self | ||
| .resources | ||
| .iter() | ||
| .map(|(type_id, queued)| (type_id, queued.id)) | ||
| .collect::<Vec<_>>(); | ||
| let dynamic_registrations = self | ||
| .dynamic_registrations | ||
| .iter() | ||
| .map(|queued| queued.id) | ||
| .collect::<Vec<_>>(); | ||
| write!(f, "components: {components:?}, resources: {resources:?}, dynamic_registrations: {dynamic_registrations:?}") | ||
| write!( | ||
| f, | ||
| "components: {components:?}, dynamic_registrations: {dynamic_registrations:?}" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -526,7 +502,7 @@ impl<'w> ComponentsQueuedRegistrator<'w> { | |
| .queued | ||
| .write() | ||
| .unwrap_or_else(PoisonError::into_inner) | ||
| .resources | ||
| .components | ||
| .entry(type_id) | ||
| .or_insert_with(|| { | ||
| // SAFETY: The id was just generated. | ||
|
|
@@ -633,7 +609,7 @@ impl<'w> ComponentsQueuedRegistrator<'w> { | |
| unsafe { | ||
| registrator | ||
| .components | ||
| .register_resource_unchecked(type_id, id, descriptor); | ||
| .register_non_send_unchecked(type_id, id, descriptor); | ||
| } | ||
| }, | ||
| ) | ||
|
|
@@ -667,15 +643,15 @@ impl<'w> ComponentsQueuedRegistrator<'w> { | |
| unsafe { | ||
| registrator | ||
| .components | ||
| .register_resource_unchecked(type_id, id, descriptor); | ||
| .register_non_send_unchecked(type_id, id, descriptor); | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /// This is a queued version of [`ComponentsRegistrator::register_resource_with_descriptor`]. | ||
| /// This is a queued version of [`ComponentsRegistrator::register_non_send_with_descriptor`]. | ||
| /// This will reserve an id and queue the registration. | ||
| /// These registrations will be carried out at the next opportunity. | ||
| /// | ||
|
|
@@ -684,7 +660,7 @@ impl<'w> ComponentsQueuedRegistrator<'w> { | |
| /// Technically speaking, the returned [`ComponentId`] is not valid, but it will become valid later. | ||
| /// See type level docs for details. | ||
| #[inline] | ||
| pub fn queue_register_resource_with_descriptor( | ||
| pub fn queue_register_non_send_with_descriptor( | ||
| &self, | ||
| descriptor: ComponentDescriptor, | ||
| ) -> ComponentId { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we should consider deprecating this in favor of register_component