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