-// 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
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;
}
});
-// 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
-// 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
/*!
\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.
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)));
}
/*!
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.
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()
{
}
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:
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;
-// 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
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...>;
-// 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
{
};
- 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,
};
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>;
}
}
-// 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
{
};
- 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,
};
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>;
}
}
-// 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
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>
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{});
}
}
}
-// 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
{
};
- 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
-// 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
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
{
-// 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
-// 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
{
};
- 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...>;
-// 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
struct TypeList
{
static constexpr std::size_t size{sizeof...(Types)};
-
};
}
}
-// 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
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;
}
}