3 ms·
How are entity id's managed? When an entity "dies", can its id be re-used? From a Rust-on-WASM perspective, it might be useful to limit the entity id's to ~52
by prideout 4y ago
How are entity id's managed? When an entity "dies", can its id be re-used?
From a Rust-on-WASM perspective, it might be useful to limit the entity id's to ~52 bits or less, since native JavaScript numbers are doubles.
- ickk 4y agoEntity is essentially a u64, which is composed of a 32 bit index and a 32 bit generation. Despawned entities free their index, and which ever new Entity takes its place gets a new generation.
- djmcnab 4y ago> From a Rust-on-WASM perspective, it might be useful to limit the entity id's to ~52 bits or less, since native JavaScript numbers are doubles. Since compiling to web uses WebAssembly, we can just use native 64 bit integers for our entities. In general, we avoid introducing differences between web and native targets, and this is no exception. If you do need to round-trip full entities using JavaScript, you should either store them in one of the native non-broken integer types (such as `BigInt` or `BigUint64Array`), or just store the `index` and `generation` as seperate `number`s. It's worth recognising that in most cases, you should only need to exchange the entity `id` with different systems, as the `generation` is mainly used to panic on use-after-free conditions.
- james7132 4y agoEntity as a type is an generational ID. We only support up to 2^32 entities in a World, which makes up the bottom 32 bits. The top 32 bits is the generation. Once we destroy an entity, it's ID is reused, but the generation is increased.