bevy/crates
Gonçalo Rica Pais da Silva e6a324a11a
Unified identifer for entities & relations (#9797)
# Objective

The purpose of this PR is to begin putting together a unified identifier
structure that can be used by entities and later components (as
entities) as well as relationship pairs for relations, to enable all of
these to be able to use the same storages. For the moment, to keep
things small and focused, only `Entity` is being changed to make use of
the new `Identifier` type, keeping `Entity`'s API and
serialization/deserialization the same. Further changes are for
follow-up PRs.

## Solution

`Identifier` is a wrapper around `u64` split into two `u32` segments
with the idea of being generalised to not impose restrictions on
variants. That is for `Entity` to do. Instead, it is a general API for
taking bits to then merge and map into a `u64` integer. It exposes
low/high methods to return the two value portions as `u32` integers,
with then the MSB masked for usage as a type flag, enabling entity kind
discrimination and future activation/deactivation semantics.

The layout in this PR for `Identifier` is described as below, going from
MSB -> LSB.

```
|F| High value                    | Low value                      |
|_|_______________________________|________________________________|
|1| 31                            | 32                             |

F = Bit Flags
```

The high component in this implementation has only 31 bits, but that
still leaves 2^31 or 2,147,483,648 values that can be stored still, more
than enough for any generation/relation kinds/etc usage. The low part is
a full 32-bit index. The flags allow for 1 bit to be used for
entity/pair discrimination, as these have different usages for the
low/high portions of the `Identifier`. More bits can be reserved for
more variants or activation/deactivation purposes, but this currently
has no use in bevy.

More bits could be reserved for future features at the cost of bits for
the high component, so how much to reserve is up for discussion. Also,
naming of the struct and methods are also subject to further
bikeshedding and feedback.

Also, because IDs can have different variants, I wonder if
`Entity::from_bits` needs to return a `Result` instead of potentially
panicking on receiving an invalid ID.

PR is provided as an early WIP to obtain feedback and notes on whether
this approach is viable.

---

## Changelog

### Added

New `Identifier` struct for unifying IDs.

### Changed

`Entity` changed to use new `Identifier`/`IdentifierMask` as the
underlying ID logic.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: vero <email@atlasdostal.com>
2024-01-13 01:09:32 +00:00
..
bevy_a11y resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_animation Update glam, encase and hexasphere (#11082) 2024-01-08 22:58:45 +00:00
bevy_app resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_asset Better error message on incorrect asset label (#11254) 2024-01-08 22:45:07 +00:00
bevy_audio resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_core Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_core_pipeline Revert "Implement minimal reflection probes. (#10057)" (#11307) 2024-01-12 20:41:51 +00:00
bevy_derive Reexport winit::platform::android::activity::* in bevy_winit (#11011) 2023-12-19 20:15:03 +00:00
bevy_diagnostic Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_ecs Unified identifer for entities & relations (#9797) 2024-01-13 01:09:32 +00:00
bevy_ecs_compile_fail_tests Rename WorldQueryData & WorldQueryFilter to QueryData & QueryFilter (#10779) 2023-12-12 19:45:50 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_gizmos resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_gltf assets should be kept on CPU by default (#11212) 2024-01-05 05:53:47 +00:00
bevy_hierarchy Rename "AddChild" to "PushChild" (#11194) 2024-01-04 16:06:14 +00:00
bevy_input Extend Touches with clear and reset methods (#10930) 2024-01-04 23:13:29 +00:00
bevy_internal Revert "Implement minimal reflection probes. (#10057)" (#11307) 2024-01-12 20:41:51 +00:00
bevy_log Print to stderr from panic handler in LogPlugin (#11170) 2024-01-01 17:10:20 +00:00
bevy_macro_utils Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Implement bounding volume types (#10946) 2024-01-10 23:18:51 +00:00
bevy_mikktspace Update glam, encase and hexasphere (#11082) 2024-01-08 22:58:45 +00:00
bevy_pbr Revert "Implement minimal reflection probes. (#10057)" (#11307) 2024-01-12 20:41:51 +00:00
bevy_ptr Simplify equality assertions (#10988) 2023-12-16 23:58:41 +00:00
bevy_reflect Update glam, encase and hexasphere (#11082) 2024-01-08 22:58:45 +00:00
bevy_reflect_compile_fail_tests Fix nested generics in Reflect derive (#10791) 2023-11-29 01:46:09 +00:00
bevy_render Revert "Implement minimal reflection probes. (#10057)" (#11307) 2024-01-12 20:41:51 +00:00
bevy_scene Change Entity::generation from u32 to NonZeroU32 for niche optimization (#9907) 2024-01-08 23:03:00 +00:00
bevy_sprite assets should be kept on CPU by default (#11212) 2024-01-05 05:53:47 +00:00
bevy_tasks Replace or document ignored doctests (#11040) 2024-01-01 16:50:56 +00:00
bevy_text resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_time Add paused run condition (#11313) 2024-01-12 22:18:57 +00:00
bevy_transform Rename "AddChild" to "PushChild" (#11194) 2024-01-04 16:06:14 +00:00
bevy_ui resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_utils Add static assertions to bevy_utils for compile-time checks (#11182) 2024-01-02 22:08:30 +00:00
bevy_window Remove CanvasParentResizePlugin (#11057) 2023-12-21 20:01:22 +00:00
bevy_winit resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00