Skip to content

Commit f2d4dc3

Browse files
committed
Stop inserting RelationshipTarget on SpawnRelatedBundle
1 parent 4e694ae commit f2d4dc3

File tree

2 files changed

+27
-48
lines changed

2 files changed

+27
-48
lines changed

crates/bevy_ecs/src/hierarchy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ pub fn validate_parent_has_component<C: Component>(
475475
}
476476
}
477477

478-
/// Returns a [`SpawnRelatedBundle`] that will insert the [`Children`] component, spawn a [`SpawnableList`] of entities with given bundles that
479-
/// relate to the [`Children`] entity via the [`ChildOf`] component, and reserve space in the [`Children`] for each spawned entity.
478+
/// Returns a [`SpawnRelatedBundle`] that will spawn a [`SpawnableList`] of entities with given bundles that
479+
/// relate to the [`Children`] entity via the [`ChildOf`] component.
480480
///
481481
/// Any additional arguments will be interpreted as bundles to be spawned.
482482
///

crates/bevy_ecs/src/spawn.rs

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ macro_rules! spawnable_list_impl {
163163

164164
all_tuples!(spawnable_list_impl, 0, 12, P);
165165

166-
/// A [`Bundle`] that:
167-
/// 1. Contains a [`RelationshipTarget`] component (associated with the given [`Relationship`]). This reserves space for the [`SpawnableList`].
168-
/// 2. Spawns a [`SpawnableList`] of related entities with a given [`Relationship`].
166+
/// A [`Bundle`] that spawns a [`SpawnableList`] of related entities with a given [`Relationship`].
169167
///
170168
/// This is intended to be created using [`SpawnRelated`].
171169
pub struct SpawnRelatedBundle<R: Relationship, L: SpawnableList<R>> {
@@ -182,50 +180,40 @@ impl<R: Relationship, L: SpawnableList<R>> BundleEffect for SpawnRelatedBundle<R
182180
}
183181
}
184182

185-
// SAFETY: This internally relies on the RelationshipTarget's Bundle implementation, which is sound.
183+
// SAFETY: This is a blank implementation.
186184
unsafe impl<R: Relationship, L: SpawnableList<R> + Send + Sync + 'static> Bundle
187185
for SpawnRelatedBundle<R, L>
188186
{
189187
fn component_ids(
190-
components: &mut crate::component::ComponentsRegistrator,
191-
ids: &mut impl FnMut(crate::component::ComponentId),
188+
_components: &mut crate::component::ComponentsRegistrator,
189+
_ids: &mut impl FnMut(crate::component::ComponentId),
192190
) {
193-
<R::RelationshipTarget as Bundle>::component_ids(components, ids);
194191
}
195192

196193
fn get_component_ids(
197-
components: &crate::component::Components,
198-
ids: &mut impl FnMut(Option<crate::component::ComponentId>),
194+
_components: &crate::component::Components,
195+
_ids: &mut impl FnMut(Option<crate::component::ComponentId>),
199196
) {
200-
<R::RelationshipTarget as Bundle>::get_component_ids(components, ids);
201197
}
202198

203199
fn register_required_components(
204-
components: &mut crate::component::ComponentsRegistrator,
205-
required_components: &mut crate::component::RequiredComponents,
200+
_components: &mut crate::component::ComponentsRegistrator,
201+
_required_components: &mut crate::component::RequiredComponents,
206202
) {
207-
<R::RelationshipTarget as Bundle>::register_required_components(
208-
components,
209-
required_components,
210-
);
211203
}
212204
}
213205
impl<R: Relationship, L: SpawnableList<R>> DynamicBundle for SpawnRelatedBundle<R, L> {
214206
type Effect = Self;
215207

216208
fn get_components(
217209
self,
218-
func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>),
210+
_func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>),
219211
) -> Self::Effect {
220-
<R::RelationshipTarget as RelationshipTarget>::with_capacity(self.list.size_hint())
221-
.get_components(func);
222212
self
223213
}
224214
}
225215

226-
/// A [`Bundle`] that:
227-
/// 1. Contains a [`RelationshipTarget`] component (associated with the given [`Relationship`]). This reserves space for a single entity.
228-
/// 2. Spawns a single related entity containing the given `B` [`Bundle`] and the given [`Relationship`].
216+
/// A [`Bundle`] that spawns a single related entity containing the given `B` [`Bundle`] and the given [`Relationship`].
229217
///
230218
/// This is intended to be created using [`SpawnRelated`].
231219
pub struct SpawnOneRelated<R: Relationship, B: Bundle> {
@@ -244,54 +232,45 @@ impl<R: Relationship, B: Bundle> DynamicBundle for SpawnOneRelated<R, B> {
244232

245233
fn get_components(
246234
self,
247-
func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>),
235+
_func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>),
248236
) -> Self::Effect {
249-
<R::RelationshipTarget as RelationshipTarget>::with_capacity(1).get_components(func);
250237
self
251238
}
252239
}
253240

