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 "PropertyTools/property_macros.h"
23 
24 CORE_BEGIN_NAMESPACE()
25 /** Extend propertysystem with the enums */
26 DECLARE_PROPERTY_TYPE(CORE3D_NS::EnvironmentComponent::Background);
27 
28 // Declare their metadata
29 BEGIN_ENUM(EnvironmentComponentBackgroundTypeMetaData, CORE3D_NS::EnvironmentComponent::Background)
30 DECL_ENUM(CORE3D_NS::EnvironmentComponent::Background, NONE, "None")
31 DECL_ENUM(CORE3D_NS::EnvironmentComponent::Background, IMAGE, "Image")
32 DECL_ENUM(CORE3D_NS::EnvironmentComponent::Background, CUBEMAP, "Cubemap")
33 DECL_ENUM(CORE3D_NS::EnvironmentComponent::Background, EQUIRECTANGULAR, "Equirectangular")
34 END_ENUM(EnvironmentComponentBackgroundTypeMetaData, CORE3D_NS::EnvironmentComponent::Background)
35 CORE_END_NAMESPACE()
36 
37 CORE3D_BEGIN_NAMESPACE()
38 using BASE_NS::array_view;
39 using BASE_NS::countof;
40 
41 using CORE_NS::BaseManager;
42 using CORE_NS::IComponentManager;
43 using CORE_NS::IEcs;
44 using CORE_NS::Property;
45 
46 class EnvironmentComponentManager final : public BaseManager<EnvironmentComponent, IEnvironmentComponentManager> {
47     BEGIN_PROPERTY(EnvironmentComponent, ComponentMetadata)
48 #include <3d/ecs/components/environment_component.h>
49     END_PROPERTY();
50     const array_view<const Property> componentMetaData_ { ComponentMetadata, countof(ComponentMetadata) };
51 
52 public:
EnvironmentComponentManager(IEcs & ecs)53     explicit EnvironmentComponentManager(IEcs& ecs)
54         : BaseManager<EnvironmentComponent, IEnvironmentComponentManager>(ecs, CORE_NS::GetName<EnvironmentComponent>())
55     {}
56 
57     ~EnvironmentComponentManager() = default;
58 
PropertyCount() const59     size_t PropertyCount() const override
60     {
61         return componentMetaData_.size();
62     }
63 
MetaData(size_t index) const64     const Property* MetaData(size_t index) const override
65     {
66         if (index < componentMetaData_.size()) {
67             return &componentMetaData_[index];
68         }
69         return nullptr;
70     }
71 
MetaData() const72     array_view<const Property> MetaData() const override
73     {
74         return componentMetaData_;
75     }
76 };
77 
IEnvironmentComponentManagerInstance(IEcs & ecs)78 IComponentManager* IEnvironmentComponentManagerInstance(IEcs& ecs)
79 {
80     return new EnvironmentComponentManager(ecs);
81 }
82 
IEnvironmentComponentManagerDestroy(IComponentManager * instance)83 void IEnvironmentComponentManagerDestroy(IComponentManager* instance)
84 {
85     delete static_cast<EnvironmentComponentManager*>(instance);
86 }
87 
88 CORE3D_END_NAMESPACE()
89