Documentation for module 'NDK'
Former-commit-id: a6c2075cfbfd0eccf2b77def71c0d42684bed590 [formerly 36ece2bc6a148bde6cacf45084821d20edcd115e] [formerly 4a6988792ec026e65be6850c46dfe8ddda92a885 [formerly fd3f4f975de5c427f3adc98b220446fd255be396]] Former-commit-id: c87fdc9483202842267c60eff3d619f0df2963bf [formerly ee35202f1b2df7ca20da5b6d8b13147f2b92c933] Former-commit-id: dad5de1b00bb4413f7aa191ca06b7d43b659f32a
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a BaseSystem object with an index
|
||||
*
|
||||
* \param systemId Index of the system
|
||||
*/
|
||||
|
||||
inline BaseSystem::BaseSystem(SystemIndex systemId) :
|
||||
m_updateEnabled(true),
|
||||
m_systemIndex(systemId)
|
||||
@@ -15,6 +21,12 @@ namespace Ndk
|
||||
SetUpdateRate(30);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a BaseSystem object by copy semantic
|
||||
*
|
||||
* \param system System to copy
|
||||
*/
|
||||
|
||||
inline BaseSystem::BaseSystem(const BaseSystem& system) :
|
||||
m_excludedComponents(system.m_excludedComponents),
|
||||
m_requiredComponents(system.m_requiredComponents),
|
||||
@@ -25,36 +37,74 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables the system
|
||||
*
|
||||
* \param enable Should the system be enabled
|
||||
*/
|
||||
|
||||
inline void BaseSystem::Enable(bool enable)
|
||||
{
|
||||
m_updateEnabled = enable;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets every entities that system handle
|
||||
* \return A constant reference to the list of entities
|
||||
*/
|
||||
|
||||
inline const std::vector<EntityHandle>& BaseSystem::GetEntities() const
|
||||
{
|
||||
return m_entities;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the index of the system
|
||||
* \return Index of the system
|
||||
*/
|
||||
|
||||
inline SystemIndex BaseSystem::GetIndex() const
|
||||
{
|
||||
return m_systemIndex;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the rate of update for the system
|
||||
* \return Update rate
|
||||
*/
|
||||
|
||||
inline float BaseSystem::GetUpdateRate() const
|
||||
{
|
||||
return (m_updateRate > 0.f) ? 1.f / m_updateRate : 0.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the world on which the system operate
|
||||
* \return World in which the system is
|
||||
*/
|
||||
|
||||
inline World& BaseSystem::GetWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not the system is enabled
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
inline bool BaseSystem::IsEnabled() const
|
||||
{
|
||||
return m_updateEnabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not the system has the entity
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param entity Pointer to the entity
|
||||
*/
|
||||
|
||||
inline bool BaseSystem::HasEntity(const Entity* entity) const
|
||||
{
|
||||
if (!entity)
|
||||
@@ -63,12 +113,24 @@ namespace Ndk
|
||||
return m_entityBits.UnboundedTest(entity->GetId());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the rate of update for the system
|
||||
*
|
||||
* \param updatePerSecond Update rate, 0 means as much as possible
|
||||
*/
|
||||
|
||||
inline void BaseSystem::SetUpdateRate(float updatePerSecond)
|
||||
{
|
||||
m_updateCounter = 0.f;
|
||||
m_updateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the system
|
||||
*
|
||||
* \param elapsedTime Delta time used for the update
|
||||
*/
|
||||
|
||||
inline void BaseSystem::Update(float elapsedTime)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
@@ -88,6 +150,10 @@ namespace Ndk
|
||||
OnUpdate(elapsedTime);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Excludes some component from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
void BaseSystem::Excludes()
|
||||
{
|
||||
@@ -96,6 +162,10 @@ namespace Ndk
|
||||
ExcludesComponent(GetComponentIndex<ComponentType>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Excludes some components from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType1, typename ComponentType2, typename... Rest>
|
||||
void BaseSystem::Excludes()
|
||||
{
|
||||
@@ -103,16 +173,31 @@ namespace Ndk
|
||||
Excludes<ComponentType2, Rest...>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Excludes some component from the system by index
|
||||
*
|
||||
* \param index Index of the component
|
||||
*/
|
||||
|
||||
inline void BaseSystem::ExcludesComponent(ComponentIndex index)
|
||||
{
|
||||
m_excludedComponents.UnboundedSet(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the next index for the system
|
||||
* \return Next unique index for the system
|
||||
*/
|
||||
|
||||
inline SystemIndex BaseSystem::GetNextIndex()
|
||||
{
|
||||
return s_nextIndex++;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires some component from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
void BaseSystem::Requires()
|
||||
{
|
||||
@@ -121,6 +206,10 @@ namespace Ndk
|
||||
RequiresComponent(GetComponentIndex<ComponentType>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires some components from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType1, typename ComponentType2, typename... Rest>
|
||||
void BaseSystem::Requires()
|
||||
{
|
||||
@@ -128,11 +217,21 @@ namespace Ndk
|
||||
Requires<ComponentType2, Rest...>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires some component for the system by index
|
||||
*
|
||||
* \param index Index of the component
|
||||
*/
|
||||
|
||||
inline void BaseSystem::RequiresComponent(ComponentIndex index)
|
||||
{
|
||||
m_requiredComponents.UnboundedSet(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires any component from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType>
|
||||
void BaseSystem::RequiresAny()
|
||||
{
|
||||
@@ -141,6 +240,10 @@ namespace Ndk
|
||||
RequiresAnyComponent(GetComponentIndex<ComponentType>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires any components from the system
|
||||
*/
|
||||
|
||||
template<typename ComponentType1, typename ComponentType2, typename... Rest>
|
||||
void BaseSystem::RequiresAny()
|
||||
{
|
||||
@@ -148,11 +251,25 @@ namespace Ndk
|
||||
RequiresAny<ComponentType2, Rest...>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Requires any component for the system by index
|
||||
*
|
||||
* \param index Index of the component
|
||||
*/
|
||||
|
||||
inline void BaseSystem::RequiresAnyComponent(ComponentIndex index)
|
||||
{
|
||||
m_requiredAnyComponents.UnboundedSet(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds an entity to a system
|
||||
*
|
||||
* \param entity Pointer to the entity
|
||||
*
|
||||
* \remark Produces a NazaraAssert if entity is invalid
|
||||
*/
|
||||
|
||||
inline void BaseSystem::AddEntity(Entity* entity)
|
||||
{
|
||||
NazaraAssert(entity, "Invalid entity");
|
||||
@@ -165,6 +282,14 @@ namespace Ndk
|
||||
OnEntityAdded(entity);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes an entity to a system
|
||||
*
|
||||
* \param entity Pointer to the entity
|
||||
*
|
||||
* \remark Produces a NazaraAssert if entity is invalid
|
||||
*/
|
||||
|
||||
inline void BaseSystem::RemoveEntity(Entity* entity)
|
||||
{
|
||||
NazaraAssert(entity, "Invalid entity");
|
||||
@@ -172,16 +297,25 @@ namespace Ndk
|
||||
auto it = std::find(m_entities.begin(), m_entities.end(), *entity);
|
||||
NazaraAssert(it != m_entities.end(), "Entity is not part of this system");
|
||||
|
||||
// Pour éviter de déplacer beaucoup de handles, on swap le dernier avec celui à supprimer
|
||||
// To avoid moving a lot of handles, we swap and pop
|
||||
std::swap(*it, m_entities.back());
|
||||
m_entities.pop_back(); // On le sort du vector
|
||||
m_entities.pop_back(); // We get it out of the vector
|
||||
|
||||
m_entityBits.Reset(entity->GetId());
|
||||
entity->UnregisterSystem(m_systemIndex);
|
||||
|
||||
OnEntityRemoved(entity); // Et on appelle le callback
|
||||
OnEntityRemoved(entity); // And we alert our callback
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Validates an entity to a system
|
||||
*
|
||||
* \param entity Pointer to the entity
|
||||
* \param justAdded Is the entity newly added
|
||||
*
|
||||
* \remark Produces a NazaraAssert if entity is invalid or if system does not hold this entity
|
||||
*/
|
||||
|
||||
inline void BaseSystem::ValidateEntity(Entity* entity, bool justAdded)
|
||||
{
|
||||
NazaraAssert(entity, "Invalid entity");
|
||||
@@ -190,11 +324,20 @@ namespace Ndk
|
||||
OnEntityValidation(entity, justAdded);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the world on which the system operates
|
||||
*/
|
||||
|
||||
inline void BaseSystem::SetWorld(World* world) noexcept
|
||||
{
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Initializes the BaseSystem
|
||||
* \return true
|
||||
*/
|
||||
|
||||
inline bool BaseSystem::Initialize()
|
||||
{
|
||||
s_nextIndex = 0;
|
||||
@@ -202,6 +345,10 @@ namespace Ndk
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uninitializes the BaseSystem
|
||||
*/
|
||||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Nothing to do
|
||||
|
||||
Reference in New Issue
Block a user