diff --git a/SDK/include/NDK/BaseComponent.hpp b/SDK/include/NDK/BaseComponent.hpp index 01c6c7a7b..f548c7cd3 100644 --- a/SDK/include/NDK/BaseComponent.hpp +++ b/SDK/include/NDK/BaseComponent.hpp @@ -17,6 +17,8 @@ namespace Ndk BaseComponent(nzUInt32 componentId); virtual ~BaseComponent(); + virtual BaseComponent* Clone() const = 0; + nzUInt32 GetComponentId() const; static nzUInt32 GetNextId(); diff --git a/SDK/include/NDK/Component.hpp b/SDK/include/NDK/Component.hpp index 861725959..d06a160a1 100644 --- a/SDK/include/NDK/Component.hpp +++ b/SDK/include/NDK/Component.hpp @@ -19,8 +19,11 @@ namespace Ndk Component(); virtual ~Component(); - static nzUInt32 GetId(); + virtual BaseComponent* Clone() const override; }; + + template + constexpr nzUInt32 GetComponentId(); } #include diff --git a/SDK/include/NDK/Component.inl b/SDK/include/NDK/Component.inl index 65b751d7b..34314f84f 100644 --- a/SDK/include/NDK/Component.inl +++ b/SDK/include/NDK/Component.inl @@ -2,11 +2,13 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp +#include + namespace Ndk { template Component::Component() : - BaseComponent(GetId()) + BaseComponent(GetComponentId()) { } @@ -14,7 +16,15 @@ namespace Ndk Component::~Component() = default; template - nzUInt32 Component::GetId() + virtual BaseComponent* Component::Clone() const + { + static_assert::value, "ComponentType should be copy-constructible"> + + return new ComponentType(static_cast(*this)); + } + + template + constexpr nzUInt32 GetComponentId() { return ComponentType::ComponentId; }