Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Entities::Actor Class Reference

An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform. More...

#include <Actor.h>

Inheritance diagram for Engine::Entities::Actor:
Collaboration diagram for Engine::Entities::Actor:

Public Member Functions

 Actor (const SpawnContext &context)
 ~Actor () override=default
template<typename T, typename... Args>
requires detail::ConstructibleWithActorContext<T, Args...>
T * addComponent (Args &&... args)
 Adds a component using this actor's scene, ECS entity and scene node where supported.
virtual void beginPlay ()
 Gets executed when the actor is spawned into the world.
void tick (double deltaTime) override
 Executed every frame.
virtual void endPlay ()
 Gets executed when an actor is getting removed from the scene.
virtual std::string getActorName () const
void destroyActor ()
 Queues this actor for destruction after the current tick finishes.
void destroyActorImmediate ()
 Destroys this actor immediately. Prefer destroyActor() during gameplay/tick code.
glm::vec3 getActorLocation () const
 Gets the actors location in the world.
glm::vec3 getActorRotation () const
 Gets the actors rotation in the world.
glm::quat getActorRotationQuat () const
 Gets the actors world rotation.
glm::vec3 getActorScale () const
 Scales the actor to world scale.
void setActorLocation (glm::vec3 newLocation) const
 Set the new world location for this actor.
void setActorRotation (glm::vec3 newRotation) const
 Sets the world rotation.
void rotateActor (glm::vec3 deltaRotation) const
 Applies an incremental rotation to the actor using quaternion multiplication. Use this instead of getActorRotation() + setActorRotation() for continuous rotation to avoid euler angle instability/jiggling.
void setActorScale (glm::vec3 newScale) const
 sets the world scale for this actor
glm::vec3 getForwardVector () const
 Gets the forward world vector.
glm::vec3 getRightVector () const
 Gets the right.
glm::vec3 getUpVector () const
 Gets the up world vector.
glm::mat4 getWorldTransform () const
 Gets the model matrix.
virtual bool drawImGui () const
 Allows drawing custom Imgui panels for the editor.
ScenegetOwningScene () const
 Get the pointer to the scene this entity is a part of.
EngineKerngetEngine () const
 Gets the engine this actor belongs to.
Core::PhysicsEnginegetPhysicsEngine () const
 Gets the physics engine through this actor's owning engine.
std::shared_ptr< SceneNodegetSceneNode () const
 Getter for the scene graph node for this object.
Public Member Functions inherited from Engine::Entities::Entity
 Entity ()
 ~Entity () override
void enableTick (bool enable)
 Enables or disables ticking for this entity.
void setTickPriority (int32_t priority)
int32_t getTickPriority () const
void tick (double deltaTime) override
 Executes every frame if tick is enabled.
template<typename T, typename... Args>
requires std::is_base_of_v<Components::Logic, T> && std::is_constructible_v<T, Args...>
T * addComponent (Args &&... args)
 Adds a component to the entity. Checks for uniqueness if the component defines 'static constexpr bool IsUnique = true;'.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
T * getComponent () const
 Returns the first component of type T found.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
std::vector< T * > getComponents () const
 Returns all components of type T.
void removeComponent (Components::Logic *component)
 Removes a specific component instance.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
bool removeFirstComponent ()
 Removes the first component of type T found.
template<typename T>
requires std::is_base_of_v<Components::Logic, T>
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.
bool canTick () const
 Tells you if the entity can execute its tick function.
bool canEverTick () const
 Tells if this entity can ever tick.
entt::entity getEcsEntity () const
 Gets the ECS entity handle for this Entity.
Public Member Functions inherited from Engine::Core::ITickable
virtual ~ITickable ()=default
virtual void preTick ()
 Function which executes immediately before the execution of ITickable::preTick()
virtual void postTick ()
 Function which executes immediately after the execution of ITickable::postTick()

Protected Attributes

std::optional< std::shared_ptr< SceneNode > > sceneNode
Protected Attributes inherited from Engine::Entities::Entity
std::vector< std::unique_ptr< Components::Logic > > components_
 List of all logical components.
entt::entity data_ = entt::null
bool allowTicking_ = false
int32_t tickPriority_ = 0

Private Member Functions

template<typename T, typename First, typename... Rest>
T * addComponentWithSceneEntityFirstNodeRest (First &&first, Rest &&... rest)

Private Attributes

SceneowningScene_ = nullptr
std::weak_ptr< Components::ScenerootComponent_
bool hasEndedPlay_ = false

Additional Inherited Members

Protected Member Functions inherited from Engine::Entities::Entity
uuids::uuid getUUID () const
 Getter for the UUID of this entity.
std::string getUuidString () const
 Getter for the UUID of this entity as a string.

Detailed Description

An Actor is similar to an Engine::Entities::Entity. An actor is an Entity with a transform.

Definition at line 64 of file Actor.h.

Constructor & Destructor Documentation

◆ Actor()

Engine::Entities::Actor::Actor ( const SpawnContext & context)
explicit

◆ ~Actor()

Engine::Entities::Actor::~Actor ( )
overridedefault

References Engine::Entities::Entity::addComponent().

Here is the call graph for this function:

Member Function Documentation

◆ addComponent()

template<typename T, typename... Args>
requires detail::ConstructibleWithActorContext<T, Args...>
T * Engine::Entities::Actor::addComponent ( Args &&... args)
inline

Adds a component using this actor's scene, ECS entity and scene node where supported.

Common actor-owned components can be spawned as addComponent<T>(args...) without manually passing getOwningScene(), getEcsEntity()/data_ or getSceneNode(). Explicit constructor calls still resolve to Entity::addComponent when this overload is not constructible.

Definition at line 83 of file Actor.h.

