From 24ce103fbb0ba1f526db0cb3642ee1b12b005520 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 5 Mar 2016 23:33:24 +0900 Subject: [PATCH] Added EC/Meta/TypeListGet, WIP in Bitset, Manager TODO, get a ForEach type recursion working for Bitset. --- src/CMakeLists.txt | 1 + src/EC/Bitset.hpp | 19 +++++++++++++++++++ src/EC/EC.hpp | 1 + src/EC/Manager.hpp | 34 ++++++++++++++++++++++++++++++++-- src/EC/Meta/Meta.hpp | 1 + src/EC/Meta/TypeListGet.hpp | 37 +++++++++++++++++++++++++++++++++++++ src/test/MetaTest.cpp | 22 ++++++++++++++++++++++ 7 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/EC/Meta/TypeListGet.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 944a724..4aad22b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/EC/Bitset.hpp b/src/EC/Bitset.hpp index f95470d..6e92e32 100644 --- a/src/EC/Bitset.hpp +++ b/src/EC/Bitset.hpp @@ -5,6 +5,7 @@ #include #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::value]; } + + template + static constexpr Bitset generateBitset() + { + //TODO + Bitset bitset; +/* + for(unsigned int i = 0; i < Contents::size; ++i) + { + if(EC::Meta::Contains, Combined>::value) + { + bitset[EC::Meta::IndexOf, Combined>::value] = true; + } + } +*/ + + return bitset; + } }; } diff --git a/src/EC/EC.hpp b/src/EC/EC.hpp index 9e7b952..12ff954 100644 --- a/src/EC/EC.hpp +++ b/src/EC/EC.hpp @@ -1,3 +1,4 @@ #include "Bitset.hpp" +#include "Manager.hpp" diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index ed8c412..530c6c6 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -2,16 +2,46 @@ #ifndef EC_MANAGER_HPP #define EC_MANAGER_HPP +#define EC_INIT_ENTITIES_SIZE 1024 + +#include +#include + +#include "Meta/Combine.hpp" +#include "Bitset.hpp" + namespace EC { - template + template struct Manager { public: using Combined = EC::Meta::Combine; + using BitsetType = EC::Bitset; + + Manager() + { + entities.resize(EC_INIT_ENTITIES_SIZE); + + for(auto entity : entities) + { + entity->first = false; + } + } + + template + std::size_t addEntity() + { + //TODO + BitsetType newEntity; + return 0; + } private: - using BitsetType = EC::Bitset; + using ComponentsStorage = EC::Meta::Morph >; + using EntitiesType = std::tuple; + + std::vector entities; }; } diff --git a/src/EC/Meta/Meta.hpp b/src/EC/Meta/Meta.hpp index 0ac0ebd..0123c8e 100644 --- a/src/EC/Meta/Meta.hpp +++ b/src/EC/Meta/Meta.hpp @@ -1,5 +1,6 @@ #include "TypeList.hpp" +#include "TypeListGet.hpp" #include "Combine.hpp" #include "Contains.hpp" #include "ContainsAll.hpp" diff --git a/src/EC/Meta/TypeListGet.hpp b/src/EC/Meta/TypeListGet.hpp new file mode 100644 index 0000000..d4af1ff --- /dev/null +++ b/src/EC/Meta/TypeListGet.hpp @@ -0,0 +1,37 @@ + +#ifndef EC_META_TYPE_LIST_GET_HPP +#define EC_META_TYPE_LIST_GET_HPP + +#include + +#include "TypeList.hpp" +#include "IndexOf.hpp" + +namespace EC +{ + namespace Meta + { + template + struct TypeListGetHelper + { + using type = TTypeList; + }; + + template class TTTypeList, unsigned int Index, typename Type, typename... Rest> + struct TypeListGetHelper, Index> + { + using type = + typename std::conditional< + Index == EC::Meta::IndexOf::value, + Type, + typename TypeListGetHelper, Index>::type + >::type; + }; + + template + using TypeListGet = typename TypeListGetHelper::type; + } +} + +#endif + diff --git a/src/test/MetaTest.cpp b/src/test/MetaTest.cpp index 0b8b444..84638f5 100644 --- a/src/test/MetaTest.cpp +++ b/src/test/MetaTest.cpp @@ -159,3 +159,25 @@ TEST(Meta, Morph) EXPECT_TRUE(isSame); } +TEST(Meta, TypeListGet) +{ + bool isSame = std::is_same >::value; + EXPECT_TRUE(isSame); + + isSame = std::is_same >::value; + EXPECT_TRUE(isSame); + + isSame = std::is_same >::value; + EXPECT_TRUE(isSame); + + isSame = std::is_same >::value; + EXPECT_TRUE(isSame); + + const unsigned int temp = 4; + isSame = std::is_same >::value; + EXPECT_TRUE(isSame); + + isSame = std::is_same >::value; + EXPECT_TRUE(isSame); +} +