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/light_component.h>
17 
18 #include "ComponentTools/base_manager.h"
19 #include "ComponentTools/base_manager.inl"
20 #include "ecs/components/layer_flag_bits_metadata.h"
21 
22 #define IMPLEMENT_MANAGER
23 #include "PropertyTools/property_macros.h"
24 
25 CORE_BEGIN_NAMESPACE()
26 /** Extend propertysystem with the enums */
27 DECLARE_PROPERTY_TYPE(CORE3D_NS::LightComponent::Type);
28 
29 // Declare their metadata
30 BEGIN_ENUM(LightTypeMetaData, CORE3D_NS::LightComponent::Type)
31 DECL_ENUM(CORE3D_NS::LightComponent::Type, DIRECTIONAL, "Directional")
32 DECL_ENUM(CORE3D_NS::LightComponent::Type, POINT, "Point")
33 DECL_ENUM(CORE3D_NS::LightComponent::Type, SPOT, "Spot")
34 END_ENUM(LightTypeMetaData, CORE3D_NS::LightComponent::Type)
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 using CORE_NS::PropertyFlags;
46 
47 class LightComponentManager final : public BaseManager<LightComponent, ILightComponentManager> {
48     BEGIN_PROPERTY(LightComponent, ComponentMetadata)
49 #include <3d/ecs/components/light_component.h>
50     END_PROPERTY();
51     const array_view<const Property> componentMetaData_ { ComponentMetadata, countof(ComponentMetadata) };
52 
53 public:
LightComponentManager(IEcs & ecs)54     explicit LightComponentManager(IEcs& ecs)
55         : BaseManager<LightComponent, ILightComponentManager>(ecs, CORE_NS::GetName<LightComponent>())
56     {}
57 
58     ~LightComponentManager() = default;
59 
PropertyCount() const60     size_t PropertyCount() const override
61     {
62         return componentMetaData_.size();
63     }
64 
MetaData(size_t index) const65     const Property* MetaData(size_t index) const override
66     {
67         if (index < componentMetaData_.size()) {
68             return &componentMetaData_[index];
69         }
70         return nullptr;
71     }
72 
MetaData() const73     array_view<const Property> MetaData() const override
74     {
75         return componentMetaData_;
76     }
77 };
78 
ILightComponentManagerInstance(IEcs & ecs)79 IComponentManager* ILightComponentManagerInstance(IEcs& ecs)
80 {
81     return new LightComponentManager(ecs);
82 }
83 
ILightComponentManagerDestroy(IComponentManager * instance)84 void ILightComponentManagerDestroy(IComponentManager* instance)
85 {
86     delete static_cast<LightComponentManager*>(instance);
87 }
88 CORE3D_END_NAMESPACE()
89