From f6bbe396fafbe6cacded064455d96fb8e348c2e4 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 15 Oct 2019 09:32:30 +0200 Subject: [PATCH] Sdk/World: Add CloneEntity(const EntityHandle&) overload --- ChangeLog.md | 1 + SDK/include/NDK/World.hpp | 1 + SDK/src/NDK/World.cpp | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 79425fab0..90403a1b5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -289,6 +289,7 @@ Nazara Development Kit: - ⚠️ Made AbstractTextAreaWidget which is inherited by TextAreaWidget - ⚠️ Added RichTextAreaWidget - ⚠️ Console now supports text color in history +- Added World::CloneEntity overload taking an EntityHandle const reference, allowing to copy entities from other worlds # 0.4: diff --git a/SDK/include/NDK/World.hpp b/SDK/include/NDK/World.hpp index 891c3df11..ca6e917b7 100644 --- a/SDK/include/NDK/World.hpp +++ b/SDK/include/NDK/World.hpp @@ -46,6 +46,7 @@ namespace Ndk void Clear() noexcept; const EntityHandle& CloneEntity(EntityId id); + const EntityHandle& CloneEntity(const EntityHandle& entity); inline void DisableProfiler(); inline void EnableProfiler(bool enable = true); diff --git a/SDK/src/NDK/World.cpp b/SDK/src/NDK/World.cpp index d8a1ec0e3..dc848625a 100644 --- a/SDK/src/NDK/World.cpp +++ b/SDK/src/NDK/World.cpp @@ -157,16 +157,26 @@ namespace Ndk return EntityHandle::InvalidHandle; } + return CloneEntity(original); + } + + /*! + * \brief Clones the entity + * \return The clone newly created + * + * \param original Entity handle + * + * \remark Cloning a disabled entity will produce an enabled clone + */ + const EntityHandle& World::CloneEntity(const EntityHandle& original) + { const EntityHandle& clone = CreateEntity(); if (!original->IsEnabled()) clone->Disable(); const Nz::Bitset<>& componentBits = original->GetComponentBits(); for (std::size_t i = componentBits.FindFirst(); i != componentBits.npos; i = componentBits.FindNext(i)) - { - std::unique_ptr component(original->GetComponent(ComponentIndex(i)).Clone()); - clone->AddComponent(std::move(component)); - } + clone->AddComponent(original->GetComponent(ComponentIndex(i)).Clone()); clone->Enable();