Added GetComponents to Component Manager #305
|
@ -23,7 +23,7 @@
|
|||
#include "SH_API.h"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
|
||||
|
||||
#include <tuple>
|
||||
#include <cassert>
|
||||
|
||||
namespace SHADE
|
||||
|
@ -151,6 +151,32 @@ namespace SHADE
|
|||
return (componentSet.GetSparseSet<T>()->GetElement_s(EntityHandleGenerator::GetIndex(entityID)));
|
||||
}
|
||||
|
||||
/*!*************************************************************************
|
||||
* \brief
|
||||
* Gets the Component of the entity with the specified entityID
|
||||
*
|
||||
* This is the safe version of GetComponent_s which does a HasComponent to make
|
||||
* sure that the entity has such a component and returns nullptr if it doesn't
|
||||
*
|
||||
* This safe version also checks if the sparse set of this component type
|
||||
* has been created in SHComponentManager and creates one if it doesn't
|
||||
*
|
||||
* @tparam T...
|
||||
* Pack of Types for all the Components to get.
|
||||
* \param entityID
|
||||
* EntityID of the entity that we are trying to get the component of.
|
||||
* \return
|
||||
* A tuple of pointers to all the components specified.
|
||||
* Returns nullptr if the entity does not contain such a component.
|
||||
***************************************************************************/
|
||||
|
||||
template<typename ...T>
|
||||
static std::enable_if_t<(... && std::is_base_of_v<SHComponent, T>), std::tuple<T*...>> GetComponents(EntityID entityID) noexcept
|
||||
{
|
||||
return std::make_tuple<T*...>(GetComponent_s<T>(entityID)...);
|
||||
}
|
||||
|
||||
|
||||
/*!*************************************************************************
|
||||
* \brief
|
||||
* Gets the Component of the entity with the specified entityID
|
||||
|
|
Loading…
Reference in New Issue