#include void Table_each(void) { flecs::world ecs; ecs.entity().add(); auto e2 = ecs.entity().add(); ecs.filter() .each([&](flecs::entity e, Position& p) { e2.add(); }); test_assert(e2.has()); } void Table_each_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add(); ecs.filter() .each([&](flecs::entity e, Position& p) { test_expect_abort(); e1.add(); }); test_assert(false); } void Table_each_without_entity(void) { flecs::world ecs; ecs.entity().add(); auto e2 = ecs.entity().add(); ecs.filter() .each([&](Position& p) { e2.add(); }); test_assert(e2.has()); } void Table_each_without_entity_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add(); ecs.filter() .each([&](Position& p) { test_expect_abort(); e1.add(); }); test_assert(false); } void Table_iter(void) { flecs::world ecs; ecs.entity().add(); auto e2 = ecs.entity().add(); ecs.filter() .iter([&](flecs::iter& it, Position* p) { e2.add(); }); test_assert(e2.has()); } void Table_iter_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add(); ecs.filter() .iter([&](flecs::iter& it, Position* p) { test_expect_abort(); e1.add(); }); test_assert(false); } void Table_iter_without_components(void) { flecs::world ecs; ecs.entity().add(); auto e2 = ecs.entity().add(); ecs.filter() .iter([&](flecs::iter& it) { e2.add(); }); test_assert(e2.has()); } void Table_iter_without_components_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add(); ecs.filter() .iter([&](flecs::iter& it) { test_expect_abort(); e1.add(); }); test_assert(false); } void Table_multi_get(void) { flecs::world ecs; auto e1 = ecs.entity().add().add(); auto e2 = ecs.entity().add(); test_bool(true, e1.get([&](const Position& p, const Velocity& v) { e2.add(); })); test_assert(e2.has()); } void Table_multi_get_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add().add(); auto e2 = ecs.entity().add(); test_bool(true, e1.get([&](const Position& p, const Velocity& v) { test_expect_abort(); e2.add(); })); test_assert(false); } void Table_multi_set(void) { flecs::world ecs; auto e1 = ecs.entity().add().add(); auto e2 = ecs.entity().add(); e1.set([&](Position& p, Velocity& v) { e2.add(); }); test_assert(e2.has()); } void Table_multi_set_locked(void) { install_test_abort(); flecs::world ecs; auto e1 = ecs.entity().add().add(); auto e2 = ecs.entity().add(); e1.set([&](Position& p, Velocity& v) { test_expect_abort(); e2.add(); }); test_assert(false); } void Table_count(void) { flecs::world ecs; flecs::entity e = ecs.entity().set({10, 20}); ecs.entity().set({20, 30}); ecs.entity().set({30, 40}); flecs::table table = e.table(); test_int(table.count(), 3); } void Table_has_id(void) { flecs::world ecs; flecs::entity t1 = ecs.entity(); flecs::entity t2 = ecs.entity(); flecs::entity t3 = ecs.entity(); flecs::entity e = ecs.entity() .add(t1) .add(t2); ecs.entity() .add(t1) .add(t2); ecs.entity() .add(t1) .add(t2); flecs::table table = e.table(); test_assert(table.has(t1)); test_assert(table.has(t2)); test_assert(!table.has(t3)); } void Table_has_T(void) { flecs::world ecs; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); test_assert(table.has()); test_assert(table.has()); test_assert(!table.has()); } void Table_has_pair_r_t(void) { flecs::world ecs; flecs::entity r = ecs.entity(); flecs::entity t1 = ecs.entity(); flecs::entity t2 = ecs.entity(); flecs::entity t3 = ecs.entity(); flecs::entity e = ecs.entity() .add(r, t1) .add(r, t2); ecs.entity() .add(r, t1) .add(r, t2); ecs.entity() .add(r, t1) .add(r, t2); flecs::table table = e.table(); test_assert(table.has(r, t1)); test_assert(table.has(r, t2)); test_assert(!table.has(r, t3)); } void Table_has_pair_R_t(void) { flecs::world ecs; struct R { }; flecs::entity t1 = ecs.entity(); flecs::entity t2 = ecs.entity(); flecs::entity t3 = ecs.entity(); flecs::entity e = ecs.entity() .add(t1) .add(t2); ecs.entity() .add(t1) .add(t2); ecs.entity() .add(t1) .add(t2); flecs::table table = e.table(); test_assert(table.has(t1)); test_assert(table.has(t2)); test_assert(!table.has(t3)); } void Table_has_pair_R_T(void) { flecs::world ecs; struct R { }; struct T1 { }; struct T2 { }; struct T3 { }; flecs::entity e = ecs.entity() .add() .add(); ecs.entity() .add() .add(); ecs.entity() .add() .add(); flecs::table table = e.table(); test_assert((table.has())); test_assert((table.has())); test_assert((!table.has())); } void Table_get_id(void) { flecs::world ecs; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); void *ptr = table.get(ecs.id()); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 10); test_int(p[0].y, 20); test_int(p[1].x, 20); test_int(p[1].y, 30); test_int(p[2].x, 30); test_int(p[2].y, 40); ptr = table.get(ecs.id()); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 1); test_int(v[0].y, 2); test_int(v[1].x, 2); test_int(v[1].y, 3); test_int(v[2].x, 3); test_int(v[2].y, 4); } void Table_get_T(void) { flecs::world ecs; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); Position *p = table.get(); test_assert(p != NULL); test_int(p[0].x, 10); test_int(p[0].y, 20); test_int(p[1].x, 20); test_int(p[1].y, 30); test_int(p[2].x, 30); test_int(p[2].y, 40); Velocity *v = table.get(); test_assert(v != NULL); test_int(v[0].x, 1); test_int(v[0].y, 2); test_int(v[1].x, 2); test_int(v[1].y, 3); test_int(v[2].x, 3); test_int(v[2].y, 4); } void Table_get_pair_r_t(void) { flecs::world ecs; struct Tgt { }; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); void *ptr = table.get(ecs.id(), ecs.id()); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 10); test_int(p[0].y, 20); test_int(p[1].x, 20); test_int(p[1].y, 30); test_int(p[2].x, 30); test_int(p[2].y, 40); ptr = table.get(ecs.id(), ecs.id()); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 1); test_int(v[0].y, 2); test_int(v[1].x, 2); test_int(v[1].y, 3); test_int(v[2].x, 3); test_int(v[2].y, 4); } void Table_get_pair_R_t(void) { flecs::world ecs; struct Tgt { }; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); void *ptr = table.get(ecs.id()); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 10); test_int(p[0].y, 20); test_int(p[1].x, 20); test_int(p[1].y, 30); test_int(p[2].x, 30); test_int(p[2].y, 40); ptr = table.get(ecs.id()); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 1); test_int(v[0].y, 2); test_int(v[1].x, 2); test_int(v[1].y, 3); test_int(v[2].x, 3); test_int(v[2].y, 4); } void Table_get_pair_R_T(void) { flecs::world ecs; struct Tgt { }; flecs::entity e = ecs.entity() .set({10, 20}) .set({1, 2}); ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table table = e.table(); void *ptr = table.get(); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 10); test_int(p[0].y, 20); test_int(p[1].x, 20); test_int(p[1].y, 30); test_int(p[2].x, 30); test_int(p[2].y, 40); ptr = table.get(); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 1); test_int(v[0].y, 2); test_int(v[1].x, 2); test_int(v[1].y, 3); test_int(v[2].x, 3); test_int(v[2].y, 4); } void Table_range_get_id(void) { flecs::world ecs; ecs.entity() .set({10, 20}) .set({1, 2}); flecs::entity e = ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table_range table = e.range(); void *ptr = table.get(ecs.id()); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 20); test_int(p[0].y, 30); ptr = table.get(ecs.id()); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 2); test_int(v[0].y, 3); } void Table_range_get_T(void) { flecs::world ecs; ecs.entity() .set({10, 20}) .set({1, 2}); flecs::entity e = ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table_range table = e.range(); Position *p = table.get(); test_assert(p != NULL); test_int(p[0].x, 20); test_int(p[0].y, 30); Velocity *v = table.get(); test_assert(v != NULL); test_int(v[0].x, 2); test_int(v[0].y, 3); } void Table_range_get_pair_r_t(void) { flecs::world ecs; struct Tgt { }; ecs.entity() .set({10, 20}) .set({1, 2}); flecs::entity e = ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table_range table = e.range(); void *ptr = table.get(ecs.id(), ecs.id()); Position *p = static_cast(ptr); test_assert(p != NULL); test_int(p[0].x, 20); test_int(p[0].y, 30); ptr = table.get(ecs.id(), ecs.id()); Velocity *v = static_cast(ptr); test_assert(v != NULL); test_int(v[0].x, 2); test_int(v[0].y, 3); } void Table_range_get_pair_R_t(void) { flecs::world ecs; struct Tgt { }; ecs.entity() .set({10, 20}) .set({1, 2}); flecs::entity e = ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table_range table = e.range(); Position *p = table.get(ecs.id()); test_assert(p != NULL); test_int(p[0].x, 20); test_int(p[0].y, 30); Velocity *v = table.get(ecs.id()); test_assert(v != NULL); test_int(v[0].x, 2); test_int(v[0].y, 3); } void Table_range_get_pair_R_T(void) { flecs::world ecs; struct Tgt { }; ecs.entity() .set({10, 20}) .set({1, 2}); flecs::entity e = ecs.entity() .set({20, 30}) .set({2, 3}); ecs.entity() .set({30, 40}) .set({3, 4}); flecs::table_range table = e.range(); Position *p = table.get(); test_assert(p != NULL); test_int(p[0].x, 20); test_int(p[0].y, 30); Velocity *v = table.get(); test_assert(v != NULL); test_int(v[0].x, 2); test_int(v[0].y, 3); } void Table_get_depth(void) { flecs::world world; flecs::entity e1 = world.entity(); flecs::entity e2 = world.entity().child_of(e1); flecs::entity e3 = world.entity().child_of(e2); flecs::entity e4 = world.entity().child_of(e3); test_int(1, e2.table().depth(flecs::ChildOf)); test_int(2, e3.table().depth(flecs::ChildOf)); test_int(3, e4.table().depth(flecs::ChildOf)); } void Table_get_depth_w_type(void) { flecs::world world; struct Rel { }; world.component().add(flecs::Traversable); flecs::entity e1 = world.entity(); flecs::entity e2 = world.entity().add(e1); flecs::entity e3 = world.entity().add(e2); flecs::entity e4 = world.entity().add(e3); test_int(1, e2.table().depth()); test_int(2, e3.table().depth()); test_int(3, e4.table().depth()); } void Table_iter_type(void) { flecs::world ecs; auto e = ecs.entity() .add() .add(); auto table = e.table(); int32_t count = 0; for (const auto id : table.type()) { count ++; test_assert(id == ecs.id() || id == ecs.id()); } test_int(count, 2); } void Table_get_T_enum(void) { flecs::world ecs; flecs::entity e = ecs.entity() .set(Number::One); ecs.entity() .set(Number::Two); ecs.entity() .set(Number::Three); flecs::table table = e.table(); Number *n = table.get(); test_assert(n != NULL); test_int(n[0], Number::One); test_int(n[1], Number::Two); test_int(n[2], Number::Three); }