mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
StorageType parameter removed from ComponentDescriptor::new_resource (#3495)
# Objective Remove the `StorageType` parameter from `ComponentDescriptor::new_resource` as discussed in #3361. - fixes #3361 ## Solution - Parameter removed. - Basic docs added. ## Note Left a [comment](https://github.com/bevyengine/bevy/issues/3361#issuecomment-996433346) about `SparseStorage` being the more reasonable choice. Co-authored-by: r4gus <david@thesugar.de>
This commit is contained in:
parent
3ac55f0bcf
commit
c641a905dc
1 changed files with 8 additions and 3 deletions
|
@ -194,10 +194,15 @@ impl ComponentDescriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_resource<T: Resource>(storage_type: StorageType) -> Self {
|
/// Create a new `ComponentDescriptor` for a resource.
|
||||||
|
///
|
||||||
|
/// The [`StorageType`] for resources is always [`TableStorage`].
|
||||||
|
pub fn new_resource<T: Resource>() -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: std::any::type_name::<T>().to_string(),
|
name: std::any::type_name::<T>().to_string(),
|
||||||
storage_type,
|
// PERF: `SparseStorage` may actually be a more
|
||||||
|
// reasonable choice as `storage_type` for resources.
|
||||||
|
storage_type: StorageType::Table,
|
||||||
is_send_and_sync: true,
|
is_send_and_sync: true,
|
||||||
type_id: Some(TypeId::of::<T>()),
|
type_id: Some(TypeId::of::<T>()),
|
||||||
layout: Layout::new::<T>(),
|
layout: Layout::new::<T>(),
|
||||||
|
@ -308,7 +313,7 @@ impl Components {
|
||||||
// SAFE: The [`ComponentDescriptor`] matches the [`TypeId`]
|
// SAFE: The [`ComponentDescriptor`] matches the [`TypeId`]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.get_or_insert_resource_with(TypeId::of::<T>(), || {
|
self.get_or_insert_resource_with(TypeId::of::<T>(), || {
|
||||||
ComponentDescriptor::new_resource::<T>(StorageType::default())
|
ComponentDescriptor::new_resource::<T>()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue