8#include <entt/entt.hpp>
34 void tick(
double deltaTime)
override;
44 template<
typename T,
typename... Args>
requires std::is_base_of_v<Components::Logic, T>
47 if constexpr (T::IsUnique) {
50 PLOGW <<
"Attempted to add unique component " <<
typeid(T).name() <<
" which already exists on entity.";
55 auto component = std::make_unique<T>(std::forward<Args>(args)...);
56 component->setOwningEntity(
this);
57 T* rawComponent = component.get();
74 requires std::is_base_of_v<Components::Logic, T>
77 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
89 requires std::is_base_of_v<Components::Logic, T>
91 std::vector<T*> result;
93 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
94 result.push_back(typed);
105 auto it = std::ranges::find_if(
components_, [component](
const auto& ptr) {
106 return ptr.get() == component;
120 requires std::is_base_of_v<Components::Logic, T>
122 auto it = std::ranges::find_if(
components_, [](
const auto& ptr) {
123 return dynamic_cast<T*
>(ptr.get()) !=
nullptr;
139 requires std::is_base_of_v<Components::Logic, T>
148 [[nodiscard]]
const std::vector<std::unique_ptr<Components::Logic>>&
getAllComponents()
const {
Base class for all logic components that can be attached to an actor. Provides access to the scene,...
This is the interface which is used to call a tick function on an object. Everything which should be ...
entt::entity getEcsEntity() const
Gets the ECS entity handle for this Entity.
void enableTick(bool enable)
Enables or disables ticking for this entity.
T * addComponent(Args &&... args)
Adds a component to the entity. Checks for uniqueness if the component defines 'static constexpr bool...
bool removeFirstComponent()
Removes the first component of type T found.
int32_t getTickPriority() const
std::string getUuidString() const
Getter for the UUID of this entity as a string.
bool canTick() const
Tells you if the entity can execute its tick function.
std::vector< std::unique_ptr< Components::Logic > > components_
List of all logical components.
bool hasComponent() const
Checks if a component of type T exists.
const std::vector< std::unique_ptr< Components::Logic > > & getAllComponents() const
Gets all components on this entity.
void tick(double deltaTime) override
Executes every frame if tick is enabled.
void removeComponent(Components::Logic *component)
Removes a specific component instance.
bool canEverTick() const
Tells if this entity can ever tick.
uuids::uuid getUUID() const
Getter for the UUID of this entity.
std::vector< T * > getComponents() const
Returns all components of type T.
T * getComponent() const
Returns the first component of type T found.
void setTickPriority(int32_t priority)