pub fn initialize_entity_index(plugin_index: &AtomicUsize) -> usizeExpand description
Encapsulates the synchronization logic for initializing an entity’s index.
Acquires a global lock on the next available item index, but only increments
it if we successfully initialize the provided index. The index of a registered
item is assigned at runtime but only once per type. It’s possible for a single
type to attempt to initialize its index multiple times from different threads,
which is why all this synchronization is required. However, the overhead
is negligible, as this initialization only happens once upon first access.
In fact, for our use case we know we are calling this function
once for each type in each Entity’s ctor function, which
should be the only time this method is ever called for the type.