Cogs.Core
Types.cpp
1#include "Types.h"
2
3#include "Components/Core/AnimationComponent.h"
4#include "Components/Core/AssetComponent.h"
5#include "Components/Core/BillboardComponent.h"
6#include "Components/Core/CameraComponent.h"
7#include "Components/Core/CameraArrayComponent.h"
8#include "Components/Core/ClipShapeComponent.h"
9#include "Components/Core/EnvironmentComponent.h"
10#include "Components/Core/FogComponent.h"
11#include "Components/Core/InstancedMeshRenderComponent.h"
12#include "Components/Core/InstancedModelComponent.h"
13#include "Components/Core/LightComponent.h"
14#include "Components/Core/LodComponent.h"
15#include "Components/Core/MeshComponent.h"
16#include "Components/Core/MeshRenderComponent.h"
17#include "Components/Core/ModelComponent.h"
18#include "Components/Core/MotionComponent.h"
19#include "Components/Core/NearLimitComponent.h"
20#include "Components/Core/OverlayComponent.h"
21#include "Components/Core/PropertiesComponent.h"
22#include "Components/Core/RenderComponent.h"
23#include "Components/Core/SceneComponent.h"
24#include "Components/Core/ScriptComponent.h"
25#include "Components/Core/SpriteRenderComponent.h"
26#include "Components/Core/StaticModelComponent.h"
27#include "Components/Core/SubMeshRenderComponent.h"
28#include "Components/Core/SwitchComponent.h"
29#include "Components/Core/TextComponent.h"
30#include "Components/Core/Text3DComponent.h"
31#include "Components/Core/TransformComponent.h"
32
33#include "Components/Data/DataSetComponent.h"
34#include "Components/Data/TrajectoryComponent.h"
35
36#include "Components/Geometry/ExtrusionComponent.h"
37#include "Components/Geometry/ShapeComponent.h"
38#include "Components/Geometry/VariableExtrusionComponent.h"
39#include "Components/Geometry/MeshGeneratorComponent.h"
40#include "Components/Geometry/AdaptivePlanarGridComponent.h"
41#include "Components/Geometry/MarkerPointSetComponent.h"
42
43#include "Components/Appearance/MaterialComponent.h"
44#include "Components/Appearance/ScreenSizeComponent.h"
45#include "Components/Appearance/TextureGeneratorComponent.h"
46#include "Components/Appearance/FontSelectorComponent.h"
47#include "Components/Appearance/BasicOceanComponent.h"
48#include "Components/Appearance/BasicTerrainComponent.h"
49
50#include "Components/Layout/TrajectoryLayoutComponent.h"
51
52#include "Components/Behavior/TrajectoryAlignedComponent.h"
53#include "Components/Behavior/ReflectionComponent.h"
54#include "Components/Behavior/CurvedEarthPositionComponent.h"
55#include "Components/Behavior/ExpressionComponent.h"
56#include "Components/Behavior/FPSNavigationComponent.h"
57#include "Components/Behavior/OrbitingCameraController.h"
58#include "Components/Behavior/TeleportNavigationComponent.h"
59#include "Components/Behavior/PickingBeamComponent.h"
60
61#include "../Extensions/Components/FollowComponent.h"
62
63#include "Generators/MeshGenerator.h"
64#include "Generators/TextureGenerator.h"
65#include "Services/PipelineService.h"
66
67#include "Resources/ResourceFlags.h"
68
69#include "Input/InputDeviceType.h"
70
71#include "Renderer/IRenderer.h"
72
73#include "Foundation/Platform/Keyboard.h"
74#include "Foundation/Platform/Gestures.h"
75
76using namespace Cogs::Reflection;
77
78template<> Cogs::StringView getName<Cogs::Core::EntityFind>() { return "EntityFind"; }
79template<> Cogs::StringView getName<Cogs::Core::RenderMode>() { return "RenderMode"; }
80template<> Cogs::StringView getName<Cogs::Core::InputDeviceType>() { return "InputDeviceType"; }
81
82void Cogs::Core::initializeTypes()
83{
85
88
89 Field vec2Fields[] = {
90 Field(Name("x"), &glm::vec2::x),
91 Field(Name("y"), &glm::vec2::y),
92 Field(Name("r"), &glm::vec2::r),
93 Field(Name("g"), &glm::vec2::g),
94 Field(Name("s"), &glm::vec2::s),
95 Field(Name("t"), &glm::vec2::t),
96 };
97
98 TypeDatabase::createType<glm::vec2>().setFields(vec2Fields);
99
100 Field vec3Fields[] = {
101 Field(Name("x"), &glm::vec3::x),
102 Field(Name("y"), &glm::vec3::y),
103 Field(Name("z"), &glm::vec3::z),
104 Field(Name("r"), &glm::vec3::r),
105 Field(Name("g"), &glm::vec3::g),
106 Field(Name("b"), &glm::vec3::b),
107 };
108
109 TypeDatabase::createType<glm::vec3>().setFields(vec3Fields);
110
111 Field vec4Fields[] = {
112 Field(Name("x"), &glm::vec4::x),
113 Field(Name("y"), &glm::vec4::y),
114 Field(Name("z"), &glm::vec4::z),
115 Field(Name("w"), &glm::vec4::w),
116 Field(Name("r"), &glm::vec4::r),
117 Field(Name("g"), &glm::vec4::g),
118 Field(Name("b"), &glm::vec4::b),
119 Field(Name("a"), &glm::vec4::a),
120 };
121
122 TypeDatabase::createType<glm::vec4>().setFields(vec4Fields);
123
124 TypeDatabase::createType<glm::quat>().setFields(vec4Fields);;
125 TypeDatabase::createType<glm::mat4>();
126
127 TypeDatabase::createType<glm::dvec2>();
128 TypeDatabase::createType<glm::dvec3>();
129 TypeDatabase::createType<glm::dvec4>();
130 TypeDatabase::createType<glm::dquat>();
131 TypeDatabase::createType<glm::dmat4>();
132
133 Field ivec2Fields[] = {
134 Field(Name("x"), &glm::ivec2::x),
135 Field(Name("y"), &glm::ivec2::y),
136 Field(Name("r"), &glm::ivec2::r),
137 Field(Name("g"), &glm::ivec2::g),
138 };
139 TypeDatabase::createType<glm::ivec2>().setFields(ivec2Fields);
140 Field ivec3Fields[] = {
141 Field(Name("x"), &glm::ivec3::x),
142 Field(Name("y"), &glm::ivec3::y),
143 Field(Name("z"), &glm::ivec3::z),
144 Field(Name("r"), &glm::ivec3::r),
145 Field(Name("g"), &glm::ivec3::g),
146 Field(Name("b"), &glm::ivec3::b),
147 };
148 TypeDatabase::createType<glm::ivec3>().setFields(ivec3Fields);
149 Field ivec4Fields[] = {
150 Field(Name("x"), &glm::ivec4::x),
151 Field(Name("y"), &glm::ivec4::y),
152 Field(Name("z"), &glm::ivec4::z),
153 Field(Name("w"), &glm::ivec4::w),
154 Field(Name("r"), &glm::ivec4::r),
155 Field(Name("g"), &glm::ivec4::g),
156 Field(Name("b"), &glm::ivec4::b),
157 Field(Name("a"), &glm::ivec4::a),
158 };
159 TypeDatabase::createType<glm::ivec4>().setFields(ivec4Fields);
160 Field uvec2Fields[] = {
161 Field(Name("x"), &glm::uvec2::x),
162 Field(Name("y"), &glm::uvec2::y),
163 Field(Name("r"), &glm::uvec2::r),
164 Field(Name("g"), &glm::uvec2::g),
165 };
166 TypeDatabase::createType<glm::uvec2>().setFields(uvec2Fields);
167 Field uvec3Fields[] = {
168 Field(Name("x"), &glm::uvec3::x),
169 Field(Name("y"), &glm::uvec3::y),
170 Field(Name("z"), &glm::uvec3::z),
171 Field(Name("r"), &glm::uvec3::r),
172 Field(Name("g"), &glm::uvec3::g),
173 Field(Name("b"), &glm::uvec3::b),
174 };
175 TypeDatabase::createType<glm::uvec3>().setFields(uvec3Fields);
176 Field uvec4Fields[] = {
177 Field(Name("x"), &glm::uvec4::x),
178 Field(Name("y"), &glm::uvec4::y),
179 Field(Name("z"), &glm::uvec4::z),
180 Field(Name("w"), &glm::uvec4::w),
181 Field(Name("r"), &glm::uvec4::r),
182 Field(Name("g"), &glm::uvec4::g),
183 Field(Name("b"), &glm::uvec4::b),
184 Field(Name("a"), &glm::uvec4::a),
185 };
186 TypeDatabase::createType<glm::uvec4>().setFields(uvec4Fields);
187
188 TypeDatabase::createType<std::vector<glm::vec2>>();
189 TypeDatabase::createType<std::vector<glm::vec3>>();
190 TypeDatabase::createType<std::vector<glm::vec4>>();
191 TypeDatabase::createType<std::vector<glm::mat4>>();
192 TypeDatabase::createType<std::vector<glm::quat>>();
193
194 TypeDatabase::createType<std::vector<glm::dvec2>>();
195 TypeDatabase::createType<std::vector<glm::dvec3>>();
196 TypeDatabase::createType<std::vector<glm::dvec4>>();
197 TypeDatabase::createType<std::vector<glm::dmat4>>();
198 TypeDatabase::createType<std::vector<glm::dquat>>();
199
200 TypeDatabase::createType<EntityPtr>();
201 TypeDatabase::createType<WeakEntityPtr>();
202 TypeDatabase::createType<std::vector<EntityPtr>>();
203 TypeDatabase::createType<std::vector<WeakEntityPtr>>();
204
205 TypeDatabase::createType<ResourceBufferHandle>();
206 TypeDatabase::createType<MeshHandle>();
207 TypeDatabase::createType<ModelHandle>();
208 TypeDatabase::createType<MaterialHandle>();
209 TypeDatabase::createType<MaterialInstanceHandle>();
210 TypeDatabase::createType<FontHandle>();
211 TypeDatabase::createType<TextureHandle>();
212 TypeDatabase::createType<AnimationHandle>();
213 TypeDatabase::createType<GuiDocumentHandle>();
214 TypeDatabase::createType<AssetHandle>();
215
216 TypeDatabase::createType<std::vector<TextureHandle>>();
217 TypeDatabase::createType<std::vector<MaterialHandle>>();
218 TypeDatabase::createType<std::vector<MaterialInstanceHandle>>();
219
220 TypeDatabase::createType<BufferView<uint32_t>>();
221 TypeDatabase::createType<BufferView<float>>();
222 TypeDatabase::createType<BufferView<glm::vec3>>();
223 TypeDatabase::createType<BufferView<glm::vec4>>();
224
225 static constexpr EnumeratorDef keys[] = {
226 { "A", Cogs::Key::A },
227 { "B", Cogs::Key::B },
228 { "C", Cogs::Key::C },
229 { "D", Cogs::Key::D },
230 { "E", Cogs::Key::E },
231 { "F", Cogs::Key::F },
232 { "G", Cogs::Key::G },
233 { "H", Cogs::Key::H },
234 { "I", Cogs::Key::I },
235 { "J", Cogs::Key::J },
236 { "K", Cogs::Key::K },
237 { "L", Cogs::Key::L },
238 { "M", Cogs::Key::M },
239 { "N", Cogs::Key::N },
240 { "O", Cogs::Key::O },
241 { "P", Cogs::Key::P },
242 { "Q", Cogs::Key::Q },
243 { "R", Cogs::Key::R },
244 { "S", Cogs::Key::S },
245 { "T", Cogs::Key::T },
246 { "U", Cogs::Key::U },
247 { "V", Cogs::Key::V },
248 { "W", Cogs::Key::W },
249 { "X", Cogs::Key::X },
250 { "Y", Cogs::Key::Y },
251 { "Z", Cogs::Key::Z },
252 { "Zero", Cogs::Key::Zero },
253 { "One", Cogs::Key::One },
254 { "Two", Cogs::Key::Two },
255 { "Three", Cogs::Key::Three },
256 { "Four", Cogs::Key::Four },
257 { "Five", Cogs::Key::Five },
258 { "Six", Cogs::Key::Six },
259 { "Seven", Cogs::Key::Seven },
260 { "Eight", Cogs::Key::Eight },
261 { "Nine", Cogs::Key::Nine },
262 { "Left", Cogs::Key::Left },
263 { "Right", Cogs::Key::Right },
264 { "Up", Cogs::Key::Up },
265 { "Down", Cogs::Key::Down },
266 { "Shift", Cogs::Key::Shift },
267 { "LeftShift", Cogs::Key::LeftShift },
268 { "RightShift", Cogs::Key::RightShift },
269 { "Control", Cogs::Key::Control },
270 { "LeftControl", Cogs::Key::LeftControl },
271 { "RightControl", Cogs::Key::RightControl },
272 { "Alt", Cogs::Key::Alt },
273 { "LeftAlt", Cogs::Key::LeftAlt },
274 { "RightAlt", Cogs::Key::RightAlt },
275 { "CapsLock", Cogs::Key::CapsLock },
276 { "Tab", Cogs::Key::Tab },
277 { "Escape", Cogs::Key::Escape },
278 { "Enter", Cogs::Key::Enter },
279 { "Space", Cogs::Key::Space },
280 { "Insert", Cogs::Key::Insert },
281 { "Delete", Cogs::Key::Delete },
282 { "Backspace", Cogs::Key::Backspace },
283 { "Home", Cogs::Key::Home },
284 { "End", Cogs::Key::End },
285 { "PageUp", Cogs::Key::PageUp },
286 { "PageDown", Cogs::Key::PageDown },
287 { "F1", Cogs::Key::F1 },
288 { "F2", Cogs::Key::F2 },
289 { "F3", Cogs::Key::F3 },
290 { "F4", Cogs::Key::F4 },
291 { "F5", Cogs::Key::F5 },
292 { "F6", Cogs::Key::F6 },
293 { "F7", Cogs::Key::F7 },
294 { "F8", Cogs::Key::F8 },
295 { "F9", Cogs::Key::F9 },
296 { "F10", Cogs::Key::F10 },
297 { "F11", Cogs::Key::F11 },
298 { "F12", Cogs::Key::F12 },
299 { "None", Cogs::Key::None },
300 };
301 static_assert(std::size(keys) == static_cast<size_t>(Cogs::Key::Count) + 1); // Add 1 for Key::None
302 TypeDatabase::createType<Cogs::Key>().setEnumerators(keys);
303
304 static constexpr EnumeratorDef pointerTypes[] = {
305 { "Touch", Cogs::PointerType::Touch },
306 { "Mouse", Cogs::PointerType::Mouse },
307 };
308 static_assert(std::size(pointerTypes) == static_cast<size_t>(Cogs::PointerType::Count));
309 TypeDatabase::createType<Cogs::PointerType>().setEnumerators(pointerTypes);
310
311 static constexpr EnumeratorDef mouseButtons[] = {
312 { "Left", Cogs::MouseButton::Left },
313 { "Right", Cogs::MouseButton::Right },
314 { "Middle", Cogs::MouseButton::Middle },
315 };
316 static_assert(std::size(mouseButtons) == static_cast<size_t>(Cogs::MouseButton::Count));
317 TypeDatabase::createType<Cogs::MouseButton>().setEnumerators(mouseButtons);
318
319 static constexpr EnumeratorDef inputDeviceTypes[] = {
320 { "None", InputDeviceType::None },
321 { "Keyboard", InputDeviceType::Keyboard },
322 { "Mouse", InputDeviceType::Mouse },
323 };
324 TypeDatabase::createType<Cogs::Core::InputDeviceType>().setEnumerators(inputDeviceTypes).setEnumFlags();
325
326 static constexpr EnumeratorDef addressModes[] = {
327 { "Clamp", Cogs::SamplerState::Clamp },
328 { "Wrap", Cogs::SamplerState::Wrap },
329 { "Mirror", SamplerState::AddressMode::Mirror },
330 { "Border", SamplerState::AddressMode::Border },
331 };
332 static_assert(std::size(addressModes) == static_cast<size_t>(Cogs::SamplerState::AddressMode::AddressMode_Size));
333 TypeDatabase::createType<Cogs::SamplerState::AddressMode>().setEnumerators(addressModes);
334
335 static constexpr EnumeratorDef filterModes[] = {
336 { "MinMagMipPoint", SamplerState::FilterMode::MinMagMipPoint },
337 { "MinMagMipLinear", SamplerState::FilterMode::MinMagMipLinear },
338 { "ComparisonMinMagMipPoint", SamplerState::FilterMode::ComparisonMinMagMipPoint },
339 { "ComparisonMinMagMipLinear", SamplerState::FilterMode::ComparisonMinMagMipLinear },
340 };
341 static_assert(std::size(filterModes) == static_cast<size_t>(Cogs::SamplerState::FilterMode::FilterMode_Size));
342 TypeDatabase::createType<Cogs::SamplerState::FilterMode>().setEnumerators(filterModes);
343
344 static constexpr EnumeratorDef fileContentHints[] = {
345 {"None", Cogs::FileContentsHints::None },
346 {"ZStdDecompress", Cogs::FileContentsHints::ZStdDecompress },
347 {"BrotliDecompress", Cogs::FileContentsHints::BrotliDecompress }
348 };
349 TypeDatabase::createType<Cogs::FileContentsHints>().setEnumerators(fileContentHints);
350
351 registerResourceFlagTypes();
352
353 MeshComponent::registerType();
354 TransformComponent::registerType();
355 SceneComponent::registerType();
356 RenderComponent::registerType();
357 MeshRenderComponent::registerType();
358 SubMeshRenderComponent::registerType();
359 InstancedMeshRenderComponent::registerType();
360 SpriteRenderComponent::registerType();
361 TextComponent::registerType();
362 Text3DComponent::registerType();
363 BillboardComponent::registerType();
364 OverlayComponent::registerType();
365 LightComponent::registerType();
366 CameraComponent::registerType();
367 CameraArrayComponent::registerType();
368 ClipShapeComponent::registerType();
369 ClipShapeRefComponent::registerType();
370 FogComponent::registerType();
371 LodComponent::registerType();
372 ScriptComponent::registerType();
373 EnvironmentComponent::registerType();
374 AnimationComponent::registerType();
375 AssetComponent::registerType();
376 PropertiesComponent::registerType();
377
378 MeshGeneratorComponent::registerType();
379 ScreenSizeComponent::registerType();
380 TextureGeneratorComponent::registerType();
381 TrajectoryComponent::registerType();
382 ExtrusionComponent::registerType();
383 MaterialComponent::registerType();
384 ShapeComponent::registerType();
385 ModelComponent::registerType();
386 InstancedModelComponent::registerType();
387 StaticModelComponent::registerType();
388 TrajectoryLayoutComponent::registerType();
389 DataSetComponent::registerType();
390 VariableExtrusionComponent::registerType();
391 AdaptivePlanarGridComponent::registerType();
392
393
394 DynamicComponent::registerType();
395 MotionComponent::registerType();
396 SwitchComponent::registerType();
397 FollowComponent::registerType();
398 MarkerPointSetComponent::registerType();
399 BasicTerrainComponent::registerType();
400
401 TrajectoryAlignedComponent::registerType();
402 FPSNavigationComponent::registerType();
403 OrbitingCameraController::registerType();
404 TeleportNavigationComponent::registerType();
405 PickingBeamComponent::registerType();
406 CurvedEarthPositionComponent::registerType();
407 ReflectionComponent::registerType();
408 NearLimitComponent::registerType();
409 ExpressionComponent::registerType();
410
411 FontSelectorComponent::registerType();
412 BasicOceanComponent::registerType();
413
414 Reflection::TypeDatabase::createType<MeshGenerator>();
415 Reflection::TypeDatabase::createType<TextureGenerator>();
416 Reflection::TypeDatabase::createType<PipelineService>();
417
418 static constexpr EnumeratorDef enums[] = {
419 { "Default", GraphicsDeviceType::Default },
420 { "Default", GraphicsDeviceType::Unknown },
421 { "Direct3D11", GraphicsDeviceType::Direct3D11 },
422 { "Direct3D12", GraphicsDeviceType::Direct3D12 },
423 { "Vulkan", GraphicsDeviceType::Vulkan },
424 { "OpenGL20", GraphicsDeviceType::OpenGL20 },
425 { "OpenGLES30", GraphicsDeviceType::OpenGLES30 },
426 { "WebGPU", GraphicsDeviceType::WebGPU },
427 { "Null", GraphicsDeviceType::Null },
428 };
429
430 Reflection::TypeDatabase::createType<GraphicsDeviceType>().setEnumerators(enums);
431
432 static constexpr EnumeratorDef entityFindEnums[] = {
433 { "Default", EntityFind::Default },
434 { "PartialNameMatch", EntityFind::PartialNameMatch },
435 { "NonRecursive", EntityFind::NonRecursive },
436 };
437 Reflection::TypeDatabase::createType<EntityFind>().setEnumerators(entityFindEnums).
438 setEnumFlags();
439
440 static constexpr EnumeratorDef renderModeEnums[] = {
441 { "Normal", RenderMode::Normal },
442 { "Wireframe", RenderMode::Wireframe },
443 { "Box", RenderMode::Box },
444 };
445 Reflection::TypeDatabase::createType<RenderMode>().setEnumerators(renderModeEnums);
446
447 static constexpr EnumeratorDef depthFuncEnums[] = {
448 { "Less", DepthFunc::Less },
449 { "LessOrEqual", DepthFunc::LessOrEqual },
450 { "Always", DepthFunc::Always },
451 { "NotEqual", DepthFunc::NotEqual },
452 { "Equal", DepthFunc::Equal },
453 };
454 Reflection::TypeDatabase::createType<DepthFunc>().setEnumerators(depthFuncEnums);
455
456}
457
458void Cogs::Core::cleanupTypes() {
459 Reflection::TypeDatabase::clear();
460}
static COGSFOUNDATION_API void registerType()
Register the Component type in the global type database.
Definition: Component.cpp:17
static void registerType()
Register the Entity type in the global type database.
Definition: Entity.cpp:9
Field definition describing a single data member of a data structure.
Definition: Field.h:70
static void initializeBaseTypes()
Initialize the set of types describing built in C++ types like int, float etc.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains reflection support.
Definition: Component.h:11
@ BrotliDecompress
A hint that the contents are Brotli (Google) compressed and is allowed to be decompressed during tran...
@ ZStdDecompress
A hint that the contents are Zstandard (Facebook) compressed and is allowed to be decompressed during...
Represents an unique name.
Definition: Name.h:70
@ Clamp
Texture coordinates are clamped to the [0, 1] range.
Definition: SamplerState.h:17
@ Wrap
Texture coordinates automatically wrap around to [0, 1] range.
Definition: SamplerState.h:19