9#include <entt/entt.hpp>
35 void tick(
double deltaTime)
override;
45 template<
typename T,
typename... Args>
46 requires std::is_base_of_v<Components::Logic, T> && std::is_constructible_v<T, Args...>
49 if constexpr (T::IsUnique) {
52 PLOGW <<
"Attempted to add unique component " <<
typeid(T).name() <<
" which already exists on entity.";
57 auto component = std::make_unique<T>(std::forward<Args>(args)...);
58 component->setOwningEntity(
this);
59 T* rawComponent = component.get();
76 requires std::is_base_of_v<Components::Logic, T>
79 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
91 requires std::is_base_of_v<Components::Logic, T>
93 std::vector<T*> result;
95 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
96 result.push_back(typed);
107 auto it = std::ranges::find_if(
components_, [component](
const auto& ptr) {
108 return ptr.get() == component;
122 requires std::is_base_of_v<Components::Logic, T>
124 auto it = std::ranges::find_if(
components_, [](
const auto& ptr) {
125 return dynamic_cast<T*
>(ptr.get()) !=
nullptr;
141 requires std::is_base_of_v<Components::Logic, T>
150 [[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)