Add const fns to Manager, obey 80 char line limit
This commit is contained in:
parent
bc70089822
commit
396ede1c76
13 changed files with 153 additions and 44 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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...>;
|
||||
|
|
|
@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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...>;
|
||||
|
|
|
@ -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)};
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue