Sdk/EntityList: Automatically remove entities from lists on destruction
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -257,11 +258,10 @@ namespace Ndk
|
||||
return m_removedComponentBits;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers a system for the entity
|
||||
*
|
||||
* \param index Index of the system
|
||||
*/
|
||||
inline void Entity::RegisterEntityList(EntityList* list)
|
||||
{
|
||||
m_containedInLists.push_back(list);
|
||||
}
|
||||
|
||||
inline void Entity::RegisterSystem(SystemIndex index)
|
||||
{
|
||||
@@ -289,6 +289,16 @@ namespace Ndk
|
||||
* \param index Index of the system
|
||||
*/
|
||||
|
||||
inline void Entity::UnregisterEntityList(EntityList* list)
|
||||
{
|
||||
auto it = std::find(m_containedInLists.begin(), m_containedInLists.end(), list);
|
||||
assert(it != m_containedInLists.end());
|
||||
|
||||
// Swap and pop idiom
|
||||
*it = m_containedInLists.back();
|
||||
m_containedInLists.pop_back();
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterSystem(SystemIndex index)
|
||||
{
|
||||
m_systemBits.UnboundedReset(index);
|
||||
|
||||
Reference in New Issue
Block a user