diff --git a/SDK/include/NDK/BaseComponent.hpp b/SDK/include/NDK/BaseComponent.hpp index d9ae7410a..f4b3a80bc 100644 --- a/SDK/include/NDK/BaseComponent.hpp +++ b/SDK/include/NDK/BaseComponent.hpp @@ -26,14 +26,11 @@ namespace Ndk ComponentIndex GetIndex() const; - template - static ComponentIndex Register(const char (&name)[N]); - - static ComponentIndex Register(ComponentId id, Factory factoryFunc); - protected: ComponentIndex m_componentIndex; + static ComponentIndex RegisterComponent(ComponentId id, Factory factoryFunc); + private: struct ComponentEntry { diff --git a/SDK/include/NDK/BaseComponent.inl b/SDK/include/NDK/BaseComponent.inl index e090b746e..de0ecd643 100644 --- a/SDK/include/NDK/BaseComponent.inl +++ b/SDK/include/NDK/BaseComponent.inl @@ -3,8 +3,6 @@ // For conditions of distribution and use, see copyright notice in Prerequesites.hpp #include -#include -#include namespace Ndk { @@ -18,25 +16,7 @@ namespace Ndk return m_componentIndex; } - template - ComponentIndex BaseComponent::Register(const char (&name)[N]) - { - // Il faut que notre composant possède un constructeur par défaut (pour la factory) - static_assert(std::is_default_constructible::value, "ComponentType should be default-constructible"); - - // On récupère la chaîne de caractère sous la forme d'un nombre qui servira d'identifiant unique - ComponentId id = BuildComponentId(name); - - // On utilise les lambda pour créer une fonction factory - auto factory = []() -> BaseComponent* - { - return new ComponentType; - }; - - return Register(id, factory); - } - - inline ComponentIndex BaseComponent::Register(ComponentId id, Factory factoryFunc) + inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc) { // Nous allons rajouter notre composant à la fin ComponentIndex index = s_entries.size(); diff --git a/SDK/include/NDK/BaseSystem.hpp b/SDK/include/NDK/BaseSystem.hpp index b5d7441d1..b68b13472 100644 --- a/SDK/include/NDK/BaseSystem.hpp +++ b/SDK/include/NDK/BaseSystem.hpp @@ -34,13 +34,13 @@ namespace Ndk bool HasEntity(const Entity* entity) const; - static SystemIndex GetNextIndex(); - protected: template void Excludes(); template void Excludes(); void ExcludesComponent(ComponentIndex index); + static SystemIndex GetNextIndex(); + template void Requires(); template void Requires(); void RequiresComponent(ComponentIndex index); diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 596591e1f..5b44ec006 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -35,11 +35,6 @@ namespace Ndk return m_entityBits.UnboundedTest(entity->GetId()); } - inline SystemIndex BaseSystem::GetNextIndex() - { - return s_nextIndex++; - } - template void BaseSystem::Excludes() { @@ -60,6 +55,11 @@ namespace Ndk m_excludedComponents.UnboundedSet(index); } + inline SystemIndex BaseSystem::GetNextIndex() + { + return s_nextIndex++; + } + template void BaseSystem::Requires() { diff --git a/SDK/include/NDK/Component.hpp b/SDK/include/NDK/Component.hpp index 09f23a281..e3026dbad 100644 --- a/SDK/include/NDK/Component.hpp +++ b/SDK/include/NDK/Component.hpp @@ -19,6 +19,11 @@ namespace Ndk virtual ~Component(); BaseComponent* Clone() const override; + + static ComponentIndex RegisterComponent(ComponentId id); + + template + static ComponentIndex RegisterComponent(const char (&name)[N]); }; } diff --git a/SDK/include/NDK/Component.inl b/SDK/include/NDK/Component.inl index 9aee60c35..fab8bed6f 100644 --- a/SDK/include/NDK/Component.inl +++ b/SDK/include/NDK/Component.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp +#include #include namespace Ndk @@ -23,4 +24,31 @@ namespace Ndk return new ComponentType(static_cast(*this)); } + + template + ComponentIndex Component::RegisterComponent(ComponentId id) + { + // Il faut que notre composant possède un constructeur par défaut (pour la factory) + static_assert(std::is_default_constructible::value, "ComponentType should be default-constructible"); + + // On utilise les lambda pour créer une fonction factory + auto factory = []() -> BaseComponent* + { + return new ComponentType; + }; + + // Je ne sais pas si c'est un bug de GCC ou si c'est quelque chose que j'ai mal compris + // mais le fait est que ça ne compile pas si je ne précise pas Basecomponent:: + return BaseComponent::RegisterComponent(id, factory); + } + + 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 + ComponentId id = BuildComponentId(name); + return RegisterComponent(id); + } + } diff --git a/SDK/include/NDK/System.hpp b/SDK/include/NDK/System.hpp index c49db14c5..91774fead 100644 --- a/SDK/include/NDK/System.hpp +++ b/SDK/include/NDK/System.hpp @@ -19,6 +19,8 @@ namespace Ndk virtual ~System(); BaseSystem* Clone() const override; + + static SystemIndex RegisterSystem(); }; } diff --git a/SDK/include/NDK/System.inl b/SDK/include/NDK/System.inl index 3360505cd..98b5f06da 100644 --- a/SDK/include/NDK/System.inl +++ b/SDK/include/NDK/System.inl @@ -24,4 +24,11 @@ namespace Ndk return new SystemType(static_cast(*this)); } + + template + SystemIndex System::RegisterSystem() + { + return GetNextIndex(); + } + }