]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Added EC/Meta/TypeListGet, WIP in Bitset, Manager
authorStephen Seo <seo.disparate@gmail.com>
Sat, 5 Mar 2016 14:33:24 +0000 (23:33 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 5 Mar 2016 14:33:24 +0000 (23:33 +0900)
TODO, get a ForEach type recursion working for Bitset.

src/CMakeLists.txt
src/EC/Bitset.hpp
src/EC/EC.hpp
src/EC/Manager.hpp
src/EC/Meta/Meta.hpp
src/EC/Meta/TypeListGet.hpp [new file with mode: 0644]
src/test/MetaTest.cpp

index 944a724700b26bbec25bfa46ab632b622bf22607..4aad22b006b8060835fb331bf588f7ef7019cd56 100644 (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)
index f95470d94c47ba8eac9bc6a6d435fcf74388c024..6e92e3233b46dc361f39a6f0dfa4e8ea6fd99875 100644 (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;
+        }
     };
 }
 
index 9e7b95200b17f1678436fcf42d6c5952c6849b99..12ff9547ddd348a12fbe8a845d37165ae13b7d94 100644 (file)
@@ -1,3 +1,4 @@
 
 #include "Bitset.hpp"
+#include "Manager.hpp"
 
index ed8c4124c4843f8f02b42f63d64c9ef106d5327e..530c6c6f861d75863c865a0cf764b7aeb87b5841 100644 (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;
 
     };
 }
index 0ac0ebdb4ab006e7fbe00cbd0f035370780ef5e8..0123c8e9d735630b429409c4d611e91de80e23ee 100644 (file)
@@ -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 (file)
index 0000000..d4af1ff
--- /dev/null
@@ -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
+
index 0b8b444be9a28a511fd327d9433bb4de34a273d8..84638f5c1e4f0e90c61f25206a5274e78acf47f3 100644 (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);
+}
+