mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +00:00
[ecs] Add a function to remove a component from all entities
While simple component pools can be cleared simply by zeroing their counts, ones that have a delete function need that function to be called for all the components in the pool otherwise leaks can happen.
This commit is contained in:
parent
de2cc21c7e
commit
ac0079f872
2 changed files with 16 additions and 0 deletions
|
@ -238,6 +238,7 @@ void ECS_SortComponentPool (ecs_registry_t *registry, uint32_t component,
|
|||
|
||||
uint32_t ECS_NewEntity (ecs_registry_t *registry);
|
||||
void ECS_DelEntity (ecs_registry_t *registry, uint32_t ent);
|
||||
void ECS_RemoveEntities (ecs_registry_t *registry, uint32_t component);
|
||||
|
||||
void *Ent_AddComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry);
|
||||
void Ent_RemoveComponent (uint32_t ent, uint32_t comp,
|
||||
|
|
|
@ -216,3 +216,18 @@ ECS_DelEntity (ecs_registry_t *registry, uint32_t ent)
|
|||
Ent_RemoveComponent (ent, i, registry);
|
||||
}
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
ECS_RemoveEntities (ecs_registry_t *registry, uint32_t component)
|
||||
{
|
||||
ecs_pool_t *pool = ®istry->comp_pools[component];
|
||||
const component_t *comp = ®istry->components[component];
|
||||
__auto_type destroy = comp->destroy;
|
||||
if (destroy) {
|
||||
byte *data = registry->comp_pools[component].data;
|
||||
for (uint32_t i = 0; i < pool->count; i++) {
|
||||
destroy (data + i * comp->size);
|
||||
}
|
||||
}
|
||||
pool->count = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue