Core/ObjectHandle: Remade object handle system

This commit is contained in:
Jérôme Leclercq
2018-10-12 15:46:40 +02:00
parent 3933d5007d
commit 4c4822eef9
9 changed files with 107 additions and 180 deletions

View File

@@ -8,8 +8,8 @@
#define NDK_ENTITY_HPP
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Core/Signal.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/Prerequisites.hpp>

View File

@@ -20,6 +20,7 @@ namespace Ndk
EntityOwner(EntityOwner&& handle) noexcept = default;
~EntityOwner();
void Release();
void Reset(Entity* entity = nullptr);
void Reset(EntityOwner&& handle);

View File

@@ -2,6 +2,7 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/EntityOwner.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <functional>
#include <limits>
@@ -36,16 +37,23 @@ namespace Ndk
Reset(nullptr);
}
/*!
* \brief Release the ownership of the entity without killing it
*/
inline void EntityOwner::Release()
{
EntityHandle::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)
m_object->Kill();
if (IsValid())
GetObject()->Kill();
EntityHandle::Reset(entity);
}
@@ -55,11 +63,10 @@ namespace Ndk
*
* \param handle EntityOwner to move into this
*/
inline void EntityOwner::Reset(EntityOwner&& handle)
{
Reset(handle.GetObject());
handle.m_object = nullptr;
handle.Release();
}
/*!