From 9eba331f347af8cf6c6f022b2998dbdf96a04a32 Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Sun, 21 Aug 2016 13:48:52 +0200 Subject: [PATCH] Documentation for module 'NDK' Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]] Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401] Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da --- SDK/include/NDK/Algorithm.inl | 50 +- SDK/include/NDK/Application.inl | 48 +- SDK/include/NDK/BaseComponent.hpp | 2 +- SDK/include/NDK/BaseComponent.inl | 47 +- SDK/include/NDK/BaseSystem.hpp | 2 +- SDK/include/NDK/BaseSystem.inl | 153 +++++- SDK/include/NDK/Component.hpp | 2 +- SDK/include/NDK/Component.inl | 35 +- .../NDK/Components/CameraComponent.inl | 174 ++++++- .../NDK/Components/CollisionComponent.inl | 29 ++ .../NDK/Components/GraphicsComponent.inl | 67 +++ SDK/include/NDK/Components/LightComponent.inl | 4 + .../NDK/Components/ListenerComponent.inl | 15 + SDK/include/NDK/Components/NodeComponent.inl | 9 + .../Components/ParticleEmitterComponent.inl | 21 + .../NDK/Components/ParticleGroupComponent.inl | 39 ++ .../NDK/Components/PhysicsComponent.inl | 187 +++++++- .../NDK/Components/VelocityComponent.inl | 19 + SDK/include/NDK/Console.inl | 40 ++ SDK/include/NDK/Entity.inl | 173 ++++++- SDK/include/NDK/EntityList.inl | 42 +- SDK/include/NDK/EntityOwner.inl | 36 ++ SDK/include/NDK/LuaAPI.inl | 443 +++++++++++++++++- SDK/include/NDK/LuaBinding.inl | 28 ++ SDK/include/NDK/Prerequesites.hpp | 6 +- SDK/include/NDK/Sdk.inl | 5 + SDK/include/NDK/StateMachine.inl | 38 ++ SDK/include/NDK/System.hpp | 4 +- SDK/include/NDK/System.inl | 29 +- SDK/include/NDK/Systems/PhysicsSystem.inl | 10 + SDK/include/NDK/Systems/RenderSystem.inl | 77 +++ SDK/include/NDK/World.hpp | 1 - SDK/include/NDK/World.inl | 136 +++++- SDK/src/NDK/Application.cpp | 10 + SDK/src/NDK/BaseComponent.cpp | 28 ++ SDK/src/NDK/BaseSystem.cpp | 44 +- SDK/src/NDK/Components/CameraComponent.cpp | 88 ++++ SDK/src/NDK/Components/CollisionComponent.cpp | 43 +- SDK/src/NDK/Components/GraphicsComponent.cpp | 54 ++- .../Components/ParticleEmitterComponent.cpp | 13 + SDK/src/NDK/Components/PhysicsComponent.cpp | 32 ++ SDK/src/NDK/Console.cpp | 88 ++++ SDK/src/NDK/Entity.cpp | 80 +++- SDK/src/NDK/LuaAPI.cpp | 21 + SDK/src/NDK/LuaBinding.cpp | 16 + SDK/src/NDK/LuaBinding_Audio.cpp | 10 + SDK/src/NDK/LuaBinding_Core.cpp | 10 + SDK/src/NDK/LuaBinding_Graphics.cpp | 10 + SDK/src/NDK/LuaBinding_Math.cpp | 10 + SDK/src/NDK/LuaBinding_Network.cpp | 10 + SDK/src/NDK/LuaBinding_Renderer.cpp | 10 + SDK/src/NDK/LuaBinding_SDK.cpp | 18 + SDK/src/NDK/LuaBinding_Utility.cpp | 10 + SDK/src/NDK/Sdk.cpp | 19 + SDK/src/NDK/State.cpp | 6 + SDK/src/NDK/Systems/ListenerSystem.cpp | 26 +- SDK/src/NDK/Systems/ParticleSystem.cpp | 18 + SDK/src/NDK/Systems/PhysicsSystem.cpp | 40 +- SDK/src/NDK/Systems/RenderSystem.cpp | 44 ++ SDK/src/NDK/Systems/VelocitySystem.cpp | 19 + SDK/src/NDK/World.cpp | 95 +++- build/scripts/tools/unittests.lua | 13 +- tests/SDK/NDK/Application.cpp | 22 + tests/SDK/NDK/BaseSystem.cpp | 64 +++ tests/SDK/NDK/Component.cpp | 31 ++ tests/SDK/NDK/Entity.cpp | 101 ++++ tests/SDK/NDK/EntityList.cpp | 41 ++ tests/SDK/NDK/EntityOwner.cpp | 29 ++ tests/SDK/NDK/StateMachine.cpp | 48 ++ tests/SDK/NDK/System.cpp | 42 ++ tests/SDK/NDK/Systems/ListenerSystem.cpp | 43 ++ tests/SDK/NDK/Systems/PhysicsSystem.cpp | 34 ++ tests/SDK/NDK/Systems/RenderSystem.cpp | 44 ++ tests/SDK/NDK/Systems/VelocitySystem.cpp | 28 ++ tests/SDK/NDK/World.cpp | 103 ++++ 75 files changed, 3374 insertions(+), 112 deletions(-) create mode 100644 tests/SDK/NDK/Application.cpp create mode 100644 tests/SDK/NDK/BaseSystem.cpp create mode 100644 tests/SDK/NDK/Component.cpp create mode 100644 tests/SDK/NDK/Entity.cpp create mode 100644 tests/SDK/NDK/EntityList.cpp create mode 100644 tests/SDK/NDK/EntityOwner.cpp create mode 100644 tests/SDK/NDK/StateMachine.cpp create mode 100644 tests/SDK/NDK/System.cpp create mode 100644 tests/SDK/NDK/Systems/ListenerSystem.cpp create mode 100644 tests/SDK/NDK/Systems/PhysicsSystem.cpp create mode 100644 tests/SDK/NDK/Systems/RenderSystem.cpp create mode 100644 tests/SDK/NDK/Systems/VelocitySystem.cpp create mode 100644 tests/SDK/NDK/World.cpp diff --git a/SDK/include/NDK/Algorithm.inl b/SDK/include/NDK/Algorithm.inl index dd5f49cd4..fbdad365b 100644 --- a/SDK/include/NDK/Algorithm.inl +++ b/SDK/include/NDK/Algorithm.inl @@ -6,7 +6,15 @@ namespace Ndk { - ///TODO: constexpr avec le C++14 + /*! + * \ingroup NDK + * \brief Builds a component id based on a name + * \return Identifier for the component + * + * \param name Name to generate id from + */ + + ///TODO: constexpr with the C++14 template ComponentId BuildComponentId(const char (&name)[N]) { @@ -19,18 +27,38 @@ namespace Ndk return componentId; } + /*! + * \ingroup NDK + * \brief Gets the component id of a component + * \return Identifier for the component + */ + template ComponentIndex GetComponentIndex() { return ComponentType::componentIndex; } + /*! + * \ingroup NDK + * \brief Gets the system id of a system + * \return Identifier for the system + */ + template SystemIndex GetSystemIndex() { return SystemType::systemIndex; } + /*! + * \ingroup NDK + * \brief Initializes the a component + * \return Identifier for the component + * + * \param name Name to generate id from + */ + template ComponentIndex InitializeComponent(const char (&name)[N]) { @@ -38,6 +66,12 @@ namespace Ndk return ComponentType::componentIndex; } + /*! + * \ingroup NDK + * \brief Initializes the a system + * \return Identifier for the system + */ + template SystemIndex InitializeSystem() { @@ -45,12 +79,26 @@ namespace Ndk return SystemType::systemIndex; } + /*! + * \brief Checks whether the parameter is a component + * \return true If it is the case + * + * \param component Component to check + */ + template bool IsComponent(C& component) { return component.GetIndex() == GetComponentIndex(); } + /*! + * \brief Checks whether the parameter is a system + * \return true If it is the case + * + * \param system System to check + */ + template bool IsSystem(S& system) { diff --git a/SDK/include/NDK/Application.inl b/SDK/include/NDK/Application.inl index 96e8768ce..0d21d1b94 100644 --- a/SDK/include/NDK/Application.inl +++ b/SDK/include/NDK/Application.inl @@ -8,6 +8,12 @@ namespace Ndk { + /*! + * \brief Constructs an Application object by default + * + * \remark Produces a NazaraAssert if there's more than one application instance currently running + */ + inline Application::Application() : #ifndef NDK_SERVER m_exitOnClosedWindows(true), @@ -24,6 +30,10 @@ namespace Ndk Sdk::Initialize(); } + /*! + * \brief Destructs the object + */ + inline Application::~Application() { m_worlds.clear(); @@ -31,13 +41,20 @@ namespace Ndk m_windows.clear(); #endif - // Libération du SDK + // Free of SDK Sdk::Uninitialize(); - // Libération automatique des modules + // Automatic free of modules s_application = nullptr; } + /*! + * \brief Adds a window to the application + * \return A reference to the newly created windows + * + * \param args Arguments used to create the window + */ + #ifndef NDK_SERVER template T& Application::AddWindow(Args&&... args) @@ -49,6 +66,13 @@ namespace Ndk } #endif + /*! + * \brief Adds a world to the application + * \return A reference to the newly created world + * + * \param args Arguments used to create the world + */ + template World& Application::AddWorld(Args&&... args) { @@ -56,11 +80,22 @@ namespace Ndk return m_worlds.back(); } + /*! + * \brief Gets the update time of the application + * \return Update rate + */ + inline float Application::GetUpdateTime() const { return m_updateTime; } + /*! + * \brief Makes the application exit when there's no more open window + * + * \param exitOnClosedWindows Should exit be called when no more window is open + */ + #ifndef NDK_SERVER inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows) { @@ -68,11 +103,20 @@ namespace Ndk } #endif + /*! + * \brief Quits the application + */ + inline void Application::Quit() { m_shouldQuit = true; } + /*! + * \brief Gets the singleton instance of the application + * \return Singleton application + */ + inline Application* Application::Instance() { return s_application; diff --git a/SDK/include/NDK/BaseComponent.hpp b/SDK/include/NDK/BaseComponent.hpp index f045ae2a6..0a48c394d 100644 --- a/SDK/include/NDK/BaseComponent.hpp +++ b/SDK/include/NDK/BaseComponent.hpp @@ -27,7 +27,7 @@ namespace Ndk BaseComponent(BaseComponent&&) = default; virtual ~BaseComponent(); - virtual BaseComponent* Clone() const = 0; + virtual std::unique_ptr Clone() const = 0; ComponentIndex GetIndex() const; diff --git a/SDK/include/NDK/BaseComponent.inl b/SDK/include/NDK/BaseComponent.inl index 341ddb651..0e8af931f 100644 --- a/SDK/include/NDK/BaseComponent.inl +++ b/SDK/include/NDK/BaseComponent.inl @@ -7,34 +7,60 @@ namespace Ndk { + /*! + * \brief Constructs a BaseComponent object with an index + * + * \param index Index of the component + */ + inline BaseComponent::BaseComponent(ComponentIndex index) : m_componentIndex(index), m_entity(nullptr) { } + /*! + * \brief Gets the index of the component + * \return Index of the component + */ + inline ComponentIndex BaseComponent::GetIndex() const { return m_componentIndex; } + /*! + * \brief Gets the maximal index of the components + * \return Index of the maximal component + */ + inline ComponentIndex BaseComponent::GetMaxComponentIndex() { return static_cast(s_entries.size()); } + /*! + * \brief Registers a component + * \return Index of the registered component + * + * \param id Index of the component + * \param factory Factory to create the component + * + * \remark Produces a NazaraAssert if the identifier is already in use + */ + inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc) { - // Nous allons rajouter notre composant à la fin + // We add our component to the end ComponentIndex index = static_cast(s_entries.size()); s_entries.resize(index + 1); - // On récupère et on affecte + // We retrieve it and affect it ComponentEntry& entry = s_entries.back(); entry.factory = factoryFunc; entry.id = id; - // Une petite assertion pour s'assurer que l'identifiant n'est pas déjà utilisé + // We ensure that id is not already in use NazaraAssert(s_idToIndex.find(id) == s_idToIndex.end(), "This id is already in use"); s_idToIndex[id] = index; @@ -42,6 +68,10 @@ namespace Ndk return index; } + /*! + * \brief Sets the entity on which the component operates + */ + inline void BaseComponent::SetEntity(Entity* entity) { if (m_entity != entity) @@ -55,12 +85,21 @@ namespace Ndk } } + /*! + * \brief Initializes the BaseComponent + * \return true + */ + inline bool BaseComponent::Initialize() { - // Rien à faire + // Nothing to do return true; } + /*! + * \brief Uninitializes the BaseComponent + */ + inline void BaseComponent::Uninitialize() { s_entries.clear(); diff --git a/SDK/include/NDK/BaseSystem.hpp b/SDK/include/NDK/BaseSystem.hpp index 969f2b773..a4ff0bf41 100644 --- a/SDK/include/NDK/BaseSystem.hpp +++ b/SDK/include/NDK/BaseSystem.hpp @@ -29,7 +29,7 @@ namespace Ndk inline void Enable(bool enable = true); - virtual BaseSystem* Clone() const = 0; + virtual std::unique_ptr Clone() const = 0; bool Filters(const Entity* entity) const; diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 490b32e76..1afc242c0 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -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& 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 void BaseSystem::Excludes() { @@ -96,6 +162,10 @@ namespace Ndk ExcludesComponent(GetComponentIndex()); } + /*! + * \brief Excludes some components from the system + */ + template void BaseSystem::Excludes() { @@ -103,16 +173,31 @@ namespace Ndk Excludes(); } + /*! + * \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 void BaseSystem::Requires() { @@ -121,6 +206,10 @@ namespace Ndk RequiresComponent(GetComponentIndex()); } + /*! + * \brief Requires some components from the system + */ + template void BaseSystem::Requires() { @@ -128,11 +217,21 @@ namespace Ndk Requires(); } + /*! + * \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 void BaseSystem::RequiresAny() { @@ -141,6 +240,10 @@ namespace Ndk RequiresAnyComponent(GetComponentIndex()); } + /*! + * \brief Requires any components from the system + */ + template void BaseSystem::RequiresAny() { @@ -148,11 +251,25 @@ namespace Ndk RequiresAny(); } + /*! + * \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 diff --git a/SDK/include/NDK/Component.hpp b/SDK/include/NDK/Component.hpp index e3026dbad..b0f61fd92 100644 --- a/SDK/include/NDK/Component.hpp +++ b/SDK/include/NDK/Component.hpp @@ -18,7 +18,7 @@ namespace Ndk Component(); virtual ~Component(); - BaseComponent* Clone() const override; + std::unique_ptr Clone() const override; static ComponentIndex RegisterComponent(ComponentId id); diff --git a/SDK/include/NDK/Component.inl b/SDK/include/NDK/Component.inl index 833395957..6ca3f1944 100644 --- a/SDK/include/NDK/Component.inl +++ b/SDK/include/NDK/Component.inl @@ -7,6 +7,18 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::Component + * \brief NDK class that represents a component for an entity which interacts with a system + * + * \remark This class is meant to be derived as CRTP: "Component" + */ + + /*! + * \brief Constructs a Component object by default + */ + template Component::Component() : BaseComponent(GetComponentIndex()) @@ -16,19 +28,30 @@ namespace Ndk template Component::~Component() = default; + /*! + * \brief Clones the component + * \return The clone newly created + * + * \remark The component to clone should be trivially copy constructible + */ + template - BaseComponent* Component::Clone() const + std::unique_ptr Component::Clone() const { ///FIXME: Pas encore supporté par GCC (4.9.2) //static_assert(std::is_trivially_copy_constructible::value, "ComponentType must be copy-constructible"); - return new ComponentType(static_cast(*this)); + return std::make_unique(static_cast(*this)); } + /*! + * \brief Registers the component by assigning it an index + */ + template ComponentIndex Component::RegisterComponent(ComponentId id) { - // On utilise les lambda pour créer une fonction factory + //We use the lambda to create a factory function auto factory = []() -> BaseComponent* { return nullptr; //< Temporary workaround to allow non-default-constructed components, will be updated for serialization @@ -38,11 +61,15 @@ namespace Ndk return BaseComponent::RegisterComponent(id, factory); } + /*! + * \brief Registers the component by assigning it an index based on the name + */ + template template ComponentIndex Component::RegisterComponent(const char (&name)[N]) { - // On récupère la chaîne de caractère sous la forme d'un nombre qui servira d'identifiant unique + // We convert the string to a number which will be used as unique identifier ComponentId id = BuildComponentId(name); return RegisterComponent(id); } diff --git a/SDK/include/NDK/Components/CameraComponent.inl b/SDK/include/NDK/Components/CameraComponent.inl index d91c357eb..d42d0e152 100644 --- a/SDK/include/NDK/Components/CameraComponent.inl +++ b/SDK/include/NDK/Components/CameraComponent.inl @@ -8,6 +8,10 @@ namespace Ndk { + /*! + * \brief Constructs an CameraComponent object by default + */ + inline CameraComponent::CameraComponent() : m_projectionType(Nz::ProjectionType_Perspective), m_targetRegion(0.f, 0.f, 1.f, 1.f), @@ -25,6 +29,12 @@ namespace Ndk { } + /*! + * \brief Constructs a CameraComponent object by copy semantic + * + * \param camera CameraComponent to copy + */ + inline CameraComponent::CameraComponent(const CameraComponent& camera) : Component(camera), AbstractViewer(camera), @@ -45,30 +55,51 @@ namespace Ndk SetTarget(camera.m_target); } + /*! + * \brief Ensures the frustum is up to date + */ + inline void CameraComponent::EnsureFrustumUpdate() const { if (!m_frustumUpdated) UpdateFrustum(); } + /*! + * \brief Ensures the projection matrix is up to date + */ + inline void CameraComponent::EnsureProjectionMatrixUpdate() const { if (!m_projectionMatrixUpdated) UpdateProjectionMatrix(); } + /*! + * \brief Ensures the view matrix is up to date + */ + inline void CameraComponent::EnsureViewMatrixUpdate() const { if (!m_viewMatrixUpdated) UpdateViewMatrix(); } + /*! + * \brief Ensures the view port is up to date + */ + inline void CameraComponent::EnsureViewportUpdate() const { if (!m_viewportUpdated) UpdateViewport(); } + /*! + * \brief Gets the aspect ratio of the camera + * \return Aspect ratio of the camera + */ + inline float CameraComponent::GetAspectRatio() const { EnsureViewportUpdate(); @@ -76,11 +107,21 @@ namespace Ndk return m_aspectRatio; } + /*! + * \brief Gets the field of view of the camera + * \return Field of view of the camera + */ + inline float CameraComponent::GetFOV() const { return m_fov; } + /*! + * \brief Gets the frutum of the camera + * \return A constant reference to the frustum of the camera + */ + inline const Nz::Frustumf& CameraComponent::GetFrustum() const { EnsureFrustumUpdate(); @@ -88,11 +129,21 @@ namespace Ndk return m_frustum; } + /*! + * \brief Gets the layer of the camera + * \return Layer of the camera + */ + inline unsigned int CameraComponent::GetLayer() const { return m_layer; } + /*! + * \brief Gets the projection matrix of the camera + * \return A constant reference to the projection matrix of the camera + */ + inline const Nz::Matrix4f& CameraComponent::GetProjectionMatrix() const { EnsureProjectionMatrixUpdate(); @@ -100,26 +151,51 @@ namespace Ndk return m_projectionMatrix; } + /*! + * \brief Gets the projection type of the camera + * \return Projection type of the camera + */ + inline Nz::ProjectionType CameraComponent::GetProjectionType() const { return m_projectionType; } + /*! + * \brief Gets the size of the camera + * \return Size of the camera + */ + inline const Nz::Vector2f & CameraComponent::GetSize() const { return m_size; } + /*! + * \brief Gets the target of the camera + * \return A constant reference to the render target of the camera + */ + inline const Nz::RenderTarget* CameraComponent::GetTarget() const { return m_target; } + /*! + * \brief Gets the target region of the camera + * \return A constant reference to the target region of the camera + */ + inline const Nz::Rectf& CameraComponent::GetTargetRegion() const { return m_targetRegion; } + /*! + * \brief Gets the view matrix of the camera + * \return A constant reference to the view matrix of the camera + */ + inline const Nz::Matrix4f& CameraComponent::GetViewMatrix() const { EnsureViewMatrixUpdate(); @@ -127,6 +203,11 @@ namespace Ndk return m_viewMatrix; } + /*! + * \brief Gets the view port of the camera + * \return A constant reference to the view port of the camera + */ + inline const Nz::Recti& CameraComponent::GetViewport() const { EnsureViewportUpdate(); @@ -134,16 +215,34 @@ namespace Ndk return m_viewport; } + /*! + * \brief Gets the Z far distance of the camera + * \return Z far distance of the camera + */ + inline float CameraComponent::GetZFar() const { return m_zFar; } + /*! + * \brief Gets the Z near distance of the camera + * \return Z near distance of the camera + */ + inline float CameraComponent::GetZNear() const { return m_zNear; } + /*! + * \brief Sets the field of view of the camera + * + * \param fov Field of view of the camera + * + * \remark Produces a NazaraAssert if angle is zero + */ + inline void CameraComponent::SetFOV(float fov) { NazaraAssert(!Nz::NumberEquals(fov, 0.f), "FOV must be different from zero"); @@ -152,6 +251,12 @@ namespace Ndk InvalidateProjectionMatrix(); } + /*! + * \brief Sets the projection type of the camera + * + * \param projectionType Projection type of the camera + */ + inline void CameraComponent::SetProjectionType(Nz::ProjectionType projectionType) { m_projectionType = projectionType; @@ -159,6 +264,12 @@ namespace Ndk InvalidateProjectionMatrix(); } + /*! + * \brief Sets the size of the camera + * + * \param size Size of the camera + */ + inline void CameraComponent::SetSize(const Nz::Vector2f& size) { m_size = size; @@ -166,11 +277,24 @@ namespace Ndk InvalidateProjectionMatrix(); } + /*! + * \brief Sets the size of the camera + * + * \param width Size in X of the camera + * \param height Size in Y of the camera + */ + inline void CameraComponent::SetSize(float width, float height) { SetSize({width, height}); } + /*! + * \brief Sets the target of the camera + * + * \param renderTarget A constant reference to the render target of the camera + */ + inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget) { m_target = renderTarget; @@ -186,6 +310,12 @@ namespace Ndk } } + /*! + * \brief Sets the target region of the camera + * + * \param region A constant reference to the target region of the camera + */ + inline void CameraComponent::SetTargetRegion(const Nz::Rectf& region) { m_targetRegion = region; @@ -193,17 +323,31 @@ namespace Ndk InvalidateViewport(); } + /*! + * \brief Sets the view port of the camera + * + * \param viewport A constant reference to the view port of the camera + * + * \remark Produces a NazaraAssert if the camera has no target + */ + inline void CameraComponent::SetViewport(const Nz::Recti& viewport) { NazaraAssert(m_target, "Component has no render target"); - // On calcule la région nécessaire pour produire ce viewport avec la taille actuelle de la cible - float invWidth = 1.f/m_target->GetWidth(); - float invHeight = 1.f/m_target->GetHeight(); + // We compute the region necessary to make this view port with the actual size of the target + float invWidth = 1.f / m_target->GetWidth(); + float invHeight = 1.f / m_target->GetHeight(); SetTargetRegion(Nz::Rectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height)); } + /*! + * \brief Sets the Z far distance of the camera + * + * \param zFar Z far distance of the camera + */ + inline void CameraComponent::SetZFar(float zFar) { m_zFar = zFar; @@ -211,6 +355,14 @@ namespace Ndk InvalidateProjectionMatrix(); } + /*! + * \brief Sets the Z near distance of the camera + * + * \param zNear Z near distance of the camera + * + * \remark Produces a NazaraAssert if zNear is zero + */ + inline void CameraComponent::SetZNear(float zNear) { NazaraAssert(!Nz::NumberEquals(zNear, 0.f), "zNear cannot be zero"); @@ -219,23 +371,39 @@ namespace Ndk InvalidateProjectionMatrix(); } + /*! + * \brief Invalidates the frustum + */ + inline void CameraComponent::InvalidateFrustum() const { m_frustumUpdated = false; } + /*! + * \brief Invalidates the projection matrix + */ + inline void CameraComponent::InvalidateProjectionMatrix() const { m_frustumUpdated = false; m_projectionMatrixUpdated = false; } + /*! + * \brief Invalidates the view matrix + */ + inline void CameraComponent::InvalidateViewMatrix() const { m_frustumUpdated = false; m_viewMatrixUpdated = false; } + /*! + * \brief Invalidates the view port + */ + inline void CameraComponent::InvalidateViewport() const { m_frustumUpdated = false; diff --git a/SDK/include/NDK/Components/CollisionComponent.inl b/SDK/include/NDK/Components/CollisionComponent.inl index 58356ac9e..b08e7054e 100644 --- a/SDK/include/NDK/Components/CollisionComponent.inl +++ b/SDK/include/NDK/Components/CollisionComponent.inl @@ -9,23 +9,47 @@ namespace Ndk { + /*! + * \brief Constructs a CollisionComponent object with a geometry + * + * \param geom Reference to a geometry symbolizing the entity + */ + inline CollisionComponent::CollisionComponent(Nz::PhysGeomRef geom) : m_geom(std::move(geom)), m_bodyUpdated(false) { } + /*! + * \brief Constructs a CollisionComponent object by copy semantic + * + * \param collision CollisionComponent to copy + */ + inline CollisionComponent::CollisionComponent(const CollisionComponent& collision) : m_geom(collision.m_geom), m_bodyUpdated(false) { } + /*! + * \brief Gets the geometry representing the entity + * \return A constant reference to the physics geometry + */ + inline const Nz::PhysGeomRef& CollisionComponent::GetGeom() const { return m_geom; } + /*! + * \brief Assigns the geometry to this component + * \return A reference to this + * + * \param geom Reference to a geometry symbolizing the entity + */ + inline CollisionComponent& CollisionComponent::operator=(Nz::PhysGeomRef geom) { SetGeom(geom); @@ -33,6 +57,11 @@ namespace Ndk return *this; } + /*! + * \brief Gets the static body used by the entity + * \return A pointer to the entity + */ + inline Nz::PhysObject* CollisionComponent::GetStaticBody() { return m_staticBody.get(); diff --git a/SDK/include/NDK/Components/GraphicsComponent.inl b/SDK/include/NDK/Components/GraphicsComponent.inl index 0d9cb7af4..01cd7a2e3 100644 --- a/SDK/include/NDK/Components/GraphicsComponent.inl +++ b/SDK/include/NDK/Components/GraphicsComponent.inl @@ -7,6 +7,12 @@ namespace Ndk { + /*! + * \brief Constructs a GraphicsComponent object by copy semantic + * + * \param graphicsComponent GraphicsComponent to copy + */ + inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) : Component(graphicsComponent), HandledObject(graphicsComponent), @@ -20,6 +26,12 @@ namespace Ndk Attach(r.renderable, r.data.renderOrder); } + /*! + * \brief Adds the renderable elements to the render queue + * + * \param renderQueue Queue to be added + */ + inline void GraphicsComponent::AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const { EnsureTransformMatrixUpdate(); @@ -36,6 +48,13 @@ namespace Ndk } } + /*! + * \brief Attaches a renderable to the entity + * + * \param renderable Reference to a renderable element + * \param renderOrder Render order of the element + */ + inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder) { m_renderables.emplace_back(m_transformMatrix); @@ -48,6 +67,10 @@ namespace Ndk InvalidateBoundingVolume(); } + /*! + * \brief Clears every renderable elements + */ + inline void GraphicsComponent::Clear() { m_renderables.clear(); @@ -55,6 +78,12 @@ namespace Ndk InvalidateBoundingVolume(); } + /*! + * \brief Detaches a renderable to the entity + * + * \param renderable Reference to a renderable element + */ + inline void GraphicsComponent::Detach(const Nz::InstancedRenderable* renderable) { for (auto it = m_renderables.begin(); it != m_renderables.end(); ++it) @@ -68,18 +97,34 @@ namespace Ndk } } + /*! + * \brief Ensures the bounding volume is up to date + */ + inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const { if (!m_boundingVolumeUpdated) UpdateBoundingVolume(); } + /*! + * \brief Ensures the transformation matrix is up to date + */ + inline void GraphicsComponent::EnsureTransformMatrixUpdate() const { if (!m_transformMatrixUpdated) UpdateTransformMatrix(); } + /*! + * \brief Gets the set of renderable elements + * + * \param renderables Pointer to the list of renderables + * + * \remark Produces a NazaraAssert if renderables is invalid + */ + inline void GraphicsComponent::GetAttachedRenderables(RenderableList* renderables) const { NazaraAssert(renderables, "Invalid renderable list"); @@ -89,11 +134,21 @@ namespace Ndk renderables->push_back(r.renderable); } + /*! + * \brief Gets the number of renderable elements attached to the entity + * \return Number of renderable elements + */ + inline std::size_t GraphicsComponent::GetAttachedRenderableCount() const { return m_renderables.size(); } + /*! + * \brief Gets the bouding volume of the entity + * \return A constant reference to the bounding volume + */ + inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const { EnsureBoundingVolumeUpdate(); @@ -101,17 +156,29 @@ namespace Ndk return m_boundingVolume; } + /*! + * \brief Invalidates the bounding volume + */ + inline void GraphicsComponent::InvalidateBoundingVolume() { m_boundingVolumeUpdated = false; } + /*! + * \brief Invalidates every renderable elements + */ + inline void GraphicsComponent::InvalidateRenderables() { for (Renderable& r : m_renderables) r.dataUpdated = false; } + /*! + * \brief Invalidates the transformation matrix + */ + inline void GraphicsComponent::InvalidateTransformMatrix() { m_boundingVolumeUpdated = false; diff --git a/SDK/include/NDK/Components/LightComponent.inl b/SDK/include/NDK/Components/LightComponent.inl index f06fcb24c..ba11703c5 100644 --- a/SDK/include/NDK/Components/LightComponent.inl +++ b/SDK/include/NDK/Components/LightComponent.inl @@ -4,6 +4,10 @@ namespace Ndk { + /*! + * \brief Constructs an LightComponent object with a light type + */ + inline LightComponent::LightComponent(Nz::LightType lightType) : Nz::Light(lightType) { diff --git a/SDK/include/NDK/Components/ListenerComponent.inl b/SDK/include/NDK/Components/ListenerComponent.inl index 7dc7b0391..f2276e439 100644 --- a/SDK/include/NDK/Components/ListenerComponent.inl +++ b/SDK/include/NDK/Components/ListenerComponent.inl @@ -4,16 +4,31 @@ namespace Ndk { + /*! + * \brief Constructs an ListenerComponent object by default + */ + inline ListenerComponent::ListenerComponent() : m_isActive(true) { } + /*! + * \brief Checks whether the listener is activated + * \param true If it is the case + */ + inline bool ListenerComponent::IsActive() const { return m_isActive; } + /*! + * \brief Enables the listener + * + * \param active Should the listener be active + */ + inline void ListenerComponent::SetActive(bool active) { m_isActive = active; diff --git a/SDK/include/NDK/Components/NodeComponent.inl b/SDK/include/NDK/Components/NodeComponent.inl index e6d49c9a9..0150cbbfa 100644 --- a/SDK/include/NDK/Components/NodeComponent.inl +++ b/SDK/include/NDK/Components/NodeComponent.inl @@ -7,6 +7,15 @@ namespace Ndk { + /*! + * \brief Sets the parent node of the entity + * + * \param entity Pointer to the entity considered as parent + * \param keepDerived Should this component considered as a derived + * + * \remark Produces a NazaraAssert if entity has no component NodeComponent + */ + inline void NodeComponent::SetParent(Entity* entity, bool keepDerived) { if (entity) diff --git a/SDK/include/NDK/Components/ParticleEmitterComponent.inl b/SDK/include/NDK/Components/ParticleEmitterComponent.inl index 342b5e56f..7f8e62cd8 100644 --- a/SDK/include/NDK/Components/ParticleEmitterComponent.inl +++ b/SDK/include/NDK/Components/ParticleEmitterComponent.inl @@ -6,21 +6,42 @@ namespace Ndk { + /*! + * \brief Constructs an ParticleEmitterComponent object by default + */ + inline ParticleEmitterComponent::ParticleEmitterComponent() : m_isActive(true) { } + /*! + * \brief Enables the emission of particles + * + * \param active Should the emitter be active + */ + inline void Ndk::ParticleEmitterComponent::Enable(bool active) { m_isActive = active; } + /*! + * \brief Checks whether the emission of particles is activated + * \param true If it is the case + */ + inline bool ParticleEmitterComponent::IsActive() const { return m_isActive; } + /*! + * \brief Sets the function use for setting up particles + * + * \param func Function to set up particles + */ + inline void Ndk::ParticleEmitterComponent::SetSetupFunc(SetupFunc func) { m_setupFunc = std::move(func); diff --git a/SDK/include/NDK/Components/ParticleGroupComponent.inl b/SDK/include/NDK/Components/ParticleGroupComponent.inl index c6e0cba7b..591e78605 100644 --- a/SDK/include/NDK/Components/ParticleGroupComponent.inl +++ b/SDK/include/NDK/Components/ParticleGroupComponent.inl @@ -8,16 +8,45 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::ParticleGroupComponent + * \brief NDK class that represents the component for a group of particles + */ + + /*! + * \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a layout + * + * \param maxParticleCount Maximum number of particles to generate + * \param layout Enumeration for the layout of data information for the particles + */ + inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout) : ParticleGroup(maxParticleCount, layout) { } + /*! + * \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a particle declaration + * + * \param maxParticleCount Maximum number of particles to generate + * \param declaration Data information for the particles + */ + inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration) : ParticleGroup(maxParticleCount, std::move(declaration)) { } + /*! + * \brief Adds an emitter to the particles + * + * \param emitter Emitter for the particles + * + * \remark Produces a NazaraAssert if emitter is invalid + * \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent + */ + inline void ParticleGroupComponent::AddEmitter(Entity* emitter) { NazaraAssert(emitter && emitter->IsValid(), "Invalid entity"); @@ -27,6 +56,16 @@ namespace Ndk ParticleGroup::AddEmitter(&emitterComponent); } + + /*! + * \brief Removes an emitter to the particles + * + * \param emitter Emitter for the particles to remove + * + * \remark Produces a NazaraAssert if emitter is invalid + * \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent + */ + inline void ParticleGroupComponent::RemoveEmitter(Entity* emitter) { NazaraAssert(emitter && emitter->IsValid(), "Invalid entity"); diff --git a/SDK/include/NDK/Components/PhysicsComponent.inl b/SDK/include/NDK/Components/PhysicsComponent.inl index f0847842d..5682603e0 100644 --- a/SDK/include/NDK/Components/PhysicsComponent.inl +++ b/SDK/include/NDK/Components/PhysicsComponent.inl @@ -6,12 +6,27 @@ namespace Ndk { + /*! + * \brief Constructs a PhysicsComponent object by copy semantic + * + * \param physics PhysicsComponent to copy + */ + inline PhysicsComponent::PhysicsComponent(const PhysicsComponent& physics) { - // Pas de copie de l'objet physique (étant donné que nous n'allons le créer qu'une fois attaché à une entité) + // No copy of physical object (because we only create it when attached to an entity) NazaraUnused(physics); } + /*! + * \brief Applies a force to the entity + * + * \param force Force to apply on the entity + * \param coordSys System coordinates to consider + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys) { NazaraAssert(m_object, "Invalid physics object"); @@ -19,6 +34,16 @@ namespace Ndk m_object->AddForce(force, coordSys); } + /*! + * \brief Applies a force to the entity + * + * \param force Force to apply on the entity + * \param point Point where to apply the force + * \param coordSys System coordinates to consider + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys) { NazaraAssert(m_object, "Invalid physics object"); @@ -26,13 +51,30 @@ namespace Ndk m_object->AddForce(force, point, coordSys); } + /*! + * \brief Applies a torque to the entity + * + * \param torque Torque to apply on the entity + * \param coordSys System coordinates to consider + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys) { NazaraAssert(m_object, "Invalid physics object"); - m_object->AddForce(torque, coordSys); + m_object->AddTorque(torque, coordSys); } + /*! + * \brief Enables auto sleep of physics object + * + * \param autoSleep Should the physics of the object be disabled when too far from others + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::EnableAutoSleep(bool autoSleep) { NazaraAssert(m_object, "Invalid physics object"); @@ -40,6 +82,13 @@ namespace Ndk m_object->EnableAutoSleep(autoSleep); } + /*! + * \brief Gets the AABB of the physics object + * \return AABB of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Boxf PhysicsComponent::GetAABB() const { NazaraAssert(m_object, "Invalid physics object"); @@ -47,6 +96,13 @@ namespace Ndk return m_object->GetAABB(); } + /*! + * \brief Gets the angular velocity of the physics object + * \return Angular velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Vector3f PhysicsComponent::GetAngularVelocity() const { NazaraAssert(m_object, "Invalid physics object"); @@ -54,6 +110,13 @@ namespace Ndk return m_object->GetAngularVelocity(); } + /*! + * \brief Gets the gravity factor of the physics object + * \return Gravity factor of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline float PhysicsComponent::GetGravityFactor() const { NazaraAssert(m_object, "Invalid physics object"); @@ -61,6 +124,13 @@ namespace Ndk return m_object->GetGravityFactor(); } + /*! + * \brief Gets the mass of the physics object + * \return Mass of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline float PhysicsComponent::GetMass() const { NazaraAssert(m_object, "Invalid physics object"); @@ -68,6 +138,15 @@ namespace Ndk return m_object->GetMass(); } + /*! + * \brief Gets the gravity center of the physics object + * \return Gravity center of the object + * + * \param coordSys System coordinates to consider + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Vector3f PhysicsComponent::GetMassCenter(Nz::CoordSys coordSys) const { NazaraAssert(m_object, "Invalid physics object"); @@ -75,6 +154,13 @@ namespace Ndk return m_object->GetMassCenter(coordSys); } + /*! + * \brief Gets the matrix of the physics object + * \return Matrix of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline const Nz::Matrix4f& PhysicsComponent::GetMatrix() const { NazaraAssert(m_object, "Invalid physics object"); @@ -82,6 +168,13 @@ namespace Ndk return m_object->GetMatrix(); } + /*! + * \brief Gets the position of the physics object + * \return Position of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Vector3f PhysicsComponent::GetPosition() const { NazaraAssert(m_object, "Invalid physics object"); @@ -89,6 +182,13 @@ namespace Ndk return m_object->GetPosition(); } + /*! + * \brief Gets the rotation of the physics object + * \return Rotation of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Quaternionf PhysicsComponent::GetRotation() const { NazaraAssert(m_object, "Invalid physics object"); @@ -96,6 +196,13 @@ namespace Ndk return m_object->GetRotation(); } + /*! + * \brief Gets the velocity of the physics object + * \return Velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Vector3f PhysicsComponent::GetVelocity() const { NazaraAssert(m_object, "Invalid physics object"); @@ -103,6 +210,13 @@ namespace Ndk return m_object->GetVelocity(); } + /*! + * \brief Checks whether the auto sleep is enabled + * \return true If it is the case + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline bool PhysicsComponent::IsAutoSleepEnabled() const { NazaraAssert(m_object, "Invalid physics object"); @@ -110,6 +224,13 @@ namespace Ndk return m_object->IsAutoSleepEnabled(); } + /*! + * \brief Checks whether the entity is currently sleeping + * \return true If it is the case + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline bool PhysicsComponent::IsSleeping() const { NazaraAssert(m_object, "Invalid physics object"); @@ -117,6 +238,14 @@ namespace Ndk return m_object->IsSleeping(); } + /*! + * \brief Sets the angular velocity of the physics object + * + * \param angularVelocity Angular velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetAngularVelocity(const Nz::Vector3f& angularVelocity) { NazaraAssert(m_object, "Invalid physics object"); @@ -124,6 +253,14 @@ namespace Ndk m_object->SetAngularVelocity(angularVelocity); } + /*! + * \brief Sets the gravity factor of the physics object + * + * \param gravityFactor Gravity factor of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetGravityFactor(float gravityFactor) { NazaraAssert(m_object, "Invalid physics object"); @@ -131,6 +268,15 @@ namespace Ndk m_object->SetGravityFactor(gravityFactor); } + /*! + * \brief Sets the mass of the physics object + * + * \param mass Mass of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + * \remark Produces a NazaraAssert if the mass is negative + */ + inline void PhysicsComponent::SetMass(float mass) { NazaraAssert(m_object, "Invalid physics object"); @@ -139,6 +285,14 @@ namespace Ndk m_object->SetMass(mass); } + /*! + * \brief Sets the gravity center of the physics object + * + * \param center Gravity center of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetMassCenter(const Nz::Vector3f& center) { NazaraAssert(m_object, "Invalid physics object"); @@ -146,6 +300,14 @@ namespace Ndk m_object->SetMassCenter(center); } + /*! + * \brief Sets the position of the physics object + * + * \param position Position of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetPosition(const Nz::Vector3f& position) { NazaraAssert(m_object, "Invalid physics object"); @@ -153,6 +315,14 @@ namespace Ndk m_object->SetPosition(position); } + /*! + * \brief Sets the rotation of the physics object + * + * \param rotation Rotation of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetRotation(const Nz::Quaternionf& rotation) { NazaraAssert(m_object, "Invalid physics object"); @@ -160,6 +330,14 @@ namespace Ndk m_object->SetRotation(rotation); } + /*! + * \brief Sets the velocity of the physics object + * + * \param velocity Velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent::SetVelocity(const Nz::Vector3f& velocity) { NazaraAssert(m_object, "Invalid physics object"); @@ -167,6 +345,11 @@ namespace Ndk m_object->SetVelocity(velocity); } + /*! + * \brief Gets the underlying physics object + * \return A reference to the physics object + */ + inline Nz::PhysObject& PhysicsComponent::GetPhysObject() { return *m_object.get(); diff --git a/SDK/include/NDK/Components/VelocityComponent.inl b/SDK/include/NDK/Components/VelocityComponent.inl index 1c2f0ed87..e72eca8b7 100644 --- a/SDK/include/NDK/Components/VelocityComponent.inl +++ b/SDK/include/NDK/Components/VelocityComponent.inl @@ -7,11 +7,30 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::VelocityComponent + * \brief NDK class that represents the component for velocity + */ + + /*! + * \brief Constructs a VelocityComponent object with a velocity + * + * \param velocity Linear velocity + */ + inline VelocityComponent::VelocityComponent(const Nz::Vector3f& velocity) : linearVelocity(velocity) { } + /*! + * \brief Assigns the velocity to this component + * \return A reference to this + * + * \param vel Linear velocity + */ + inline VelocityComponent& VelocityComponent::operator=(const Nz::Vector3f& vel) { linearVelocity = vel; diff --git a/SDK/include/NDK/Console.inl b/SDK/include/NDK/Console.inl index 5fb16bb1b..94a6daf91 100644 --- a/SDK/include/NDK/Console.inl +++ b/SDK/include/NDK/Console.inl @@ -7,41 +7,81 @@ namespace Ndk { + /*! + * \brief Gets the character size + * \return Height of the character + */ + inline unsigned int Console::GetCharacterSize() const { return m_characterSize; } + /*! + * \brief Gets the entity representing the history of the console + * \return History of the console + */ + inline const EntityHandle& Console::GetHistory() const { return m_history; } + /*! + * \brief Gets the entity representing the background of the console's history + * \return Background history of the console + */ + inline const EntityHandle& Console::GetHistoryBackground() const { return m_historyBackground; } + /*! + * \brief Gets the entity representing the input of the console + * \return Input of the console + */ + inline const EntityHandle& Console::GetInput() const { return m_input; } + /*! + * \brief Gets the entity representing the background of the console's input + * \return Background input of the console + */ + inline const EntityHandle& Console::GetInputBackground() const { return m_inputBackground; } + /*! + * \brief Gets the size of the console + * \return Size (Width, Height) of the console + */ + inline const Nz::Vector2f& Console::GetSize() const { return m_size; } + /*! + * \brief Gets the font used by the console + * \return A reference to the font currenty used + */ + inline const Nz::FontRef& Console::GetTextFont() const { return m_defaultFont; } + /*! + * \brief Checks whether the console is visible + * \return true If it is the case + */ + inline bool Console::IsVisible() const { return m_opened; diff --git a/SDK/include/NDK/Entity.inl b/SDK/include/NDK/Entity.inl index a03130b0d..535f2c1f4 100644 --- a/SDK/include/NDK/Entity.inl +++ b/SDK/include/NDK/Entity.inl @@ -11,16 +11,29 @@ namespace Ndk { + /*! + * \brief Adds a component to the entity + * \return A reference to the newly added component + * + * \param args Arguments to create in place the component to add to the entity + */ + template ComponentType& Entity::AddComponent(Args&&... args) { static_assert(std::is_base_of::value, "ComponentType is not a component"); - // Allocation et affectation du component + // Affectation and return of the component std::unique_ptr ptr(new ComponentType(std::forward(args)...)); return static_cast(AddComponent(std::move(ptr))); } + /*! + * \brief Enables the entity + * + * \param enable Should the entity be enabled + */ + inline void Entity::Enable(bool enable) { if (m_enabled != enable) @@ -30,9 +43,17 @@ namespace Ndk } } + /*! + * \brief Gets a component in the entity by index + * \return A reference to the component + * + * \param index Index of the component + * + * \remark Produces a NazaraAssert if component is not available in this entity or is invalid + */ + inline BaseComponent& Entity::GetComponent(ComponentIndex index) { - ///DOC: Le component doit être présent NazaraAssert(HasComponent(index), "This component is not part of the entity"); BaseComponent* component = m_components[index].get(); @@ -41,19 +62,33 @@ namespace Ndk return *component; } + /*! + * \brief Gets a component in the entity by type + * \return A reference to the component + * + * \remark Produces a NazaraAssert if component is not available in this entity + */ + template ComponentType& Entity::GetComponent() { - ///DOC: Le component doit être présent static_assert(std::is_base_of::value, "ComponentType is not a component"); ComponentIndex index = GetComponentIndex(); return static_cast(GetComponent(index)); } + /*! + * \brief Gets a component in the entity by index + * \return A constant reference to the component + * + * \param index Index of the component + * + * \remark Produces a NazaraAssert if component is not available in this entity or is invalid + */ + inline const BaseComponent& Entity::GetComponent(ComponentIndex index) const { - ///DOC: Le component doit être présent NazaraAssert(HasComponent(index), "This component is not part of the entity"); BaseComponent* component = m_components[index].get(); @@ -62,41 +97,79 @@ namespace Ndk return *component; } + /*! + * \brief Gets a component in the entity by type + * \return A constant reference to the component + * + * \remark Produces a NazaraAssert if component is not available in this entity + */ + template const ComponentType& Entity::GetComponent() const { - ///DOC: Le component doit être présent static_assert(std::is_base_of::value, "ComponentType is not a component"); ComponentIndex index = GetComponentIndex(); return static_cast(GetComponent(index)); } + /*! + * \brief Gets the bits representing the components in the entiy + * \return A constant reference to the set of component's bits + */ + inline const Nz::Bitset<>& Entity::GetComponentBits() const { return m_componentBits; } + /*! + * \brief Gets the identifier of the entity + * \return Identifier of the entity + */ + inline EntityId Entity::GetId() const { return m_id; } + /*! + * \brief Gets the bits representing the systems in the entiy + * \return A constant reference to the set of system's bits + */ + inline const Nz::Bitset<>& Entity::GetSystemBits() const { return m_systemBits; } + /*! + * \brief Gets the world in which the entity is + * \return Pointer to the world + */ + inline World* Entity::GetWorld() const { return m_world; } + /*! + * \brief Checks whether or not a component is present in the entity by index + * \return true If it is the case + * + * \param index Index of the component + */ + inline bool Entity::HasComponent(ComponentIndex index) const { return m_componentBits.UnboundedTest(index); } + /*! + * \brief Checks whether or not a component is present in the entity by type + * \return true If it is the case + */ + template bool Entity::HasComponent() const { @@ -106,16 +179,54 @@ namespace Ndk return HasComponent(index); } + /*! + * \brief Checks whether or not the entity is enabled + * \return true If it is the case + */ + inline bool Entity::IsEnabled() const { return m_enabled; } + /*! + * \brief Checks whether or not the entity is valid + * \return true If it is the case + */ + inline bool Entity::IsValid() const { return m_valid; } + /*! + * \brief Removes every components + */ + + inline void Entity::RemoveAllComponents() + { + m_removedComponentBits = m_componentBits; + + Invalidate(); + } + + /*! + * \brief Removes a component in the entity by index + * + * \param index Index of the component + */ + + inline void Entity::RemoveComponent(ComponentIndex index) + { + m_removedComponentBits.UnboundedSet(index); + + Invalidate(); + } + + /*! + * \brief Removes a component in the entity by type + */ + template void Entity::RemoveComponent() { @@ -125,19 +236,10 @@ namespace Ndk RemoveComponent(index); } - inline void Entity::RemoveAllComponents() - { - m_removedComponentBits = m_componentBits; - - Invalidate(); - } - - inline void Entity::RemoveComponent(ComponentIndex index) - { - m_removedComponentBits.UnboundedSet(index); - - Invalidate(); - } + /*! + * \brief Gives a string representation + * \return A string representation of the object: "Entity(GetId())" + */ inline Nz::String Entity::ToString() const { @@ -145,16 +247,35 @@ namespace Ndk return ss << "Entity(" << GetId() << ')'; } + /*! + * \brief Gets the bits representing the removed components in the entiy + * \return A constant reference to the set of remove component's bits + */ + inline Nz::Bitset<>& Entity::GetRemovedComponentBits() { return m_removedComponentBits; } + /*! + * \brief Registers a system for the entity + * + * \param index Index of the system + */ + inline void Entity::RegisterSystem(SystemIndex index) { m_systemBits.UnboundedSet(index); } + /*! + * \brief Sets the world of the entity + * + * \param world World in which the entity will be + * + * \remark Produces a NazaraAssert if world is invalid + */ + inline void Entity::SetWorld(World* world) noexcept { NazaraAssert(world, "An entity must be attached to a world at any time"); @@ -162,6 +283,12 @@ namespace Ndk m_world = world; } + /*! + * \brief Unregisters a system for the entity + * + * \param index Index of the system + */ + inline void Entity::UnregisterSystem(SystemIndex index) { m_systemBits.UnboundedReset(index); @@ -173,10 +300,16 @@ namespace std template<> struct hash { + /*! + * \brief Specialisation of std to hash + * \return Result of the hash + * + * \param handle Entity to hash + */ size_t operator()(const Ndk::EntityHandle& handle) const { - // Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée - // pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante) + // Hash the pointer will work until the entity is updated and moved + // so, we have to hash the ID of the entity (which is constant) Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits::max(); return hash()(id); diff --git a/SDK/include/NDK/EntityList.inl b/SDK/include/NDK/EntityList.inl index 94fa3472f..224fdd1dc 100644 --- a/SDK/include/NDK/EntityList.inl +++ b/SDK/include/NDK/EntityList.inl @@ -7,22 +7,54 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::EntityList + * \brief NDK class that represents a set of entities to help performing batch operations + */ + + /*! + * \brief Clears the set from every entities + */ + inline void EntityList::Clear() { m_entities.clear(); m_entityBits.Clear(); } + /*! + * \brief Checks whether or not the set contains the entity + * \return true If it is the case + * + * \param entity Pointer to the entity + */ + inline bool EntityList::Has(const Entity* entity) { return entity && entity->IsValid() && Has(entity->GetId()); } + /*! + * \brief Checks whether or not the set contains the entity by id + * \return true If it is the case + * + * \param id Identifier of the entity + */ + inline bool EntityList::Has(EntityId entity) { return m_entityBits.UnboundedTest(entity); } + /*! + * \brief Inserts the entity into the set + * + * \param entity Pointer to the entity + * + * \remark If entity is already contained, no action is performed + */ + inline void EntityList::Insert(Entity* entity) { if (!Has(entity)) @@ -32,6 +64,14 @@ namespace Ndk } } + /*! + * \brief Removes the entity from the set + * + * \param entity Pointer to the entity + * + * \remark If entity is not contained, no action is performed + */ + inline void EntityList::Remove(Entity* entity) { if (Has(entity)) @@ -40,7 +80,7 @@ namespace Ndk NazaraAssert(it != m_entities.end(), "Entity should be part of the vector"); 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.UnboundedSet(entity->GetId(), false); } } diff --git a/SDK/include/NDK/EntityOwner.inl b/SDK/include/NDK/EntityOwner.inl index 6efc2b30e..2cb64f1e8 100644 --- a/SDK/include/NDK/EntityOwner.inl +++ b/SDK/include/NDK/EntityOwner.inl @@ -8,17 +8,41 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::EntityOwner + * \brief NDK class that represents the owner of the entity and so its lifetime + */ + + /*! + * \brief Constructs a EntityOwner object + * + * \param entity Entity to own + */ + inline EntityOwner::EntityOwner(Entity* entity) : EntityOwner() { Reset(entity); } + /*! + * \brief Destructs the object and calls Reset + * + * \see Reset + */ + inline EntityOwner::~EntityOwner() { Reset(nullptr); } + /*! + * \brief Resets the ownership of the entity, previous is killed + * + * \param entity Entity to own + */ + inline void EntityOwner::Reset(Entity* entity) { if (m_object) @@ -27,12 +51,24 @@ namespace Ndk EntityHandle::Reset(entity); } + /*! + * \brief Resets the ownership of the entity by move semantic + * + * \param handle EntityOwner to move into this + */ + inline void EntityOwner::Reset(EntityOwner&& handle) { Reset(handle.GetObject()); handle.m_object = nullptr; } + /*! + * \brief Resets the ownership of the entity to the affected one + * + * \param entity Entity to own + */ + inline EntityOwner& EntityOwner::operator=(Entity* entity) { Reset(entity); diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index a09d6c459..6f1b73234 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -26,6 +26,11 @@ namespace Ndk { + /*! + * \brief Gets the internal binding for Lua + * \return A pointer to the binding + */ + inline LuaBinding* LuaAPI::GetBinding() { return s_binding; @@ -34,6 +39,15 @@ namespace Ndk namespace Nz { + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param color Resulting color + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Color* color, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -46,6 +60,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param angles Resulting euler angles + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag) { switch (instance.GetType(index)) @@ -66,6 +89,15 @@ namespace Nz } } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param angles Resulting euler angles + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag) { EulerAnglesd anglesDouble; @@ -75,6 +107,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param fontRef Resulting reference to a font + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, FontRef* fontRef, TypeTag) { *fontRef = *static_cast(instance.CheckUserdata(index, "Font")); @@ -82,6 +123,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a font + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, FontParams* params, TypeTag) { NazaraUnused(params); @@ -93,6 +143,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a mesh + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -106,6 +165,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param rect Resulting rectangle + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectd* rect, TypeTag) { instance.CheckType(index, LuaType_Table); @@ -118,6 +186,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param rect Resulting rectangle + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectf* rect, TypeTag) { Rectd rectDouble; @@ -127,6 +204,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param rect Resulting rectangle + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectui* rect, TypeTag) { Rectd rectDouble; @@ -136,6 +222,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag) { switch (instance.GetType(index)) @@ -156,6 +251,15 @@ namespace Nz } } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag) { Quaterniond quatDouble; @@ -165,6 +269,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param address Resulting IP address + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag) { switch (instance.GetType(index)) @@ -179,6 +292,15 @@ namespace Nz } } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector2D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag) { switch (instance.GetType(index)) @@ -200,6 +322,15 @@ namespace Nz } } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector2D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag) { Vector2d vecDouble; @@ -209,6 +340,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector2D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag) { Vector2d vecDouble; @@ -218,6 +358,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector3D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag) { switch (instance.GetType(index)) @@ -239,6 +388,15 @@ namespace Nz } } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector3D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag) { Vector3d vecDouble; @@ -248,6 +406,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param vec Resulting vector3D + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag) { Vector3d vecDouble; @@ -257,6 +424,15 @@ namespace Nz return ret; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param handle Resulting entity + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::EntityHandle* handle, TypeTag) { *handle = *static_cast(instance.CheckUserdata(index, "Entity")); @@ -264,6 +440,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param handle Resulting world + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::WorldHandle* handle, TypeTag) { *handle = *static_cast(instance.CheckUserdata(index, "World")); @@ -272,6 +457,16 @@ namespace Nz } #ifndef NDK_SERVER + + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param renderable Resulting reference to a instanced renderable + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag) { if (instance.IsOfType(index, "InstancedRenderable")) @@ -281,6 +476,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a material + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -295,6 +499,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a model + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -307,6 +520,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a music + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MusicParams* params, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -316,6 +538,15 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for a sound buffer + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag) { instance.CheckType(index, Nz::LuaType_Table); @@ -324,9 +555,16 @@ namespace Nz return 1; } + #endif - + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting euler angles + */ inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd&& val, TypeTag) { @@ -334,18 +572,42 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting euler angles + */ + inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf&& val, TypeTag) { instance.PushInstance("EulerAngles", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting reference to a font + */ + inline int LuaImplReplyVal(const LuaInstance& instance, FontRef&& val, TypeTag) { instance.PushInstance("Font", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting size information for a font + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Font::SizeInfo&& val, TypeTag) { instance.PushTable(); @@ -357,114 +619,266 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting quaternion + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond&& val, TypeTag) { instance.PushInstance("Quaternion", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting quaternion + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf&& val, TypeTag) { instance.PushInstance("Quaternion", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting IP address + */ + inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag) { instance.PushInstance("IpAddress", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting rectangle + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag) { instance.PushInstance("Rect", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting rectangle + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Rectf&& val, TypeTag) { instance.PushInstance("Rect", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting rectangle + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Rectui&& val, TypeTag) { instance.PushInstance("Rect", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector2D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag) { instance.PushInstance("Vector2", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector2D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector2f&& val, TypeTag) { instance.PushInstance("Vector2", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector2D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector2ui&& val, TypeTag) { instance.PushInstance("Vector2", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector3D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d&& val, TypeTag) { instance.PushInstance("Vector3", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector3D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f&& val, TypeTag) { instance.PushInstance("Vector3", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting vector3D + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui&& val, TypeTag) { instance.PushInstance("Vector3", val); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param ptr Resulting entity + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag) { instance.PushInstance("Entity", ptr); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param ptr Resulting application + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Application* ptr, TypeTag) { instance.PushInstance("Application", ptr); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting entity + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle&& handle, TypeTag) { instance.PushInstance("Entity", handle); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting node component + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle&& handle, TypeTag) { instance.PushInstance("NodeComponent", handle); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting velocity component + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::VelocityComponentHandle&& handle, TypeTag) { instance.PushInstance("VelocityComponent", handle); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param ptr Resulting world + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag) { instance.PushInstance("World", ptr); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param ptr Resulting world + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle&& handle, TypeTag) { instance.PushInstance("World", handle); @@ -472,22 +886,49 @@ namespace Nz } #ifndef NDK_SERVER + + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting console + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::ConsoleHandle&& handle, TypeTag) { instance.PushInstance("Console", handle); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting graphics component + */ + inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle&& handle, TypeTag) { instance.PushInstance("GraphicsComponent", handle); return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting sound buffer + */ + inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag) { instance.PushInstance("SoundBuffer", val); return 1; } + #endif + } diff --git a/SDK/include/NDK/LuaBinding.inl b/SDK/include/NDK/LuaBinding.inl index 64e3eb453..e4ae72254 100644 --- a/SDK/include/NDK/LuaBinding.inl +++ b/SDK/include/NDK/LuaBinding.inl @@ -6,6 +6,14 @@ namespace Ndk { + /*! + * \brief Binds a component to a name + * + * \param name Name used to retrieve the component + * + * \remark Produces a NazaraAssert if name is empty + */ + template void LuaBinding::BindComponent(const Nz::String& name) { @@ -24,6 +32,16 @@ namespace Ndk m_componentBindingByName[name] = T::componentIndex; } + /*! + * \brief Adds a component to an entity + * \return 1 in case of success + * + * \param instance Lua instance that will interact with the component + * \param handle Entity which component will be added to + * + * \remark T must be a subtype of BaseComponent + */ + template int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle) { @@ -34,6 +52,16 @@ namespace Ndk return 1; } + /*! + * \brief Pushes a component + * \return 1 in case of success + * + * \param instance Lua instance that will interact with the component + * \param component Component that will be pushed + * + * \remark T must be a subtype of BaseComponent + */ + template int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component) { diff --git a/SDK/include/NDK/Prerequesites.hpp b/SDK/include/NDK/Prerequesites.hpp index d75ed0eb0..f3532c70d 100644 --- a/SDK/include/NDK/Prerequesites.hpp +++ b/SDK/include/NDK/Prerequesites.hpp @@ -27,11 +27,11 @@ #include -// Version du SDK +// Version of SDK #define NDK_VERSION_MAJOR 0 #define NDK_VERSION_MINOR 1 -// Importation/Exportation de l'API +// Importation/Exportation of the API #if defined(NAZARA_PLATFORM_WINDOWS) #if !defined(NDK_STATIC) #ifdef NDK_BUILD @@ -49,7 +49,7 @@ #define NDK_API #endif #else - // À commenter pour tenter quand même une compilation + // To comment to force a compilation #error This operating system is not fully supported by the Nazara Development Kit #define NDK_API diff --git a/SDK/include/NDK/Sdk.inl b/SDK/include/NDK/Sdk.inl index 0bdc1e2cd..3cbafab66 100644 --- a/SDK/include/NDK/Sdk.inl +++ b/SDK/include/NDK/Sdk.inl @@ -4,6 +4,11 @@ namespace Ndk { + /*! + * \brief Checks whether the module is initialized + * \return true if module is initialized + */ + inline bool Sdk::IsInitialized() { return s_referenceCounter != 0; diff --git a/SDK/include/NDK/StateMachine.inl b/SDK/include/NDK/StateMachine.inl index 7b5109ab5..c522f5431 100644 --- a/SDK/include/NDK/StateMachine.inl +++ b/SDK/include/NDK/StateMachine.inl @@ -8,6 +8,21 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::StateMachine + * \brief NDK class that represents a state machine, to represent the multiple states of your program + */ + + /*! + * \brief Constructs a StateMachine object with an original state + * + * \param originalState State which is the entry point of the application + * + * \remark Calls "Enter" on the state + * \remark Produces a NazaraAssert if nullptr is given + */ + inline StateMachine::StateMachine(std::shared_ptr originalState) : m_currentState(std::move(originalState)) { @@ -15,22 +30,45 @@ namespace Ndk m_currentState->Enter(*this); } + /*! + * \brief Destructs the object + * + * \remark Calls "Leave" on the state + */ + inline StateMachine::~StateMachine() { m_currentState->Leave(*this); } + /*! + * \brief Changes the current state of the machine + * + * \param state Next state to represent + */ inline void StateMachine::ChangeState(std::shared_ptr state) { m_nextState = std::move(state); } + /*! + * \brief Gets the current state of the machine + * \return A constant reference to the state + */ + inline const std::shared_ptr& StateMachine::GetCurrentState() const { return m_currentState; } + /*! + * \brief Updates the state + * \return True if update is successful + * + * \param elapsedTime Delta time used for the update + */ + inline bool StateMachine::Update(float elapsedTime) { if (m_nextState) diff --git a/SDK/include/NDK/System.hpp b/SDK/include/NDK/System.hpp index 6d1d423dc..b5a50f76f 100644 --- a/SDK/include/NDK/System.hpp +++ b/SDK/include/NDK/System.hpp @@ -11,7 +11,7 @@ namespace Ndk { - template + template class System : public BaseSystem { public: @@ -20,7 +20,7 @@ namespace Ndk System(System&&) = default; virtual ~System(); - BaseSystem* Clone() const override; + std::unique_ptr Clone() const override; System& operator=(const System&) = delete; System& operator=(System&&) = default; diff --git a/SDK/include/NDK/System.inl b/SDK/include/NDK/System.inl index 9b382d924..d0359cc63 100644 --- a/SDK/include/NDK/System.inl +++ b/SDK/include/NDK/System.inl @@ -7,6 +7,18 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::System + * \brief NDK class that represents a system which interacts on a world + * + * \remark This class is meant to be derived as CRTP: "System" + */ + + /*! + * \brief Constructs a System object by default + */ + template System::System() : BaseSystem(GetSystemIndex()) @@ -16,15 +28,26 @@ namespace Ndk template System::~System() = default; + /*! + * \brief Clones the system + * \return The clone newly created + * + * \remark The system to clone should be trivially copy constructible + */ + template - BaseSystem* System::Clone() const + std::unique_ptr System::Clone() const { - ///FIXME: Pas encore supporté par GCC (4.9.2) + ///FIXME: Not fully supported in GCC (4.9.2) //static_assert(std::is_trivially_copy_constructible::value, "SystemType should be copy-constructible"); - return new SystemType(static_cast(*this)); + return std::make_unique(static_cast(*this)); } + /*! + * \brief Registers the system by assigning it an index + */ + template SystemIndex System::RegisterSystem() { diff --git a/SDK/include/NDK/Systems/PhysicsSystem.inl b/SDK/include/NDK/Systems/PhysicsSystem.inl index e9fb52c49..bfe886cb1 100644 --- a/SDK/include/NDK/Systems/PhysicsSystem.inl +++ b/SDK/include/NDK/Systems/PhysicsSystem.inl @@ -4,11 +4,21 @@ namespace Ndk { + /*! + * \brief Gets the physical world + * \return A reference to the physical world + */ + inline Nz::PhysWorld& PhysicsSystem::GetWorld() { return m_world; } + /*! + * \brief Gets the physical world + * \return A constant reference to the physical world + */ + inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const { return m_world; diff --git a/SDK/include/NDK/Systems/RenderSystem.inl b/SDK/include/NDK/Systems/RenderSystem.inl index 4f7afe63d..4b758aa92 100644 --- a/SDK/include/NDK/Systems/RenderSystem.inl +++ b/SDK/include/NDK/Systems/RenderSystem.inl @@ -4,58 +4,119 @@ namespace Ndk { + /*! + * \brief Constructs a RenderSystem object by copy semantic + * + * \param renderSystem RenderSystem to copy + */ + inline RenderSystem::RenderSystem(const RenderSystem& renderSystem) : System(renderSystem) { } + /*! + * \brief Changes the render technique used for the system + * \return A reference to the render technique type + */ + template inline T& RenderSystem::ChangeRenderTechnique() { + static_assert(std::is_base_of::value, "RenderTechnique is not a subtype of AbstractRenderTechnique"); return static_cast(ChangeRenderTechnique(std::make_unique())); } + /*! + * \brief Changes the render technique used for the system + * \return A reference to the abstract render technique + * + * \param renderTechnique Render technique to use + */ + inline Nz::AbstractRenderTechnique& RenderSystem::ChangeRenderTechnique(std::unique_ptr&& renderTechnique) { m_renderTechnique = std::move(renderTechnique); return *m_renderTechnique.get(); } + /*! + * \brief Gets the background used for rendering + * \return A reference to the background + */ + inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const { return m_background; } + /*! + * \brief Gets the coordinates matrix used for rendering + * \return A constant reference to the matrix of coordinates + */ + inline const Nz::Matrix4f& RenderSystem::GetCoordinateSystemMatrix() const { return m_coordinateSystemMatrix; } + /*! + * \brief Gets the "forward" global direction + * \return The forward direction, by default, it's -UnitZ() (Right hand coordinates) + */ + inline Nz::Vector3f RenderSystem::GetGlobalForward() const { return Nz::Vector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33); } + /*! + * \brief Gets the "right" global direction + * \return The right direction, by default, it's UnitX() (Right hand coordinates) + */ + inline Nz::Vector3f RenderSystem::GetGlobalRight() const { return Nz::Vector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31); } + /*! + * \brief Gets the "up" global direction + * \return The up direction, by default, it's UnitY() (Right hand coordinates) + */ + inline Nz::Vector3f RenderSystem::GetGlobalUp() const { return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32); } + /*! + * \brief Gets the render technique used for rendering + * \return A reference to the abstract render technique being used + */ + inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const { return *m_renderTechnique.get(); } + /*! + * \brief Sets the background used for rendering + * + * \param background A reference to the background + */ + inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background) { m_background = std::move(background); } + /*! + * \brief Sets the "forward" global direction + * + * \param direction The new forward direction + */ + inline void RenderSystem::SetGlobalForward(const Nz::Vector3f& direction) { m_coordinateSystemMatrix.m13 = -direction.x; @@ -65,6 +126,12 @@ namespace Ndk InvalidateCoordinateSystem(); } + /*! + * \brief Sets the "right" global direction + * + * \param direction The new right direction + */ + inline void RenderSystem::SetGlobalRight(const Nz::Vector3f& direction) { m_coordinateSystemMatrix.m11 = direction.x; @@ -74,6 +141,12 @@ namespace Ndk InvalidateCoordinateSystem(); } + /*! + * \brief Sets the "up" global direction + * + * \param direction The new up direction + */ + inline void RenderSystem::SetGlobalUp(const Nz::Vector3f& direction) { m_coordinateSystemMatrix.m12 = direction.x; @@ -83,6 +156,10 @@ namespace Ndk InvalidateCoordinateSystem(); } + /*! + * \brief Invalidates the matrix of coordinates for the system + */ + inline void RenderSystem::InvalidateCoordinateSystem() { m_coordinateSystemInvalidated = true; diff --git a/SDK/include/NDK/World.hpp b/SDK/include/NDK/World.hpp index 2e20d03a9..5d1dabb77 100644 --- a/SDK/include/NDK/World.hpp +++ b/SDK/include/NDK/World.hpp @@ -43,7 +43,6 @@ namespace Ndk inline EntityList CreateEntities(unsigned int count); void Clear() noexcept; - const EntityHandle& CloneEntity(EntityId id); const EntityHandle& GetEntity(EntityId id); diff --git a/SDK/include/NDK/World.inl b/SDK/include/NDK/World.inl index ba2b33bd4..9960aef05 100644 --- a/SDK/include/NDK/World.inl +++ b/SDK/include/NDK/World.inl @@ -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&& 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 SystemType& World::AddSystem(Args&&... args) { static_assert(std::is_base_of::value, "SystemType is not a component"); - // Allocation et affectation du component + // Allocation and affectation of the system std::unique_ptr ptr(new SystemType(std::forward(args)...)); return static_cast(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 SystemType& World::GetSystem() { - ///DOC: Le système doit être présent static_assert(std::is_base_of::value, "SystemType is not a system"); SystemIndex index = GetSystemIndex(); return static_cast(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 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 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); diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index df2dfa12c..5e3331d73 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -6,6 +6,16 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::Application + * \brief NDK class that represents the application, it offers a set of tools to ease the development + */ + + /*! + * \brief Runs the application by updating worlds, taking care about windows, ... + */ + bool Application::Run() { #ifndef NDK_SERVER diff --git a/SDK/src/NDK/BaseComponent.cpp b/SDK/src/NDK/BaseComponent.cpp index 1a0b85168..39d67d211 100644 --- a/SDK/src/NDK/BaseComponent.cpp +++ b/SDK/src/NDK/BaseComponent.cpp @@ -6,22 +6,50 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::BaseComponent + * \brief NDK class that represents the common base of all components + * + * \remark This class is meant to be purely abstract, for type erasure + */ + BaseComponent::~BaseComponent() = default; + /*! + * \brief Operation to perform when component is attached to an entity + */ + void BaseComponent::OnAttached() { } + /*! + * \brief Operation to perform when component is attached to this component + * + * \param component Component being attached + */ + void BaseComponent::OnComponentAttached(BaseComponent& component) { NazaraUnused(component); } + /*! + * \brief Operation to perform when component is detached from this component + * + * \param component Component being detached + */ + void BaseComponent::OnComponentDetached(BaseComponent& component) { NazaraUnused(component); } + /*! + * \brief Operation to perform when component is detached from an entity + */ + void BaseComponent::OnDetached() { } diff --git a/SDK/src/NDK/BaseSystem.cpp b/SDK/src/NDK/BaseSystem.cpp index a69f13550..8a2a9dce5 100644 --- a/SDK/src/NDK/BaseSystem.cpp +++ b/SDK/src/NDK/BaseSystem.cpp @@ -6,12 +6,31 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::BaseSystem + * \brief NDK class that represents the common base of all systems + * + * \remark This class is meant to be purely abstract, for type erasure + */ + + /*! + * \brief Destructs the object and unregisters it-self on every entities + */ + BaseSystem::~BaseSystem() { for (const EntityHandle& entity : m_entities) entity->UnregisterSystem(m_systemIndex); } + /*! + * \brief Checks whether the key of the entity matches the lock of the system + * \return true If it is the case + * + * \param Pointer to the entity + */ + bool BaseSystem::Filters(const Entity* entity) const { if (!entity) @@ -21,13 +40,13 @@ namespace Ndk m_filterResult.PerformsAND(m_requiredComponents, components); if (m_filterResult != m_requiredComponents) - return false; // Au moins un component requis n'est pas présent + return false; // At least one required component is not available m_filterResult.PerformsAND(m_excludedComponents, components); if (m_filterResult.TestAny()) - return false; // Au moins un component exclu est présent + return false; // At least one excluded component is available - // Si nous avons une liste de composants nécessaires + // If we have a list of needed components if (m_requiredAnyComponents.TestAny()) { if (!m_requiredAnyComponents.Intersects(components)) @@ -37,16 +56,35 @@ namespace Ndk return true; } + /*! + * \brief Operation to perform when entity is added to the system + * + * \param Pointer to the entity + */ + void BaseSystem::OnEntityAdded(Entity* entity) { NazaraUnused(entity); } + /*! + * \brief Operation to perform when entity is removed to the system + * + * \param Pointer to the entity + */ + void BaseSystem::OnEntityRemoved(Entity* entity) { NazaraUnused(entity); } + /*! + * \brief Operation to perform when entity is validated for the system + * + * \param entity Pointer to the entity + * \param justAdded Is the entity newly added + */ + void BaseSystem::OnEntityValidation(Entity* entity, bool justAdded) { NazaraUnused(entity); diff --git a/SDK/src/NDK/Components/CameraComponent.cpp b/SDK/src/NDK/Components/CameraComponent.cpp index 1b7a3e06d..71c653823 100644 --- a/SDK/src/NDK/Components/CameraComponent.cpp +++ b/SDK/src/NDK/Components/CameraComponent.cpp @@ -9,6 +9,18 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::CameraComponent + * \brief NDK class that represents the component for camera + */ + + /*! + * \brief Applys the view of the camera + * + * \remark Produces a NazaraAssert if the camera has no target + */ + void CameraComponent::ApplyView() const { NazaraAssert(m_target, "CameraComponent has no target"); @@ -23,6 +35,12 @@ namespace Ndk Nz::Renderer::SetViewport(m_viewport); } + /*! + * \brief Gets the eye position of the camera + * + * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent + */ + Nz::Vector3f CameraComponent::GetEyePosition() const { NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); @@ -30,6 +48,12 @@ namespace Ndk return m_entity->GetComponent().GetPosition(); } + /*! + * \brief Gets the forward direction of the camera + * + * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent + */ + Nz::Vector3f CameraComponent::GetForward() const { NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); @@ -37,6 +61,12 @@ namespace Ndk return m_entity->GetComponent().GetForward(); } + /*! + * \brief Sets the layer of the camera in case of multiples fields + * + * \param layer Layer of the camera + */ + void CameraComponent::SetLayer(unsigned int layer) { m_layer = layer; @@ -44,6 +74,10 @@ namespace Ndk m_entity->Invalidate(); // Invalidate the entity to make it passes through RenderSystem validation } + /*! + * \brief Operation to perform when component is attached to an entity + */ + void CameraComponent::OnAttached() { if (m_entity->HasComponent()) @@ -52,6 +86,12 @@ namespace Ndk InvalidateViewMatrix(); } + /*! + * \brief Operation to perform when component is attached to this component + * + * \param component Component being attached + */ + void CameraComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) @@ -63,6 +103,12 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from this component + * + * \param component Component being detached + */ + void CameraComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) @@ -73,6 +119,10 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from an entity + */ + void CameraComponent::OnDetached() { m_nodeInvalidationSlot.Disconnect(); @@ -80,6 +130,12 @@ namespace Ndk InvalidateViewMatrix(); } + /*! + * \brief Operation to perform when the node is invalidated + * + * \param node Pointer to the node + */ + void CameraComponent::OnNodeInvalidated(const Nz::Node* node) { NazaraUnused(node); @@ -88,6 +144,12 @@ namespace Ndk InvalidateViewMatrix(); } + /*! + * \brief Operation to perform when the render target is released + * + * \param renderTarget Pointer to the RenderTarget + */ + void CameraComponent::OnRenderTargetRelease(const Nz::RenderTarget* renderTarget) { if (renderTarget == m_target) @@ -96,6 +158,12 @@ namespace Ndk NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget)); } + /*! + * \brief Operation to perform when the render target has its size changed + * + * \param renderTarget Pointer to the RenderTarget + */ + void CameraComponent::OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget) { if (renderTarget == m_target) @@ -104,6 +172,10 @@ namespace Ndk NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget)); } + /*! + * \brief Updates the frustum of the camera + */ + void CameraComponent::UpdateFrustum() const { EnsureProjectionMatrixUpdate(); @@ -114,6 +186,10 @@ namespace Ndk m_frustumUpdated = true; } + /*! + * \brief Updates the project matrix of the camera + */ + void CameraComponent::UpdateProjectionMatrix() const { switch (m_projectionType) @@ -139,6 +215,12 @@ namespace Ndk m_projectionMatrixUpdated = true; } + /*! + * \brief Updates the view matrix of the camera + * + * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent + */ + void CameraComponent::UpdateViewMatrix() const { NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); @@ -150,6 +232,12 @@ namespace Ndk m_viewMatrixUpdated = true; } + /*! + * \brief Updates the view port of the camera + * + * \remark Produces a NazaraAssert if entity has no target + */ + void CameraComponent::UpdateViewport() const { NazaraAssert(m_target, "CameraComponent has no target"); diff --git a/SDK/src/NDK/Components/CollisionComponent.cpp b/SDK/src/NDK/Components/CollisionComponent.cpp index 49e8d8328..0f812e73b 100644 --- a/SDK/src/NDK/Components/CollisionComponent.cpp +++ b/SDK/src/NDK/Components/CollisionComponent.cpp @@ -11,13 +11,27 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::CollisionComponent + * \brief NDK class that represents the component for collision (meant for static objects) + */ + + /*! + * \brief Sets geometry for the entity + * + * \param geom Geometry used for collisions + * + * \remark Produces a NazaraAssert if the entity has no physics component and has no static body + */ + void CollisionComponent::SetGeom(Nz::PhysGeomRef geom) { m_geom = std::move(geom); if (m_entity->HasComponent()) { - // On met à jour la géométrie du PhysObject associé au PhysicsComponent + // We update the geometry of the PhysiscsObject linked to the PhysicsComponent PhysicsComponent& physComponent = m_entity->GetComponent(); physComponent.GetPhysObject().SetGeom(m_geom); } @@ -28,6 +42,13 @@ namespace Ndk } } + /*! + * \brief Initializes the static body + * + * \remark Produces a NazaraAssert if entity is invalid + * \remark Produces a NazaraAssert if entity is not linked to a world, or the world has no physics system + */ + void CollisionComponent::InitializeStaticBody() { NazaraAssert(m_entity, "Invalid entity"); @@ -41,24 +62,44 @@ namespace Ndk m_staticBody->EnableAutoSleep(false); } + /*! + * \brief Operation to perform when component is attached to an entity + */ + void CollisionComponent::OnAttached() { if (!m_entity->HasComponent()) InitializeStaticBody(); } + /*! + * \brief Operation to perform when component is attached to this component + * + * \param component Component being attached + */ + void CollisionComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) m_staticBody.reset(); } + /*! + * \brief Operation to perform when component is detached from this component + * + * \param component Component being detached + */ + void CollisionComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) InitializeStaticBody(); } + /*! + * \brief Operation to perform when component is detached from an entity + */ + void CollisionComponent::OnDetached() { m_staticBody.reset(); diff --git a/SDK/src/NDK/Components/GraphicsComponent.cpp b/SDK/src/NDK/Components/GraphicsComponent.cpp index 88ccd4ca1..759d3f24b 100644 --- a/SDK/src/NDK/Components/GraphicsComponent.cpp +++ b/SDK/src/NDK/Components/GraphicsComponent.cpp @@ -9,7 +9,23 @@ namespace Ndk { - void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index) + /*! + * \ingroup NDK + * \class Ndk::GraphicsComponent + * \brief NDK class that represents the component for graphics + */ + + /*! + * \brief Invalidates the data for renderable + * + * \param renderable Renderable to invalidate + * \param flags Flags for the instance + * \param index Index of the renderable to invalidate + * + * \remark Produces a NazaraAssert if index is out of bound + */ + + void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable , Nz::UInt32 flags, std::size_t index) { NazaraAssert(index < m_renderables.size(), "Invalid renderable index"); NazaraUnused(renderable); @@ -19,6 +35,10 @@ namespace Ndk r.renderable->InvalidateData(&r.data, flags); } + /*! + * \brief Operation to perform when component is attached to an entity + */ + void GraphicsComponent::OnAttached() { if (m_entity->HasComponent()) @@ -27,6 +47,12 @@ namespace Ndk InvalidateTransformMatrix(); } + /*! + * \brief Operation to perform when component is attached to this component + * + * \param component Component being attached + */ + void GraphicsComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) @@ -38,6 +64,12 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from this component + * + * \param component Component being detached + */ + void GraphicsComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) @@ -48,6 +80,10 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from an entity + */ + void GraphicsComponent::OnDetached() { m_nodeInvalidationSlot.Disconnect(); @@ -55,6 +91,12 @@ namespace Ndk InvalidateTransformMatrix(); } + /*! + * \brief Operation to perform when the node is invalidated + * + * \param node Pointer to the node + */ + void GraphicsComponent::OnNodeInvalidated(const Nz::Node* node) { NazaraUnused(node); @@ -63,6 +105,10 @@ namespace Ndk InvalidateTransformMatrix(); } + /*! + * \brief Updates the bounding volume + */ + void GraphicsComponent::UpdateBoundingVolume() const { EnsureTransformMatrixUpdate(); @@ -75,6 +121,12 @@ namespace Ndk m_boundingVolumeUpdated = true; } + /*! + * \brief Updates the transform matrix of the renderable + * + * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent + */ + void GraphicsComponent::UpdateTransformMatrix() const { NazaraAssert(m_entity && m_entity->HasComponent(), "GraphicsComponent requires NodeComponent"); diff --git a/SDK/src/NDK/Components/ParticleEmitterComponent.cpp b/SDK/src/NDK/Components/ParticleEmitterComponent.cpp index 2ae4365e6..e700b6497 100644 --- a/SDK/src/NDK/Components/ParticleEmitterComponent.cpp +++ b/SDK/src/NDK/Components/ParticleEmitterComponent.cpp @@ -7,6 +7,19 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::ParticleEmitterComponent + * \brief NDK class that represents the component emitter of particles + */ + + /*! + * \brief Sets up the particles + * + * \param mapper Mapper containing layout information of each particle + * \param count Number of particles + */ + void ParticleEmitterComponent::SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const { if (m_isActive && m_setupFunc) diff --git a/SDK/src/NDK/Components/PhysicsComponent.cpp b/SDK/src/NDK/Components/PhysicsComponent.cpp index cc23c0954..6cfd1077d 100644 --- a/SDK/src/NDK/Components/PhysicsComponent.cpp +++ b/SDK/src/NDK/Components/PhysicsComponent.cpp @@ -12,6 +12,18 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::PhysicsComponent + * \brief NDK class that represents the component for physics (meant for dynamic objects) + */ + + /*! + * \brief Operation to perform when component is attached to an entity + * + * \remark Produces a NazaraAssert if the world does not have a physics system + */ + void PhysicsComponent::OnAttached() { World* entityWorld = m_entity->GetWorld(); @@ -33,6 +45,14 @@ namespace Ndk m_object->SetMass(1.f); } + /*! + * \brief Operation to perform when component is attached to this component + * + * \param component Component being attached + * + * \remark Produces a NazaraAssert if physical object is invalid + */ + void PhysicsComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) @@ -42,6 +62,14 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from this component + * + * \param component Component being detached + * + * \remark Produces a NazaraAssert if physical object is invalid + */ + void PhysicsComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) @@ -51,6 +79,10 @@ namespace Ndk } } + /*! + * \brief Operation to perform when component is detached from an entity + */ + void PhysicsComponent::OnDetached() { m_object.reset(); diff --git a/SDK/src/NDK/Console.cpp b/SDK/src/NDK/Console.cpp index d157d7dbe..dd379cd4a 100644 --- a/SDK/src/NDK/Console.cpp +++ b/SDK/src/NDK/Console.cpp @@ -19,6 +19,20 @@ namespace Ndk constexpr std::size_t s_inputPrefixSize = Nz::CountOf(s_inputPrefix) - 1; } + /*! + * \ingroup NDK + * \class Ndk::Console + * \brief NDK class that represents a console to help development with Lua scripting + */ + + /*! + * \brief Constructs a Console object with a world to interact with + * + * \param world World to interact with + * \param size (Width, Height) of the console + * \param instance Lua instance that will interact with the world + */ + Console::Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance) : m_historyPosition(0), m_defaultFont(Nz::Font::GetDefault()), @@ -86,18 +100,35 @@ namespace Ndk Layout(); } + /*! + * \brief Adds a line to the console + * + * \param text New line of text + * \param color Color for the text + */ + void Console::AddLine(const Nz::String& text, const Nz::Color& color) { AddLineInternal(text, color); RefreshHistory(); } + /*! + * \brief Clears the console + */ + void Console::Clear() { m_historyLines.clear(); RefreshHistory(); } + /*! + * \brief Sends a character to the console + * + * \param character Character that will be added to the console + */ + void Console::SendCharacter(char32_t character) { switch (character) @@ -131,6 +162,12 @@ namespace Ndk m_inputTextSprite->Update(m_inputDrawer); } + /*! + * \brief Sends an event to the console + * + * \param event Event to be takin into consideration by the console + */ + void Console::SendEvent(Nz::WindowEvent event) { switch (event.type) @@ -170,6 +207,12 @@ namespace Ndk } } + /*! + * \brief Sets the character size + * + * \param size Size of the font + */ + void Console::SetCharacterSize(unsigned int size) { m_characterSize = size; @@ -182,6 +225,12 @@ namespace Ndk Layout(); } + /*! + * \brief Sets the console size + * + * \param size (Width, Height) of the console + */ + void Console::SetSize(const Nz::Vector2f& size) { m_size = size; @@ -189,6 +238,14 @@ namespace Ndk Layout(); } + /*! + * \brief Sets the text font + * + * \param font Reference to a valid font + * + * \remark Produces a NazaraAssert if font is invalid or null + */ + void Console::SetTextFont(Nz::FontRef font) { NazaraAssert(font && font->IsValid(), "Invalid font"); @@ -200,6 +257,12 @@ namespace Ndk Layout(); } + /*! + * \brief Shows the console + * + * \param show Should the console be showed + */ + void Console::Show(bool show) { if (m_opened != show) @@ -213,11 +276,22 @@ namespace Ndk } } + /*! + * \brief Adds a line to the history of the console + * + * \param text New line of text + * \param color Color for the text + */ + void Console::AddLineInternal(const Nz::String& text, const Nz::Color& color) { m_historyLines.emplace_back(Line{color, text}); } + /*! + * \brief Performs this action when an input is added to the console + */ + void Console::ExecuteInput() { Nz::String input = m_inputDrawer.GetText(); @@ -237,12 +311,18 @@ namespace Ndk RefreshHistory(); } + /*! + * \brief Places the console according to its layout + */ + void Console::Layout() { unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight; Ndk::NodeComponent& inputNode = m_input->GetComponent(); + NazaraError(inputNode.GetPosition().ToString()); inputNode.SetPosition(0.f, m_size.y - lineHeight - 5.f); + NazaraError(inputNode.GetPosition().ToString()); float historyHeight = m_size.y - lineHeight - 5.f - 2.f; m_historyBackgroundSprite->SetSize(m_size.x, historyHeight); @@ -250,14 +330,22 @@ namespace Ndk m_maxHistoryLines = static_cast(std::ceil(historyHeight / lineHeight)); Ndk::NodeComponent& historyNode = m_history->GetComponent(); + NazaraError(historyNode.GetPosition().ToString()); historyNode.SetPosition(0.f, historyHeight - m_maxHistoryLines * lineHeight); + NazaraError(historyNode.GetPosition().ToString()); Ndk::NodeComponent& inputBackgroundNode = m_inputBackground->GetComponent(); + NazaraError(inputBackgroundNode.GetPosition().ToString()); inputBackgroundNode.SetPosition(0.f, historyHeight + 2.f); + NazaraError(inputBackgroundNode.GetPosition().ToString()); m_inputBackgroundSprite->SetSize(m_size.x, m_size.y - historyHeight); } + /*! + * \brief Refreshes the history of the console + */ + void Console::RefreshHistory() { m_historyDrawer.Clear(); diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index ecd74ebc0..815d0dc1b 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -8,6 +8,18 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::Entity + * \brief NDK class that represents an entity in a world + */ + + /*! + * \brief Constructs a Entity object by move semantic + * + * \param entity Entity to move into this + */ + Entity::Entity(Entity&& entity) : HandledObject(std::move(entity)), m_components(std::move(entity.m_components)), @@ -20,35 +32,57 @@ namespace Ndk { } + /*! + * \brief Constructs a Entity object linked to a world and with an id + * + * \param world World in which the entity interact + * \param id Identifier of the entity + */ + Entity::Entity(World* world, EntityId id) : m_id(id), m_world(world) { } + /*! + * \brief Destructs the object and calls Destroy + * + * \see Destroy + */ + Entity::~Entity() { Destroy(); } + /*! + * \brief Adds a component to the entity + * \return A reference to the newly added component + * + * \param componentPtr Component to add to the entity + * + * \remark Produces a NazaraAssert if component is nullptr + */ + BaseComponent& Entity::AddComponent(std::unique_ptr&& componentPtr) { NazaraAssert(componentPtr, "Component must be valid"); ComponentIndex index = componentPtr->GetIndex(); - // Nous nous assurons que le vecteur de component est suffisamment grand pour contenir le nouveau component + // We ensure that the vector has enough space if (index >= m_components.size()) m_components.resize(index + 1); - // Affectation et retour du component + // Affectation and return of the component m_components[index] = std::move(componentPtr); m_componentBits.UnboundedSet(index); m_removedComponentBits.UnboundedReset(index); Invalidate(); - // On récupère le component et on informe les composants existants du nouvel arrivant + // We get the new component and we alert other existing components of the new one BaseComponent& component = *m_components[index].get(); component.SetEntity(this); @@ -61,34 +95,57 @@ namespace Ndk return component; } + /*! + * \brief Clones the entity + * \return The clone newly created + * + * \remark The close is enable by default, even if the original is disabled + * \remark Produces a NazaraAssert if the entity is not valid + */ + const EntityHandle& Entity::Clone() const { - ///DOC: The clone is enabled by default, even if the original entity is disabled NazaraAssert(IsValid(), "Invalid entity"); return m_world->CloneEntity(m_id); } + /*! + * \brief Kills the entity + */ + void Entity::Kill() { m_world->KillEntity(this); } + /*! + * \brief Invalidates the entity + */ + void Entity::Invalidate() { - // On informe le monde que nous avons besoin d'une mise à jour + // We alert everyone that we have been updated m_world->Invalidate(m_id); } + /*! + * \brief Creates the entity + */ + void Entity::Create() { m_enabled = true; m_valid = true; } + /*! + * \brief Destroys the entity + */ + void Entity::Destroy() { - // On informe chaque système + // We alert each system for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index)) { if (m_world->HasSystem(index)) @@ -104,12 +161,19 @@ namespace Ndk m_valid = false; } + /*! + * \brief Destroys a component by index + * + * \param index Index of the component + * + * \remark If component is not available, no action is performed + */ + void Entity::DestroyComponent(ComponentIndex index) { - ///DOC: N'a aucun effet si le component n'est pas présent if (HasComponent(index)) { - // On récupère le component et on informe les composants du détachement + // We get the component and we alert existing components of the deleted one BaseComponent& component = *m_components[index].get(); for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i)) { diff --git a/SDK/src/NDK/LuaAPI.cpp b/SDK/src/NDK/LuaAPI.cpp index a1b84bf5d..1bf4eec35 100644 --- a/SDK/src/NDK/LuaAPI.cpp +++ b/SDK/src/NDK/LuaAPI.cpp @@ -5,12 +5,29 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::LuaAPI + * \brief NDK class that represents the api used for Lua + */ + + /*! + * \brief Initializes the LuaAPI module + * \return true if initialization is successful + */ + bool LuaAPI::Initialize() { s_binding = new LuaBinding; return true; } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the engine & SDK + */ + void LuaAPI::RegisterClasses(Nz::LuaInstance& instance) { if (!s_binding && !Initialize()) @@ -22,6 +39,10 @@ namespace Ndk s_binding->RegisterClasses(instance); } + /*! + * \brief Uninitializes the LuaAPI module + */ + void LuaAPI::Uninitialize() { delete s_binding; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 6acc05a46..822654a39 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -4,6 +4,16 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::LuaBinding + * \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting + */ + + /*! + * \brief Binds modules to Lua + */ + LuaBinding::LuaBinding() : // Core clockClass("Clock"), @@ -65,6 +75,12 @@ namespace Ndk #endif } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the engine & SDK + */ + void LuaBinding::RegisterClasses(Nz::LuaInstance& instance) { RegisterCore(instance); diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index 89452d720..b825b1876 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -6,6 +6,10 @@ namespace Ndk { + /*! + * \brief Binds Audio module to Lua + */ + void LuaBinding::BindAudio() { /*********************************** Nz::Music **********************************/ @@ -164,6 +168,12 @@ namespace Ndk soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Audio classes + */ + void LuaBinding::RegisterAudio(Nz::LuaInstance& instance) { musicClass.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 09cbda604..78c73eea1 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -6,6 +6,10 @@ namespace Ndk { + /*! + * \brief Binds Core module to Lua + */ + void LuaBinding::BindCore() { /*********************************** Nz::Clock **********************************/ @@ -254,6 +258,12 @@ namespace Ndk }); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Core classes + */ + void LuaBinding::RegisterCore(Nz::LuaInstance& instance) { // Classes diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index 289002746..4c9288428 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -6,6 +6,10 @@ namespace Ndk { + /*! + * \brief Binds Graphics module to Lua + */ + void LuaBinding::BindGraphics() { /*********************************** Nz::InstancedRenderable ***********************************/ @@ -40,6 +44,12 @@ namespace Ndk modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Graphics classes + */ + void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance) { instancedRenderable.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index c1d7b487e..1c53caa69 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -7,6 +7,10 @@ namespace Ndk { + /*! + * \brief Binds Math module to Lua + */ + void LuaBinding::BindMath() { /*********************************** Nz::EulerAngles **********************************/ @@ -673,6 +677,12 @@ namespace Ndk }); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Math classes + */ + void LuaBinding::RegisterMath(Nz::LuaInstance& instance) { eulerAnglesClass.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index dc17c5d00..67f40cb4d 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -5,6 +5,10 @@ namespace Ndk { + /*! + * \brief Binds Network module to Lua + */ + void LuaBinding::BindNetwork() { /*********************************** Nz::AbstractSocket **********************************/ @@ -132,6 +136,12 @@ namespace Ndk }); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Network classes + */ + void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance) { // Classes diff --git a/SDK/src/NDK/LuaBinding_Renderer.cpp b/SDK/src/NDK/LuaBinding_Renderer.cpp index 78b9fe561..79f1780a3 100644 --- a/SDK/src/NDK/LuaBinding_Renderer.cpp +++ b/SDK/src/NDK/LuaBinding_Renderer.cpp @@ -7,10 +7,20 @@ namespace Ndk { + /*! + * \brief Binds Renderer module to Lua + */ + void LuaBinding::BindRenderer() { } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Renderer classes + */ + void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance) { } diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index b371e76e3..5b6ad7dc9 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -7,6 +7,10 @@ namespace Ndk { + /*! + * \brief Binds SDK module to Lua + */ + void LuaBinding::BindSDK() { /*********************************** Ndk::Application **********************************/ @@ -143,6 +147,12 @@ namespace Ndk #endif } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the SDK classes + */ + void LuaBinding::RegisterSDK(Nz::LuaInstance& instance) { // Classes @@ -173,6 +183,14 @@ namespace Ndk instance.SetGlobal("ComponentType"); } + /*! + * \brief Gets the index of the component + * \return A pointer to the binding linked to a component + * + * \param instance Lua instance that will interact with the component + * \param argIndex Index of the component + */ + LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex) { switch (instance.GetType(argIndex)) diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 4ccb18fa6..416662b23 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -6,6 +6,10 @@ namespace Ndk { + /*! + * \brief Binds Utility module to Lua + */ + void LuaBinding::BindUtility() { /*********************************** Nz::AbstractImage **********************************/ @@ -308,6 +312,12 @@ namespace Ndk }); } + /*! + * \brief Registers the classes that will be used by the Lua instance + * + * \param instance Lua instance that will interact with the Utility classes + */ + void LuaBinding::RegisterUtility(Nz::LuaInstance& instance) { abstractImage.Register(instance); diff --git a/SDK/src/NDK/Sdk.cpp b/SDK/src/NDK/Sdk.cpp index 964913bf8..bd3bf33e4 100644 --- a/SDK/src/NDK/Sdk.cpp +++ b/SDK/src/NDK/Sdk.cpp @@ -34,6 +34,19 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::Sdk + * \brief NDK class that represents the software development kit, a set of tools made to ease the conception of application + */ + + /*! + * \brief Initializes the Sdk module + * \return true if initialization is successful + * + * \remark Produces a NazaraNotice + */ + bool Sdk::Initialize() { if (s_referenceCounter++ > 0) @@ -104,6 +117,12 @@ namespace Ndk } } + /*! + * \brief Uninitializes the Sdk module + * + * \remark Produces a NazaraNotice + */ + void Sdk::Uninitialize() { if (s_referenceCounter != 1) diff --git a/SDK/src/NDK/State.cpp b/SDK/src/NDK/State.cpp index e256a7f1c..701b98565 100644 --- a/SDK/src/NDK/State.cpp +++ b/SDK/src/NDK/State.cpp @@ -6,5 +6,11 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::State + * \brief NDK class that represents a state of your application + */ + State::~State() = default; } diff --git a/SDK/src/NDK/Systems/ListenerSystem.cpp b/SDK/src/NDK/Systems/ListenerSystem.cpp index 28fce2e0a..9c7333d34 100644 --- a/SDK/src/NDK/Systems/ListenerSystem.cpp +++ b/SDK/src/NDK/Systems/ListenerSystem.cpp @@ -10,11 +10,29 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::ListenerSystem + * \brief NDK class that represents the audio system + * + * \remark This system is enabled if the entity owns the trait: ListenerComponent and NodeComponent + */ + + /*! + * \brief Constructs an ListenerSystem object by default + */ + ListenerSystem::ListenerSystem() { Requires(); } + /*! + * \brief Operation to perform when system is updated + * + * \param elapsedTime Delta time used for the update + */ + void ListenerSystem::OnUpdate(float elapsedTime) { NazaraUnused(elapsedTime); @@ -23,18 +41,18 @@ namespace Ndk for (const Ndk::EntityHandle& entity : GetEntities()) { - // Le listener est-il actif ? + // Is the listener actif ? const ListenerComponent& listener = entity->GetComponent(); if (!listener.IsActive()) continue; - // On récupère la position et la rotation pour les affecter au listener + // We get the position and the rotation to affect these to the listener const NodeComponent& node = entity->GetComponent(); Nz::Audio::SetListenerPosition(node.GetPosition(Nz::CoordSys_Global)); Nz::Audio::SetListenerRotation(node.GetRotation(Nz::CoordSys_Global)); - // On vérifie la présence d'une donnée de vitesse, et on l'affecte - // (La vitesse du listener Audio ne le fait pas se déplacer, mais affecte par exemple l'effet Doppler) + // We verify the presence of a component of velocity + // (The listener'speed does not move it, but disturbs the sound like Doppler effect) if (entity->HasComponent()) { const VelocityComponent& velocity = entity->GetComponent(); diff --git a/SDK/src/NDK/Systems/ParticleSystem.cpp b/SDK/src/NDK/Systems/ParticleSystem.cpp index a9f63cb6c..9321c0ec2 100644 --- a/SDK/src/NDK/Systems/ParticleSystem.cpp +++ b/SDK/src/NDK/Systems/ParticleSystem.cpp @@ -7,11 +7,29 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::ParticleSystem + * \brief NDK class that represents the particle system + * + * \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: ParticleGroupComponent + */ + + /*! + * \brief Constructs an ParticleSystem object by default + */ + ParticleSystem::ParticleSystem() { Requires(); } + /*! + * \brief Operation to perform when system is updated + * + * \param elapsedTime Delta time used for the update + */ + void ParticleSystem::OnUpdate(float elapsedTime) { for (const Ndk::EntityHandle& entity : GetEntities()) diff --git a/SDK/src/NDK/Systems/PhysicsSystem.cpp b/SDK/src/NDK/Systems/PhysicsSystem.cpp index 3d429a686..442784c22 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem.cpp @@ -10,24 +10,50 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::PhysicsSystem + * \brief NDK class that represents the physics system + * + * \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: CollisionComponent or PhysicsComponent + * \remark Static objects do not have a velocity specified by the physical engine + */ + + /*! + * \brief Constructs an PhysicsSystem object by default + */ + PhysicsSystem::PhysicsSystem() { Requires(); RequiresAny(); } + /*! + * \brief Constructs a PhysicsSystem object by copy semantic + * + * \param system PhysicsSystem to copy + */ + PhysicsSystem::PhysicsSystem(const PhysicsSystem& system) : System(system), m_world() { } + /*! + * \brief Operation to perform when entity is validated for the system + * + * \param entity Pointer to the entity + * \param justAdded Is the entity newly added + */ + void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded) { - // Si l'entité ne vient pas d'être ajoutée au système, il est possible qu'elle fasse partie du mauvais tableau + // If entity has not been just added to the system, it is possible that it does not own to the right array if (!justAdded) { - // On prend le tableau inverse de celui dont l'entité devrait faire partie + // We take the inverted array from which the entity should belong to auto& entities = (entity->HasComponent()) ? m_staticObjects : m_dynamicObjects; entities.Remove(entity); } @@ -36,6 +62,12 @@ namespace Ndk entities.Insert(entity); } + /*! + * \brief Operation to perform when system is updated + * + * \param elapsedTime Delta time used for the update + */ + void PhysicsSystem::OnUpdate(float elapsedTime) { m_world.Step(elapsedTime); @@ -63,8 +95,8 @@ namespace Ndk Nz::Quaternionf newRotation = node.GetRotation(Nz::CoordSys_Global); Nz::Vector3f newPosition = node.GetPosition(Nz::CoordSys_Global); - // Pour déplacer des objets statiques et assurer les collisions, il faut leur définir une vitesse - // (note importante: le moteur physique n'applique pas la vitesse sur les objets statiques) + // To move static objects and ensure their collisions, we have to specify them a velocity + // (/!\: the physical motor does not apply the speed on static objects) if (newPosition != oldPosition) { physObj->SetPosition(newPosition); diff --git a/SDK/src/NDK/Systems/RenderSystem.cpp b/SDK/src/NDK/Systems/RenderSystem.cpp index fcfd5c6a5..107676206 100644 --- a/SDK/src/NDK/Systems/RenderSystem.cpp +++ b/SDK/src/NDK/Systems/RenderSystem.cpp @@ -14,6 +14,21 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::RenderSystem + * \brief NDK class that represents the rendering system + * + * \remark This system is enabled if the entity is a 'camera' with the trait: CameraComponent and NodeComponent + * or a drawable element with trait: GraphicsComponent and NodeComponent + * or a light element with trait: LightComponent and NodeComponent + * or a set of particles with trait: ParticleGroupComponent + */ + + /*! + * \brief Constructs an RenderSystem object by default + */ + RenderSystem::RenderSystem() : m_coordinateSystemMatrix(Nz::Matrix4f::Identity()), m_coordinateSystemInvalidated(true) @@ -23,6 +38,12 @@ namespace Ndk SetUpdateRate(0.f); } + /*! + * \brief Operation to perform when an entity is removed + * + * \param entity Pointer to the entity + */ + void RenderSystem::OnEntityRemoved(Entity* entity) { m_cameras.Remove(entity); @@ -33,6 +54,13 @@ namespace Ndk m_pointSpotLights.Remove(entity); } + /*! + * \brief Operation to perform when entity is validated for the system + * + * \param entity Pointer to the entity + * \param justAdded Is the entity newly added + */ + void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) { NazaraUnused(justAdded); @@ -82,6 +110,12 @@ namespace Ndk m_particleGroups.Remove(entity); } + /*! + * \brief Operation to perform when system is updated + * + * \param elapsedTime Delta time used for the update + */ + void RenderSystem::OnUpdate(float elapsedTime) { NazaraUnused(elapsedTime); @@ -146,6 +180,12 @@ namespace Ndk } } + /*! + * \brief Updates the directional shadow maps according to the position of the viewer + * + * \param viewer Viewer of the scene + */ + void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer) { if (!m_shadowRT.IsValid()) @@ -191,6 +231,10 @@ namespace Ndk } } + /*! + * \brief Updates the point spot shadow maps + */ + void RenderSystem::UpdatePointSpotShadowMaps() { if (!m_shadowRT.IsValid()) diff --git a/SDK/src/NDK/Systems/VelocitySystem.cpp b/SDK/src/NDK/Systems/VelocitySystem.cpp index 2d3264039..e8cfe2f23 100644 --- a/SDK/src/NDK/Systems/VelocitySystem.cpp +++ b/SDK/src/NDK/Systems/VelocitySystem.cpp @@ -9,12 +9,31 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::VelocitySystem + * \brief NDK class that represents the velocity system + * + * \remark This system is enabled if the entity owns the trait: NodeComponent and VelocityComponent + * but it's disabled with the trait: PhysicsComponent + */ + + /*! + * \brief Constructs an VelocitySystem object by default + */ + VelocitySystem::VelocitySystem() { Requires(); Excludes(); } + /*! + * \brief Operation to perform when system is updated + * + * \param elapsedTime Delta time used for the update + */ + void VelocitySystem::OnUpdate(float elapsedTime) { for (const Ndk::EntityHandle& entity : GetEntities()) diff --git a/SDK/src/NDK/World.cpp b/SDK/src/NDK/World.cpp index 8e5ff99f0..938722feb 100644 --- a/SDK/src/NDK/World.cpp +++ b/SDK/src/NDK/World.cpp @@ -16,12 +16,28 @@ namespace Ndk { + /*! + * \ingroup NDK + * \class Ndk::World + * \brief NDK class that represents a world + */ + + /*! + * \brief Destructs the object and calls Clear + * + * \see Clear + */ + World::~World() noexcept { - // La destruction doit se faire dans un ordre précis + // The destruct must be done in an ordered way Clear(); } + /*! + * \brief Adds default systems to the world + */ + void World::AddDefaultSystems() { AddSystem(); @@ -34,40 +50,49 @@ namespace Ndk #endif } + /*! + * \brief Creates an entity in the world + * \return The entity created + */ + const EntityHandle& World::CreateEntity() { EntityId id; if (!m_freeIdList.empty()) { - // On récupère un identifiant + // We get an identifier id = m_freeIdList.back(); m_freeIdList.pop_back(); } else { - // On alloue une nouvelle entité + // We allocate a new entity id = m_entities.size(); - // Impossible d'utiliser emplace_back à cause de la portée + // We can't use emplace_back due to the scope m_entities.push_back(Entity(this, id)); } - // On initialise l'entité et on l'ajoute à la liste des entités vivantes + // We initialise the entity and we add it to the list of alive entities Entity& entity = m_entities[id].entity; entity.Create(); m_aliveEntities.emplace_back(&entity); - m_entities[id].aliveIndex = m_aliveEntities.size()-1; + m_entities[id].aliveIndex = m_aliveEntities.size() - 1; return m_aliveEntities.back(); } + /*! + * \brief Clears the world from every entities + * + * \remark Every handles are correctly invalidated, entities are immediately invalidated + */ + void World::Clear() noexcept { - ///DOC: Tous les handles sont correctement invalidés, les entités sont immédiatement invalidées - - // Destruction des entités d'abord, et des handles ensuite - // ceci pour éviter que les handles n'informent les entités inutilement lors de leur destruction + // First, destruction of entities, then handles + // This is made to avoid that handle warn uselessly entities before their destruction m_entities.clear(); m_aliveEntities.clear(); @@ -75,6 +100,15 @@ namespace Ndk m_killedEntities.Clear(); } + /*! + * \brief Clones the entity + * \return The clone newly created + * + * \param id Identifier of the entity + * + * \remark Produces a NazaraError if the entity to clone does not exist + */ + const EntityHandle& World::CloneEntity(EntityId id) { EntityHandle original = GetEntity(id); @@ -96,14 +130,29 @@ namespace Ndk return GetEntity(clone->GetId()); } + /*! + * \brief Kills an entity + * + * \param Pointer to the entity + * + * \remark No change is done if entity is invalid + */ + void World::KillEntity(Entity* entity) { - ///DOC: Ignoré si l'entité est invalide - if (IsEntityValid(entity)) m_killedEntities.UnboundedSet(entity->GetId(), true); } + /*! + * \brief Gets an entity + * \return A constant reference to the modified entity + * + * \param id Identifier of the entity + * + * \remark Produces a NazaraError if entity identifier is not valid + */ + const EntityHandle& World::GetEntity(EntityId id) { if (IsEntityIdValid(id)) @@ -115,9 +164,15 @@ namespace Ndk } } + /*! + * \brief Updates the world + * + * \remark Produces a NazaraAssert if an entity is invalid + */ + void World::Update() { - // Gestion des entités tuées depuis le dernier appel + // Handle killed entities before last call for (std::size_t i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i)) { EntityBlock& block = m_entities[i]; @@ -125,32 +180,32 @@ namespace Ndk NazaraAssert(entity.IsValid(), "Entity must be valid"); - // Remise en file d'attente de l'identifiant d'entité + // Send back the identifier of the entity to the free queue m_freeIdList.push_back(entity.GetId()); - // Destruction de l'entité (invalidation du handle par la même occasion) + // Destruction of the entity (invalidation of handle by the same way) entity.Destroy(); - // Nous allons sortir le handle de la liste des entités vivantes - // en swappant le handle avec le dernier handle, avant de pop + // We take out the handle from the list of alive entities + // With the idiom swap and pop NazaraAssert(block.aliveIndex < m_aliveEntities.size(), "Alive index out of range"); - if (block.aliveIndex < m_aliveEntities.size()-1) // S'il ne s'agit pas du dernier handle + if (block.aliveIndex < m_aliveEntities.size() - 1) // If it's not the last handle { EntityHandle& lastHandle = m_aliveEntities.back(); EntityHandle& myHandle = m_aliveEntities[block.aliveIndex]; myHandle = std::move(lastHandle); - // On n'oublie pas de corriger l'indice associé à l'entité + // We don't forget to update the index associated to the entity m_entities[myHandle->GetId()].aliveIndex = block.aliveIndex; } m_aliveEntities.pop_back(); } m_killedEntities.Reset(); - // Gestion des entités nécessitant une mise à jour de leurs systèmes + // Handle of entities which need an update from the systems for (std::size_t i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i)) { NazaraAssert(i < m_entities.size(), "Entity index out of range"); diff --git a/build/scripts/tools/unittests.lua b/build/scripts/tools/unittests.lua index 0d3dcc7d2..b423b390f 100644 --- a/build/scripts/tools/unittests.lua +++ b/build/scripts/tools/unittests.lua @@ -14,17 +14,10 @@ TOOL.Includes = { TOOL.Files = { "../tests/main.cpp", - "../tests/Engine/**.cpp" + "../tests/Engine/**.cpp", + "../tests/SDK/**.cpp" } TOOL.Libraries = { - "NazaraCore", - "NazaraAudio", - "NazaraLua", - "NazaraGraphics", - "NazaraRenderer", - "NazaraNetwork", - "NazaraNoise", - "NazaraPhysics", - "NazaraUtility" + "NazaraSDK" } diff --git a/tests/SDK/NDK/Application.cpp b/tests/SDK/NDK/Application.cpp new file mode 100644 index 000000000..994bd022b --- /dev/null +++ b/tests/SDK/NDK/Application.cpp @@ -0,0 +1,22 @@ +#include +#include + +SCENARIO("Application", "[NDK][APPLICATION]") +{ + GIVEN("An application") + { + Ndk::Application application; + application.AddWorld(); + Nz::Window& window = application.AddWindow(); + + WHEN("We close the open window") + { + window.Close(); + + THEN("Application should close") + { + REQUIRE(!application.Run()); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/BaseSystem.cpp b/tests/SDK/NDK/BaseSystem.cpp new file mode 100644 index 000000000..e4ca2e1c9 --- /dev/null +++ b/tests/SDK/NDK/BaseSystem.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +namespace +{ + class TestSystem : public Ndk::System + { + public: + TestSystem() + { + Requires(); + Excludes(); + } + + ~TestSystem() = default; + + static Ndk::SystemIndex systemIndex; + + private: + void OnUpdate(float elapsedTime) override + { + } + }; + + Ndk::SystemIndex TestSystem::systemIndex; +} + +SCENARIO("BaseSystem", "[NDK][BASESYSTEM]") +{ + GIVEN("Our TestSystem") + { + Ndk::World world; + Ndk::BaseSystem& system = world.AddSystem(); + REQUIRE(&system.GetWorld() == &world); + + WHEN("We add an entity") + { + const Ndk::EntityHandle& entity = world.CreateEntity(); + entity->AddComponent(); + + THEN("System should have it") + { + world.Update(1.f); + REQUIRE(system.HasEntity(entity)); + } + } + + WHEN("We add an entity with excluded component") + { + const Ndk::EntityHandle& entity = world.CreateEntity(); + entity->AddComponent(); + entity->AddComponent(); + + THEN("System should not have it") + { + world.Update(1.f); + REQUIRE(!system.HasEntity(entity)); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Component.cpp b/tests/SDK/NDK/Component.cpp new file mode 100644 index 000000000..f00bb9006 --- /dev/null +++ b/tests/SDK/NDK/Component.cpp @@ -0,0 +1,31 @@ +#include +#include + +namespace +{ + class TestComponent : public Ndk::Component + { + public: + static Ndk::ComponentIndex componentIndex; + }; + + Ndk::ComponentIndex TestComponent::componentIndex; +} + +SCENARIO("Component", "[NDK][COMPONENT]") +{ + GIVEN("Our TestComponent") + { + TestComponent testComponent; + + WHEN("We clone it") + { + std::unique_ptr clone = testComponent.Clone(); + + THEN("We should get a copy") + { + REQUIRE(dynamic_cast(clone.get()) != nullptr); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Entity.cpp b/tests/SDK/NDK/Entity.cpp new file mode 100644 index 000000000..d784e28ad --- /dev/null +++ b/tests/SDK/NDK/Entity.cpp @@ -0,0 +1,101 @@ +#include +#include +#include + +namespace +{ + class UpdatableComponent : public Ndk::Component + { + public: + bool IsUpdated() + { + return m_updated; + } + + void SetUpdated() + { + m_updated = true; + } + + static Ndk::ComponentIndex componentIndex; + + private: + bool m_updated = false; + }; + + Ndk::ComponentIndex UpdatableComponent::componentIndex; + + class UpdateSystem : public Ndk::System + { + public: + UpdateSystem() + { + Requires(); + } + + ~UpdateSystem() = default; + + static Ndk::SystemIndex systemIndex; + + private: + void OnUpdate(float elapsedTime) override + { + for (const Ndk::EntityHandle& entity : GetEntities()) + { + UpdatableComponent& updatable = entity->GetComponent(); + updatable.SetUpdated(); + } + } + }; + + Ndk::SystemIndex UpdateSystem::systemIndex; +} + +SCENARIO("Entity", "[NDK][ENTITY]") +{ + GIVEN("A world & an entity") + { + Ndk::World world; + Ndk::BaseSystem& system = world.AddSystem(); + const Ndk::EntityHandle& entity = world.CreateEntity(); + + WHEN("We add our UpdateComponent") + { + UpdatableComponent& updatableComponent = entity->AddComponent(); + REQUIRE(!updatableComponent.IsUpdated()); + + THEN("Update the world should update the entity's component") + { + world.Update(1.f); + UpdatableComponent& updatableComponentGet = entity->GetComponent(); + REQUIRE(updatableComponentGet.IsUpdated()); + } + + THEN("Update the world should not update the entity's component if it's disabled") + { + entity->Enable(false); + world.Update(1.f); + UpdatableComponent& updatableComponentGet = entity->GetComponent(); + REQUIRE(!updatableComponentGet.IsUpdated()); + } + + THEN("We can remove its component") + { + entity->RemoveComponent(Ndk::GetComponentIndex()); + world.Update(1.f); + REQUIRE(!entity->HasComponent()); + } + } + + WHEN("We kill our entity") + { + entity->Kill(); + world.Update(1.f); + + THEN("It's no more valid") + { + REQUIRE(!world.IsEntityValid(entity)); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/EntityList.cpp b/tests/SDK/NDK/EntityList.cpp new file mode 100644 index 000000000..4b76766d5 --- /dev/null +++ b/tests/SDK/NDK/EntityList.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +SCENARIO("EntityList", "[NDK][ENTITYLIST]") +{ + GIVEN("A world & a set of entities") + { + Ndk::World world; + const Ndk::EntityHandle& entity = world.CreateEntity(); + Ndk::EntityList entityList; + entityList.Insert(entity); + + WHEN("We ask if entity is in there") + { + THEN("These results are expected") + { + REQUIRE(entityList.Has(entity->GetId())); + const Ndk::EntityHandle& entity = world.CreateEntity(); + REQUIRE(!entityList.Has(entity->GetId())); + } + } + + WHEN("We remove then insert") + { + entityList.Remove(*entityList.begin()); + + THEN("Set should be empty") + { + REQUIRE(entityList.empty()); + } + + entityList.Insert(entity); + + THEN("With one element") + { + REQUIRE(!entityList.empty()); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/EntityOwner.cpp b/tests/SDK/NDK/EntityOwner.cpp new file mode 100644 index 000000000..eb9a29edf --- /dev/null +++ b/tests/SDK/NDK/EntityOwner.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +SCENARIO("EntityOwner", "[NDK][ENTITYOWNER]") +{ + GIVEN("A world & an entity") + { + Ndk::World world; + const Ndk::EntityHandle& entity = world.CreateEntity(); + + WHEN("We set the ownership of the entity to our owner") + { + Ndk::EntityOwner entityOwner(entity); + + THEN("Entity is still valid") + { + REQUIRE(entity.IsValid()); + } + + THEN("Resetting or getting out of scope is no more valid") + { + entityOwner.Reset(); + world.Update(1.f); + REQUIRE(!entity.IsValid()); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/StateMachine.cpp b/tests/SDK/NDK/StateMachine.cpp new file mode 100644 index 000000000..604aa6f9f --- /dev/null +++ b/tests/SDK/NDK/StateMachine.cpp @@ -0,0 +1,48 @@ +#include +#include + +class TestState : public Ndk::State +{ + public: + void Enter(Ndk::StateMachine& fsm) override + { + m_isUpdated = false; + } + + bool IsUpdated() const + { + return m_isUpdated; + } + + void Leave(Ndk::StateMachine& fsm) override + { + } + + bool Update(Ndk::StateMachine& fsm, float elapsedTime) override + { + m_isUpdated = true; + } + + private: + bool m_isUpdated; +}; + +SCENARIO("State & StateMachine", "[NDK][STATE]") +{ + GIVEN("A statemachine with our TestState") + { + std::shared_ptr testState = std::make_shared(); + Ndk::StateMachine stateMachine(testState); + REQUIRE(!testState->IsUpdated()); + + WHEN("We update our machine") + { + stateMachine.Update(1.f); + + THEN("Our state has been updated") + { + REQUIRE(testState->IsUpdated()); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/System.cpp b/tests/SDK/NDK/System.cpp new file mode 100644 index 000000000..ca1917124 --- /dev/null +++ b/tests/SDK/NDK/System.cpp @@ -0,0 +1,42 @@ +#include +#include + +namespace +{ + class TestSystem : public Ndk::System + { + public: + TestSystem() + { + } + + ~TestSystem() = default; + + static Ndk::SystemIndex systemIndex; + + private: + void OnUpdate(float elapsedTime) override + { + } + }; + + Ndk::SystemIndex TestSystem::systemIndex; +} + +SCENARIO("System", "[NDK][SYSTEM]") +{ + GIVEN("Our TestSystem") + { + TestSystem testSystem; + + WHEN("We clone it") + { + std::unique_ptr clone = testSystem.Clone(); + + THEN("We should get a copy") + { + REQUIRE(dynamic_cast(clone.get()) != nullptr); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Systems/ListenerSystem.cpp b/tests/SDK/NDK/Systems/ListenerSystem.cpp new file mode 100644 index 000000000..2792dbc25 --- /dev/null +++ b/tests/SDK/NDK/Systems/ListenerSystem.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include + +SCENARIO("ListenerSystem", "[NDK][LISTENERSYSTEM]") +{ + GIVEN("A world and an entity with listener & node components") + { + Ndk::World world; + const Ndk::EntityHandle& entity = world.CreateEntity(); + Ndk::ListenerComponent& listenerComponent = entity->AddComponent(); + Ndk::NodeComponent& nodeComponent = entity->AddComponent(); + + WHEN("We move our entity") + { + Nz::Vector3f position = Nz::Vector3f::Unit() * 3.f; + nodeComponent.SetPosition(position); + Nz::Quaternionf rotation = Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::Up()); + nodeComponent.SetRotation(rotation); + world.Update(1.f); + + THEN("Our listener should have moved") + { + REQUIRE(Nz::Audio::GetListenerPosition() == position); + REQUIRE(Nz::Audio::GetListenerRotation() == rotation); + } + + THEN("With a component of velocity") + { + Ndk::VelocityComponent& velocityComponent = entity->AddComponent(); + Nz::Vector3f velocity = Nz::Vector3f::Unit() * 2.f; + velocityComponent.linearVelocity = velocity; + + world.Update(1.f); + REQUIRE(Nz::Audio::GetListenerVelocity() == velocity); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Systems/PhysicsSystem.cpp b/tests/SDK/NDK/Systems/PhysicsSystem.cpp new file mode 100644 index 000000000..2aa3c313e --- /dev/null +++ b/tests/SDK/NDK/Systems/PhysicsSystem.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + +SCENARIO("PhysicsSystem", "[NDK][PHYSICSSYSTEM]") +{ + GIVEN("A world and a static entity & a dynamic entity") + { + Ndk::World world; + const Ndk::EntityHandle& staticEntity = world.CreateEntity(); + Ndk::CollisionComponent& collisionComponentStatic = staticEntity->AddComponent(); + Ndk::NodeComponent& nodeComponentStatic = staticEntity->AddComponent(); + + const Ndk::EntityHandle& dynamicEntity = world.CreateEntity(); + Ndk::NodeComponent& nodeComponentDynamic = dynamicEntity->AddComponent(); + Ndk::PhysicsComponent& physicsComponentDynamic = dynamicEntity->AddComponent(); + + WHEN("We make collide these two entities") + { + nodeComponentDynamic.SetPosition(-Nz::Vector3f::UnitZ()); + physicsComponentDynamic.AddForce(Nz::Vector3f::UnitZ()); + + THEN("The dynamic entity should have hit the static one") + { + world.Update(1.f); // On origin + world.Update(1.f); // On origin due to collision + REQUIRE(nodeComponentStatic.GetPosition().SquaredDistance(nodeComponentDynamic.GetPosition()) < 0.2f); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Systems/RenderSystem.cpp b/tests/SDK/NDK/Systems/RenderSystem.cpp new file mode 100644 index 000000000..f106b3aae --- /dev/null +++ b/tests/SDK/NDK/Systems/RenderSystem.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +SCENARIO("RenderSystem", "[NDK][RenderSystem]") +{ + GIVEN("A world with a camera, a drawable, a light and some particles") + { + Ndk::World world; + const Ndk::EntityHandle& cameraEntity = world.CreateEntity(); + Ndk::CameraComponent& cameraComponentCamera = cameraEntity->AddComponent(); + Ndk::NodeComponent& nodeComponentCamera = cameraEntity->AddComponent(); + + const Ndk::EntityHandle& drawableEntity = world.CreateEntity(); + Ndk::GraphicsComponent& graphicsComponentDrawable = drawableEntity->AddComponent(); + Nz::SpriteRef sprite = Nz::Sprite::New(); + graphicsComponentDrawable.Attach(sprite); + Ndk::NodeComponent& nodeComponentDrawable = drawableEntity->AddComponent(); + + const Ndk::EntityHandle& lightEntity = world.CreateEntity(); + Ndk::LightComponent& lightComponentLight = lightEntity->AddComponent(); + Ndk::NodeComponent& nodeComponentLight = lightEntity->AddComponent(); + + const Ndk::EntityHandle& particlesEntity = world.CreateEntity(); + Ndk::ParticleGroupComponent& particleGroupComponentParticles = particlesEntity->AddComponent(1, Nz::ParticleLayout_Sprite); + + WHEN("We change the render technique to ForwardRenderTechnique") + { + Ndk::RenderSystem& renderSystem = world.GetSystem(); + renderSystem.ChangeRenderTechnique(); + + THEN("The render system should be ForwardRenderTechnique") + { + REQUIRE(renderSystem.GetRenderTechnique().GetType() == Nz::RenderTechniqueType_BasicForward); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/Systems/VelocitySystem.cpp b/tests/SDK/NDK/Systems/VelocitySystem.cpp new file mode 100644 index 000000000..bfde34896 --- /dev/null +++ b/tests/SDK/NDK/Systems/VelocitySystem.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +SCENARIO("VelocitySystem", "[NDK][VELOCITYSYSTEM]") +{ + GIVEN("A world and an entity with velocity & node components") + { + Ndk::World world; + const Ndk::EntityHandle& entity = world.CreateEntity(); + Ndk::VelocityComponent& velocityComponent = entity->AddComponent(); + Ndk::NodeComponent& nodeComponent = entity->AddComponent(); + + WHEN("We give a speed to our entity") + { + Nz::Vector3f velocity = Nz::Vector3f::Unit() * 2.f; + velocityComponent.linearVelocity = velocity; + world.Update(1.f); + + THEN("Our entity should have moved") + { + REQUIRE(nodeComponent.GetPosition().SquaredDistance(velocity) < 0.2f); + } + } + } +} \ No newline at end of file diff --git a/tests/SDK/NDK/World.cpp b/tests/SDK/NDK/World.cpp new file mode 100644 index 000000000..431490490 --- /dev/null +++ b/tests/SDK/NDK/World.cpp @@ -0,0 +1,103 @@ +#include +#include +#include + +namespace +{ + class UpdatableComponent : public Ndk::Component + { + public: + bool IsUpdated() + { + return m_updated; + } + + void SetUpdated() + { + m_updated = true; + } + + static Ndk::ComponentIndex componentIndex; + + private: + bool m_updated = false; + }; + + Ndk::ComponentIndex UpdatableComponent::componentIndex; + + class UpdateSystem : public Ndk::System + { + public: + UpdateSystem() + { + Requires(); + } + + ~UpdateSystem() = default; + + static Ndk::SystemIndex systemIndex; + + private: + void OnUpdate(float elapsedTime) override + { + for (const Ndk::EntityHandle& entity : GetEntities()) + { + UpdatableComponent& updatable = entity->GetComponent(); + updatable.SetUpdated(); + } + } + }; + + Ndk::SystemIndex UpdateSystem::systemIndex; +} + +SCENARIO("World", "[NDK][WORLD]") +{ + GIVEN("A brave new world and the update system") + { + Ndk::World world; + Ndk::BaseSystem& system = world.AddSystem(); + + WHEN("We had a new entity with an updatable component and a system") + { + const Ndk::EntityHandle& entity = world.CreateEntity(); + UpdatableComponent& component = entity->AddComponent(); + + THEN("We can get our entity and our system") + { + const Ndk::EntityHandle& fetchedEntity = world.GetEntity(entity->GetId()); + REQUIRE(fetchedEntity->GetWorld() == &world); + } + + THEN("We can clone it") + { + const Ndk::EntityHandle& clone = world.CloneEntity(entity->GetId()); + REQUIRE(world.IsEntityValid(clone)); + } + } + + AND_WHEN("We update our world with our entity") + { + REQUIRE(&world.GetSystem(UpdateSystem::systemIndex) == &world.GetSystem()); + const Ndk::EntityHandle& entity = world.CreateEntity(); + UpdatableComponent& component = entity->AddComponent(); + + THEN("Our entity component must be updated") + { + world.Update(1.f); + + REQUIRE(component.IsUpdated()); + } + + THEN("We kill our entity") + { + REQUIRE(entity->IsValid()); + + world.KillEntity(entity); + world.Update(1.f); + + REQUIRE(!world.IsEntityValid(entity)); + } + } + } +} \ No newline at end of file