From 66dca4e12c7ef1dcc08cd6dc2e262945d31f42a1 Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Thu, 11 May 2023 11:53:22 -0700 Subject: [PATCH] Change return type of world::id() to flecs::entity --- flecs.h | 6 +++--- include/flecs/addons/cpp/mixins/id/impl.hpp | 4 ++-- include/flecs/addons/cpp/mixins/id/mixin.inl | 2 +- test/cpp_api/project.json | 3 ++- test/cpp_api/src/Entity.cpp | 10 ++++++++++ test/cpp_api/src/main.cpp | 7 ++++++- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/flecs.h b/flecs.h index 4148cec28..c48e07b02 100644 --- a/flecs.h +++ b/flecs.h @@ -19189,7 +19189,7 @@ struct world { * \memberof flecs::world */ template -flecs::id id() const; +flecs::entity id() const; /** Id factory. * @@ -24810,8 +24810,8 @@ inline flecs::entity id::type_id() const { // Id mixin implementation template -inline flecs::id world::id() const { - return flecs::id(m_world, _::cpp_type::id(m_world)); +inline flecs::entity world::id() const { + return flecs::entity(m_world, _::cpp_type::id(m_world)); } template diff --git a/include/flecs/addons/cpp/mixins/id/impl.hpp b/include/flecs/addons/cpp/mixins/id/impl.hpp index e4e4df459..7989aff72 100644 --- a/include/flecs/addons/cpp/mixins/id/impl.hpp +++ b/include/flecs/addons/cpp/mixins/id/impl.hpp @@ -67,8 +67,8 @@ inline flecs::entity id::type_id() const { // Id mixin implementation template -inline flecs::id world::id() const { - return flecs::id(m_world, _::cpp_type::id(m_world)); +inline flecs::entity world::id() const { + return flecs::entity(m_world, _::cpp_type::id(m_world)); } template diff --git a/include/flecs/addons/cpp/mixins/id/mixin.inl b/include/flecs/addons/cpp/mixins/id/mixin.inl index 344bad9c1..36c903011 100644 --- a/include/flecs/addons/cpp/mixins/id/mixin.inl +++ b/include/flecs/addons/cpp/mixins/id/mixin.inl @@ -8,7 +8,7 @@ * \memberof flecs::world */ template -flecs::id id() const; +flecs::entity id() const; /** Id factory. * diff --git a/test/cpp_api/project.json b/test/cpp_api/project.json index cf4c06ba6..94dada04c 100644 --- a/test/cpp_api/project.json +++ b/test/cpp_api/project.json @@ -259,7 +259,8 @@ "to_view", "to_view_from_stage", "set_alias", - "emplace_w_observer" + "emplace_w_observer", + "world_id_to_entity" ] }, { "id": "Pairs", diff --git a/test/cpp_api/src/Entity.cpp b/test/cpp_api/src/Entity.cpp index c64944f02..bf7e34ea3 100644 --- a/test/cpp_api/src/Entity.cpp +++ b/test/cpp_api/src/Entity.cpp @@ -4305,3 +4305,13 @@ void Entity_emplace_w_observer() { test_int(e.get()->x, 10); test_int(e.get()->y, 20); } + +void Entity_world_id_to_entity() { + flecs::world ecs; + + flecs::entity e1 = ecs.component(); + flecs::entity e2 = ecs.id(); + test_assert(e1 == e2); + flecs::id id = ecs.id(); + test_assert(e1 == id); +} diff --git a/test/cpp_api/src/main.cpp b/test/cpp_api/src/main.cpp index 885e3f0f4..7dbd66a4b 100644 --- a/test/cpp_api/src/main.cpp +++ b/test/cpp_api/src/main.cpp @@ -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); @@ -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 } }; @@ -5896,7 +5901,7 @@ static bake_test_suite suites[] = { "Entity", NULL, NULL, - 239, + 240, Entity_testcases }, {