From d58ace926d87e3e2fdb253ad0935d5ffb4b89cb6 Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Mon, 7 Oct 2024 23:43:31 -0700 Subject: [PATCH] #1390 Fix issue with modified where first type is a tag --- distr/flecs.h | 8 +++-- include/flecs/addons/cpp/entity.hpp | 8 +++-- test/cpp/project.json | 4 ++- test/cpp/src/Pairs.cpp | 47 +++++++++++++++++++++++++++++ test/cpp/src/main.cpp | 12 +++++++- 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/distr/flecs.h b/distr/flecs.h index af48a9b005..11ae2c1aa1 100644 --- a/distr/flecs.h +++ b/distr/flecs.h @@ -25516,9 +25516,13 @@ struct entity : entity_builder * @tparam First The first part of the pair. * @tparam Second the second part of the pair. */ - template + template >> void modified() const { - this->modified(_::type::id(world_)); + auto first = _::type::id(world_); + auto second = _::type::id(world_); + ecs_assert(_::type::size() != 0, ECS_INVALID_PARAMETER, + "operation invalid for empty type"); + this->modified(first, second); } /** Signal that the first part of a pair was modified. diff --git a/include/flecs/addons/cpp/entity.hpp b/include/flecs/addons/cpp/entity.hpp index 040b09f907..a8cce4dffa 100644 --- a/include/flecs/addons/cpp/entity.hpp +++ b/include/flecs/addons/cpp/entity.hpp @@ -191,9 +191,13 @@ struct entity : entity_builder * @tparam First The first part of the pair. * @tparam Second the second part of the pair. */ - template + template >> void modified() const { - this->modified(_::type::id(world_)); + auto first = _::type::id(world_); + auto second = _::type::id(world_); + ecs_assert(_::type::size() != 0, ECS_INVALID_PARAMETER, + "operation invalid for empty type"); + this->modified(first, second); } /** Signal that the first part of a pair was modified. diff --git a/test/cpp/project.json b/test/cpp/project.json index bbea71e780..7d35c391a8 100644 --- a/test/cpp/project.json +++ b/test/cpp/project.json @@ -363,7 +363,9 @@ "deref_pair_obj", "deref_const_pair_obj", "set_R_existing_value", - "symmetric_w_childof" + "symmetric_w_childof", + "modified_tag_second", + "modified_tag_first" ] }, { "id": "Enum", diff --git a/test/cpp/src/Pairs.cpp b/test/cpp/src/Pairs.cpp index 160e06ed16..48694723e5 100644 --- a/test/cpp/src/Pairs.cpp +++ b/test/cpp/src/Pairs.cpp @@ -1253,3 +1253,50 @@ void Pairs_symmetric_w_childof(void) { test_assert(bob.has(alice)); } + +void Pairs_modified_tag_second(void) { + flecs::world ecs; + + int32_t count = 0; + ecs.observer() + .term_at(0).second() + .event(flecs::OnSet) + .each([&](Position& p) { + test_int(p.x, 10); + test_int(p.y, 20); + count ++; + }); + + flecs::entity e = ecs.entity(); + + Position& p = e.ensure(); + p.x = 10; + p.y = 20; + e.modified(); + + test_int(count, 1); +} + +void Pairs_modified_tag_first(void) { + flecs::world ecs; + + int32_t count = 0; + ecs.observer() + .with() + .event(flecs::OnSet) + .each([&](flecs::iter& it, size_t row) { + auto p = it.field_at(0, row); + test_int(p.x, 10); + test_int(p.y, 20); + count ++; + }); + + flecs::entity e = ecs.entity(); + + Position& p = e.ensure(); + p.x = 10; + p.y = 20; + e.modified(); + + test_int(count, 1); +} diff --git a/test/cpp/src/main.cpp b/test/cpp/src/main.cpp index 1055236a1a..d1fdaf7e55 100644 --- a/test/cpp/src/main.cpp +++ b/test/cpp/src/main.cpp @@ -354,6 +354,8 @@ void Pairs_deref_pair_obj(void); void Pairs_deref_const_pair_obj(void); void Pairs_set_R_existing_value(void); void Pairs_symmetric_w_childof(void); +void Pairs_modified_tag_second(void); +void Pairs_modified_tag_first(void); // Testsuite 'Enum' void Enum_standard_enum_reflection(void); @@ -2745,6 +2747,14 @@ bake_test_case Pairs_testcases[] = { { "symmetric_w_childof", Pairs_symmetric_w_childof + }, + { + "modified_tag_second", + Pairs_modified_tag_second + }, + { + "modified_tag_first", + Pairs_modified_tag_first } }; @@ -6739,7 +6749,7 @@ static bake_test_suite suites[] = { "Pairs", NULL, NULL, - 68, + 70, Pairs_testcases }, {