Is it possible to create/remove entities while iterating over them? Is it possible to create an “entity_iterator” structure that handles this process? For example:
struct world {
entity entities[100];
uint32_t entity_count;
};
for(entity_iterator iterator = iterate_entities(world); is_valid(&iterator); next(&iterator) {
entity* e = iterator.current_entity;
if(e->value == 1) {
entity* newe = add_entity(world);
// initialize new entity here
} else {
delete_entity(world, e);
}
}
If this is not possible how do game engines handle entity creation/removal? Do they have some sort of queues?
This is how i create/remove entities:
Entity* created_entity = &entities[entity_count++];
uint32_t entity_index_to_remove = 1;
entities[entity_index_to_remove = entities[--entity_count];
Thanks