Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8014,10 +8014,11 @@ ecs_record_t* flecs_new_entity(
ecs_flags32_t evt_flags)
{
ecs_assert(r != NULL, ECS_INTERNAL_ERROR, NULL);
int32_t row = ecs_table_count(table);
r->table = &world->store.root;
flecs_table_append(world, table, entity, ctor, true);
int32_t row = ecs_table_count(table) - 1;
r->table = table;
r->row = ECS_ROW_TO_RECORD(row, r->row & ECS_ROW_FLAGS_MASK);
flecs_table_append(world, table, entity, ctor, true);

ecs_assert(ecs_table_count(table) > row, ECS_INTERNAL_ERROR, NULL);
flecs_actions_new(world, table, row, 1, diff, evt_flags, ctor, true);
Expand Down Expand Up @@ -8056,14 +8057,12 @@ void flecs_move_entity(
/* Invoke remove actions for removed components */
flecs_actions_move_remove(world, src_table, dst_table, src_row, 1, diff);

record->table = dst_table;
record->row = ECS_ROW_TO_RECORD(dst_row, record->row & ECS_ROW_FLAGS_MASK);

/* Copy entity & components from src_table to dst_table */
flecs_table_move(world, entity, entity, dst_table, dst_row,
src_table, src_row, ctor);
ecs_assert(record->table == dst_table, ECS_INTERNAL_ERROR, NULL);

record->table = dst_table;
record->row = ECS_ROW_TO_RECORD(dst_row, record->row & ECS_ROW_FLAGS_MASK);

flecs_table_delete(world, src_table, src_row, false);

flecs_actions_move_add(world, dst_table, src_table, dst_row, 1, diff,
Expand Down
13 changes: 6 additions & 7 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ ecs_record_t* flecs_new_entity(
ecs_flags32_t evt_flags)
{
ecs_assert(r != NULL, ECS_INTERNAL_ERROR, NULL);
int32_t row = ecs_table_count(table);
r->table = &world->store.root;
flecs_table_append(world, table, entity, ctor, true);
int32_t row = ecs_table_count(table) - 1;
r->table = table;
r->row = ECS_ROW_TO_RECORD(row, r->row & ECS_ROW_FLAGS_MASK);
flecs_table_append(world, table, entity, ctor, true);

ecs_assert(ecs_table_count(table) > row, ECS_INTERNAL_ERROR, NULL);
flecs_actions_new(world, table, row, 1, diff, evt_flags, ctor, true);
Expand Down Expand Up @@ -213,14 +214,12 @@ void flecs_move_entity(
/* Invoke remove actions for removed components */
flecs_actions_move_remove(world, src_table, dst_table, src_row, 1, diff);

record->table = dst_table;
record->row = ECS_ROW_TO_RECORD(dst_row, record->row & ECS_ROW_FLAGS_MASK);

/* Copy entity & components from src_table to dst_table */
flecs_table_move(world, entity, entity, dst_table, dst_row,
src_table, src_row, ctor);
ecs_assert(record->table == dst_table, ECS_INTERNAL_ERROR, NULL);

record->table = dst_table;
record->row = ECS_ROW_TO_RECORD(dst_row, record->row & ECS_ROW_FLAGS_MASK);

flecs_table_delete(world, src_table, src_row, false);

flecs_actions_move_add(world, dst_table, src_table, dst_row, 1, diff,
Expand Down
4 changes: 2 additions & 2 deletions test/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,6 @@
"delete_mixed_tree_3",
"delete_mixed_tree_4",
"delete_mixed_tree_5",
"instantiate_parent_w_has_in_hook",
"add_prefab_tag_after_hierarchy_creation",
"defer_add_prefab_tag_after_hierarchy_creation",
"add_prefab_tag_after_hierarchy_creation_2",
Expand Down Expand Up @@ -1713,7 +1712,8 @@
"has_in_on_add_hook_new",
"has_in_on_add_hook_move",
"get_in_on_add_hook_new",
"get_in_on_add_hook_move"
"get_in_on_add_hook_move",
"get_name_in_on_add_hook_move"
]
}, {
"id": "Pairs",
Expand Down
41 changes: 37 additions & 4 deletions test/core/src/ComponentLifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -4418,7 +4418,7 @@ static void HasHook(ecs_iter_t *it) {

for (int i = 0; i < it->count; i ++) {
ecs_entity_t e = it->entities[i];
test_assert(ecs_has(world, e, Position));
test_assert(!ecs_has(world, e, Position));
has_hook_invoked ++;
}
}
Expand All @@ -4431,13 +4431,12 @@ static void GetHook(ecs_iter_t *it) {

for (int i = 0; i < it->count; i ++) {
ecs_entity_t e = it->entities[i];
test_assert(ecs_has(world, e, Position));
test_assert(ecs_get(world, e, Position) == &p[i]);
test_assert(!ecs_has(world, e, Position));
test_assert(ecs_get(world, e, Position) == NULL);
get_hook_invoked ++;
}
}


void ComponentLifecycle_has_in_on_add_hook_new(void) {
ecs_world_t *world = ecs_mini();

Expand Down Expand Up @@ -4513,3 +4512,37 @@ void ComponentLifecycle_get_in_on_add_hook_move(void) {

ecs_fini(world);
}

static int get_name_hook_invoked = 0;

static void GetNameHook(ecs_iter_t *it) {
ecs_world_t *world = it->world;

for (int i = 0; i < it->count; i ++) {
ecs_entity_t e = it->entities[i];
const char *name = ecs_get_name(world, e);
test_assert(name != NULL);
test_str(name, "TestEntity");
get_name_hook_invoked ++;
}
}

void ComponentLifecycle_get_name_in_on_add_hook_move(void) {
ecs_world_t *world = ecs_mini();

ECS_COMPONENT_DEFINE(world, Position);

ecs_set_hooks(world, Position, {
.on_add = GetNameHook
});

ecs_entity_t e = ecs_entity(world, { .name = "TestEntity" });
test_int(get_name_hook_invoked, 0);

ecs_add(world, e, Position);
test_int(get_name_hook_invoked, 1);

test_str(ecs_get_name(world, e), "TestEntity");

ecs_fini(world);
}
37 changes: 0 additions & 37 deletions test/core/src/NonFragmentingChildOf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6055,43 +6055,6 @@ void NonFragmentingChildOf_delete_mixed_tree_5(void) {
ecs_fini(world);
}

static int dummy_hook_invoked = 0;

static void DummyHook(ecs_iter_t *it) {
ecs_world_t *world = it->world;
Position *p = ecs_field(it, Position, 0);

for (int i = 0; i < it->count; i ++) {
ecs_entity_t e = it->entities[i];
test_assert(ecs_has(world, e, Position));
test_assert(ecs_get(world, e, Position) == &p[i]);
dummy_hook_invoked ++;
}
}

void NonFragmentingChildOf_instantiate_parent_w_has_in_hook(void) {
ecs_world_t* world = ecs_mini();

ECS_COMPONENT_DEFINE(world, Position);

ecs_set_hooks(world, Position, {
.on_add = DummyHook
});

ecs_entity_t prefab = ecs_new_w_id(world, EcsPrefab);
ecs_entity_t prefab_child = ecs_new_w_parent(world, prefab, NULL);
ecs_set(world, prefab_child, Position, {10, 20});
test_int(dummy_hook_invoked, 1);

ecs_new_w_pair(world, EcsIsA, prefab);
test_int(dummy_hook_invoked, 2);

ecs_new_w_pair(world, EcsIsA, prefab);
test_int(dummy_hook_invoked, 3);

ecs_fini(world);
}

void NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation(void) {
ecs_world_t* world = ecs_mini();

Expand Down
14 changes: 7 additions & 7 deletions test/core/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ void NonFragmentingChildOf_delete_mixed_tree_2(void);
void NonFragmentingChildOf_delete_mixed_tree_3(void);
void NonFragmentingChildOf_delete_mixed_tree_4(void);
void NonFragmentingChildOf_delete_mixed_tree_5(void);
void NonFragmentingChildOf_instantiate_parent_w_has_in_hook(void);
void NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation(void);
void NonFragmentingChildOf_defer_add_prefab_tag_after_hierarchy_creation(void);
void NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation_2(void);
Expand Down Expand Up @@ -1653,6 +1652,7 @@ void ComponentLifecycle_has_in_on_add_hook_new(void);
void ComponentLifecycle_has_in_on_add_hook_move(void);
void ComponentLifecycle_get_in_on_add_hook_new(void);
void ComponentLifecycle_get_in_on_add_hook_move(void);
void ComponentLifecycle_get_name_in_on_add_hook_move(void);

// Testsuite 'Pairs'
void Pairs_type_w_one_pair(void);
Expand Down Expand Up @@ -6937,10 +6937,6 @@ bake_test_case NonFragmentingChildOf_testcases[] = {
"delete_mixed_tree_5",
NonFragmentingChildOf_delete_mixed_tree_5
},
{
"instantiate_parent_w_has_in_hook",
NonFragmentingChildOf_instantiate_parent_w_has_in_hook
},
{
"add_prefab_tag_after_hierarchy_creation",
NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation
Expand Down Expand Up @@ -9654,6 +9650,10 @@ bake_test_case ComponentLifecycle_testcases[] = {
{
"get_in_on_add_hook_move",
ComponentLifecycle_get_in_on_add_hook_move
},
{
"get_name_in_on_add_hook_move",
ComponentLifecycle_get_name_in_on_add_hook_move
}
};

Expand Down Expand Up @@ -15960,7 +15960,7 @@ static bake_test_suite suites[] = {
"NonFragmentingChildOf",
NULL,
NULL,
239,
238,
NonFragmentingChildOf_testcases
},
{
Expand Down Expand Up @@ -16058,7 +16058,7 @@ static bake_test_suite suites[] = {
"ComponentLifecycle",
ComponentLifecycle_setup,
NULL,
138,
139,
ComponentLifecycle_testcases
},
{
Expand Down
Loading