]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Add const fns to Manager, obey 80 char line limit
authorStephen Seo <seo.disparate@gmail.com>
Wed, 20 Sep 2017 08:16:26 +0000 (17:16 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 20 Sep 2017 08:18:29 +0000 (17:18 +0900)
13 files changed:
src/EC/Bitset.hpp
src/EC/EC.hpp
src/EC/Manager.hpp
src/EC/Meta/Combine.hpp
src/EC/Meta/Contains.hpp
src/EC/Meta/ContainsAll.hpp
src/EC/Meta/ForEach.hpp
src/EC/Meta/IndexOf.hpp
src/EC/Meta/Matching.hpp
src/EC/Meta/Meta.hpp
src/EC/Meta/Morph.hpp
src/EC/Meta/TypeList.hpp
src/EC/Meta/TypeListGet.hpp

index b6faf73ccb6ecafd2b0e1fd34ed3b0cf243dca6a..e3dc07b853454e80897ef3830d35370c19d6be75 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -53,7 +54,8 @@ namespace EC
             EC::Meta::forEach<Contents>([&bitset] (auto t) {
                 if(EC::Meta::Contains<decltype(t), Combined>::value)
                 {
-                    bitset[EC::Meta::IndexOf<decltype(t), Combined>::value] = true;
+                    bitset[EC::Meta::IndexOf<decltype(t), Combined>::value] =
+                        true;
                 }
             });
 
index 9b58346195e20ffdb64b72a4d62d0ea41a0bf7e2..77590af45427d1a09404cd8e5efc4a17f9322500 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
index d3c297e50edc864dbf9b401b1866f5d1393d8be5..263f501aa7c69be8f1138e5ea2d1b3b20dbea4f5 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -29,7 +30,8 @@ namespace EC
     /*!
         \brief Manages an EntityComponent system.
 
-        EC::Manager must be created with a list of all used Components and all used tags.
+        EC::Manager must be created with a list of all used Components and all
+        used tags.
 
         Note that all components must have a default constructor.
 
@@ -181,7 +183,8 @@ namespace EC
         template <typename Component>
         Component& getEntityData(const std::size_t& index)
         {
-            return std::get<std::vector<Component> >(componentsStorage).at(std::get<std::size_t>(entities.at(index)));
+            return std::get<std::vector<Component> >(componentsStorage).at(
+                std::get<std::size_t>(entities.at(index)));
         }
 
         /*!
@@ -202,6 +205,41 @@ namespace EC
             return getEntityData<Component>(index);
         }
 
+        /*!
+            \brief Returns a const reference to a component belonging to the
+                given Entity.
+
+            This function will return a const reference to a Component
+            regardless of whether or not the Entity actually owns the reference.
+            If the Entity doesn't own the Component, changes to the Component
+            will not affect any Entity. It is recommended to use hasComponent()
+            to determine if the Entity actually owns that Component.
+        */
+        template <typename Component>
+        const Component& getEntityData(const std::size_t& index) const
+        {
+            return std::get<std::vector<Component> >(componentsStorage).at(
+                std::get<std::size_t>(entities.at(index)));
+        }
+
+        /*!
+            \brief Returns a const reference to a component belonging to the
+                given Entity.
+
+            Note that this function is the same as getEntityData() (const).
+
+            This function will return a const reference to a Component
+            regardless of whether or not the Entity actually owns the reference.
+            If the Entity doesn't own the Component, changes to the Component
+            will not affect any Entity. It is recommended to use hasComponent()
+            to determine if the Entity actually owns that Component.
+        */
+        template <typename Component>
+        const Component& getEntityComponent(const std::size_t& index) const
+        {
+            return getEntityData<Component>(index);
+        }
+
         /*!
             \brief Checks whether or not the given Entity has the given
                 Component.
@@ -240,7 +278,8 @@ namespace EC
             result in entity IDs changing if some Entities were marked for
             deletion.
 
-            <b>This function should be called periodically to correctly handle deletion of entities.</b>
+            <b>This function should be called periodically to correctly handle
+            deletion of entities.</b>
         */
         void cleanup()
         {
@@ -478,7 +517,8 @@ namespace EC
         }
 
     private:
-        std::unordered_map<std::size_t, std::function<void()> > forMatchingFunctions;
+        std::unordered_map<std::size_t, std::function<void()> >
+            forMatchingFunctions;
         std::size_t functionIndex = 0;
 
     public:
@@ -664,9 +704,11 @@ namespace EC
         std::size_t keepSomeMatchingFunctions(List list)
         {
             std::size_t deletedCount = 0;
-            for(auto iter = forMatchingFunctions.begin(); iter != forMatchingFunctions.end();)
+            for(auto iter = forMatchingFunctions.begin();
+                iter != forMatchingFunctions.end();)
             {
-                if(std::find(list.begin(), list.end(), iter->first) == list.end())
+                if(std::find(list.begin(), list.end(), iter->first)
+                    == list.end())
                 {
                     iter = forMatchingFunctions.erase(iter);
                     ++deletedCount;
index fab07965f807b11af531a0acd870b8f552488ff0..348cd0f4e28cd1516d03010c010c48c2fc32ffe6 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -18,7 +19,10 @@ namespace EC
             using type = TypeList<>;
         };
 
-        template <template <typename...> class TTypeListA, template <typename...> class TTypeListB, typename... TypesA, typename... TypesB>
+        template <
+            template <typename...> class TTypeListA,
+            template <typename...> class TTypeListB,
+            typename... TypesA, typename... TypesB>
         struct CombineHelper<TTypeListA<TypesA...>, TTypeListB<TypesB...> >
         {
             using type = TypeList<TypesA..., TypesB...>;
index 1d50d40a3933ccf5183bee99dea6dae59c1c4fba..32d725d0dedad8d1c15dc18cc911cce005d3fa92 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -19,7 +20,11 @@ namespace EC
         {
         };
 
-        template <typename T, template <typename...> class TTypeList, typename Type, typename... Types>
+        template <
+            typename T,
+            template <typename...> class TTypeList,
+            typename Type,
+            typename... Types>
         struct ContainsHelper<T, TTypeList<Type, Types...> > :
             std::conditional<
                 std::is_same<T, Type>::value,
@@ -30,7 +35,8 @@ 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>;
     }
 }
 
index c990cf00ad80d88a56b9b03a0e2422cea27ef24e..699b7f552970ceee239c2f4faeecb57a31f0dde6 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -19,7 +20,11 @@ namespace EC
         {
         };
 
-        template <template <typename...> class TTypeListA, typename Type, typename... Types, typename TTypeListB>
+        template <
+            template <typename...> class TTypeListA,
+            typename Type,
+            typename... Types,
+            typename TTypeListB>
         struct ContainsAllHelper<TTypeListA<Type, Types...>, TTypeListB> :
             std::conditional<
                 Contains<Type, TTypeListB>::value,
@@ -30,7 +35,8 @@ namespace EC
         };
 
         template <typename TTypeListA, typename TTypeListB>
-        using ContainsAll = std::integral_constant<bool, ContainsAllHelper<TTypeListA, TTypeListB>::value>;
+        using ContainsAll = std::integral_constant<
+            bool, ContainsAllHelper<TTypeListA, TTypeListB>::value>;
     }
 }
 
