Skip to content

Commit 2711ece

Browse files
#1855 Don't create component record when registering trait
1 parent 76c7900 commit 2711ece

File tree

8 files changed

+41
-14
lines changed

8 files changed

+41
-14
lines changed

distr/flecs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,7 +4079,7 @@ void flecs_register_flag_for_trait(
40794079
flecs_errstr_1(ecs_id_str(world, e)));
40804080
}
40814081

4082-
ecs_component_record_t *cr = flecs_components_ensure(world, e);
4082+
ecs_component_record_t *cr = flecs_components_get(world, e);
40834083
if (cr) {
40844084
changed |= flecs_set_id_flag(world, cr, flag, trait);
40854085
}
@@ -37652,7 +37652,7 @@ void flecs_component_record_check_constraints(
3765237652
flecs_errstr(ecs_get_path(world, rel)));
3765337653
} else {
3765437654
ecs_throw(ECS_CONSTRAINT_VIOLATED,
37655-
"cannot use '%s' by itself: it has the Relationhip trait "
37655+
"cannot use '%s' by itself: it has the Relationship trait "
3765637656
"and must be used in pair with target",
3765737657
flecs_errstr(ecs_get_path(world, rel)));
3765837658
}
@@ -43389,9 +43389,9 @@ void flecs_add_overrides_for_base(
4338943389
ecs_id_t to_add = 0;
4339043390
if (ECS_HAS_ID_FLAG(id, AUTO_OVERRIDE)) {
4339143391
to_add = id & ~ECS_AUTO_OVERRIDE;
43392-
ecs_component_record_t *cr = flecs_components_get(
43393-
world, to_add);
43394-
if (cr && (cr->flags & EcsIdDontFragment)) {
43392+
43393+
ecs_flags32_t cr_flags = flecs_component_get_flags(world, to_add);
43394+
if (cr_flags & EcsIdDontFragment) {
4339543395
to_add = 0;
4339643396

4339743397
/* Add flag to base table. Cheaper to do here vs adding an

src/bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void flecs_register_flag_for_trait(
209209
flecs_errstr_1(ecs_id_str(world, e)));
210210
}
211211

212-
ecs_component_record_t *cr = flecs_components_ensure(world, e);
212+
ecs_component_record_t *cr = flecs_components_get(world, e);
213213
if (cr) {
214214
changed |= flecs_set_id_flag(world, cr, flag, trait);
215215
}

src/storage/component_index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ void flecs_component_record_check_constraints(
513513
flecs_errstr(ecs_get_path(world, rel)));
514514
} else {
515515
ecs_throw(ECS_CONSTRAINT_VIOLATED,
516-
"cannot use '%s' by itself: it has the Relationhip trait "
516+
"cannot use '%s' by itself: it has the Relationship trait "
517517
"and must be used in pair with target",
518518
flecs_errstr(ecs_get_path(world, rel)));
519519
}

src/storage/table_graph.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,9 @@ void flecs_add_overrides_for_base(
866866
ecs_id_t to_add = 0;
867867
if (ECS_HAS_ID_FLAG(id, AUTO_OVERRIDE)) {
868868
to_add = id & ~ECS_AUTO_OVERRIDE;
869-
ecs_component_record_t *cr = flecs_components_get(
870-
world, to_add);
871-
if (cr && (cr->flags & EcsIdDontFragment)) {
869+
870+
ecs_flags32_t cr_flags = flecs_component_get_flags(world, to_add);
871+
if (cr_flags & EcsIdDontFragment) {
872872
to_add = 0;
873873

874874
/* Add flag to base table. Cheaper to do here vs adding an

test/addons/src/Memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void Memory_sparse_component_memory(void) {
419419

420420
{
421421
ecs_component_memory_t mem = ecs_component_memory_get(world);
422-
test_assert(mem.bytes_sparse_components > 0);
422+
test_assert(mem.bytes_sparse_components == 0);
423423
}
424424

425425
ecs_new_w(world, Position);
@@ -446,7 +446,7 @@ void Memory_sparse_tag_memory(void) {
446446

447447
{
448448
ecs_component_memory_t mem = ecs_component_memory_get(world);
449-
test_assert(mem.bytes_sparse_components > 0);
449+
test_assert(mem.bytes_sparse_components == 0);
450450
}
451451

452452
ecs_add_id(world, Foo, EcsSparse);

test/core/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,8 @@
15221522
"force_relationship_on_relationship",
15231523
"force_target_on_component",
15241524
"force_target_on_relationship",
1525-
"force_target_on_target"
1525+
"force_target_on_target",
1526+
"relationship_with_exclusive"
15261527
]
15271528
}, {
15281529
"id": "Trigger",

test/core/src/Pairs.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,3 +3218,24 @@ void Pairs_force_target_on_target(void) {
32183218
ecs_fini(world);
32193219
}
32203220

3221+
void Pairs_relationship_with_exclusive(void) {
3222+
ecs_world_t *world = ecs_mini();
3223+
3224+
ecs_entity_t Rel = ecs_new(world);
3225+
ecs_add_id(world, Rel, EcsRelationship);
3226+
ecs_add_id(world, Rel, EcsExclusive);
3227+
3228+
ecs_entity_t tgt_a = ecs_new(world);
3229+
ecs_entity_t tgt_b = ecs_new(world);
3230+
3231+
ecs_entity_t e = ecs_new(world);
3232+
ecs_add_pair(world, e, Rel, tgt_a);
3233+
test_assert(ecs_has_pair(world, e, Rel, tgt_a));
3234+
test_assert(!ecs_has_pair(world, e, Rel, tgt_b));
3235+
3236+
ecs_add_pair(world, e, Rel, tgt_b);
3237+
test_assert(!ecs_has_pair(world, e, Rel, tgt_a));
3238+
test_assert(ecs_has_pair(world, e, Rel, tgt_b));
3239+
3240+
ecs_fini(world);
3241+
}

test/core/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ void Pairs_force_relationship_on_relationship(void);
14621462
void Pairs_force_target_on_component(void);
14631463
void Pairs_force_target_on_relationship(void);
14641464
void Pairs_force_target_on_target(void);
1465+
void Pairs_relationship_with_exclusive(void);
14651466

14661467
// Testsuite 'Trigger'
14671468
void Trigger_on_add_trigger_before_table(void);
@@ -8457,6 +8458,10 @@ bake_test_case Pairs_testcases[] = {
84578458
{
84588459
"force_target_on_target",
84598460
Pairs_force_target_on_target
8461+
},
8462+
{
8463+
"relationship_with_exclusive",
8464+
Pairs_relationship_with_exclusive
84608465
}
84618466
};
84628467

@@ -13898,7 +13903,7 @@ static bake_test_suite suites[] = {
1389813903
"Pairs",
1389913904
NULL,
1390013905
NULL,
13901-
125,
13906+
126,
1390213907
Pairs_testcases
1390313908
},
1390413909
{

0 commit comments

Comments
 (0)