Skip to content

Commit 54f99b6

Browse files
committed
#839 Ensure on_add hooks are invoked when using bulk_init
1 parent 3451ca3 commit 54f99b6

File tree

9 files changed

+170
-139
lines changed

9 files changed

+170
-139
lines changed

examples/c/systems/system_ctx/project.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
"flecs"
77
],
88
"public": false
9+
},
10+
"lang.c": {
11+
"${os linux}": {
12+
"lib": ["m"]
13+
}
914
}
10-
}
15+
}

examples/c/systems/time_interval/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <time_interval.h>
2-
#include <basics.h>
32
#include <stdio.h>
43

54
// This example shows how to run a system at a specified time interval.

examples/cpp/systems/system_ctx/project.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
],
88
"public": false,
99
"language": "c++"
10+
},
11+
"lang.cpp": {
12+
"${os linux}": {
13+
"lib": ["m"]
14+
}
1015
}
11-
}
16+
}

examples/cpp/systems/system_ctx/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ int main(int, char *[]) {
3333
auto sys = ecs.system<const Position, const Radius>("Collide")
3434
.ctx(&q_collide)
3535
.each([](flecs::iter& it, size_t i, const Position& p1, const Radius& r1) {
36-
CollisionQuery *q_collide = it.ctx<CollisionQuery>();
36+
CollisionQuery *w = it.ctx<CollisionQuery>();
3737
flecs::entity e1 = it.entity(i);
3838

39-
q_collide->each([&](flecs::entity e2, const Position& p2, const Radius& r2) {
39+
q->each([&](flecs::entity e2, const Position& p2, const Radius& r2) {
4040
if (e1 == e2) {
4141
// don't collide with self
4242
return;

flecs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,9 +3819,7 @@ int32_t flecs_table_grow_data(
38193819
/* Initialize entity ids and record ptrs */
38203820
int32_t i;
38213821
if (ids) {
3822-
for (i = 0; i < to_add; i ++) {
3823-
e[i] = ids[i];
3824-
}
3822+
ecs_os_memcpy_n(e, ids, ecs_entity_t, to_add);
38253823
} else {
38263824
ecs_os_memset(e, 0, ECS_SIZEOF(ecs_entity_t) * to_add);
38273825
}
@@ -3834,6 +3832,8 @@ int32_t flecs_table_grow_data(
38343832
ecs_type_info_t *ti = type_info[i];
38353833
flecs_table_grow_column(world, column, ti, to_add, size, true);
38363834
ecs_assert(columns[i].size == size, ECS_INTERNAL_ERROR, NULL);
3835+
flecs_run_add_hooks(world, table, ti, column, e, table->type.array[i],
3836+
cur_count, to_add, false);
38373837
}
38383838

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

43054305
flecs_table_check_sanity(table);
4306-
43074306
int32_t cur_count = flecs_table_data_count(data);
43084307
int32_t result = flecs_table_grow_data(
43094308
world, table, data, to_add, cur_count + to_add, ids);
43104309
flecs_table_check_sanity(table);
4310+
43114311
return result;
43124312
}
43134313

src/table.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,7 @@ int32_t flecs_table_grow_data(
14381438
/* Initialize entity ids and record ptrs */
14391439
int32_t i;
14401440
if (ids) {
1441-
for (i = 0; i < to_add; i ++) {
1442-
e[i] = ids[i];
1443-
}
1441+
ecs_os_memcpy_n(e, ids, ecs_entity_t, to_add);
14441442
} else {
14451443
ecs_os_memset(e, 0, ECS_SIZEOF(ecs_entity_t) * to_add);
14461444
}
@@ -1453,6 +1451,8 @@ int32_t flecs_table_grow_data(
14531451
ecs_type_info_t *ti = type_info[i];
14541452
flecs_table_grow_column(world, column, ti, to_add, size, true);
14551453
ecs_assert(columns[i].size == size, ECS_INTERNAL_ERROR, NULL);
1454+
flecs_run_add_hooks(world, table, ti, column, e, table->type.array[i],
1455+
cur_count, to_add, false);
14561456
}
14571457

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

19241924
flecs_table_check_sanity(table);
1925-
19261925
int32_t cur_count = flecs_table_data_count(data);
19271926
int32_t result = flecs_table_grow_data(
19281927
world, table, data, to_add, cur_count + to_add, ids);
19291928
flecs_table_check_sanity(table);
1929+
19301930
return result;
19311931
}
19321932

test/api/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@
815815
"ctor_on_move_pair",
816816
"move_on_realloc",
817817
"move_on_bulk_new",
818+
"on_add_on_bulk_new",
818819
"move_on_delete",
819820
"move_dtor_on_delete",
820821
"copy_on_override_pair",

0 commit comments

Comments
 (0)