index 34b8e51f64247afa166734b3e8322347302257d3..0668b6168ec429c0c1d8fadde1fe2e1839c0b60f 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -15,9 +16,11 @@ namespace EC
     namespace Meta
     {
         template <typename Function, typename TTuple, std::size_t... Indices>
-        constexpr void forEachHelper(Function&& function, TTuple tuple, std::index_sequence<Indices...>)
+        constexpr void forEachHelper(
+            Function&& function, TTuple tuple, std::index_sequence<Indices...>)
         {
-            return (void)std::initializer_list<int>{(function(std::move(std::get<Indices>(tuple))), 0)...};
+            return (void)std::initializer_list<int>{(function(std::move(
+                std::get<Indices>(tuple))), 0)...};
         }
 
         template <typename TTypeList, typename Function>
@@ -27,7 +30,8 @@ namespace EC
             using TTupleSize = std::tuple_size<TTuple>;
             using IndexSeq = std::make_index_sequence<TTupleSize::value>;
 
-            return forEachHelper(std::forward<Function>(function), TTuple{}, IndexSeq{});
+            return forEachHelper(
+                std::forward<Function>(function), TTuple{}, IndexSeq{});
         }
     }
 }
index fe91fb72c21bf3e0f11655d74c2da581d5c9f214..db155d843817a172e3accae4ba94f4ab5ec0bcb8 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -17,13 +18,20 @@ namespace EC
         {
         };
 
-        template <typename T, template <typename...> class TTypeList, typename... Types>
+        template <
+            typename T,
+            template <typename...> class TTypeList,
+            typename... Types>
         struct IndexOf<T, TTypeList<T, Types...> > :
             std::integral_constant<std::size_t, 0>
         {
         };
 
-        template <typename T, template <typename...> class TTypeList, typename Type, typename... Types>
+        template <
+            typename T,
+            template <typename...> class TTypeList,
+            typename Type,
+            typename... Types>
         struct IndexOf<T, TTypeList<Type, Types...> > :
             std::integral_constant<std::size_t, 1 +
                 IndexOf<T, TTypeList<Types...> >::value
