Files
NazaraEngine/SDK/include/NDK/Entity.hpp
S6066 ab9bd52b1c Update Entity.hpp
Former-commit-id: 1d99c5e8ecc59365b5e7b8a38ca6b7d728afe61e [formerly 8ad7a1c88ab8bfc98b3d31cc475ba5f1da2b640a] [formerly b8e21adaa60f4709451afbf5b38546e3129a1d5e [formerly 29cf1e9d53f54156ec4d691c4155d510139a8f0b]]
Former-commit-id: 0c981c02a27181bbb8771bf4c3524a0a3a935f60 [formerly aaf146a3ca97aaa7b0c9601b7e277b0a2b66936b]
Former-commit-id: 4f2fda343a111f80d6f9827d3a377fe07d2f59b5
2016-08-23 16:49:47 +02:00

98 lines
2.5 KiB
C++

// 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_ENTITY_HPP
#define NDK_ENTITY_HPP
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <NDK/Algorithm.hpp>
#include <memory>
#include <vector>
namespace Ndk
{
class BaseComponent;
class Entity;
class World;
using EntityHandle = Nz::ObjectHandle<Entity>;
class NDK_API Entity : public Nz::HandledObject<Entity>
{
friend class BaseSystem;
friend World;
public:
Entity(const Entity&) = delete;
Entity(Entity&& entity);
~Entity();
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 = true);
inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent();
inline const BaseComponent& GetComponent(ComponentIndex index) const;
template<typename ComponentType> const ComponentType& GetComponent() const;
inline const Nz::Bitset<>& GetComponentBits() const;
inline EntityId GetId() const;
inline const Nz::Bitset<>& GetSystemBits() const;
inline World* GetWorld() const;
inline bool HasComponent(ComponentIndex index) const;
template<typename ComponentType> bool HasComponent() const;
void Kill();
void Invalidate();
inline bool IsEnabled() const;
inline bool IsValid() const;
inline void RemoveAllComponents();
inline void RemoveComponent(ComponentIndex index);
template<typename ComponentType> void RemoveComponent();
inline Nz::String ToString() const;
Entity& operator=(const Entity&) = delete;
Entity& operator=(Entity&&) = delete;
private:
Entity(World* world, EntityId id);
void Create();
void Destroy();
void DestroyComponent(ComponentIndex index);
inline Nz::Bitset<>& GetRemovedComponentBits();
inline void RegisterSystem(SystemIndex index);
inline void SetWorld(World* world) noexcept;
inline void UnregisterSystem(SystemIndex index);
std::vector<std::unique_ptr<BaseComponent>> m_components;
Nz::Bitset<> m_componentBits;
Nz::Bitset<> m_removedComponentBits;
Nz::Bitset<> m_systemBits;
EntityId m_id;
World* m_world;
bool m_enabled;
bool m_valid;
};
}
#include <NDK/Entity.inl>
#endif // NDK_ENTITY_HPP