#include #include #include #include #include struct C0 { C0(int x = 0, int y = 0) : x(x), y(y) {} int x, y; }; struct C1 { int vx, vy; }; struct C2 {}; struct C3 {}; struct T0 {}; struct T1 {}; using ListComponentsAll = EC::Meta::TypeList; using ListComponentsSome = EC::Meta::TypeList; using ListTagsAll = EC::Meta::TypeList; using ListAll = EC::Meta::TypeList; using EmptyList = EC::Meta::TypeList<>; using MixedList = EC::Meta::TypeList; TEST(EC, Bitset) { { EC::Bitset bitset; bitset[1] = true; bitset[3] = true; auto genBitset = EC::Bitset::generateBitset(); EXPECT_EQ(bitset, genBitset); } { EC::Bitset bitset; bitset[2] = true; bitset[5] = true; auto genBitset = EC::Bitset::generateBitset(); EXPECT_EQ(bitset, genBitset); } } TEST(EC, Manager) { EC::Manager manager; std::size_t e0 = manager.addEntity(); std::size_t e1 = manager.addEntity(); manager.addComponent(e0, 5, 5); manager.addComponent(e0); manager.addComponent(e1); manager.addComponent(e1); manager.addTag(e1); { auto& vel = manager.getEntityData(e0); vel.vx = 1; vel.vy = 1; } auto posUpdate = [] (std::size_t id, C0& pos, C1& vel) { pos.x += vel.vx; pos.y += vel.vy; }; auto updateTag = [] (std::size_t id, C0& pos, C1& vel) { pos.x = pos.y = vel.vx = vel.vy = 0; }; manager.forMatchingSignature >(posUpdate); manager.forMatchingSignature >(posUpdate); manager.forMatchingSignature >(updateTag); { auto& pos = manager.getEntityData(e0); EXPECT_EQ(pos.x, 7); EXPECT_EQ(pos.y, 7); } { bool has = manager.hasComponent(e1); EXPECT_TRUE(has); has = manager.hasTag(e1); EXPECT_TRUE(has); } manager.deleteEntity(e0); manager.cleanup(); std::size_t edata = std::get(manager.getEntityInfo(0)); EXPECT_EQ(edata, 1); std::size_t e2 = manager.addEntity(); manager.addTag(e2); std::size_t count = 0; auto updateTagOnly = [&count] (std::size_t id) { std::cout << "UpdateTagOnly was run." << std::endl; ++count; }; manager.forMatchingSignature >(updateTagOnly); EXPECT_EQ(2, count); manager.deleteEntity(e1); manager.deleteEntity(e2); manager.cleanup(); }