Added EC/Meta/TypeListGet, WIP in Bitset, Manager

TODO, get a ForEach type recursion working for Bitset.
This commit is contained in:
Stephen Seo 2016-03-05 23:33:24 +09:00
parent d8dfba8361
commit 24ce103fbb
7 changed files with 113 additions and 2 deletions

View file

@ -10,6 +10,7 @@ set(EntityComponentSystem_HEADERS
EC/Meta/Morph.hpp
EC/Meta/Meta.hpp
EC/Bitset.hpp
EC/Manager.hpp
EC/EC.hpp)
add_library(EntityComponentSystem INTERFACE)

View file

@ -5,6 +5,7 @@
#include <bitset>
#include "Meta/TypeList.hpp"
#include "Meta/Combine.hpp"
#include "Meta/IndexOf.hpp"
namespace EC
{
@ -25,6 +26,24 @@ namespace EC
{
return (*this)[EC::Meta::IndexOf<Tag, Combined>::value];
}
template <typename Contents>
static constexpr Bitset<ComponentsList, TagsList> generateBitset()
{
//TODO
Bitset<ComponentsList, TagsList> bitset;
/*
for(unsigned int i = 0; i < Contents::size; ++i)
{
if(EC::Meta::Contains<EC::Meta::TypeListGet<Contents, i>, Combined>::value)
{
bitset[EC::Meta::IndexOf<EC::Meta::TypeListGet<Contents, i>, Combined>::value] = true;
}
}
*/
return bitset;
}
};
}

View file

@ -1,3 +1,4 @@
#include "Bitset.hpp"
#include "Manager.hpp"

View file

@ -2,16 +2,46 @@
#ifndef EC_MANAGER_HPP
#define EC_MANAGER_HPP
#define EC_INIT_ENTITIES_SIZE 1024
#include <cstddef>
#include <tuple>
#include "Meta/Combine.hpp"
#include "Bitset.hpp"
namespace EC
{
template <typename ComponentsList, typename TagsList, typename Signatures>
template <typename ComponentsList, typename TagsList>
struct Manager
{
public:
using Combined = EC::Meta::Combine<ComponentsList, TagsList>;
using BitsetType = EC::Bitset<ComponentsList, TagsList>;
Manager()
{
entities.resize(EC_INIT_ENTITIES_SIZE);
for(auto entity : entities)
{
entity->first = false;
}
}
template <typename EComponentsList>
std::size_t addEntity()
{
//TODO
BitsetType newEntity;
return 0;
}
private:
using BitsetType = EC::Bitset<ComponentsList, TagsList>;
using ComponentsStorage = EC::Meta::Morph<ComponentsList, std::tuple<> >;
using EntitiesType = std::tuple<bool, BitsetType>;
std::vector<EntitiesType> entities;
};
}

View file

@ -1,5 +1,6 @@
#include "TypeList.hpp"
#include "TypeListGet.hpp"
#include "Combine.hpp"
#include "Contains.hpp"
#include "ContainsAll.hpp"

View file

@ -0,0 +1,37 @@
#ifndef EC_META_TYPE_LIST_GET_HPP
#define EC_META_TYPE_LIST_GET_HPP
#include <type_traits>
#include "TypeList.hpp"
#include "IndexOf.hpp"
namespace EC
{
namespace Meta
{
template <typename TTypeList, typename TTTypeList, unsigned int Index>
struct TypeListGetHelper
{
using type = TTypeList;
};
template <typename TTypeList, template <typename...> class TTTypeList, unsigned int Index, typename Type, typename... Rest>
struct TypeListGetHelper<TTypeList, TTTypeList<Type, Rest...>, Index>
{
using type =
typename std::conditional<
Index == EC::Meta::IndexOf<Type, TTypeList>::value,
Type,
typename TypeListGetHelper<TTypeList, TTTypeList<Rest...>, Index>::type
>::type;
};
template <typename TTypeList, unsigned int Index>
using TypeListGet = typename TypeListGetHelper<TTypeList, TTypeList, Index>::type;
}
}
#endif

View file

@ -159,3 +159,25 @@ TEST(Meta, Morph)
EXPECT_TRUE(isSame);
}
TEST(Meta, TypeListGet)
{
bool isSame = std::is_same<C0, EC::Meta::TypeListGet<ListAll, 0> >::value;
EXPECT_TRUE(isSame);
isSame = std::is_same<C1, EC::Meta::TypeListGet<ListAll, 1> >::value;
EXPECT_TRUE(isSame);
isSame = std::is_same<C2, EC::Meta::TypeListGet<ListAll, 2> >::value;
EXPECT_TRUE(isSame);
isSame = std::is_same<C3, EC::Meta::TypeListGet<ListAll, 3> >::value;
EXPECT_TRUE(isSame);
const unsigned int temp = 4;
isSame = std::is_same<T0, EC::Meta::TypeListGet<ListAll, temp> >::value;
EXPECT_TRUE(isSame);
isSame = std::is_same<T1, EC::Meta::TypeListGet<ListAll, 5> >::value;
EXPECT_TRUE(isSame);
}