#pragma once #include #include #include #include #include #include #include #include "entitypool.hpp" #include "typetracker.hpp" #include "component.hpp" class GameInstance; class World; class Entity { friend class EntityPool; public: uint32_t GetID() { return m_id; } template T* Add() { T* t = new T; GetEntPool().RegisterComponent(this, t); return t; } Component* Add(Component* component) { GetEntPool().RegisterComponent(this, component); return component; } Component* Add(const std::string& componentName) { auto types = TypeTracker::GetTypes(); for(auto type : types) { if(type.first == componentName) return Add(type.second); } return nullptr; } Component* Add(std::type_index type) { return Add(Utility::GetTypeName(type)); } template void Remove() { GetEntPool().RemoveComponent(this, typeid(T)); } void Remove(Component* component) { GetEntPool().RemoveComponent(this, component); } void RemoveAll() { GetEntPool().RemoveComponents(this); } void Duplicate(Component* component) { GetEntPool().DuplicateComponent(this, component); } template T* Get() { auto components = GetEntPool().GetComponents(this); for(auto& itr : components) { if(itr.first.type == typeid(T)) return static_cast(itr.second); } return nullptr; } Transform* GetTransform() { return Get(); } template std::vector GetComponentsOf() { std::vector tmp; auto components = GetEntPool().GetComponents(this); for(auto& itr : components) { if(itr.first.type == typeid(T)) tmp.push_back(static_cast(itr.second)); } return tmp; } std::vector GetComponents() { std::vector tmp; auto components = GetEntPool().GetComponents(this); for(auto& itr : components) { tmp.push_back(itr.second); } return tmp; } GameInstance* GetGame() const { return m_gameInstance; } World* GetWorld() const { return m_world; } std::string name; std::string tag; protected: //you should be using the entity pool! Entity(const std::string& requestedName = "Entity", uint32_t requestedID = -1); GameInstance* m_gameInstance = nullptr; World* m_world = nullptr; private: uint32_t m_id = -1; };