five-on-it / packages/sim/src/lifetimes
packages/sim/src/lifetimes
An entity's life under its id. bitECS hands a freed id to the next entity made (the id last freed first), so a pedestrian taken away and another put out in the same step are one id to everyone who keeps state by it: the snapshot encoders, the clients' remotes. The world keeps a generation per id (generationOf: eight bits, wrapping), turned over whenever the id is freed, and every removal goes through removeSimEntity, so the snapshots carry each entity's life (EntityState.gen) and an id that comes back is a new entity on the wire, never the old one moved.