Skip to content

Commit 5f3b50e

Browse files
committed
change
1 parent 798fe9a commit 5f3b50e

12 files changed

Lines changed: 25 additions & 34 deletions

File tree

src/addons/flecs_cpp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ ecs_cpp_get_mut_t ecs_cpp_set(
600600

601601
if (dst.ti->hooks.on_replace) {
602602
flecs_invoke_replace_hook(
603-
world, prev_table, entity, id, dst.ptr, new_ptr, dst.ti);
603+
world, prev_table, entity, id, dst.ptr, new_ptr, dst.ti, prev_table);
604604
}
605605

606606
done:
@@ -655,7 +655,7 @@ ecs_cpp_get_mut_t ecs_cpp_assign(
655655

656656
if (dst.ti->hooks.on_replace) {
657657
flecs_invoke_replace_hook(
658-
world, prev_table, entity, id, dst.ptr, new_ptr, dst.ti);
658+
world, prev_table, entity, id, dst.ptr, new_ptr, dst.ti, prev_table);
659659
}
660660

661661
done:

src/commands.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void* flecs_defer_set(
540540
/* Call on_replace hook before copying the new value. */
541541
if (ti->hooks.on_replace) {
542542
flecs_invoke_replace_hook(
543-
world, r->table, entity, id, ptr.ptr, value, ti);
543+
world, r->table, entity, id, ptr.ptr, value, ti, r->table);
544544
}
545545

546546
flecs_type_info_copy(ptr.ptr, value, 1, ti);
@@ -616,7 +616,7 @@ void* flecs_defer_cpp_set(
616616
/* Call on_replace hook before copying the new value. */
617617
if (ti->hooks.on_replace) {
618618
flecs_invoke_replace_hook(
619-
world, r->table, entity, id, ptr.ptr, value, ti);
619+
world, r->table, entity, id, ptr.ptr, value, ti, r->table);
620620
}
621621
}
622622

@@ -650,7 +650,7 @@ void* flecs_defer_cpp_assign(
650650
ecs_iter_action_t on_replace = ptr.ti->hooks.on_replace;
651651
if (on_replace) {
652652
flecs_invoke_replace_hook(
653-
world, r->table, entity, id, ptr.ptr, value, ptr.ti);
653+
world, r->table, entity, id, ptr.ptr, value, ptr.ti, r->table);
654654
}
655655

