Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ObjectComponent.h
Go to the documentation of this file.
1#pragma once
2
3#include "Object.h"
4#include "system/message.h"
5//#include "system/system_consts.h"
6#include <memory>
8
9class GameObject;
10
11// Components processing types in order of execution
12enum class ComponentType
13{
14 None = 0, // no processing or used for extra data components for entities
15 GameObject, // general game object component
16 Physics,
17 AI,
18 Visual,
19 Audio,
20 System,
22 Count // used in World to size arrays
23};
24//---------------------------------------------------------------------------------------------
25class ObjectComponent : public Object
26{
27public:
28 explicit ObjectComponent() = default;
29 virtual ~ObjectComponent() = default;
30
31 inline Object* GetEntity() const { return owner; }
32 virtual void SetEntity(Object* _owner) { owner = _owner; }
33
34 // Which Type this property participates in
35 virtual ComponentType GetComponentType() const = 0;
36
37 virtual void Initialize() {}
38
39 // Called during the update loop (for Physics/AI/Audio)
40 virtual void Process() {}
41
42 // Called during the render Type (for Render properties)
43 virtual void Render() {}
44 virtual void RenderDebug() {}
45
46 // Called when a message is delivered to this property (via owner forwarding)
47 virtual void OnEvent(const Message& /*msg*/);
48
49 // Set the owner object of this component
50 virtual void SetOwner(Object* _owner)
51 {
52 owner = _owner;
53 gao = (GameObject*)(owner);
54 }
55 inline Object* GetOwner() const { return owner; }
56
57protected:
58 Object* owner = nullptr;
59 static float& fDt; // reference to global frame delta time
60 GameObject* gao = nullptr;
61};
62
63//---------------------------------------------------------------------------------------------
64// Inherited properties - minimal implementations
66{
67public:
68 explicit PhysicsComponent() = default;
69 virtual ~PhysicsComponent() override = default;
70 virtual ComponentType GetComponentType() const override { return ComponentType::Physics; }
71 virtual void Process() override {/* Basic physics integration should be implemented by project-specific code.*/ }
72 virtual void OnEvent(const Message& msg) override;
73};
74//---------------------------------------------------------------------------------------------
76{
77public:
78 explicit AIComponent() = default;
79 virtual ~AIComponent() override = default;
80 virtual ComponentType GetComponentType() const override { return ComponentType::AI; }
81 virtual void SetOwner(Object* _owner) override;
82 virtual void Process() override {/*AI logic goes here.*/ }
83 virtual void OnEvent(const Message& msg) override;
84
85protected:
86
87};
88//---------------------------------------------------------------------------------------------
90{
91public:
92 explicit VisualComponent() = default;
93 virtual ~VisualComponent() override = default;
94 virtual ComponentType GetComponentType() const override { return ComponentType::Visual; }
95 virtual void Render() override{/* Drawing logic goes here.*/}
96 virtual void OnEvent(const Message & msg) override;
97};
98//---------------------------------------------------------------------------------------------
100{
101public:
102 explicit AudioComponent() = default;
103 virtual ~AudioComponent() override = default;
104 virtual ComponentType GetComponentType() const override { return ComponentType::Audio; }
105 virtual void Process() override{/* Audio update logic goes here. */}
106 virtual void OnEvent(const Message & msg) override;
107};
108//---------------------------------------------------------------------------------------------
110{
111 public:
112 explicit SystemComponent() = default;
113 virtual ~SystemComponent() override = default;
114 virtual ComponentType GetComponentType() const override { return ComponentType::System; }
115 virtual void Process() override{/* System update logic goes here. */}
116 virtual void OnEvent(const Message & msg) override;
117};
118//---------------------------------------------------------------------------------------------
120{
121 public:
122 explicit ProcessusComponent() = default;
123 virtual ~ProcessusComponent() override = default;
124 virtual ComponentType GetComponentType() const override { return ComponentType::Processus; }
125 virtual void Process() override{/* Processus update logic goes here. */}
126 virtual void OnEvent(const Message & msg) override;
127};
128//---------------------------------------------------------------------------------------------
130{
131public:
132 explicit GameObjectComponent() = default;
133 virtual ~GameObjectComponent() override = default;
134 virtual ComponentType GetComponentType() const override { return ComponentType::GameObject; }
135 virtual void OnEvent(const Message& msg) override;
136};
137
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
ComponentType
virtual ~AIComponent() override=default
virtual ComponentType GetComponentType() const override
virtual void OnEvent(const Message &msg) override
virtual void Process() override
AIComponent()=default
virtual void SetOwner(Object *_owner) override
virtual void Process() override
AudioComponent()=default
virtual void OnEvent(const Message &msg) override
virtual ComponentType GetComponentType() const override
virtual ~AudioComponent() override=default
virtual ComponentType GetComponentType() const override
GameObjectComponent()=default
virtual void OnEvent(const Message &msg) override
virtual ~GameObjectComponent() override=default
virtual void OnEvent(const Message &)
virtual void RenderDebug()
virtual void SetEntity(Object *_owner)
ObjectComponent()=default
virtual void Render()
virtual void Process()
virtual void Initialize()
virtual ComponentType GetComponentType() const =0
static float & fDt
Object * GetOwner() const
virtual void SetOwner(Object *_owner)
Object * GetEntity() const
GameObject * gao
virtual ~ObjectComponent()=default
virtual void OnEvent(const Message &msg) override
virtual ComponentType GetComponentType() const override
virtual ~PhysicsComponent() override=default
virtual void Process() override
PhysicsComponent()=default
virtual ComponentType GetComponentType() const override
virtual void Process() override
ProcessusComponent()=default
virtual void OnEvent(const Message &msg) override
virtual ~ProcessusComponent() override=default
SystemComponent()=default
virtual void OnEvent(const Message &msg) override
virtual void Process() override
virtual ComponentType GetComponentType() const override
virtual ~SystemComponent() override=default
virtual void OnEvent(const Message &msg) override
virtual ComponentType GetComponentType() const override
VisualComponent()=default
virtual ~VisualComponent() override=default
virtual void Render() override