From 1d8920d1c7c1754f1980f3cce3eb86e3f883c8cc Mon Sep 17 00:00:00 2001 From: Greg Snook <25618525+gsnook@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:53:16 -0700 Subject: [PATCH] Simplified parameters --- include/flecs.h | 12 +++---- src/storage/table.c | 8 ++--- test/core/src/Table.c | 83 +++++++++---------------------------------- 3 files changed, 24 insertions(+), 79 deletions(-) diff --git a/include/flecs.h b/include/flecs.h index 9b539bfbd..c0701eb86 100644 --- a/include/flecs.h +++ b/include/flecs.h @@ -5974,21 +5974,17 @@ int32_t ecs_search_relation( ecs_id_t *id_out, struct ecs_table_record_t **tr_out); -/** Remove all entities in a table. Optionally, notify all observers and - * deallocate table memory. Retaining table memory can be efficient when - * planning to refill the table with operations like ecs_bulk_init +/** Remove all entities in a table. Does not deallocate table memory. + * Retaining table memory can be efficient when planning + * to refill the table with operations like ecs_bulk_init * * @param world The world. * @param table The table to clear. - * @param notify Call OnRemove hooks. - * @param deallocate Deallocate unused table memory. */ FLECS_API void ecs_table_clear_entities( ecs_world_t* world, - ecs_table_t* table, - bool notify, - bool deallocate); + ecs_table_t* table); /** @} */ diff --git a/src/storage/table.c b/src/storage/table.c index e526b3844..f34539f77 100644 --- a/src/storage/table.c +++ b/src/storage/table.c @@ -956,14 +956,12 @@ const ecs_entity_t* ecs_table_entities( return table->data.entities; } -/* Cleanup, optionally run OnRemove, clear entity index, deactivate table, optionally free allocations */ +/* Cleanup, no OnRemove, delete from entity index, deactivate table, retain allocations */ void ecs_table_clear_entities( ecs_world_t* world, - ecs_table_t* table, - bool notify, - bool deallocate) + ecs_table_t* table) { - flecs_table_fini_data(world, table, notify, true, true, deallocate); + flecs_table_fini_data(world, table, true, true, true, false); } /* Cleanup, no OnRemove, clear entity index, deactivate table, free allocations */ diff --git a/test/core/src/Table.c b/test/core/src/Table.c index 9dd17f723..63fecbfbb 100644 --- a/test/core/src/Table.c +++ b/test/core/src/Table.c @@ -618,8 +618,7 @@ void Table_has_any_pair(void) { ecs_fini(world); } -static -void Clear_table_and_verify_members_not_alive(bool notify, bool dealloc) { +void Table_clear_table_kills_entities(void) { ecs_world_t *world = ecs_mini(); ECS_COMPONENT(world, Position); @@ -631,7 +630,7 @@ void Clear_table_and_verify_members_not_alive(bool notify, bool dealloc) { ecs_table_t *table = ecs_get_table(world, e1); - ecs_table_clear_entities(world, table, notify, dealloc); + ecs_table_clear_entities(world, table); test_assert(!ecs_is_alive(world, e1)); test_assert(!ecs_is_alive(world, e2)); @@ -640,15 +639,7 @@ void Clear_table_and_verify_members_not_alive(bool notify, bool dealloc) { ecs_fini(world); } -void Table_clear_table_kills_entities(void) { - Clear_table_and_verify_members_not_alive(true, true); - Clear_table_and_verify_members_not_alive(false, true); - Clear_table_and_verify_members_not_alive(true, false); - Clear_table_and_verify_members_not_alive(false, false); -} - -static -void Clear_table_and_verify_new_members_exist(bool notify, bool dealloc) { +void Table_clear_table_add_new(void) { ecs_world_t *world = ecs_mini(); ecs_entity_t ecs_id(Position) = ecs_component(world, { @@ -664,7 +655,7 @@ void Clear_table_and_verify_new_members_exist(bool notify, bool dealloc) { ecs_table_t *table = ecs_get_table(world, e1); - ecs_table_clear_entities(world, table, notify, dealloc); + ecs_table_clear_entities(world, table); ecs_id(Position) = ecs_component(world, { .entity = ecs_new(world), @@ -688,15 +679,7 @@ void Clear_table_and_verify_new_members_exist(bool notify, bool dealloc) { ecs_fini(world); } -void Table_clear_table_add_new(void) { - Clear_table_and_verify_new_members_exist(true, true); - Clear_table_and_verify_new_members_exist(false, true); - Clear_table_and_verify_new_members_exist(true, false); - Clear_table_and_verify_new_members_exist(false, false); -} - -static -void Clear_table_and_check_size(bool notify, bool dealloc) { +void Table_clear_table_check_size(void) { ecs_world_t *world = ecs_mini(); ECS_COMPONENT(world, Position); @@ -709,24 +692,16 @@ void Clear_table_and_check_size(bool notify, bool dealloc) { ecs_table_t *table = ecs_get_table(world, e1); const int32_t size = ecs_table_size(table); - ecs_table_clear_entities(world, table, notify, dealloc); + ecs_table_clear_entities(world, table); - const int32_t expected_size = dealloc ? 0 : size; - test_int(expected_size, ecs_table_size(table)); + test_int(size, ecs_table_size(table)); test_int(0, ecs_table_count(table)); ecs_fini(world); } -void Table_clear_table_check_size(void) { - Clear_table_and_check_size(true, true); - Clear_table_and_check_size(false, true); - Clear_table_and_check_size(true, false); - Clear_table_and_check_size(false, false); -} -static -void Clear_table_twice_and_check_size(bool first_dealloc, bool second_dealloc) { +void Table_clear_table_twice_check_size(void) { ecs_world_t *world = ecs_mini(); ECS_COMPONENT(world, Position); @@ -739,23 +714,15 @@ void Clear_table_twice_and_check_size(bool first_dealloc, bool second_dealloc) { ecs_table_t *table = ecs_get_table(world, e1); const int32_t size = ecs_table_size(table); - ecs_table_clear_entities(world, table, true, first_dealloc); - ecs_table_clear_entities(world, table, true, second_dealloc); + ecs_table_clear_entities(world, table); + ecs_table_clear_entities(world, table); - const int32_t expected_size = (first_dealloc || second_dealloc) ? 0 : size; - test_int(expected_size, ecs_table_size(table)); + test_int(size, ecs_table_size(table)); test_int(0, ecs_table_count(table)); ecs_fini(world); } -void Table_clear_table_twice_check_size(void) { - Clear_table_twice_and_check_size(true, true); - Clear_table_twice_and_check_size(false, true); - Clear_table_twice_and_check_size(true, false); - Clear_table_twice_and_check_size(false, false); -} - static int on_remove_position = 0; static void ecs_on_remove(Position)(ecs_iter_t *it) { @@ -770,8 +737,7 @@ static void ecs_on_remove(Position)(ecs_iter_t *it) { } } -static -void Verify_on_remove_hooks_table_clear(bool notify, bool dealloc) { +void Table_clear_table_on_remove_hooks(void) { ecs_world_t *world = ecs_mini(); on_remove_position = 0; @@ -786,27 +752,19 @@ void Verify_on_remove_hooks_table_clear(bool notify, bool dealloc) { ecs_entity_t e3 = ecs_insert(world, ecs_value(Position, {10, 20})); ecs_table_t *table = ecs_get_table(world, e1); - ecs_table_clear_entities(world, table, notify, dealloc); + ecs_table_clear_entities(world, table); test_int(on_remove_position, 3); ecs_fini(world); } -void Table_clear_table_on_remove_hooks(void) { - Verify_on_remove_hooks_table_clear(true, true); - Verify_on_remove_hooks_table_clear(false, true); - Verify_on_remove_hooks_table_clear(true, false); - Verify_on_remove_hooks_table_clear(false, false); -} - static void Observer(ecs_iter_t *it) { probe_system_w_ctx(it, it->ctx); } -static -void Check_on_remove_when_clearing_table(bool notify, bool dealloc) { +void Table_clear_table_on_remove_observer(void) { ecs_world_t *world = ecs_mini(); ECS_COMPONENT(world, Position); @@ -828,17 +786,10 @@ void Check_on_remove_when_clearing_table(bool notify, bool dealloc) { test_int(ctx.invoked, 0); ecs_table_t *table = ecs_get_table(world, e1); - ecs_table_clear_entities(world, table, notify, dealloc); + ecs_table_clear_entities(world, table); - test_int(ctx.invoked, notify ? 1 : 0); - test_int(ctx.count, notify ? 2 : 0); + test_int(ctx.invoked, 1); + test_int(ctx.count, 2); ecs_fini(world); } - -void Table_clear_table_on_remove_observer(void) { - Check_on_remove_when_clearing_table(true, true); - Check_on_remove_when_clearing_table(false, true); - Check_on_remove_when_clearing_table(true, false); - Check_on_remove_when_clearing_table(false, false); -}