mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
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:
parent
fc202f2e3d
commit
ab6a5cac9f
2 changed files with 14 additions and 18 deletions
|
@ -442,7 +442,9 @@ unsafe impl<'a, T: Resource> SystemParam for Res<'a, T> {
|
||||||
type Item<'w, 's> = Res<'w, T>;
|
type Item<'w, 's> = Res<'w, T>;
|
||||||
|
|
||||||
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
|
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();
|
let combined_access = system_meta.component_access_set.combined_access();
|
||||||
assert!(
|
assert!(
|
||||||
!combined_access.has_write(component_id),
|
!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>;
|
type Item<'w, 's> = ResMut<'w, T>;
|
||||||
|
|
||||||
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
|
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();
|
let combined_access = system_meta.component_access_set.combined_access();
|
||||||
if combined_access.has_write(component_id) {
|
if combined_access.has_write(component_id) {
|
||||||
panic!(
|
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 {
|
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
|
||||||
system_meta.set_non_send();
|
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();
|
let combined_access = system_meta.component_access_set.combined_access();
|
||||||
assert!(
|
assert!(
|
||||||
!combined_access.has_write(component_id),
|
!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 {
|
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State {
|
||||||
system_meta.set_non_send();
|
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();
|
let combined_access = system_meta.component_access_set.combined_access();
|
||||||
if combined_access.has_write(component_id) {
|
if combined_access.has_write(component_id) {
|
||||||
panic!(
|
panic!(
|
||||||
|
|
|
@ -1835,7 +1835,7 @@ impl World {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if `component_id` is not registered as a `Send` component type in this `World`
|
/// Panics if `component_id` is not registered as a `Send` component type in this `World`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn initialize_resource_internal(
|
pub(crate) fn initialize_resource_internal(
|
||||||
&mut self,
|
&mut self,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
) -> &mut ResourceData<true> {
|
) -> &mut ResourceData<true> {
|
||||||
|
@ -1850,7 +1850,7 @@ impl World {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// panics if `component_id` is not registered in this world
|
/// panics if `component_id` is not registered in this world
|
||||||
#[inline]
|
#[inline]
|
||||||
fn initialize_non_send_internal(
|
pub(crate) fn initialize_non_send_internal(
|
||||||
&mut self,
|
&mut self,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
) -> &mut ResourceData<false> {
|
) -> &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).
|
/// 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,
|
/// This should be called before doing operations that might operate on queued entities,
|
||||||
/// such as inserting a [`Component`].
|
/// such as inserting a [`Component`].
|
||||||
|
|
Loading…
Reference in a new issue