SDK/Entity: Add entity cloning
Former-commit-id: e855800df2110a15bbe808673549baed12c0a80d [formerly eee65fd713e594fbcb76b74bcee243ad7d670113] [formerly 00cab4a7320aacceeeddceeffba4475e48ee7c2e [formerly 256bcefb089172041e2a21c28e8486e70b288884]] Former-commit-id: 78fa9291af60f0b02858a9b0127d60fec6a96521 [formerly ae13e29e620506aa1921b0faecc54b1a63609097] Former-commit-id: ae1a27340b2b21f4d04e2df8f7a5aea3c50f6e3b
This commit is contained in:
parent
9bf253f09d
commit
5fa172e7f5
|
|
@ -34,6 +34,8 @@ namespace Ndk
|
|||
BaseComponent& AddComponent(std::unique_ptr<BaseComponent>&& component);
|
||||
template<typename ComponentType, typename... Args> ComponentType& AddComponent(Args&&... args);
|
||||
|
||||
const EntityHandle& Clone() const;
|
||||
|
||||
inline void Enable(bool enable);
|
||||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ namespace Ndk
|
|||
|
||||
void Clear() noexcept;
|
||||
|
||||
const EntityHandle& CloneEntity(EntityId id);
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities();
|
||||
inline BaseSystem& GetSystem(SystemIndex index);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@ namespace Ndk
|
|||
return component;
|
||||
}
|
||||
|
||||
const EntityHandle& Entity::Clone() const
|
||||
{
|
||||
///DOC: The clone is enabled by default, even if the original entity is disabled
|
||||
NazaraAssert(IsValid(), "Invalid entity");
|
||||
|
||||
return m_world->CloneEntity(m_id);
|
||||
}
|
||||
|
||||
void Entity::Kill()
|
||||
{
|
||||
m_world->KillEntity(this);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
|
|
@ -74,6 +75,27 @@ namespace Ndk
|
|||
m_killedEntities.Clear();
|
||||
}
|
||||
|
||||
const EntityHandle& World::CloneEntity(EntityId id)
|
||||
{
|
||||
EntityHandle original = GetEntity(id);
|
||||
if (!original)
|
||||
{
|
||||
NazaraError("Invalid entity ID");
|
||||
return EntityHandle::InvalidHandle;
|
||||
}
|
||||
|
||||
EntityHandle clone = CreateEntity();
|
||||
|
||||
const Nz::Bitset<>& componentBits = original->GetComponentBits();
|
||||
for (std::size_t i = componentBits.FindFirst(); i != componentBits.npos; i = componentBits.FindNext(i))
|
||||
{
|
||||
std::unique_ptr<BaseComponent> component(original->GetComponent(ComponentIndex(i)).Clone());
|
||||
clone->AddComponent(std::move(component));
|
||||
}
|
||||
|
||||
return GetEntity(clone->GetId());
|
||||
}
|
||||
|
||||
void World::KillEntity(Entity* entity)
|
||||
{
|
||||
///DOC: Ignoré si l'entité est invalide
|
||||
|
|
|
|||
Loading…
Reference in New Issue