News for hackers. Stuff that matters.
Re:Bevy 0.9: data oriented game engine built in Rust by prideout on Saturday November 12, 2022 @04:56PM (#33577517)
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.

Re:Bevy 0.9: data oriented game engine built in Rust by djmcnab on Saturday November 12, 2022 @05:27PM (#33577799)
> 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.

Re:Bevy 0.9: data oriented game engine built in Rust by ickk on Saturday November 12, 2022 @05:01PM (#33577561)
Entity 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.
Re:Bevy 0.9: data oriented game engine built in Rust by james7132 on Saturday November 12, 2022 @07:29PM (#33578705)
Entity 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.