Ndk: Add EntityOwner class

Former-commit-id: ef7486e39124642cb1d1b8c24c4c726dc592486b
This commit is contained in:
Lynix 2015-12-18 13:27:09 +01:00
parent 39f2c4eb07
commit 26e7fa1686
4 changed files with 115 additions and 2 deletions

View File

@ -71,7 +71,7 @@ namespace Ndk
static const EntityHandle InvalidHandle;
private:
protected:
void OnEntityDestroyed();
void OnEntityMoved(Entity* newEntity);

View File

@ -135,7 +135,7 @@ namespace Ndk
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
{
Reset(handle);
Reset(std::move(handle));
return *this;
}

View File

@ -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 <NDK/EntityHandle.hpp>
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 <NDK/EntityOwner.inl>
#endif // NDK_ENTITYOwner_HPP

View File

@ -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 <Nazara/Core/StringStream.hpp>
#include <functional>
#include <limits>
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<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
{
};
}