1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <PropertyTools/core_metadata.inl>
16
17 #include <core/property/scoped_handle.h>
18
19 #include <meta/ext/engine/internal_access.h>
20 #include <meta/interface/engine/intf_engine_data.h>
21 #include <meta/interface/engine/intf_engine_value.h>
22 #include <meta/interface/intf_object_registry.h>
23
24 META_BEGIN_NAMESPACE()
25
26 // clang-format off
27 using SingleAndArrayTypes = TypeList<
28 bool,
29 int8_t,
30 int16_t,
31 int32_t,
32 int64_t,
33 uint8_t,
34 uint16_t,
35 uint32_t,
36 uint64_t,
37 float,
38 double,
39 #ifdef __APPLE__
40 size_t,
41 #endif
42 BASE_NS::Math::Vec2,
43 BASE_NS::Math::Vec3,
44 BASE_NS::Math::Vec4,
45 BASE_NS::Math::UVec2,
46 BASE_NS::Math::UVec3,
47 BASE_NS::Math::UVec4,
48 BASE_NS::Math::IVec2,
49 BASE_NS::Math::IVec3,
50 BASE_NS::Math::IVec4,
51 BASE_NS::Math::Quat,
52 BASE_NS::Math::Mat3X3,
53 BASE_NS::Math::Mat4X4,
54 BASE_NS::Uid,
55 CORE_NS::Entity,
56 CORE_NS::EntityReference,
57 BASE_NS::string,
58 CORE_NS::IPropertyHandle*
59 >;
60 using VectorTypes = TypeList<
61 BASE_NS::vector<float>,
62 BASE_NS::vector<BASE_NS::Math::Mat4X4>,
63 BASE_NS::vector<CORE_NS::EntityReference>
64 >;
65 // clang-format on
66
67 namespace Internal {
68 namespace {
69
70 template<bool ArrayTypes, typename... List>
RegisterBasicEngineTypes(IEngineData & d,TypeList<List...>)71 void RegisterBasicEngineTypes(IEngineData& d, TypeList<List...>)
72 {
73 (d.RegisterInternalValueAccess(MetaType<List>::coreType, CreateShared<EngineInternalValueAccess<List>>()), ...);
74 if constexpr (ArrayTypes) {
75 (d.RegisterInternalValueAccess(
76 MetaType<List[]>::coreType, CreateShared<EngineInternalArrayValueAccess<List>>()),
77 ...);
78 }
79 }
80
81 template<bool ArrayTypes, typename... List>
UnRegisterBasicEngineTypes(IEngineData & d,TypeList<List...>)82 void UnRegisterBasicEngineTypes(IEngineData& d, TypeList<List...>)
83 {
84 (d.UnregisterInternalValueAccess(MetaType<List>::coreType), ...);
85 if constexpr (ArrayTypes) {
86 (d.UnregisterInternalValueAccess(MetaType<List[]>::coreType), ...);
87 }
88 }
89 } // namespace
90
RegisterEngineTypes(IObjectRegistry & registry)91 void RegisterEngineTypes(IObjectRegistry& registry)
92 {
93 auto& pr = registry.GetEngineData();
94 RegisterBasicEngineTypes<true>(pr, SingleAndArrayTypes {});
95 RegisterBasicEngineTypes<false>(pr, VectorTypes {});
96 }
97
UnRegisterEngineTypes(IObjectRegistry & registry)98 void UnRegisterEngineTypes(IObjectRegistry& registry)
99 {
100 auto& pr = registry.GetEngineData();
101 UnRegisterBasicEngineTypes<false>(pr, VectorTypes {});
102 UnRegisterBasicEngineTypes<true>(pr, SingleAndArrayTypes {});
103 }
104
105 } // namespace Internal
106 META_END_NAMESPACE()
107