Skip to content

Commit

Permalink
#1000 Fix issue with calling .get() on table/range from stage
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jul 6, 2023
1 parent d073a1a commit 798f735
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29666,11 +29666,11 @@ inline flecs::type iter::type() const {
}

inline flecs::table iter::table() const {
return flecs::table(m_iter->world, m_iter->table);
return flecs::table(m_iter->real_world, m_iter->table);
}

inline flecs::table_range iter::range() const {
return flecs::table_range(m_iter->world, m_iter->table,
return flecs::table_range(m_iter->real_world, m_iter->table,
m_iter->offset, m_iter->count);
}

Expand Down
4 changes: 2 additions & 2 deletions include/flecs/addons/cpp/impl/iter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ inline flecs::type iter::type() const {
}

inline flecs::table iter::table() const {
return flecs::table(m_iter->world, m_iter->table);
return flecs::table(m_iter->real_world, m_iter->table);
}

inline flecs::table_range iter::range() const {
return flecs::table_range(m_iter->world, m_iter->table,
return flecs::table_range(m_iter->real_world, m_iter->table,
m_iter->offset, m_iter->count);
}

Expand Down
4 changes: 3 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@
"startup_system",
"interval_tick_source",
"rate_tick_source",
"nested_rate_tick_source"
"nested_rate_tick_source",
"table_get",
"range_get"
]
}, {
"id": "Event",
Expand Down
50 changes: 50 additions & 0 deletions test/cpp_api/src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,3 +2146,53 @@ void System_nested_rate_tick_source() {
test_int(2, sys_a_invoked);
test_int(1, sys_b_invoked);
}

void System_table_get() {
flecs::world ecs;

flecs::entity e1 = ecs.entity().set<Position>({10, 20});
flecs::entity e2 = ecs.entity().set<Position>({20, 30});

auto s = ecs.system()
.with<Position>()
.each([&](flecs::iter& iter, size_t index) {
flecs::entity e = iter.entity(index);
const Position *p = &iter.table().get<Position>()[index];
test_assert(p != nullptr);
test_assert(e == e1 || e == e2);
if (e == e1) {
test_int(p->x, 10);
test_int(p->y, 20);
} else if (e == e2) {
test_int(p->x, 20);
test_int(p->y, 30);
}
});

s.run();
}

void System_range_get() {
flecs::world ecs;

flecs::entity e1 = ecs.entity().set<Position>({10, 20});
flecs::entity e2 = ecs.entity().set<Position>({20, 30});

auto s = ecs.system()
.with<Position>()
.each([&](flecs::iter& iter, size_t index) {
flecs::entity e = iter.entity(index);
const Position *p = &iter.range().get<Position>()[index];
test_assert(p != nullptr);
test_assert(e == e1 || e == e2);
if (e == e1) {
test_int(p->x, 10);
test_int(p->y, 20);
} else if (e == e2) {
test_int(p->x, 20);
test_int(p->y, 30);
}
});

s.run();
}
12 changes: 11 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ void System_startup_system(void);
void System_interval_tick_source(void);
void System_rate_tick_source(void);
void System_nested_rate_tick_source(void);
void System_table_get(void);
void System_range_get(void);

// Testsuite 'Event'
void Event_evt_1_id_entity(void);
Expand Down Expand Up @@ -3010,6 +3012,14 @@ bake_test_case System_testcases[] = {
{
"nested_rate_tick_source",
System_nested_rate_tick_source
},
{
"table_get",
System_table_get
},
{
"range_get",
System_range_get
}
};

Expand Down Expand Up @@ -6091,7 +6101,7 @@ static bake_test_suite suites[] = {
"System",
NULL,
NULL,
64,
66,
System_testcases
},
{
Expand Down

0 comments on commit 798f735

Please sign in to comment.