Skip to content

Commit

Permalink
#839 Ensure on_add hooks are invoked when using bulk_init
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 20, 2022
1 parent 3451ca3 commit 54f99b6
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 139 deletions.
7 changes: 6 additions & 1 deletion examples/c/systems/system_ctx/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"flecs"
],
"public": false
},
"lang.c": {
"${os linux}": {
"lib": ["m"]
}
}
}
}
1 change: 0 additions & 1 deletion examples/c/systems/time_interval/src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <time_interval.h>
#include <basics.h>
#include <stdio.h>

// This example shows how to run a system at a specified time interval.
Expand Down
7 changes: 6 additions & 1 deletion examples/cpp/systems/system_ctx/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
],
"public": false,
"language": "c++"
},
"lang.cpp": {
"${os linux}": {
"lib": ["m"]
}
}
}
}
4 changes: 2 additions & 2 deletions examples/cpp/systems/system_ctx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ int main(int, char *[]) {
auto sys = ecs.system<const Position, const Radius>("Collide")
.ctx(&q_collide)
.each([](flecs::iter& it, size_t i, const Position& p1, const Radius& r1) {
CollisionQuery *q_collide = it.ctx<CollisionQuery>();
CollisionQuery *w = it.ctx<CollisionQuery>();
flecs::entity e1 = it.entity(i);

q_collide->each([&](flecs::entity e2, const Position& p2, const Radius& r2) {
q->each([&](flecs::entity e2, const Position& p2, const Radius& r2) {
if (e1 == e2) {
// don't collide with self
return;
Expand Down
8 changes: 4 additions & 4 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3819,9 +3819,7 @@ int32_t flecs_table_grow_data(
/* Initialize entity ids and record ptrs */
int32_t i;
if (ids) {
for (i = 0; i < to_add; i ++) {
e[i] = ids[i];
}
ecs_os_memcpy_n(e, ids, ecs_entity_t, to_add);
} else {
ecs_os_memset(e, 0, ECS_SIZEOF(ecs_entity_t) * to_add);
}
Expand All @@ -3834,6 +3832,8 @@ int32_t flecs_table_grow_data(
ecs_type_info_t *ti = type_info[i];
flecs_table_grow_column(world, column, ti, to_add, size, true);
ecs_assert(columns[i].size == size, ECS_INTERNAL_ERROR, NULL);
flecs_run_add_hooks(world, table, ti, column, e, table->type.array[i],
cur_count, to_add, false);
}

/* Add elements to each switch column */
Expand Down Expand Up @@ -4303,11 +4303,11 @@ int32_t flecs_table_appendn(
ecs_assert(!table->lock, ECS_LOCKED_STORAGE, NULL);

flecs_table_check_sanity(table);

int32_t cur_count = flecs_table_data_count(data);
int32_t result = flecs_table_grow_data(
world, table, data, to_add, cur_count + to_add, ids);
flecs_table_check_sanity(table);

return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,7 @@ int32_t flecs_table_grow_data(
/* Initialize entity ids and record ptrs */
int32_t i;
if (ids) {
for (i = 0; i < to_add; i ++) {
e[i] = ids[i];
}
ecs_os_memcpy_n(e, ids, ecs_entity_t, to_add);
} else {
ecs_os_memset(e, 0, ECS_SIZEOF(ecs_entity_t) * to_add);
}
Expand All @@ -1453,6 +1451,8 @@ int32_t flecs_table_grow_data(
ecs_type_info_t *ti = type_info[i];
flecs_table_grow_column(world, column, ti, to_add, size, true);
ecs_assert(columns[i].size == size, ECS_INTERNAL_ERROR, NULL);
flecs_run_add_hooks(world, table, ti, column, e, table->type.array[i],
cur_count, to_add, false);
}

/* Add elements to each switch column */
Expand Down Expand Up @@ -1922,11 +1922,11 @@ int32_t flecs_table_appendn(
ecs_assert(!table->lock, ECS_LOCKED_STORAGE, NULL);

flecs_table_check_sanity(table);

int32_t cur_count = flecs_table_data_count(data);
int32_t result = flecs_table_grow_data(
world, table, data, to_add, cur_count + to_add, ids);
flecs_table_check_sanity(table);

return result;
}

Expand Down
1 change: 1 addition & 0 deletions test/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
"ctor_on_move_pair",
"move_on_realloc",
"move_on_bulk_new",
"on_add_on_bulk_new",
"move_on_delete",
"move_dtor_on_delete",
"copy_on_override_pair",
Expand Down
Loading

0 comments on commit 54f99b6

Please sign in to comment.