Documentation for module 'NDK'
Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]] Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401] Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da
This commit is contained in:
@@ -7,47 +7,80 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a World object
|
||||
*
|
||||
* \param addDefaultSystems Should default provided systems be used
|
||||
*/
|
||||
|
||||
inline World::World(bool addDefaultSystems)
|
||||
{
|
||||
if (addDefaultSystems)
|
||||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a World object by move semantic
|
||||
*
|
||||
* \param world World to move into this
|
||||
*/
|
||||
|
||||
inline World::World(World&& world) noexcept :
|
||||
HandledObject(std::move(world))
|
||||
{
|
||||
operator=(std::move(world));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a system to the world
|
||||
* \return A reference to the newly created system
|
||||
*
|
||||
* \param system System to add to the world
|
||||
*/
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
|
||||
SystemIndex index = system->GetIndex();
|
||||
|
||||
// Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component
|
||||
// We must ensure that the vector is big enough to hold the new system
|
||||
if (index >= m_systems.size())
|
||||
m_systems.resize(index + 1);
|
||||
|
||||
// Affectation et retour du système
|
||||
// Affectation and return of system
|
||||
m_systems[index] = std::move(system);
|
||||
m_systems[index]->SetWorld(this);
|
||||
|
||||
Invalidate(); // On force une mise à jour de toutes les entités
|
||||
Invalidate(); // We force an update for every entities
|
||||
|
||||
return *m_systems[index].get();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a system to the world
|
||||
* \return A reference to the newly created system
|
||||
*
|
||||
* \param args Arguments used to create the system
|
||||
*/
|
||||
|
||||
template<typename SystemType, typename... Args>
|
||||
SystemType& World::AddSystem(Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseSystem, SystemType>::value, "SystemType is not a component");
|
||||
|
||||
// Allocation et affectation du component
|
||||
// Allocation and affectation of the system
|
||||
std::unique_ptr<SystemType> ptr(new SystemType(std::forward<Args>(args)...));
|
||||
return static_cast<SystemType&>(AddSystem(std::move(ptr)));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates multiple entities in the world
|
||||
* \return The set of entities created
|
||||
*
|
||||
* \param count Number of entities to create
|
||||
*/
|
||||
|
||||
inline World::EntityList World::CreateEntities(unsigned int count)
|
||||
{
|
||||
EntityList list;
|
||||
@@ -59,14 +92,27 @@ namespace Ndk
|
||||
return list;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets every entities in the world
|
||||
* \return A constant reference to the entities
|
||||
*/
|
||||
|
||||
inline const World::EntityList& World::GetEntities()
|
||||
{
|
||||
return m_aliveEntities;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a system in the world by index
|
||||
* \return A reference to the system
|
||||
*
|
||||
* \param index Index of the system
|
||||
*
|
||||
* \remark Produces a NazaraAssert if system is not available in this world
|
||||
*/
|
||||
|
||||
inline BaseSystem& World::GetSystem(SystemIndex index)
|
||||
{
|
||||
///DOC: Le système doit être présent
|
||||
NazaraAssert(HasSystem(index), "This system is not part of the world");
|
||||
|
||||
BaseSystem* system = m_systems[index].get();
|
||||
@@ -75,21 +121,39 @@ namespace Ndk
|
||||
return *system;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a system in the world by type
|
||||
* \return A reference to the system
|
||||
*
|
||||
* \remark Produces a NazaraAssert if system is not available in this world
|
||||
*/
|
||||
|
||||
template<typename SystemType>
|
||||
SystemType& World::GetSystem()
|
||||
{
|
||||
///DOC: Le système doit être présent
|
||||
static_assert(std::is_base_of<BaseSystem, SystemType>::value, "SystemType is not a system");
|
||||
|
||||
SystemIndex index = GetSystemIndex<SystemType>();
|
||||
return static_cast<SystemType&>(GetSystem(index));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not a system is present in the world by index
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param index Index of the system
|
||||
*/
|
||||
|
||||
inline bool World::HasSystem(SystemIndex index) const
|
||||
{
|
||||
return index < m_systems.size() && m_systems[index];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not a system is present in the world by type
|
||||
* \return true If it is the case
|
||||
*/
|
||||
|
||||
template<typename SystemType>
|
||||
bool World::HasSystem() const
|
||||
{
|
||||
@@ -99,34 +163,69 @@ namespace Ndk
|
||||
return HasSystem(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Kills a set of entities
|
||||
*
|
||||
* \param list Set of entities to kill
|
||||
*/
|
||||
|
||||
inline void World::KillEntities(const EntityList& list)
|
||||
{
|
||||
for (const EntityHandle& entity : list)
|
||||
KillEntity(entity);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not an entity is valid
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param entity Pointer to the entity
|
||||
*/
|
||||
|
||||
inline bool World::IsEntityValid(const Entity* entity) const
|
||||
{
|
||||
return entity && entity->GetWorld() == this && IsEntityIdValid(entity->GetId());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether or not an entity is valid
|
||||
* \return true If it is the case
|
||||
*
|
||||
* \param id Identifier of the entity
|
||||
*/
|
||||
|
||||
inline bool World::IsEntityIdValid(EntityId id) const
|
||||
{
|
||||
return id < m_entities.size() && m_entities[id].entity.IsValid();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes each system from the world
|
||||
*/
|
||||
|
||||
inline void World::RemoveAllSystems()
|
||||
{
|
||||
m_systems.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes a system from the world by index
|
||||
*
|
||||
* \param index Index of the system
|
||||
*
|
||||
* \remark No change is done if system is not present
|
||||
*/
|
||||
|
||||
inline void World::RemoveSystem(SystemIndex index)
|
||||
{
|
||||
///DOC: N'a aucun effet si le système n'est pas présent
|
||||
if (HasSystem(index))
|
||||
m_systems[index].reset();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Removes a system from the world by type
|
||||
*/
|
||||
|
||||
template<typename SystemType>
|
||||
void World::RemoveSystem()
|
||||
{
|
||||
@@ -136,6 +235,12 @@ namespace Ndk
|
||||
RemoveSystem(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates the world
|
||||
*
|
||||
* \param elapsedTime Delta time used for the update
|
||||
*/
|
||||
|
||||
inline void World::Update(float elapsedTime)
|
||||
{
|
||||
Update(); //< Update entities
|
||||
@@ -148,17 +253,32 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates each entity in the world
|
||||
*/
|
||||
|
||||
inline void World::Invalidate()
|
||||
{
|
||||
m_dirtyEntities.Resize(m_entities.size(), false);
|
||||
m_dirtyEntities.Set(true); // Activation de tous les bits
|
||||
m_dirtyEntities.Set(true); // Activation of all bits
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invalidates an entity in the world
|
||||
*
|
||||
* \param id Identifier of the entity
|
||||
*/
|
||||
|
||||
inline void World::Invalidate(EntityId id)
|
||||
{
|
||||
m_dirtyEntities.UnboundedSet(id, true);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves a world into another world object
|
||||
* \return A reference to the object
|
||||
*/
|
||||
|
||||
inline World& World::operator=(World&& world) noexcept
|
||||
{
|
||||
m_aliveEntities = std::move(world.m_aliveEntities);
|
||||
|
||||
Reference in New Issue
Block a user