diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b32d907..d454bc8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,11 @@ project(EntityComponentSystem) set(EntityComponentSystem_HEADERS EC/Meta/TypeList.hpp EC/Meta/Contains.hpp - EC/Meta/IndexOf.hpp) + EC/Meta/ContainsAll.hpp + EC/Meta/IndexOf.hpp + EC/Meta/Meta.hpp + EC/Bitset.hpp + EC/EC.hpp) add_library(EntityComponentSystem INTERFACE) target_include_directories(EntityComponentSystem INTERFACE ${CMAKE_SOURCE_DIR}) diff --git a/src/EC/Bitset.hpp b/src/EC/Bitset.hpp new file mode 100644 index 0000000..6ddd1d3 --- /dev/null +++ b/src/EC/Bitset.hpp @@ -0,0 +1,29 @@ + +#ifndef EC_BITSET_HPP +#define EC_BITSET_HPP + +#include +#include "Meta/TypeList.hpp" + +namespace EC +{ + template + struct Bitset : + public std::bitset + { + template + constexpr auto getComponentBit() + { + return (*this)[EC::Meta::IndexOf::value]; + } + + template + constexpr auto getTagBit() + { + return (*this)[ComponentsList::size + EC::Meta::IndexOf::value]; + } + }; +} + +#endif + diff --git a/src/EC/EC.hpp b/src/EC/EC.hpp new file mode 100644 index 0000000..9e7b952 --- /dev/null +++ b/src/EC/EC.hpp @@ -0,0 +1,3 @@ + +#include "Bitset.hpp" + diff --git a/src/EC/Meta/Contains.hpp b/src/EC/Meta/Contains.hpp index 4dc32c8..32f05be 100644 --- a/src/EC/Meta/Contains.hpp +++ b/src/EC/Meta/Contains.hpp @@ -2,6 +2,7 @@ #ifndef EC_META_CONTAINS_HPP #define EC_META_CONTAINS_HPP +#include #include "TypeList.hpp" namespace EC @@ -25,7 +26,7 @@ namespace EC }; template - using Contains = std::integral_constant::value >; + using Contains = std::integral_constant::value>; } } diff --git a/src/EC/Meta/ContainsAll.hpp b/src/EC/Meta/ContainsAll.hpp new file mode 100644 index 0000000..cb3440c --- /dev/null +++ b/src/EC/Meta/ContainsAll.hpp @@ -0,0 +1,34 @@ + +#ifndef EC_META_CONTAINS_ALL_HPP +#define EC_META_CONTAINS_ALL_HPP + +#include "TypeList.hpp" +#include "Contains.hpp" + +namespace EC +{ + namespace Meta + { + template + struct ContainsAllHelper : + std::true_type + { + }; + + template + struct ContainsAllHelper, TTypeListB> : + std::conditional< + Contains::value, + ContainsAllHelper, TTypeListB>, + std::false_type + >::type + { + }; + + template + using ContainsAll = std::integral_constant::value>; + } +} + +#endif + diff --git a/src/EC/Meta/Meta.hpp b/src/EC/Meta/Meta.hpp index 69c2206..c157869 100644 --- a/src/EC/Meta/Meta.hpp +++ b/src/EC/Meta/Meta.hpp @@ -1,5 +1,6 @@ #include "TypeList.hpp" #include "Contains.hpp" +#include "ContainsAll.hpp" #include "IndexOf.hpp" diff --git a/src/EC/Meta/TypeList.hpp b/src/EC/Meta/TypeList.hpp index 560dbe9..053add0 100644 --- a/src/EC/Meta/TypeList.hpp +++ b/src/EC/Meta/TypeList.hpp @@ -2,8 +2,6 @@ #ifndef EC_META_TYPE_LIST_HPP #define EC_META_TYPE_LIST_HPP -#include - namespace EC { namespace Meta diff --git a/src/test/MetaTest.cpp b/src/test/MetaTest.cpp index 3bb4ea8..2564615 100644 --- a/src/test/MetaTest.cpp +++ b/src/test/MetaTest.cpp @@ -2,18 +2,23 @@ #include #include +#include struct C0 {}; struct C1 {}; struct C2 {}; struct C3 {}; +struct T0 {}; +struct T1 {}; + using listAll = EC::Meta::TypeList; using listSome = EC::Meta::TypeList; +using listTagsAll = EC::Meta::TypeList; + TEST(Meta, Contains) { - int size = listAll::size; EXPECT_EQ(size, 4); @@ -39,6 +44,18 @@ TEST(Meta, Contains) EXPECT_TRUE(result); } +TEST(Meta, ContainsAll) +{ + bool contains = EC::Meta::ContainsAll::value; + EXPECT_TRUE(contains); + + contains = EC::Meta::ContainsAll::value; + EXPECT_FALSE(contains); + + contains = EC::Meta::ContainsAll::value; + EXPECT_TRUE(contains); +} + TEST(Meta, IndexOf) { int index = EC::Meta::IndexOf::value; @@ -56,3 +73,20 @@ TEST(Meta, IndexOf) EXPECT_EQ(index, 1); } +TEST(Meta, Bitset) +{ + EC::Bitset bitset; + EXPECT_EQ(bitset.size(), listAll::size + listTagsAll::size); + + bitset[1] = true; + EXPECT_TRUE(bitset.getComponentBit()); + bitset.flip(); + EXPECT_FALSE(bitset.getComponentBit()); + + bitset.reset(); + bitset[4] = true; + EXPECT_TRUE(bitset.getTagBit()); + bitset.flip(); + EXPECT_FALSE(bitset.getTagBit()); +} +