2#include <Engine/Core/Tick.h>
9#include <entt/entt.hpp>
10#include "Engine/Component/LogicComponent.h"
51 void tick(
double deltaTime)
override;
86 template<
typename T,
typename... Args>
87 requires std::is_base_of_v<Components::Logic, T> && std::is_constructible_v<T, Args...>
90 if constexpr (T::IsUnique) {
93 PLOGW <<
"Attempted to add unique component " <<
typeid(T).name() <<
" which already exists on entity.";
98 auto component = std::make_unique<T>(std::forward<Args>(args)...);
99 component->setOwningEntity(
this);
100 T* rawComponent = component.get();
103 if (
isPlaying() && !rawComponent->hasBegunPlay() ) {
104 rawComponent->beginPlay();
115 requires std::is_base_of_v<Components::Logic, T>
118 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
130 requires std::is_base_of_v<Components::Logic, T>
132 std::vector<T*> result;
134 if (
auto typed =
dynamic_cast<T*
>(component.get())) {
135 result.push_back(typed);
146 auto it = std::ranges::find_if(
components_, [component](
const auto& ptr) {
147 return ptr.get() == component;
161 requires std::is_base_of_v<Components::Logic, T>
163 auto it = std::ranges::find_if(
components_, [](
const auto& ptr) {
164 return dynamic_cast<T*
>(ptr.get()) !=
nullptr;
180 requires std::is_base_of_v<Components::Logic, T>
189 [[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 ...
Owns entity lifetime and deferred destruction for a scene or subsystem.
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 allowTicking_
Whether ticking is currently enabled.
bool isPlaying() const
Returns whether this entity has begun play and has not ended play.
bool removeFirstComponent()
Removes the first component of type T found.
LifecycleState lifecycleState_
int32_t getTickPriority() const
Returns the tick ordering priority for this entity.
EntityContainer * owningContainer_
Entity()
Creates an entity in the constructed lifecycle state.
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.
virtual void onEngineEndPlay()
Hook called when the engine ends play for this entity.
bool isDestroyingOrDestroyed() const
virtual void onEngineBeginPlay()
Hook called when the engine begins play for this entity.
virtual void onEngineDestroyed()
Hook called when the entity is being destroyed by the engine lifecycle.
void tick(double deltaTime) override
Executes every frame if tick is enabled.
friend class EntityContainer
void destroyImmediate()
Destroys this entity immediately through its owning container.
~Entity() override
Destroys the entity and owned logic components.
entt::entity data_
ECS entity handle associated with this entity.
void removeComponent(Components::Logic *component)
Removes a specific component instance.
bool canEverTick() const
Tells if this entity can ever tick.
EntityContainer * getOwningContainer() const
Returns the container that owns this entity.
int32_t tickPriority_
Priority used to order entity ticks.
std::vector< T * > getComponents() const
Returns all components of type T.
void destroy()
Tells the scene to destroy this Entity.
T * getComponent() const
Returns the first component of type T found.
bool isPendingDestroy() const
Returns whether this entity has been queued for destruction.
void setTickPriority(int32_t priority)
Sets the tick ordering priority for this entity.