656656
ecs_cmd_t *cmd = flecs_cmd_new(stage);
@@ -1020,7 +1020,7 @@ void flecs_cmd_batch_for_entity(
10201020
const ecs_type_info_t *ti = dst.ti;
10211021
if (ti->hooks.on_replace) {
10221022
flecs_invoke_replace_hook(world, start_table, entity,
1023-
cmd->id, dst.ptr, ptr, ti);
1023+
cmd->id, dst.ptr, ptr, ti, start_table);
10241024
if (!r->table) {
10251025
/* Entity was deleted */
10261026
goto done;

src/component_actions.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void flecs_invoke_replace_hook(
7777
ecs_id_t id,
7878
const void *old_ptr,
7979
const void *new_ptr,
80-
const ecs_type_info_t *ti)
80+
const ecs_type_info_t *ti,
81+
ecs_table_t *prev_table)
8182
{
8283
int32_t defer = world->stages[0]->defer;
8384
if (defer < 0) {
@@ -110,8 +111,8 @@ void flecs_invoke_replace_hook(
110111
it.count = 1;
111112
it.offset = 0; /* Don't set row because we don't want to offset ptrs */
112113
it.flags = EcsIterIsValid;
113-
it.other_table = table;
114-
it.set_fields = (table != NULL && ecs_table_has_id(world, table, id)) ? 3 : 2;
114+
it.other_table = prev_table;
115+
it.set_fields = (prev_table != NULL && ecs_table_has_id(world, prev_table, id)) ? 3 : 2;
115116

116117
ti->hooks.on_replace(&it);
117118

src/component_actions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void flecs_invoke_replace_hook(
3030
ecs_id_t id,
3131
const void *old_ptr,
3232
const void *new_ptr,
33-
const ecs_type_info_t *ti);
33+
const ecs_type_info_t *ti,
34+
ecs_table_t *prev_table);
3435

3536
/* Add action for sparse components. */
3637
bool flecs_sparse_on_add(

src/entity.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,9 @@ int flecs_traverse_add(
10111011
}
10121012

10131013
/* Find existing table */
1014-
ecs_table_t *src_table = NULL, *table = NULL;
1014+
ecs_table_t *src_table = NULL, *table = NULL, *init_table = NULL;
10151015
ecs_record_t *r = flecs_entities_get(world, result);
1016-
table = r->table;
1016+
init_table = table = r->table;
10171017

10181018
/* Add components from the 'add' array */
10191019
if (desc->add) {
@@ -1093,7 +1093,7 @@ int flecs_traverse_add(
10931093
const ecs_type_info_t *ti = cr->type_info;
10941094
if (ti->hooks.on_replace) {
10951095
flecs_invoke_replace_hook(
1096-
world, r->table, result, v->type, ptr.ptr, v->ptr, ti);
1096+
world, r->table, result, v->type, ptr.ptr, v->ptr, ti, init_table);
10971097
}
10981098
flecs_copy_id(world, result, r, v->type,
10991099
flecs_itosize(ti->size), ptr.ptr, v->ptr, ti);
@@ -2314,7 +2314,7 @@ void flecs_set_id_move(
23142314

23152315
if (ti->hooks.on_replace) {
23162316
flecs_invoke_replace_hook(
2317-
world, prev_table, entity, component, dst.ptr, ptr, ti);
2317+
world, prev_table, entity, component, dst.ptr, ptr, ti, prev_table);
23182318
}
23192319

23202320
if (cmd_kind != EcsCmdEmplace) {
@@ -2389,7 +2389,7 @@ void ecs_set_id(
23892389

23902390
if (dst.ti->hooks.on_replace) {
23912391
flecs_invoke_replace_hook(
2392-
world, prev_table, entity, component, dst.ptr, ptr, dst.ti);
2392+
world, prev_table, entity, component, dst.ptr, ptr, dst.ti, prev_table);
23932393
}
23942394

23952395
flecs_copy_id(world, entity, r, component, size, dst.ptr, ptr, dst.ti);

test/addons/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,6 @@ const char* MultiThread_worker_kind_param[] = {"thread", "task"};
27532753
bake_test_param MultiThread_params[] = {
27542754
{"worker_kind", (char**)MultiThread_worker_kind_param, 2}
27552755
};
2756-
27572756
const char* MultiThreadStaging_worker_kind_param[] = {"thread", "task"};
27582757
bake_test_param MultiThreadStaging_params[] = {
27592758
{"worker_kind", (char**)MultiThreadStaging_worker_kind_param, 2}

test/collections/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ bake_test_case Allocator_testcases[] = {
497497
}
498498
};
499499

500+
500501
static bake_test_suite suites[] = {
501502
{
502503
"Map",

test/core/src/ComponentLifecycle.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,16 +4730,16 @@ void ComponentLifecycle_on_replace_other_table_entity_init(void) {
47304730
.ctx = &ctx,
47314731
});
47324732

4733-
/* Entity created with .set: component values set after commit to final table.
4734-
* r->table already equals the final {Position} table at hook call time. */
4733+
/* init_table = r->table before any components added (root, no Position).
4734+
* set_fields=2: bit 0 unset, new add. */
47354735
ecs_entity_t e = ecs_entity(world, {
47364736
.set = ecs_values(ecs_value(Position, {10, 20}))
47374737
});
47384738
test_int(ctx.invoked, 1);
47394739

4740-
ecs_table_t *table = ecs_get_table(world, e);
4741-
test_assert(ctx.other_table == table);
4742-
test_assert(ctx.set_fields == 3);
4740+
test_assert(ctx.other_table != ecs_get_table(world, e));
4741+
test_assert(!(ctx.set_fields & 1));
4742+
test_assert(ctx.set_fields & 2);
47434743

47444744
ecs_fini(world);
47454745
}

test/cpp_addons/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ bake_test_case Doc_testcases[] = {
399399
}
400400
};
401401

402+
402403
static bake_test_suite suites[] = {
403404
{
404405
"Misc",

test/meta/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5883,6 +5883,7 @@ bake_test_case RttCompare_testcases[] = {
58835883
}
58845884
};
58855885

5886+
58865887
static bake_test_suite suites[] = {
58875888
{
58885889
"PrimitiveTypes",

0 commit comments

Comments
 (0)