SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Component.h
1#pragma once
2
3#include "spark/core/Export.h"
4
5#include "experimental/ser/SerializerScheme.h"
6#include "spark/base/Macros.h"
7#include "spark/lib/Uuid.h"
8#include "spark/rtti/HasRtti.h"
9
10namespace spark::core
11{
12 class GameObject;
13
19 class SPARK_CORE_EXPORT Component : public rtti::HasRtti
20 {
21 DECLARE_SPARK_RTTI(Component)
22 SPARK_ALLOW_PRIVATE_SERIALIZATION
23
24 public:
29 explicit Component(GameObject* parent);
30
31 ~Component() override = default;
32
33 Component(const Component& other) = delete;
34 Component(Component&& other) noexcept = default;
35 Component& operator=(const Component& other) = delete;
36 Component& operator=(Component&& other) noexcept = default;
37
42 [[nodiscard]] const lib::Uuid& uuid() const;
43
48 [[nodiscard]] GameObject* gameObject();
49
54 [[nodiscard]] const GameObject* gameObject() const;
55
59 virtual void render() const {}
60
64 virtual void onAttach() {}
65
70 virtual void onUpdate(float dt) { SPARK_UNUSED(dt); }
71
75 virtual void onDetach() {}
76
77 private:
78 lib::Uuid m_uuid;
79 GameObject* m_gameObject = nullptr;
80 };
81}
82
83IMPLEMENT_SPARK_RTTI(spark::core::Component)
A component that can be attached to a GameObject to provide additional functionality.
Definition Component.h:20
virtual void onDetach()
Method called when the component is detached from a GameObject.
Definition Component.h:75
virtual void onAttach()
Method called when the component is attached to a GameObject.
Definition Component.h:64
virtual void onUpdate(float dt)
Method called on every frame.
Definition Component.h:70
virtual void render() const
Renders the component.
Definition Component.h:59
A GameObject is any object in the game. It contains a list of components that provides functionality ...
Definition GameObject.h:26
A 128-bit universally unique identifier (UUID).
Definition Uuid.h:22
The class anything using the RTTI should implement.
Definition HasRtti.h:16