• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include <3d/ecs/components/environment_component.h>
17 
18 #include "ComponentTools/base_manager.h"
19 #include "ComponentTools/base_manager.inl"
20 
21 #define IMPLEMENT_MANAGER
22 #include <core/property_tools/property_macros.h>
23 
24 CORE_BEGIN_NAMESPACE()
25 using CORE3D_NS::EnvironmentComponent;
26 /** Extend propertysystem with the enums */
27 DECLARE_PROPERTY_TYPE(EnvironmentComponent::Background);
28 
29 // Declare their metadata
30 ENUM_TYPE_METADATA(EnvironmentComponent::Background, ENUM_VALUE(NONE, "None"), ENUM_VALUE(IMAGE, "Image"),
31     ENUM_VALUE(CUBEMAP, "Cubemap"), ENUM_VALUE(EQUIRECTANGULAR, "Equirectangular"))
32 CORE_END_NAMESPACE()
33 
34 CORE3D_BEGIN_NAMESPACE()
35 using BASE_NS::array_view;
36 using BASE_NS::countof;
37 
38 using CORE_NS::BaseManager;
39 using CORE_NS::IComponentManager;
40 using CORE_NS::IEcs;
41 using CORE_NS::Property;
42 
43 class EnvironmentComponentManager final : public BaseManager<EnvironmentComponent, IEnvironmentComponentManager> {
44     BEGIN_PROPERTY(EnvironmentComponent, componentMetaData_)
45 #include <3d/ecs/components/environment_component.h>
46     END_PROPERTY();
47 
48 public:
EnvironmentComponentManager(IEcs & ecs)49     explicit EnvironmentComponentManager(IEcs& ecs)
50         : BaseManager<EnvironmentComponent, IEnvironmentComponentManager>(
51               ecs, CORE_NS::GetName<EnvironmentComponent>(), 2U)
52     {}
53 
54     ~EnvironmentComponentManager() = default;
55 
PropertyCount() const56     size_t PropertyCount() const override
57     {
58         return BASE_NS::countof(componentMetaData_);
59     }
60 
MetaData(size_t index) const61     const Property* MetaData(size_t index) const override
62     {
63         if (index < BASE_NS::countof(componentMetaData_)) {
64             return &componentMetaData_[index];
65         }
66         return nullptr;
67     }
68 
MetaData() const69     array_view<const Property> MetaData() const override
70     {
71         return componentMetaData_;
72     }
73 };
74 
IEnvironmentComponentManagerInstance(IEcs & ecs)75 IComponentManager* IEnvironmentComponentManagerInstance(IEcs& ecs)
76 {
77     return new EnvironmentComponentManager(ecs);
78 }
79 
IEnvironmentComponentManagerDestroy(IComponentManager * instance)80 void IEnvironmentComponentManagerDestroy(IComponentManager* instance)
81 {
82     delete static_cast<EnvironmentComponentManager*>(instance);
83 }
84 
85 CORE3D_END_NAMESPACE()
86