index 41b309f7e175b1068fe3ff3af4a2b681c9495887..b91a6f7716f2dd796d3c96be5dea1f9fc342147a 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -19,32 +20,54 @@ namespace EC
             using type = TypeList<>;
         };
 
-        template <typename TTypeListA, typename TTypeListB, typename... Matching>
+        template <typename TTypeListA, typename TTypeListB,
+            typename... Matching>
         struct MatchingHelperHelper
         {
         };
 
-        template <typename TTypeListA, typename TTypeListB, typename... Matching>
-        struct MatchingHelperHelper<TTypeListA, TTypeListB, TypeList<Matching...> >
+        template <typename TTypeListA, typename TTypeListB,
+            typename... Matching>
+        struct MatchingHelperHelper<
+            TTypeListA, TTypeListB, TypeList<Matching...> >
         {
             using type = TypeList<Matching...>;
         };
 
-        template <template <typename...> class TTypeListA, typename TTypeListB, typename Type, typename... Types, typename... Matching>
-        struct MatchingHelperHelper<TTypeListA<Type, Types...>, TTypeListB, TypeList<Matching...> > :
+        template <
+            template <typename...> class TTypeListA,
+            typename TTypeListB,
+            typename Type,
+            typename... Types,
+            typename... Matching>
+        struct MatchingHelperHelper<
+                TTypeListA<Type, Types...>,
+                TTypeListB,
+                TypeList<Matching...> > :
             std::conditional<
                 Contains<Type, TTypeListB>::value,
-                MatchingHelperHelper<TTypeListA<Types...>, TTypeListB, TypeList<Matching..., Type> >,
-                MatchingHelperHelper<TTypeListA<Types...>, TTypeListB, TypeList<Matching...> >
+                MatchingHelperHelper<
+                    TTypeListA<Types...>,
+                    TTypeListB,
+                    TypeList<Matching..., Type> >,
+                MatchingHelperHelper<
+                    TTypeListA<Types...>,
+                    TTypeListB,
+                    TypeList<Matching...> >
             >::type
         {
         };
 
-        template <template <typename...> class TTypeListA, typename TTypeListB, typename Type, typename... Types>
+        template <
+            template <typename...> class TTypeListA,
+            typename TTypeListB,
+            typename Type,
+            typename... Types>
         struct MatchingHelper<TTypeListA<Type, Types...>, TTypeListB> :
             std::conditional<
                 Contains<Type, TTypeListB>::value,
-                MatchingHelperHelper<TTypeListA<Types...>, TTypeListB, TypeList<Type> >,
+                MatchingHelperHelper<
+                    TTypeListA<Types...>, TTypeListB, TypeList<Type> >,
                 MatchingHelper<TTypeListA<Types...>, TTypeListB>
             >::type
         {
index cf6965a624d80e650066287f95dd3b445c3b428c..f7f8ca97aa701458f8e8d613b05dcf083dba808c 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
index 7394ce3427d73911b115cdb782e21d8a7e21ce69..e305c1c0bbaa93cc83112367b918f1889ef0b6a1 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -17,7 +18,10 @@ namespace EC
         {
         };
 
-        template <template <typename...> class TypeA, template <typename...> class TypeB, typename... TypesA, typename... TypesB>
+        template <
+            template <typename...> class TypeA,
+            template <typename...> class TypeB,
+            typename... TypesA, typename... TypesB>
         struct MorphHelper<TypeA<TypesA...>, TypeB<TypesB...> >
         {
             using type = TypeB<TypesA...>;
index 306b62dfcfe279532115df3577a18de1aa2816db..3b8606770c670e6751a4666fac2e31254b44baf0 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -14,7 +15,6 @@ namespace EC
         struct TypeList
         {
             static constexpr std::size_t size{sizeof...(Types)};
-
         };
     }
 }
index b9060b4beedb8104d721259ae0af53d9d65b668b..0d019c73ed46eba712785d301e5f3ec504269257 100644 (file)
@@ -1,5 +1,6 @@
 
-// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed under the Academic Free License.
+// This work derives from Vittorio Romeo's code used for cppcon 2015 licensed
+// under the Academic Free License.
 // His code is available here: https://github.com/SuperV1234/cppcon2015
 
 
@@ -21,19 +22,26 @@ namespace EC
             using type = TTypeList;
         };
 
-        template <typename TTypeList, template <typename...> class TTTypeList, unsigned int Index, typename Type, typename... Rest>
+        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
+                    typename TypeListGetHelper<
+                        TTypeList, TTTypeList<Rest...>, Index>::type
                 >::type;
         };
 
         template <typename TTypeList, unsigned int Index>
-        using TypeListGet = typename TypeListGetHelper<TTypeList, TTypeList, Index>::type;
+        using TypeListGet =
+            typename TypeListGetHelper<TTypeList, TTypeList, Index>::type;
     }
 }