From 26e7fa1686abf0fd4c7955c0f82ef5bb953a9b03 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 18 Dec 2015 13:27:09 +0100 Subject: [PATCH] Ndk: Add EntityOwner class Former-commit-id: ef7486e39124642cb1d1b8c24c4c726dc592486b --- SDK/include/NDK/EntityHandle.hpp | 2 +- SDK/include/NDK/EntityHandle.inl | 2 +- SDK/include/NDK/EntityOwner.hpp | 35 ++++++++++++++ SDK/include/NDK/EntityOwner.inl | 78 ++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 SDK/include/NDK/EntityOwner.hpp create mode 100644 SDK/include/NDK/EntityOwner.inl diff --git a/SDK/include/NDK/EntityHandle.hpp b/SDK/include/NDK/EntityHandle.hpp index c6a325b7e..8a5594dbe 100644 --- a/SDK/include/NDK/EntityHandle.hpp +++ b/SDK/include/NDK/EntityHandle.hpp @@ -71,7 +71,7 @@ namespace Ndk static const EntityHandle InvalidHandle; - private: + protected: void OnEntityDestroyed(); void OnEntityMoved(Entity* newEntity); diff --git a/SDK/include/NDK/EntityHandle.inl b/SDK/include/NDK/EntityHandle.inl index 636287878..03e7ad829 100644 --- a/SDK/include/NDK/EntityHandle.inl +++ b/SDK/include/NDK/EntityHandle.inl @@ -135,7 +135,7 @@ namespace Ndk inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle) { - Reset(handle); + Reset(std::move(handle)); return *this; } diff --git a/SDK/include/NDK/EntityOwner.hpp b/SDK/include/NDK/EntityOwner.hpp new file mode 100644 index 000000000..3e2b6cdab --- /dev/null +++ b/SDK/include/NDK/EntityOwner.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + +#pragma once + +#ifndef NDK_ENTITYOWNER_HPP +#define NDK_ENTITYOWNER_HPP + +#include + +namespace Ndk +{ + class EntityOwner : public EntityHandle + { + public: + EntityOwner() = default; + explicit EntityOwner(Entity* entity); + EntityOwner(const EntityOwner& handle); + EntityOwner(EntityOwner&& handle); + ~EntityOwner(); + + void Reset(Entity* entity = nullptr); + void Reset(const EntityOwner& handle); + void Reset(EntityOwner&& handle); + + EntityOwner& operator=(Entity* entity); + EntityOwner& operator=(const EntityOwner& handle); + EntityOwner& operator=(EntityOwner&& handle); + }; +} + +#include + +#endif // NDK_ENTITYOwner_HPP diff --git a/SDK/include/NDK/EntityOwner.inl b/SDK/include/NDK/EntityOwner.inl new file mode 100644 index 000000000..c2335268f --- /dev/null +++ b/SDK/include/NDK/EntityOwner.inl @@ -0,0 +1,78 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + +#include +#include +#include + +namespace Ndk +{ + inline EntityOwner::EntityOwner(Entity* entity) : + EntityOwner() + { + Reset(entity); + } + + inline EntityOwner::EntityOwner(const EntityOwner& handle) : + EntityHandle(handle) + { + } + + inline EntityOwner::EntityOwner(EntityOwner&& handle) : + EntityHandle(std::move(handle)) + { + } + + inline EntityOwner::~EntityOwner() + { + Reset(nullptr); + } + + inline void EntityOwner::Reset(Entity* entity) + { + if (m_entity) + m_entity->Kill(); + + EntityHandle::Reset(entity); + } + + inline void EntityOwner::Reset(const EntityOwner& handle) + { + Reset(handle.GetEntity()); + } + + inline void EntityOwner::Reset(EntityOwner&& handle) + { + Reset(handle.GetEntity()); + } + + inline EntityOwner& EntityOwner::operator=(Entity* entity) + { + Reset(entity); + + return *this; + } + + inline EntityOwner& EntityOwner::operator=(const EntityOwner& handle) + { + Reset(handle); + + return *this; + } + + inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle) + { + Reset(std::move(handle)); + + return *this; + } +} + +namespace std +{ + template<> + struct hash : public hash + { + }; +}