7#include <entt/entt.hpp>
33 void tick(
double deltaTime)
override;
43 template<
typename T,
typename... Args>
45 static_assert(std::is_base_of_v<LogicComponent, T>,
"T must derive from LogicComponent");
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_shared<T>(std::forward<Args>(args)...);
56 component->setOwningEntity(
this);
65 return component.get();
74 static_assert(std::is_base_of_v<LogicComponent, T>,
"T must derive from LogicComponent");
76 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
89 static_assert(std::is_base_of_v<LogicComponent, T>,
"T must derive from LogicComponent");
90 std::vector<T*> result;
92 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
93 result.push_back(typed);
104 auto it = std::ranges::find_if(
components, [component](
const auto& ptr) {
105 return ptr.get() == component;
120 static_assert(std::is_base_of_v<LogicComponent, T>,
"T must derive from LogicComponent");
121 auto it = std::ranges::find_if(
components, [](
const auto& ptr) {
122 return dynamic_cast<T*
>(ptr.get()) !=
nullptr;
146 [[nodiscard]]
bool canTick()
const;
177 entt::entity
data = entt::null;
bool canTick() const
Tells you if the entity can execute its tick function.
T * getComponent() const
Returns the first component of type T found.
std::string getUuidString() const
Getter for the UUID of this entity as a string.
void removeComponent(LogicComponent *component)
Removes a specific component instance.
std::vector< T * > getComponents() const
Returns all components of type T.
void tick(double deltaTime) override
Executes every frame if tick is enabled.
void enableTick(bool enable)
Enables or disables ticking for this entity.
std::vector< std::shared_ptr< LogicComponent > > components
List of all logical components.
T * addComponent(Args &&... args)
Adds a component to the entity. Checks for uniqueness if the component defines 'static constexpr bool...
bool canEverTick() const
Tells if this entity can ever tick.
uuids::uuid getUUID() const
Getter for the UUID of this entity.
bool removeFirstComponent()
Removes the first component of type T found.
bool hasComponent() const
Checks if a component of type T exists.
This is the interface which is used to call a tick function on an object. Everything which should be ...
Base class for all logic components that can be attached to an actor. Provides access to the scene,...
Log category system implementation.