254-
// SAFETY: This internally relies on the RelationshipTarget's Bundle implementation, which is sound.
241+
// SAFETY: This is a blank implementation.
255242
unsafe impl<R: Relationship, B: Bundle> Bundle for SpawnOneRelated<R, B> {
256243
fn component_ids(
257-
components: &mut crate::component::ComponentsRegistrator,
258-
ids: &mut impl FnMut(crate::component::ComponentId),
244+
_components: &mut crate::component::ComponentsRegistrator,
245+
_ids: &mut impl FnMut(crate::component::ComponentId),
259246
) {
260-
<R::RelationshipTarget as Bundle>::component_ids(components, ids);
261247
}
262248

263249
fn get_component_ids(
264-
components: &crate::component::Components,
265-
ids: &mut impl FnMut(Option<crate::component::ComponentId>),
250+
_components: &crate::component::Components,
251+
_ids: &mut impl FnMut(Option<crate::component::ComponentId>),
266252
) {
267-
<R::RelationshipTarget as Bundle>::get_component_ids(components, ids);
268253
}
269254

270255
fn register_required_components(
271-
components: &mut crate::component::ComponentsRegistrator,
272-
required_components: &mut crate::component::RequiredComponents,
256+
_components: &mut crate::component::ComponentsRegistrator,
257+
_required_components: &mut crate::component::RequiredComponents,
273258
) {
274-
<R::RelationshipTarget as Bundle>::register_required_components(
275-
components,
276-
required_components,
277-
);
278259
}
279260
}
280261

281-
/// [`RelationshipTarget`] methods that create a [`Bundle`] with a [`DynamicBundle::Effect`] that:
282-
///
283-
/// 1. Contains the [`RelationshipTarget`] component, pre-allocated with the necessary space for spawned entities.
284-
/// 2. Spawns an entity (or a list of entities) that relate to the entity the [`Bundle`] is added to via the [`RelationshipTarget::Relationship`].
262+
/// [`RelationshipTarget`] methods that create a [`Bundle`] with a [`DynamicBundle::Effect`] that
263+
/// spawns an entity (or a list of entities) that relate to the entity the [`Bundle`] is added to via the [`RelationshipTarget::Relationship`].
285264
pub trait SpawnRelated: RelationshipTarget {
286-
/// Returns a [`Bundle`] containing this [`RelationshipTarget`] component. It also spawns a [`SpawnableList`] of entities, each related to the bundle's entity
287-
/// via [`RelationshipTarget::Relationship`]. The [`RelationshipTarget`] (when possible) will pre-allocate space for the related entities.
265+
/// Returns a [`Bundle`] that spawns a [`SpawnableList`] of entities, each related to the bundle's entity
266+
/// via [`RelationshipTarget::Relationship`].
288267
///
289268
/// See [`Spawn`], [`SpawnIter`], and [`SpawnWith`] for usage examples.
290269
fn spawn<L: SpawnableList<Self::Relationship>>(
291270
list: L,
292271
) -> SpawnRelatedBundle<Self::Relationship, L>;
293272

294-
/// Returns a [`Bundle`] containing this [`RelationshipTarget`] component. It also spawns a single entity containing [`Bundle`] that is related to the bundle's entity
273+
/// Returns a [`Bundle`] that spawns a single entity containing [`Bundle`] that is related to the bundle's entity
295274
/// via [`RelationshipTarget::Relationship`].
296275
///
297276
/// ```
@@ -326,8 +305,8 @@ impl<T: RelationshipTarget> SpawnRelated for T {
326305
}
327306
}
328307

329-
/// Returns a [`SpawnRelatedBundle`] that will insert the given [`RelationshipTarget`], spawn a [`SpawnableList`] of entities with given bundles that
330-
/// relate to the [`RelationshipTarget`] entity via the [`RelationshipTarget::Relationship`] component, and reserve space in the [`RelationshipTarget`] for each spawned entity.
308+
/// Returns a [`SpawnRelatedBundle`] that will spawn a [`SpawnableList`] of entities with given bundles that
309+
/// relate to the [`RelationshipTarget`] entity via the [`RelationshipTarget::Relationship`] component.
331310
///
332311
/// The first argument is the [`RelationshipTarget`] type. Any additional arguments will be interpreted as bundles to be spawned.
333312
///

0 commit comments

Comments
 (0)