-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Move AppTypeRegistry to bevy_ecs #8901
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
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 |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| //! Types that enable reflection support. | ||
|
|
||
| use crate::entity::Entity; | ||
| use std::ops::{Deref, DerefMut}; | ||
|
|
||
| use crate as bevy_ecs; | ||
| use crate::{entity::Entity, system::Resource}; | ||
| use bevy_reflect::{ | ||
| impl_from_reflect_value, impl_reflect_value, ReflectDeserialize, ReflectSerialize, | ||
| TypeRegistryArc, | ||
| }; | ||
|
|
||
| mod component; | ||
|
|
@@ -13,5 +17,26 @@ pub use component::{ReflectComponent, ReflectComponentFns}; | |
| pub use map_entities::ReflectMapEntities; | ||
| pub use resource::{ReflectResource, ReflectResourceFns}; | ||
|
|
||
| /// A [`Resource`] storing [`TypeRegistry`](bevy_reflect::TypeRegistry) for | ||
| /// type registrations relevant to a whole app. | ||
| #[derive(Resource, Clone, Default)] | ||
| pub struct AppTypeRegistry(pub TypeRegistryArc); | ||
|
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. We could consider calling this
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. I don't want to include it in this PR. Changing the name is way more breaking than changing the crate it's defined in, as people will usually import it through
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. Agreed! |
||
|
|
||
| impl Deref for AppTypeRegistry { | ||
|
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. QQ: These won't mess with cloning right? Does this still work? fn system(registry: Res<AppTypeRegistry>) {
let registry2: AppTypeRegistry = registry.into_inner().clone();
}
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. It was implementing
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. Ah I missed that part. Awesome, sounds good! |
||
| type Target = TypeRegistryArc; | ||
|
|
||
| #[inline] | ||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl DerefMut for AppTypeRegistry { | ||
| #[inline] | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.0 | ||
| } | ||
| } | ||
|
|
||
| impl_reflect_value!((in bevy_ecs) Entity(Hash, PartialEq, Serialize, Deserialize)); | ||
| impl_from_reflect_value!(Entity); | ||
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 default a world to include this resource (under
bevy_reflectfeature)? Or is it still the responsibility of the user/bevy_appto initialize it?I'm guessing the latter, but just want to clarify.
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.
That's an interesting proposition. I like the idea. Though I'm curious of the implications with regard to
Scenes for example.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.
We should avoid automatically inserting resources whenever possible :)