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