Skip to content

Commit

Permalink
Fix issue with modified<R,T> where first type is a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 8, 2024
1 parent b002dcb commit 09cc801
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
8 changes: 6 additions & 2 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25516,9 +25516,13 @@ struct entity : entity_builder<entity>
* @tparam First The first part of the pair.
* @tparam Second the second part of the pair.
*/
template <typename First, typename Second>
template <typename First, typename Second, typename A = actual_type_t<flecs::pair<First, Second>>>
void modified() const {
this->modified<First>(_::type<Second>::id(world_));
auto first = _::type<First>::id(world_);
auto second = _::type<Second>::id(world_);
ecs_assert(_::type<A>::size() != 0, ECS_INVALID_PARAMETER,
"operation invalid for empty type");
this->modified(first, second);
}

/** Signal that the first part of a pair was modified.
Expand Down
8 changes: 6 additions & 2 deletions include/flecs/addons/cpp/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,13 @@ struct entity : entity_builder<entity>
* @tparam First The first part of the pair.
* @tparam Second the second part of the pair.
*/
template <typename First, typename Second>
template <typename First, typename Second, typename A = actual_type_t<flecs::pair<First, Second>>>
void modified() const {
this->modified<First>(_::type<Second>::id(world_));
auto first = _::type<First>::id(world_);
auto second = _::type<Second>::id(world_);
ecs_assert(_::type<A>::size() != 0, ECS_INVALID_PARAMETER,
"operation invalid for empty type");
this->modified(first, second);
}

/** Signal that the first part of a pair was modified.
Expand Down
4 changes: 3 additions & 1 deletion test/cpp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 47 additions & 0 deletions test/cpp/src/Pairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,50 @@ void Pairs_symmetric_w_childof(void) {

test_assert(bob.has<Likes>(alice));
}

void Pairs_modified_tag_second(void) {
flecs::world ecs;

int32_t count = 0;
ecs.observer<Position>()
.term_at(0).second<Tag>()
.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<Position, Tag>();
p.x = 10;
p.y = 20;
e.modified<Position, Tag>();

test_int(count, 1);
}

void Pairs_modified_tag_first(void) {
flecs::world ecs;

int32_t count = 0;
ecs.observer()
.with<Tag, Position>()
.event(flecs::OnSet)
.each([&](flecs::iter& it, size_t row) {
auto p = it.field_at<Position>(0, row);
test_int(p.x, 10);
test_int(p.y, 20);
count ++;
});

flecs::entity e = ecs.entity();

Position& p = e.ensure<Tag, Position>();
p.x = 10;
p.y = 20;
e.modified<Tag, Position>();

test_int(count, 1);
}
12 changes: 11 additions & 1 deletion test/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
};

Expand Down Expand Up @@ -6739,7 +6749,7 @@ static bake_test_suite suites[] = {
"Pairs",
NULL,
NULL,
68,
70,
Pairs_testcases
},
{
Expand Down

0 comments on commit 09cc801

Please sign in to comment.