• 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 #ifndef SCENE_SRC_CORE_ECS_OBJECT_H
17 #define SCENE_SRC_CORE_ECS_OBJECT_H
18 
19 #include <scene/base/types.h>
20 #include <scene/ext/intf_ecs_event_listener.h>
21 #include <scene/ext/intf_ecs_object.h>
22 #include <scene/ext/intf_internal_scene.h>
23 #include <shared_mutex>
24 
25 #include <core/ecs/intf_ecs.h>
26 
27 #include <meta/ext/object.h>
28 #include <meta/interface/engine/intf_engine_value_manager.h>
29 
30 SCENE_BEGIN_NAMESPACE()
31 
32 META_REGISTER_CLASS(EcsObject, "6f1d5812-ce80-4f1d-9a74-6815f3e111b0", META_NS::ObjectCategoryBits::NO_CATEGORY)
33 
34 class EcsObject : public META_NS::IntroduceInterfaces<META_NS::MetaObject, IEcsObject, IEcsEventListener> {
35     META_OBJECT(EcsObject, SCENE_NS::ClassId::EcsObject, IntroduceInterfaces)
36 
37 public:
38     BASE_NS::string GetName() const override;
39     IInternalScene::Ptr GetScene() const override;
40     CORE_NS::Entity GetEntity() const override;
41     META_NS::IEngineValueManager::Ptr GetEngineValueManager() override;
42 
43     Future<bool> AddAllEngineProperties(const META_NS::IMetadata::Ptr& object, BASE_NS::string_view component) override;
44     Future<bool> AttachEngineProperty(const META_NS::IProperty::Ptr&, BASE_NS::string_view path) override;
45     Future<META_NS::IProperty::Ptr> CreateEngineProperty(BASE_NS::string_view path) override;
46 
47 public: // call in engine thread
48     bool Build(const META_NS::IMetadata::Ptr& d) override;
49     void SyncProperties() override;
50     BASE_NS::string GetPath() const override;
51     bool SetName(const BASE_NS::string& name) override;
52 
53 protected:
54     void OnEntityEvent(CORE_NS::IEcs::EntityListener::EventType type) override;
55     void OnComponentEvent(
56         CORE_NS::IEcs::ComponentListener::EventType type, const CORE_NS::IComponentManager& component) override;
57 
58     META_NS::EnginePropertyHandle GetPropertyHandle(BASE_NS::string_view component) const;
59     bool AddEngineProperty(META_NS::IMetadata& object, const META_NS::IEngineValue::Ptr& v);
60     void AddAllComponentProperties(META_NS::IMetadata& object);
61     void AddAllProperties(META_NS::IMetadata& object, CORE_NS::IComponentManager*);
62     bool AttachEnginePropertyImpl(
63         META_NS::EnginePropertyHandle, const BASE_NS::string&, const META_NS::IProperty::Ptr&, BASE_NS::string_view);
64 
65 private:
66     IInternalScene::WeakPtr scene_;
67     CORE_NS::Entity entity_;
68     META_NS::IEngineValueManager::Ptr valueManager_;
69     // locked access
70     mutable std::shared_mutex mutex_;
71     BASE_NS::string name_;
72 };
73 
74 SCENE_END_NAMESPACE()
75 
76 #endif