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_EXT_IINTERNAL_SCENE_H 17 #define SCENE_EXT_IINTERNAL_SCENE_H 18 19 #include "3d/namespace.h" 20 #include "3d/util/intf_render_util.h" 21 #include <scene/ext/intf_internal_camera.h> 22 #include <scene/interface/intf_camera.h> 23 #include <scene/interface/intf_node.h> 24 25 #include <3d/intf_graphics_context.h> 26 #include <render/intf_render_context.h> 27 28 #include <meta/api/task_queue.h> 29 #include <meta/ext/object.h> 30 #include <meta/interface/animation/intf_animation.h> 31 #include <meta/interface/engine/intf_engine_value.h> 32 33 SCENE_BEGIN_NAMESPACE() 34 35 class IScene; 36 class IEcsObject; 37 class IComponentFactory; 38 class IEcsContext; 39 40 class IInternalScene : public CORE_NS::IInterface { 41 META_INTERFACE(CORE_NS::IInterface, IInternalScene, "24c69cfe-1d25-4546-a5cb-b63c2262065e") 42 public: 43 virtual bool Initialize() = 0; 44 virtual void Uninitialize() = 0; 45 46 virtual void RegisterComponent(const BASE_NS::Uid&, const BASE_NS::shared_ptr<IComponentFactory>&) = 0; 47 virtual void UnregisterComponent(const BASE_NS::Uid&) = 0; 48 virtual BASE_NS::shared_ptr<IComponentFactory> FindComponentFactory(const BASE_NS::Uid&) const = 0; 49 50 virtual META_NS::ITaskQueue::Ptr GetEngineTaskQueue() const = 0; 51 virtual META_NS::ITaskQueue::Ptr GetAppTaskQueue() const = 0; 52 53 virtual META_NS::IObject::Ptr CreateObject(META_NS::ObjectId id) = 0; 54 //-- node handling 55 virtual INode::Ptr CreateNode(BASE_NS::string_view path, META_NS::ObjectId id) = 0; 56 virtual INode::Ptr FindNode(BASE_NS::string_view path, META_NS::ObjectId id) const = 0; 57 virtual INode::Ptr FindNode(CORE_NS::Entity, META_NS::ObjectId id) const = 0; 58 59 virtual bool ReleaseNode(INode::Ptr&& node, bool recursive) = 0; 60 virtual bool RemoveNode(const INode::Ptr& node) = 0; 61 62 virtual BASE_NS::vector<INode::Ptr> GetChildren(const BASE_NS::shared_ptr<IEcsObject>&) const = 0; 63 virtual bool RemoveChild( 64 const BASE_NS::shared_ptr<IEcsObject>& object, const BASE_NS::shared_ptr<IEcsObject>& child) = 0; 65 virtual bool AddChild(const BASE_NS::shared_ptr<IEcsObject>& object, const INode::Ptr& child, size_t index) = 0; 66 //-- 67 68 virtual BASE_NS::vector<ICamera::Ptr> GetCameras() const = 0; 69 virtual BASE_NS::vector<META_NS::IAnimation::Ptr> GetAnimations() const = 0; 70 71 virtual IEcsContext& GetEcsContext() = 0; 72 virtual BASE_NS::shared_ptr<IScene> GetScene() const = 0; 73 virtual RENDER_NS::IRenderContext& GetRenderContext() = 0; 74 virtual CORE3D_NS::IGraphicsContext& GetGraphicsContext() = 0; 75 76 virtual void SchedulePropertyUpdate(const BASE_NS::shared_ptr<IEcsObject>& obj) = 0; 77 virtual void SyncProperties() = 0; 78 virtual void Update(bool syncProperties = true) = 0; 79 80 virtual bool SyncProperty(const META_NS::IProperty::ConstPtr& p, META_NS::EngineSyncDirection dir) = 0; 81 82 virtual void AddRenderingCamera(const IInternalCamera::Ptr& camera) = 0; 83 virtual void RemoveRenderingCamera(const IInternalCamera::Ptr& camera) = 0; 84 85 virtual bool SetRenderMode(RenderMode) = 0; 86 virtual RenderMode GetRenderMode() const = 0; 87 virtual void SetSystemGraphUri(const BASE_NS::string& uri) = 0; 88 virtual BASE_NS::string GetSystemGraphUri() = 0; 89 90 #ifdef __PHYSICS_MODULE__ 91 virtual void SetCustomRngGroup() = 0; 92 virtual void SetCustomRngGroupUri(const Core3D::IRenderUtil::CustomRngGroup& rngGroup) = 0; 93 virtual const Core3D::IRenderUtil::CustomRngGroup& GetCustomRngGroupUri() const = 0; 94 #endif 95 96 virtual void AppendCustomRenderNodeGraph(RENDER_NS::RenderHandleReference rng) = 0; 97 virtual void RenderFrame() = 0; 98 virtual bool HasPendingRender() const = 0; 99 100 public: 101 template<typename Func> AddTask(Func && func)102 auto AddTask(Func&& func) 103 { 104 return AddTask(BASE_NS::forward<Func>(func), GetEngineTaskQueue()); 105 } 106 template<typename Func> AddTask(Func && func,const META_NS::ITaskQueue::Ptr & queue)107 auto AddTask(Func&& func, const META_NS::ITaskQueue::Ptr& queue) 108 { 109 return META_NS::AddFutureTaskOrRunDirectly(queue, BASE_NS::forward<Func>(func)); 110 } 111 }; 112 113 inline Future<bool> SyncProperty(const IInternalScene::Ptr& scene, const META_NS::IProperty::ConstPtr& p, 114 META_NS::EngineSyncDirection dir = META_NS::EngineSyncDirection::AUTO) 115 { 116 return scene->AddTask([=] { return scene->SyncProperty(p, dir); }); 117 } 118 119 SCENE_END_NAMESPACE() 120 121 META_INTERFACE_TYPE(SCENE_NS::IInternalScene) 122 123 #endif