Skip to content

Commit

Permalink
Change return type of world::id<T>() to flecs::entity
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 11, 2023
1 parent 7828d0b commit 66dca4e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19189,7 +19189,7 @@ struct world {
* \memberof flecs::world
*/
template <typename T>
flecs::id id() const;
flecs::entity id() const;

/** Id factory.
*
Expand Down Expand Up @@ -24810,8 +24810,8 @@ inline flecs::entity id::type_id() const {
// Id mixin implementation

template <typename T>
inline flecs::id world::id() const {
return flecs::id(m_world, _::cpp_type<T>::id(m_world));
inline flecs::entity world::id() const {
return flecs::entity(m_world, _::cpp_type<T>::id(m_world));
}

template <typename ... Args>
Expand Down
4 changes: 2 additions & 2 deletions include/flecs/addons/cpp/mixins/id/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ inline flecs::entity id::type_id() const {
// Id mixin implementation

template <typename T>
inline flecs::id world::id() const {
return flecs::id(m_world, _::cpp_type<T>::id(m_world));
inline flecs::entity world::id() const {
return flecs::entity(m_world, _::cpp_type<T>::id(m_world));
}

template <typename ... Args>
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/cpp/mixins/id/mixin.inl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* \memberof flecs::world
*/
template <typename T>
flecs::id id() const;
flecs::entity id() const;

/** Id factory.
*
Expand Down
3 changes: 2 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
"to_view",
"to_view_from_stage",
"set_alias",
"emplace_w_observer"
"emplace_w_observer",
"world_id_to_entity"
]
}, {
"id": "Pairs",
Expand Down
10 changes: 10 additions & 0 deletions test/cpp_api/src/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4305,3 +4305,13 @@ void Entity_emplace_w_observer() {
test_int(e.get<Position>()->x, 10);
test_int(e.get<Position>()->y, 20);
}

void Entity_world_id_to_entity() {
flecs::world ecs;

flecs::entity e1 = ecs.component<Position>();
flecs::entity e2 = ecs.id<Position>();
test_assert(e1 == e2);
flecs::id id = ecs.id<Position>();
test_assert(e1 == id);
}
7 changes: 6 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void Entity_to_view(void);
void Entity_to_view_from_stage(void);
void Entity_set_alias(void);
void Entity_emplace_w_observer(void);
void Entity_world_id_to_entity(void);

// Testsuite 'Pairs'
void Pairs_add_component_pair(void);
Expand Down Expand Up @@ -2179,6 +2180,10 @@ bake_test_case Entity_testcases[] = {
{
"emplace_w_observer",
Entity_emplace_w_observer
},
{
"world_id_to_entity",
Entity_world_id_to_entity
}
};

Expand Down Expand Up @@ -5896,7 +5901,7 @@ static bake_test_suite suites[] = {
"Entity",
NULL,
NULL,
239,
240,
Entity_testcases
},
{
Expand Down

0 comments on commit 66dca4e

Please sign in to comment.