Merge pull request #305 from SHADE-DP/SP3-5-ECS

Added GetComponents to Component Manager
This commit is contained in:
XiaoQiDigipen 2023-01-09 16:59:45 +08:00 committed by GitHub
commit be337a2687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 1 deletions

View File

@ -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