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})
--- /dev/null
+
+#ifndef EC_BITSET_HPP
+#define EC_BITSET_HPP
+
+#include <bitset>
+#include "Meta/TypeList.hpp"
+
+namespace EC
+{
+ template <typename ComponentsList, typename TagsList>
+ struct Bitset :
+ public std::bitset<ComponentsList::size + TagsList::size>
+ {
+ template <typename Component>
+ constexpr auto getComponentBit()
+ {
+ return (*this)[EC::Meta::IndexOf<Component, ComponentsList>::value];
+ }
+
+ template <typename Tag>
+ constexpr auto getTagBit()
+ {
+ return (*this)[ComponentsList::size + EC::Meta::IndexOf<Tag, TagsList>::value];
+ }
+ };
+}
+
+#endif
+
--- /dev/null
+
+#include "Bitset.hpp"
+
#ifndef EC_META_CONTAINS_HPP
#define EC_META_CONTAINS_HPP
+#include <type_traits>
#include "TypeList.hpp"
namespace EC
};
template <typename T, typename TTypeList>
- using Contains = std::integral_constant<bool, ContainsHelper<T, TTypeList>::value >;
+ using Contains = std::integral_constant<bool, ContainsHelper<T, TTypeList>::value>;
}
}
--- /dev/null
+
+#ifndef EC_META_CONTAINS_ALL_HPP
+#define EC_META_CONTAINS_ALL_HPP
+
+#include "TypeList.hpp"
+#include "Contains.hpp"
+
+namespace EC
+{
+ namespace Meta
+ {
+ template <typename TTypeListA, typename TTypeListB>
+ struct ContainsAllHelper :
+ std::true_type
+ {
+ };
+
+ template <typename Type, typename... Types, typename TTypeListB>
+ struct ContainsAllHelper<TypeList<Type, Types...>, TTypeListB> :
+ std::conditional<
+ Contains<Type, TTypeListB>::value,
+ ContainsAllHelper<TypeList<Types...>, TTypeListB>,
+ std::false_type
+ >::type
+ {
+ };
+
+ template <typename TTypeListA, typename TTypeListB>
+ using ContainsAll = std::integral_constant<bool, ContainsAllHelper<TTypeListA, TTypeListB>::value>;
+ }
+}
+
+#endif
+
#include "TypeList.hpp"
#include "Contains.hpp"
+#include "ContainsAll.hpp"
#include "IndexOf.hpp"
#ifndef EC_META_TYPE_LIST_HPP
#define EC_META_TYPE_LIST_HPP
-#include <type_traits>
-
namespace EC
{
namespace Meta
#include <gtest/gtest.h>
#include <EC/Meta/Meta.hpp>
+#include <EC/EC.hpp>
struct C0 {};
struct C1 {};
struct C2 {};
struct C3 {};
+struct T0 {};
+struct T1 {};
+
using listAll = EC::Meta::TypeList<C0, C1, C2, C3>;
using listSome = EC::Meta::TypeList<C1, C3>;
+using listTagsAll = EC::Meta::TypeList<T0, T1>;
+
TEST(Meta, Contains)
{
-
int size = listAll::size;
EXPECT_EQ(size, 4);
EXPECT_TRUE(result);
}
+TEST(Meta, ContainsAll)
+{
+ bool contains = EC::Meta::ContainsAll<listSome, listAll>::value;
+ EXPECT_TRUE(contains);
+
+ contains = EC::Meta::ContainsAll<listAll, listSome>::value;
+ EXPECT_FALSE(contains);
+
+ contains = EC::Meta::ContainsAll<listAll, listAll>::value;
+ EXPECT_TRUE(contains);
+}
+
TEST(Meta, IndexOf)
{
int index = EC::Meta::IndexOf<C0, listAll>::value;
EXPECT_EQ(index, 1);
}
+TEST(Meta, Bitset)
+{
+ EC::Bitset<listAll, listTagsAll> bitset;
+ EXPECT_EQ(bitset.size(), listAll::size + listTagsAll::size);
+
+ bitset[1] = true;
+ EXPECT_TRUE(bitset.getComponentBit<C1>());
+ bitset.flip();
+ EXPECT_FALSE(bitset.getComponentBit<C1>());
+
+ bitset.reset();
+ bitset[4] = true;
+ EXPECT_TRUE(bitset.getTagBit<T0>());
+ bitset.flip();
+ EXPECT_FALSE(bitset.getTagBit<T0>());
+}
+