Radium Engine  1.5.0
SystemDisplay.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 
8 
9 // define RA_DISABLE_DEBUG_DISPLAY
10 
11 #include <Core/Utils/Color.hpp>
12 #include <Core/Utils/Singleton.hpp>
13 
14 #include <Engine/Scene/Component.hpp>
15 #include <Engine/Scene/Entity.hpp>
16 
17 #ifndef RA_DISABLE_DEBUG_DISPLAY
18 # include <Engine/Data/DrawPrimitives.hpp>
19 #endif
20 
21 namespace Ra {
22 namespace Engine {
23 namespace Scene {
24 
25 #ifndef RA_DISABLE_DEBUG_DISPLAY
26 
28 class RA_ENGINE_API DebugComponent : public Component
29 {
30  public:
31  explicit DebugComponent( Entity* entity ) : Component( "Debug", entity ) {}
32 
33  void initialize() override {};
34 
36  Rendering::RenderObject* getRenderObject( Core::Utils::Index idx );
37 };
38 
39 #endif
40 
42 class RA_ENGINE_API UiComponent : public Component
43 {
44  public:
45  explicit UiComponent( Entity* entity ) : Component( "UI", entity ) {}
46 
47  void initialize() override {}
48 };
49 
52 class RA_ENGINE_API SystemEntity : public Entity
53 {
54  RA_SINGLETON_INTERFACE( SystemEntity );
55 
56  public:
57  SystemEntity();
58 
59  ~SystemEntity() override = default;
60 
61 #ifndef RA_DISABLE_DEBUG_DISPLAY
63  static DebugComponent* dbgCmp();
64 
65 #endif
67  static UiComponent* uiCmp();
68 };
69 
70 } // namespace Scene
71 } // namespace Engine
72 } // namespace Ra
73 
74 #ifndef RA_DISABLE_DEBUG_DISPLAY
76 # define RA_DISPLAY_POINT( p, color, scale ) \
77  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
78  Ra::Engine::Data::DrawPrimitives::Primitive( \
79  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
80  Ra::Engine::Data::DrawPrimitives::Point( p, color, scale ) ) )
81 
82 # define RA_DISPLAY_VECTOR( p, v, color ) \
83  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
84  Ra::Engine::Data::DrawPrimitives::Primitive( \
85  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
86  Ra::Engine::Data::DrawPrimitives::Vector( p, v, color ) ) )
87 
88 # define RA_DISPLAY_RAY( r, color ) \
89  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
90  Ra::Engine::Data::DrawPrimitives::Primitive( \
91  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
92  Ra::Engine::Data::DrawPrimitives::Ray( r, color ) ) )
93 
94 # define RA_DISPLAY_CIRCLE( c, n, r, color ) \
95  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
96  Ra::Engine::Data::DrawPrimitives::Primitive( \
97  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
98  Ra::Engine::Data::DrawPrimitives::Circle( c, n, r, 20, color ) ) )
99 
100 # define RA_DISPLAY_TRIANGLE( a, b, c, color ) \
101  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
102  Ra::Engine::Data::DrawPrimitives::Primitive( \
103  Ra::Engine::SystemEntity::dbgCmp(), \
104  Ra::Engine::Data::DrawPrimitives::Triangle( a, b, c, color ) ) )
105 
106 # define RA_DISPLAY_NORMAL( p, n, color, scale ) \
107  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
108  Ra::Engine::Scene::DrawPrimitives::Primitive( \
109  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
110  Ra::Engine::Scene::DrawPrimitives::Normal( p, n, color, scale ) ) )
111 
112 # define RA_DISPLAY_FRAME( t, scale ) \
113  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
114  Ra::Engine::Data::DrawPrimitives::Primitive( \
115  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
116  Ra::Engine::Data::DrawPrimitives::Frame( t, scale ) ) )
117 
118 # define RA_DISPLAY_AABB( a, color ) \
119  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
120  Ra::Engine::Data::DrawPrimitives::Primitive( \
121  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
122  Ra::Engine::Data::DrawPrimitives::AABB( a, color ) ) )
123 
124 # define RA_DISPLAY_OBB( a, color ) \
125  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
126  Ra::Engine::Data::DrawPrimitives::Primitive( \
127  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
128  Ra::Engine::Data::DrawPrimitives::OBB( a, color ) ) )
129 
130 # define RA_DISPLAY_SPHERE( c, r, color ) \
131  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
132  Ra::Engine::Data::DrawPrimitives::Primitive( \
133  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
134  Ra::Engine::Data::DrawPrimitives::Sphere( c, r, color ) ) )
135 
136 # define RA_DISPLAY_CAPSULE( p1, p2, r, color ) \
137  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
138  Ra::Engine::Data::DrawPrimitives::Primitive( \
139  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
140  Ra::Engine::Data::DrawPrimitives::Capsule( p1, p2, r, color ) ) )
141 
142 # define RA_DISPLAY_LINE( a, b, color ) \
143  Ra::Engine::Scene::SystemEntity::dbgCmp()->addRenderObject( \
144  Ra::Engine::Data::DrawPrimitives::Primitive( \
145  Ra::Engine::Scene::SystemEntity::dbgCmp(), \
146  Ra::Engine::Data::DrawPrimitives::Line( a, b, color ) ) )
147 
148 # define RA_CLEAR_DEBUG_DISPLAY() \
149  { \
150  auto cmp = Ra::Engine::Scene::SystemEntity::dbgCmp(); \
151  while ( cmp->m_renderObjects.size() ) { \
152  cmp->removeRenderObject( cmp->m_renderObjects[0] ); \
153  } \
154  }
155 
156 #else // if debug display is disabled
157 
158 # define RA_DISPLAY_POINT( p, color, scale ) // Nothing
159 # define RA_DISPLAY_VECTOR( p, v, color ) // ...
160 # define RA_DISPLAY_RAY( r, color ) // ...
161 # define RA_DISPLAY_CIRCLE( c, n, r, color ) // ...
162 # define RA_DISPLAY_TRIANGLE( a, b, c, color ) // ...
163 # define RA_DISPLAY_NORMAL( p, n, color, scale ) // ...
164 # define RA_DISPLAY_FRAME( t, scale ) // ...
165 # define RA_DISPLAY_AABB( a, color ) // ...
166 # define RA_DISPLAY_OBB( a, color ) // ...
167 # define RA_DISPLAY_SPHERE( c, r, color ) // ...
168 # define RA_DISPLAY_CAPSULE( p1, p2, r, color ) // ...
169 # define RA_DISPLAY_LINE( a, b, color ) // ...
170 # define RA_CLEAR_DEBUG_DISPLAY() // ...
171 
172 #endif
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
Component for debug drawing.
void initialize() override
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
An entity is an scene element. It ties together components with a transform.
Definition: Entity.hpp:23
Component for UI drawing.
void initialize() override
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
Definition: Cage.cpp:3