bevy/crates/bevy_ecs/src
Nicola Papale 1bf271d56e
Add a public API to ArchetypeGeneration/Id (#9825)
Objective
---------

- Since #6742, It is not possible to build an `ArchetypeId` from a
`ArchetypeGeneration`
- This was useful to 3rd party crate extending the base bevy ECS
capabilities, such as [`bevy_ecs_dynamic`] and now
[`bevy_mod_dynamic_query`]
- Making `ArchetypeGeneration` opaque this way made it completely
useless, and removed the ability to limit archetype updates to a subset
of archetypes.
- Making the `index` method on `ArchetypeId` private prevented the use
of bitfields and other optimized data structure to store sets of
archetype ids. (without `transmute`)

This PR is not a simple reversal of the change. It exposes a different
API, rethought to keep the private stuff private and the public stuff
less error-prone.

- Add a `StartRange<ArchetypeGeneration>` `Index` implementation to
`Archetypes`
- Instead of converting the generation into an index, then creating a
ArchetypeId from that index, and indexing `Archetypes` with it, use
directly the old `ArchetypeGeneration` to get the range of new
archetypes.

From careful benchmarking, it seems to also be a performance improvement
(~0-5%) on add_archetypes.

---

Changelog
---------

- Added `impl Index<RangeFrom<ArchetypeGeneration>> for Archetypes` this
allows you to get a slice of newly added archetypes since the last
recorded generation.
- Added `ArchetypeId::index` and `ArchetypeId::new` methods. It should
enable 3rd party crates to use the `Archetypes` API in a meaningful way.

[`bevy_ecs_dynamic`]:
https://github.com/jakobhellermann/bevy_ecs_dynamic/tree/main
[`bevy_mod_dynamic_query`]:
https://github.com/nicopap/bevy_mod_dynamic_query/

---------

Co-authored-by: vero <email@atlasdostal.com>
2023-10-02 12:54:45 +00:00
..
entity Use EntityHashMap<Entity, T> for render world entity storage for better performance (#9903) 2023-09-27 08:28:28 +00:00
query Add a public API to ArchetypeGeneration/Id (#9825) 2023-10-02 12:54:45 +00:00
reflect Fix typos. (#9922) 2023-09-25 18:35:46 +00:00
schedule Remove States::variants and remove enum-only restriction its derive (#9945) 2023-09-30 22:32:39 +00:00
storage Improve doc formatting. (#9840) 2023-09-18 19:43:56 +00:00
system Add a public API to ArchetypeGeneration/Id (#9825) 2023-10-02 12:54:45 +00:00
world Hide UnsafeWorldCell::unsafe_world (#9741) 2023-10-02 12:46:43 +00:00
archetype.rs Add a public API to ArchetypeGeneration/Id (#9825) 2023-10-02 12:54:45 +00:00
bundle.rs Fix some nightly warnings (#9672) 2023-09-02 18:35:06 +00:00
change_detection.rs as_deref_mut() method for Mut-like types (#9912) 2023-10-02 00:53:12 +00:00
component.rs #[derive(Clone)] on Component{Info,Descriptor} (#9812) 2023-09-20 19:35:53 +00:00
event.rs Only run event systems if they have tangible work to do (#7728) 2023-09-24 00:16:33 +00:00
lib.rs Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
removal_detection.rs Hide UnsafeWorldCell::unsafe_world (#9741) 2023-10-02 12:46:43 +00:00