Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
LogicComponent.h
1#pragma once
2#include <string>
3
4namespace Engine::Core
5{
6 class SceneManager;
7} // namespace Engine::Core
8
9namespace Engine::Entities
10{
11 class Entity;
12 class Scene;
13 struct SpawnContext;
14} // namespace Engine::Entities
15
16namespace Engine::Components
17{
18 class Entity;
19
24 class Logic
25 {
26 public:
32 static constexpr bool IsUnique = false;
33
38 static constexpr const char * ComponentName = "Logic";
39
44 explicit Logic( Entities::Scene * owningScene );
45
50 explicit Logic( const Entities::SpawnContext & context );
51
55 virtual ~Logic() = default;
56
61 [[nodiscard]] virtual std::string getComponentName() const;
62
67 virtual bool drawImGui();
68
73 virtual bool drawImGuiName();
74
78 virtual void beginPlay();
79
84 virtual void tick( double deltaTime );
85
89 virtual void endPlay();
90
95 [[nodiscard]] bool hasBegunPlay() const;
96
101 [[nodiscard]] bool canTick() const;
102
107 void setCanTick( bool enable );
108
113 [[nodiscard]] Entities::Entity * getOwningEntity() const;
114
115 protected:
120 [[nodiscard]] Entities::Scene * getScene() const;
121
126 [[nodiscard]] Core::SceneManager * getSceneManager() const;
127
128 private:
129 friend class Entities::Entity;
130
136
139 bool tickEnabled = false;
140 bool hasBegunPlay_ = false;
141 };
142} // namespace Engine::Components
virtual bool drawImGui()
Draws component-specific ImGui inspector controls.
Logic(const Entities::SpawnContext &context)
Constructs a logic component from spawn context data.
virtual void beginPlay()
Called when the component is added to the scene or the game starts.
static constexpr bool IsUnique
Defines whether multiple instances of this component can exist on the same entity....
bool canTick() const
Checks if the component is currently set to tick.
virtual ~Logic()=default
Destroys the logic component.
Entities::Scene * getScene() const
Gets the scene this component belongs to.
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
virtual std::string getComponentName() const
Gets the component type name for debugging/UI.
static constexpr const char * ComponentName
Fallback component type name. Derived classes may override getComponentName() for custom labels.
bool hasBegunPlay() const
Checks whether beginPlay() has been called without a matching endPlay().
virtual bool drawImGuiName()
Used to alter the name of the entity in the outliner.
void setCanTick(bool enable)
Enables or disables ticking for this component.
Entities::Entity * getOwningEntity() const
Gets the entity this component belongs to.
Entities::Entity * owningEntity_
void setOwningEntity(Entities::Entity *entity)
Sets the owning entity. Called by Entity::addComponent().
virtual void endPlay()
Called when the component is removed or the game ends.
virtual void tick(double deltaTime)
Called every frame if ticking is enabled.
Core::SceneManager * getSceneManager() const
Helper to get the SceneManager from the owning scene.
Manages game objects within a scene, handling registration, ID allocation, and GPU buffer synchroniza...
The entity class is the base class of everything which is attached to a scene. If it is part of a sce...
Definition Entity.h:18
Owns scene entities, actor lifetime, and the scene graph root.
Definition Scene.h:84
Scene ownership data passed to actor and component constructors during spawning.