References Engine::Entities::Entity::addComponent(), addComponentWithSceneEntityFirstNodeRest(), Engine::Entities::Entity::data_, getOwningScene(), getSceneNode(), and Scene.

Here is the call graph for this function:

◆ addComponentWithSceneEntityFirstNodeRest()

template<typename T, typename First, typename... Rest>
T * Engine::Entities::Actor::addComponentWithSceneEntityFirstNodeRest ( First && first,
Rest &&... rest )
inlineprivate

Definition at line 263 of file Actor.h.

References Engine::Entities::Entity::addComponent(), Engine::Entities::Entity::data_, getOwningScene(), and getSceneNode().

Referenced by addComponent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginPlay()

virtual void Engine::Entities::Actor::beginPlay ( )
virtual

Gets executed when the actor is spawned into the world.

◆ destroyActor()

void Engine::Entities::Actor::destroyActor ( )

Queues this actor for destruction after the current tick finishes.

◆ destroyActorImmediate()

void Engine::Entities::Actor::destroyActorImmediate ( )

Destroys this actor immediately. Prefer destroyActor() during gameplay/tick code.

◆ drawImGui()

virtual bool Engine::Entities::Actor::drawImGui ( ) const
virtual

Allows drawing custom Imgui panels for the editor.

◆ endPlay()

virtual void Engine::Entities::Actor::endPlay ( )
virtual

Gets executed when an actor is getting removed from the scene.

◆ getActorLocation()

glm::vec3 Engine::Entities::Actor::getActorLocation ( ) const

Gets the actors location in the world.

Returns
vec3 | xyz | world location

◆ getActorName()

virtual std::string Engine::Entities::Actor::getActorName ( ) const
nodiscardvirtual

◆ getActorRotation()

glm::vec3 Engine::Entities::Actor::getActorRotation ( ) const

Gets the actors rotation in the world.

Returns
vec3 | pitch yaw roll | world rotation

◆ getActorRotationQuat()

glm::quat Engine::Entities::Actor::getActorRotationQuat ( ) const

Gets the actors world rotation.

Returns
quaternion | world rotation

◆ getActorScale()

glm::vec3 Engine::Entities::Actor::getActorScale ( ) const

Scales the actor to world scale.

Returns
xyz

◆ getEngine()

EngineKern * Engine::Entities::Actor::getEngine ( ) const
nodiscard

Gets the engine this actor belongs to.

Returns
Engine pointer, or nullptr if this actor is not attached to a scene

◆ getForwardVector()

glm::vec3 Engine::Entities::Actor::getForwardVector ( ) const

Gets the forward world vector.

Returns
local -z axis in world space (unit vector)

◆ getOwningScene()

Scene * Engine::Entities::Actor::getOwningScene ( ) const

Get the pointer to the scene this entity is a part of.

Returns
Scene pointer

References Scene.

Referenced by addComponent(), and addComponentWithSceneEntityFirstNodeRest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPhysicsEngine()

Core::PhysicsEngine * Engine::Entities::Actor::getPhysicsEngine ( ) const
nodiscard

Gets the physics engine through this actor's owning engine.

Returns
Physics engine pointer, or nullptr if unavailable

◆ getRightVector()

glm::vec3 Engine::Entities::Actor::getRightVector ( ) const

Gets the right.

Returns
local x+ axis in world space (unit vector)

◆ getSceneNode()

std::shared_ptr< SceneNode > Engine::Entities::Actor::getSceneNode ( ) const

Getter for the scene graph node for this object.

Returns
Node from the scene graph

Referenced by addComponent(), and addComponentWithSceneEntityFirstNodeRest().

Here is the caller graph for this function:

◆ getUpVector()

glm::vec3 Engine::Entities::Actor::getUpVector ( ) const

Gets the up world vector.

Returns
local y+ axis in world space (unit vector)

◆ getWorldTransform()

glm::mat4 Engine::Entities::Actor::getWorldTransform ( ) const

Gets the model matrix.

Returns
model matrix

◆ rotateActor()

void Engine::Entities::Actor::rotateActor ( glm::vec3 deltaRotation) const

Applies an incremental rotation to the actor using quaternion multiplication. Use this instead of getActorRotation() + setActorRotation() for continuous rotation to avoid euler angle instability/jiggling.

Parameters
deltaRotationeuler angles (degrees) to rotate by

◆ setActorLocation()

void Engine::Entities::Actor::setActorLocation ( glm::vec3 newLocation) const

Set the new world location for this actor.

Parameters
newLocationxyz

◆ setActorRotation()

void Engine::Entities::Actor::setActorRotation ( glm::vec3 newRotation) const

Sets the world rotation.

Parameters
newRotationeuler (yaw | pitch | roll)

◆ setActorScale()

void Engine::Entities::Actor::setActorScale ( glm::vec3 newScale) const

sets the world scale for this actor

Parameters
newScalexyz

◆ tick()

void Engine::Entities::Actor::tick ( double deltaTime)
overridevirtual

Executed every frame.

Parameters
deltaTimetime between this frame and the last frame

Reimplemented from Engine::Core::ITickable.

Member Data Documentation

◆ hasEndedPlay_

bool Engine::Entities::Actor::hasEndedPlay_ = false
private

Definition at line 276 of file Actor.h.

◆ owningScene_

Scene* Engine::Entities::Actor::owningScene_ = nullptr
private

Definition at line 274 of file Actor.h.

◆ rootComponent_

std::weak_ptr<Components::Scene> Engine::Entities::Actor::rootComponent_
private

Definition at line 275 of file Actor.h.

◆ sceneNode

std::optional<std::shared_ptr<SceneNode> > Engine::Entities::Actor::sceneNode
protected

Definition at line 234 of file Actor.h.


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Entity/Actor.h