Skip to content

Commit

Permalink
#81 fix issue with using ECS_SINGLETON as parent entity
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 12, 2019
1 parent 6d03882 commit 54c33db
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extern ecs_type_t
#define ECS_CHILDOF ((ecs_entity_t)1 << 62)
#define ECS_ENTITY_FLAGS_MASK ((ecs_entity_t)(ECS_INSTANCEOF | ECS_CHILDOF))
#define ECS_ENTITY_MASK ((ecs_entity_t)~ECS_ENTITY_FLAGS_MASK)
#define ECS_SINGLETON ((ecs_entity_t)(ECS_ENTITY_FLAGS_MASK - 1))
#define ECS_SINGLETON ((ecs_entity_t)(ECS_ENTITY_MASK) - 1)
#define ECS_INVALID_ENTITY (0)

/* This allows passing 0 as type to functions that accept types */
Expand Down
3 changes: 2 additions & 1 deletion test/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@
"get_parent",
"get_parent_no_matching_comp",
"get_parent_two_parents",
"get_parent_no_parent"
"get_parent_no_parent",
"singleton_as_container"
]
}, {
"id": "Prefab",
Expand Down
22 changes: 22 additions & 0 deletions test/api/src/Container.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,25 @@ void Container_get_parent_no_parent() {

ecs_fini(world);
}

void Container_singleton_as_container() {
ecs_world_t *world = ecs_init();

test_assert(((ECS_CHILDOF | ECS_SINGLETON) & ECS_ENTITY_MASK) == ECS_SINGLETON);

ECS_COMPONENT(world, Position);

ecs_entity_t child = ecs_new_child(world, ECS_SINGLETON, Position);

test_assert( ecs_contains(world, ECS_SINGLETON, child));
test_assert( ecs_has(world, child, Position));

ecs_type_t type = ecs_get_type(world, child);
ecs_entity_t *entities = ecs_vector_first(type);
test_assert(entities[0] == ecs_entity(Position));
test_assert(entities[1] == (ECS_CHILDOF | ECS_SINGLETON));
test_assert(!(entities[1] & ECS_INSTANCEOF));
test_assert((entities[1] & ECS_ENTITY_MASK) == ECS_SINGLETON);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ void Container_get_parent(void);
void Container_get_parent_no_matching_comp(void);
void Container_get_parent_two_parents(void);
void Container_get_parent_no_parent(void);
void Container_singleton_as_container(void);

// Testsuite 'Prefab'
void Prefab_new_w_prefab(void);
Expand Down Expand Up @@ -2420,7 +2421,7 @@ static bake_test_suite suites[] = {
},
{
.id = "Container",
.testcase_count = 26,
.testcase_count = 27,
.testcases = (bake_test_case[]){
{
.id = "child",
Expand Down Expand Up @@ -2525,6 +2526,10 @@ static bake_test_suite suites[] = {
{
.id = "get_parent_no_parent",
.function = Container_get_parent_no_parent
},
{
.id = "singleton_as_container",
.function = Container_singleton_as_container
}
}
},
Expand Down

0 comments on commit 54c33db

Please sign in to comment.