Ndk: Add EntityOwner class
Former-commit-id: ef7486e39124642cb1d1b8c24c4c726dc592486b
This commit is contained in:
parent
39f2c4eb07
commit
26e7fa1686
|
|
@ -71,7 +71,7 @@ namespace Ndk
|
||||||
|
|
||||||
static const EntityHandle InvalidHandle;
|
static const EntityHandle InvalidHandle;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void OnEntityDestroyed();
|
void OnEntityDestroyed();
|
||||||
void OnEntityMoved(Entity* newEntity);
|
void OnEntityMoved(Entity* newEntity);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ namespace Ndk
|
||||||
|
|
||||||
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
|
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
|
||||||
{
|
{
|
||||||
Reset(handle);
|
Reset(std::move(handle));
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue