@@ -3,15 +3,16 @@ use crate::{
3
3
identifier:: masks:: { IdentifierMask , HIGH_MASK } ,
4
4
world:: World ,
5
5
} ;
6
- use bevy_utils:: EntityHashMap ;
6
+
7
+ use super :: EntityHashMap ;
7
8
8
9
/// Operation to map all contained [`Entity`] fields in a type to new values.
9
10
///
10
11
/// As entity IDs are valid only for the [`World`] they're sourced from, using [`Entity`]
11
12
/// as references in components copied from another world will be invalid. This trait
12
13
/// allows defining custom mappings for these references via [`EntityMappers`](EntityMapper), which
13
14
/// inject the entity mapping strategy between your `MapEntities` type and the current world
14
- /// (usually by using an [`EntityHashMap<Entity, Entity >`] between source entities and entities in the
15
+ /// (usually by using an [`EntityHashMap<Entity>`] between source entities and entities in the
15
16
/// current world).
16
17
///
17
18
/// Implementing this trait correctly is required for properly loading components
@@ -47,7 +48,7 @@ pub trait MapEntities {
47
48
48
49
/// An implementor of this trait knows how to map an [`Entity`] into another [`Entity`].
49
50
///
50
- /// Usually this is done by using an [`EntityHashMap<Entity, Entity >`] to map source entities
51
+ /// Usually this is done by using an [`EntityHashMap<Entity>`] to map source entities
51
52
/// (mapper inputs) to the current world's entities (mapper outputs).
52
53
///
53
54
/// More generally, this can be used to map [`Entity`] references between any two [`Worlds`](World).
@@ -56,10 +57,10 @@ pub trait MapEntities {
56
57
///
57
58
/// ```
58
59
/// # use bevy_ecs::entity::{Entity, EntityMapper};
59
- /// # use bevy_utils ::EntityHashMap;
60
+ /// # use bevy_ecs::entity ::EntityHashMap;
60
61
/// #
61
62
/// pub struct SimpleEntityMapper {
62
- /// map: EntityHashMap<Entity, Entity >,
63
+ /// map: EntityHashMap<Entity>,
63
64
/// }
64
65
///
65
66
/// // Example implementation of EntityMapper where we map an entity to another entity if it exists
@@ -97,7 +98,7 @@ impl EntityMapper for SceneEntityMapper<'_> {
97
98
}
98
99
}
99
100
100
- /// A wrapper for [`EntityHashMap<Entity, Entity >`], augmenting it with the ability to allocate new [`Entity`] references in a destination
101
+ /// A wrapper for [`EntityHashMap<Entity>`], augmenting it with the ability to allocate new [`Entity`] references in a destination
101
102
/// world. These newly allocated references are guaranteed to never point to any living entity in that world.
102
103
///
103
104
/// References are allocated by returning increasing generations starting from an internally initialized base
@@ -110,9 +111,9 @@ pub struct SceneEntityMapper<'m> {
110
111
/// or over the network. This is required as [`Entity`] identifiers are opaque; you cannot and do not want to reuse
111
112
/// identifiers directly.
112
113
///
113
- /// On its own, a [`EntityHashMap<Entity, Entity >`] is not capable of allocating new entity identifiers, which is needed to map references
114
+ /// On its own, a [`EntityHashMap<Entity>`] is not capable of allocating new entity identifiers, which is needed to map references
114
115
/// to entities that lie outside the source entity set. This functionality can be accessed through [`SceneEntityMapper::world_scope()`].
115
- map : & ' m mut EntityHashMap < Entity , Entity > ,
116
+ map : & ' m mut EntityHashMap < Entity > ,
116
117
/// A base [`Entity`] used to allocate new references.
117
118
dead_start : Entity ,
118
119
/// The number of generations this mapper has allocated thus far.
@@ -129,18 +130,18 @@ impl<'m> SceneEntityMapper<'m> {
129
130
self . map_entity ( entity)
130
131
}
131
132
132
- /// Gets a reference to the underlying [`EntityHashMap<Entity, Entity >`].
133
- pub fn get_map ( & ' m self ) -> & ' m EntityHashMap < Entity , Entity > {
133
+ /// Gets a reference to the underlying [`EntityHashMap<Entity>`].
134
+ pub fn get_map ( & ' m self ) -> & ' m EntityHashMap < Entity > {
134
135
self . map
135
136
}
136
137
137
- /// Gets a mutable reference to the underlying [`EntityHashMap<Entity, Entity >`].
138
- pub fn get_map_mut ( & ' m mut self ) -> & ' m mut EntityHashMap < Entity , Entity > {
138
+ /// Gets a mutable reference to the underlying [`EntityHashMap<Entity>`].
139
+ pub fn get_map_mut ( & ' m mut self ) -> & ' m mut EntityHashMap < Entity > {
139
140
self . map
140
141
}
141
142
142
143
/// Creates a new [`SceneEntityMapper`], spawning a temporary base [`Entity`] in the provided [`World`]
143
- fn new ( map : & ' m mut EntityHashMap < Entity , Entity > , world : & mut World ) -> Self {
144
+ fn new ( map : & ' m mut EntityHashMap < Entity > , world : & mut World ) -> Self {
144
145
Self {
145
146
map,
146
147
// SAFETY: Entities data is kept in a valid state via `EntityMapper::world_scope`
@@ -160,14 +161,14 @@ impl<'m> SceneEntityMapper<'m> {
160
161
assert ! ( entities. reserve_generations( self . dead_start. index( ) , self . generations) ) ;
161
162
}
162
163
163
- /// Creates an [`SceneEntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity, Entity >`], then calls the
164
+ /// Creates an [`SceneEntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity>`], then calls the
164
165
/// provided function with it. This allows one to allocate new entity references in this [`World`] that are
165
166
/// guaranteed to never point at a living entity now or in the future. This functionality is useful for safely
166
167
/// mapping entity identifiers that point at entities outside the source world. The passed function, `f`, is called
167
168
/// within the scope of this world. Its return value is then returned from `world_scope` as the generic type
168
169
/// parameter `R`.
169
170
pub fn world_scope < R > (
170
- entity_map : & ' m mut EntityHashMap < Entity , Entity > ,
171
+ entity_map : & ' m mut EntityHashMap < Entity > ,
171
172
world : & mut World ,
172
173
f : impl FnOnce ( & mut World , & mut Self ) -> R ,
173
174
) -> R {
@@ -180,10 +181,8 @@ impl<'m> SceneEntityMapper<'m> {
180
181
181
182
#[ cfg( test) ]
182
183
mod tests {
183
- use bevy_utils:: EntityHashMap ;
184
-
185
184
use crate :: {
186
- entity:: { Entity , EntityMapper , SceneEntityMapper } ,
185
+ entity:: { Entity , EntityHashMap , EntityMapper , SceneEntityMapper } ,
187
186
world:: World ,
188
187
} ;
189
188
0 commit comments