Loading...
Searching...
No Matches
lib/score/model/Component.hpp
1#pragma once
2#include <score/model/EntityMap.hpp>
3#include <score/plugins/UuidKey.hpp>
4
5#if defined(SCORE_SERIALIZABLE_COMPONENTS)
6#include <score/tools/std/HashMap.hpp>
7
8#include <QByteArray>
9#endif
10
11#include <utility>
12#include <verdigris>
13namespace score
14{
16{
17};
18
24class SCORE_LIB_BASE_EXPORT Component : public QObject
25{
26 W_OBJECT(Component)
27public:
28 explicit Component(QObject* parent);
29 explicit Component(const QString& name, QObject* parent);
30 ~Component() override;
31
32 virtual UuidKey<score::Component> key() const noexcept = 0;
33 virtual bool key_match(UuidKey<score::Component> other) const noexcept = 0;
34};
35
40struct SCORE_LIB_BASE_EXPORT Components : std::vector<score::Component*>
41{
42 void add(score::Component* t);
43 void remove(score::Component* t);
44 void erase(score::Component* t);
45 void add(score::Component& t);
46 void remove(score::Component& t);
47 void erase(score::Component& t);
48};
49
56template <typename System_T>
58{
59public:
60 template <typename... Args>
61 GenericComponent(System_T& sys, Args&&... args) noexcept
62 : score::Component{std::forward<Args>(args)...}
63 , m_system{sys}
64 {
65 }
66
67 System_T& system() const noexcept { return m_system; }
68
69private:
70 System_T& m_system;
71};
72
73#if defined(SCORE_SERIALIZABLE_COMPONENTS)
74class SerializableComponent;
75using DataStreamComponents
76 = score::hash_map<UuidKey<score::SerializableComponent>, QByteArray>;
77using JSONComponents
78 = score::hash_map<UuidKey<score::SerializableComponent>, QJsonObject>;
79#endif
80}
81
82#if defined(SCORE_SERIALIZABLE_COMPONENTS)
83#if !defined(SCORE_ALL_UNITY) && !defined(__MINGW32__)
84extern template class SCORE_LIB_BASE_EXPORT
85 ossia::fast_hash_map<UuidKey<score::SerializableComponent>, QByteArray>;
86extern template class SCORE_LIB_BASE_EXPORT
87 ossia::fast_hash_map<UuidKey<score::SerializableComponent>, QJsonObject>;
88#endif
89#endif
90
94#define ABSTRACT_COMPONENT_METADATA(Type, Uuid) \
95public: \
96 using base_component_type = Type; \
97 \
98 static constexpr UuidKey<score::Component> static_key() noexcept \
99 { \
100 return_uuid(Uuid); \
101 } \
102 \
103 static constexpr bool base_key_match(UuidKey<score::Component> other) noexcept \
104 { \
105 return static_key() == other; \
106 } \
107 \
108private:
109
113#define COMPONENT_METADATA(Uuid) \
114public: \
115 static constexpr UuidKey<score::Component> static_key() noexcept \
116 { \
117 return_uuid(Uuid); \
118 } \
119 \
120 constexpr UuidKey<score::Component> key() const noexcept final override \
121 { \
122 return static_key(); \
123 } \
124 \
125 constexpr bool key_match(UuidKey<score::Component> other) \
126 const noexcept final override \
127 { \
128 return static_key() == other || base_component_type::base_key_match(other); \
129 } \
130 \
131private:
132
136#define COMMON_COMPONENT_METADATA(Uuid) \
137public: \
138 static constexpr UuidKey<score::Component> static_key() noexcept \
139 { \
140 return_uuid(Uuid); \
141 } \
142 \
143 UuidKey<score::Component> key() const noexcept final override \
144 { \
145 return static_key(); \
146 } \
147 \
148 bool key_match(UuidKey<score::Component> other) const noexcept final override \
149 { \
150 return static_key() == other; \
151 } \
152 \
153private:
Definition UuidKey.hpp:343
A component adds custom data to an Entity.
Definition lib/score/model/Component.hpp:25
A component that has a reference to a specific context object.
Definition lib/score/model/Component.hpp:58
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition lib/score/model/Component.hpp:41
Definition lib/score/model/Component.hpp:16