• 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 #ifndef SCENE_SRC_CORE_ECS_OBJECT_H
16 #define SCENE_SRC_CORE_ECS_OBJECT_H
17 
18 #include <scene/base/types.h>
19 #include <scene/ext/intf_ecs_event_listener.h>
20 #include <scene/ext/intf_ecs_object.h>
21 #include <scene/ext/intf_engine_property_init.h>
22 #include <scene/ext/intf_internal_scene.h>
23 #include <scene/ext/scene_property.h>
24 #include <shared_mutex>
25 
26 #include <core/ecs/intf_ecs.h>
27 
28 #include <meta/ext/object.h>
29 #include <meta/interface/engine/intf_engine_value_manager.h>
30 #include <meta/interface/intf_named.h>
31 
32 SCENE_BEGIN_NAMESPACE()
33 
34 META_REGISTER_CLASS(EcsObject, "6f1d5812-ce80-4f1d-9a74-6815f3e111b0", META_NS::ObjectCategoryBits::NO_CATEGORY)
35 
36 class EcsObject : public META_NS::IntroduceInterfaces<META_NS::MetaObject, IEcsObject, IEcsEventListener,
37                       IEnginePropertyInit, META_NS::INamed> {
38     META_OBJECT(EcsObject, SCENE_NS::ClassId::EcsObject, IntroduceInterfaces)
39 
40     META_BEGIN_STATIC_DATA()
41     SCENE_STATIC_DYNINIT_PROPERTY_DATA(META_NS::INamed, BASE_NS::string, Name, "NameComponent.name")
42     META_END_STATIC_DATA()
43 
44     META_IMPLEMENT_PROPERTY(BASE_NS::string, Name)
45 
46 public:
47     BASE_NS::string GetName() const override;
48     IInternalScene::Ptr GetScene() const override;
49     CORE_NS::Entity GetEntity() const override;
50     META_NS::IEngineValueManager::Ptr GetEngineValueManager() override;
51 
52     Future<bool> AddAllProperties(const META_NS::IMetadata::Ptr& object, BASE_NS::string_view component) override;
53     Future<bool> AttachProperty(const META_NS::IProperty::Ptr&, BASE_NS::string_view path) override;
54     Future<META_NS::IProperty::Ptr> CreateProperty(BASE_NS::string_view path) override;
55 
56     Future<META_NS::IProperty::Ptr> CreateProperty(const META_NS::IEngineValue::Ptr&) override;
57     virtual Future<bool> AttachProperty(const META_NS::IProperty::Ptr&, const META_NS::IEngineValue::Ptr&) override;
58 
59 public: // call in engine thread
60     bool Build(const META_NS::IMetadata::Ptr& d) override;
61     void SyncProperties() override;
62     BASE_NS::string GetPath() const override;
63     bool SetName(const BASE_NS::string& name) override;
64 
65 protected:
66     void AddPropertyUpdateHook(const META_NS::IProperty::Ptr& p);
67 
68     void OnEntityEvent(CORE_NS::IEcs::EntityListener::EventType type) override;
69     void OnComponentEvent(
70         CORE_NS::IEcs::ComponentListener::EventType type, const CORE_NS::IComponentManager& component) override;
71 
72     META_NS::EnginePropertyHandle GetPropertyHandle(BASE_NS::string_view component) const;
73     bool AddEngineProperty(META_NS::IMetadata& object, const META_NS::IEngineValue::Ptr& v);
74     void AddAllComponentProperties(META_NS::IMetadata& object);
75     void AddAllProperties(META_NS::IMetadata& object, CORE_NS::IComponentManager*);
76     bool AddAllNamedComponentProperties(META_NS::IMetadata& object, BASE_NS::string_view cv);
77 
78     bool AttachEnginePropertyImpl(
79         META_NS::EnginePropertyHandle, const BASE_NS::string&, const META_NS::IProperty::Ptr&, BASE_NS::string_view);
80 
81     bool AttachEngineProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
82     bool InitDynamicProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
83 
84     Future<bool> SetActive(bool active) override;
85 
86 private:
87     IInternalScene::WeakPtr scene_;
88     CORE_NS::Entity entity_;
89     META_NS::IEngineValueManager::Ptr valueManager_;
90 };
91 
92 SCENE_END_NAMESPACE()
93 
94 #endif
95