Remove initialize_resource<T> and friends (#12307)

# Objective
`initialize_resource<T>` and it's non-send equivalent is only used in
two locations each. Fix #6285.

## Solution
Remove them, replace their calls with their internals. Cut down on a bit
of generic codegen.

This does mean that `initialize_resource_internal` is now `pub(crate)`,
but that's likely OK given that only one variant will remain once
NonSend resources are removed from the World.
This commit is contained in:
James Liu 2024-03-05 08:09:13 -08:00 committed by GitHub
parent fc202f2e3d
commit ab6a5cac9f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 18 deletions

View file

@ -442,7 +442,9 @@ unsafe impl<'a, T: Resource> SystemParam for Res<'a, T> {
type Item<'w, 's> = Res<'w, T>;
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
let component_id = world.initialize_resource::<T>();
let component_id = world.components.init_resource::<T>();
world.initialize_resource_internal(component_id);
let combined_access = system_meta.component_access_set.combined_access();
assert!(
!combined_access.has_write(component_id),
@ -532,7 +534,9 @@ unsafe impl<'a, T: Resource> SystemParam for ResMut<'a, T> {
type Item<'w, 's> = ResMut<'w, T>;
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
let component_id = world.initialize_resource::<T>();
let component_id = world.components.init_resource::<T>();
world.initialize_resource_internal(component_id);
let combined_access = system_meta.component_access_set.combined_access();
if combined_access.has_write(component_id) {
panic!(
@ -1027,7 +1031,9 @@ unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> {
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
system_meta.set_non_send();
let component_id = world.initialize_non_send_resource::<T>();
let component_id = world.components.init_non_send::<T>();
world.initialize_non_send_internal(component_id);
let combined_access = system_meta.component_access_set.combined_access();
assert!(
!combined_access.has_write(component_id),
@ -1114,7 +1120,9 @@ unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> {
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
system_meta.set_non_send();
let component_id = world.initialize_non_send_resource::<T>();
let component_id = world.components.init_non_send::<T>();
world.initialize_non_send_internal(component_id);
let combined_access = system_meta.component_access_set.combined_access();
if combined_access.has_write(component_id) {
panic!(

View file

@ -1835,7 +1835,7 @@ impl World {
/// # Panics
/// Panics if `component_id` is not registered as a `Send` component type in this `World`
#[inline]
fn initialize_resource_internal(
pub(crate) fn initialize_resource_internal(
&mut self,
component_id: ComponentId,
) -> &mut ResourceData<true> {
@ -1850,7 +1850,7 @@ impl World {
/// # Panics
/// panics if `component_id` is not registered in this world
#[inline]
fn initialize_non_send_internal(
pub(crate) fn initialize_non_send_internal(
&mut self,
component_id: ComponentId,
) -> &mut ResourceData<false> {
@ -1862,18 +1862,6 @@ impl World {
})
}
pub(crate) fn initialize_resource<R: Resource>(&mut self) -> ComponentId {
let component_id = self.components.init_resource::<R>();
self.initialize_resource_internal(component_id);
component_id
}
pub(crate) fn initialize_non_send_resource<R: 'static>(&mut self) -> ComponentId {
let component_id = self.components.init_non_send::<R>();
self.initialize_non_send_internal(component_id);
component_id
}
/// Empties queued entities and adds them to the empty [`Archetype`](crate::archetype::Archetype).
/// This should be called before doing operations that might operate on queued entities,
/// such as inserting a [`Component`].