1 /* 2 * Copyright (C) 2023 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 API_CORE_IENGINE_H 17 #define API_CORE_IENGINE_H 18 19 #include <base/containers/array_view.h> 20 #include <base/containers/refcnt_ptr.h> 21 #include <base/containers/string_view.h> 22 #include <base/util/uid.h> 23 #include <core/ecs/intf_ecs.h> 24 #include <core/engine_info.h> 25 #include <core/namespace.h> 26 #include <core/plugin/intf_class_factory.h> 27 #include <core/plugin/intf_class_register.h> 28 #include <core/plugin/intf_interface.h> 29 #include <core/threading/intf_thread_pool.h> 30 31 CORE_BEGIN_NAMESPACE() 32 struct EngineCreateInfo; 33 class IFileManager; 34 class IImageLoaderManager; 35 36 /** \addtogroup group_iengine 37 * @{ 38 */ 39 /** Engine time (totaltime and deltatime in microseconds) */ 40 struct EngineTime { 41 /** Total time */ 42 uint64_t totalTimeUs { 0 }; 43 /** Delta time */ 44 uint64_t deltaTimeUs { 0 }; 45 }; 46 47 /** Engine interface. 48 Engine needs to be created with IEngineFactory::Create. 49 */ 50 class IEngine : public IClassFactory { 51 public: 52 static constexpr BASE_NS::Uid UID { "760877f7-0baf-422b-a1a7-35834683ddd3" }; 53 54 using Ptr = BASE_NS::refcnt_ptr<IEngine>; 55 56 /** Init engine. Create needed managers and data. 57 * Needs to be called before accessing managers. 58 */ 59 virtual void Init() = 0; 60 61 /** Tick frame. Update ECS scene. 62 * Needs to be called once per frame before RenderFrame(). 63 * @return True if ECS updated render data stores and rendering is required. 64 */ 65 virtual bool TickFrame() = 0; 66 67 /** Tick frame. Update internal and given ECS scenes. 68 * Needs to be called once per frame before RenderFrame(). 69 * @param ecsInputs ECS instances that need to be updated. 70 * @return True if rendering is required. 71 */ 72 virtual bool TickFrame(const BASE_NS::array_view<IEcs*>& ecsInputs) = 0; 73 74 /** Get file manager */ 75 virtual IFileManager& GetFileManager() = 0; 76 77 /** Return platform specific information */ 78 virtual const IPlatform& GetPlatform() const = 0; 79 80 /** Get engine time. 81 * @return EngineTime struct. 82 */ 83 virtual EngineTime GetEngineTime() const = 0; 84 85 /* returns path to engine root */ 86 virtual BASE_NS::string_view GetRootPath() = 0; 87 88 /** Creates a new ECS instance. 89 * @return ECS instance. 90 */ 91 virtual IEcs::Ptr CreateEcs() = 0; 92 93 /** Creates a new ECS instance with a shared thread pool. 94 * @param threadPool Thread pool which the ECS instance and it's managers and systems can use. 95 * @return ECS instance. 96 */ 97 virtual IEcs::Ptr CreateEcs(IThreadPool& threadPool) = 0; 98 99 virtual IImageLoaderManager& GetImageLoaderManager() = 0; 100 101 /** Get version */ 102 virtual BASE_NS::string_view GetVersion() = 0; 103 104 /** Get whether engine is build in debug mode */ 105 virtual bool IsDebugBuild() = 0; 106 107 protected: 108 IEngine() = default; 109 virtual ~IEngine() = default; 110 }; 111 GetName(const IEngine *)112inline constexpr BASE_NS::string_view GetName(const IEngine*) 113 { 114 return "IEngine"; 115 } 116 117 // factory inteface. 118 class IEngineFactory : public IInterface { 119 public: 120 static constexpr BASE_NS::Uid UID { "f2ce87a4-5a3d-4327-bc90-ff29efb398b0" }; 121 122 using Ptr = BASE_NS::refcnt_ptr<IEngineFactory>; 123 124 virtual IEngine::Ptr Create(const EngineCreateInfo& engineCreateInfo) = 0; 125 126 protected: 127 IEngineFactory() = default; 128 virtual ~IEngineFactory() = default; 129 }; 130 GetName(const IEngineFactory *)131inline constexpr BASE_NS::string_view GetName(const IEngineFactory*) 132 { 133 return "IEngineFactory"; 134 } 135 136 #if defined(CORE_DYNAMIC) && (CORE_DYNAMIC == 1) 137 /** Get version */ 138 extern BASE_NS::string_view (*GetVersion)(); 139 /** Get whether engine is build in debug mode */ 140 extern bool (*IsDebugBuild)(); 141 #else 142 /** Get version */ 143 CORE_PUBLIC BASE_NS::string_view GetVersion(); 144 /** Get whether engine is build in debug mode */ 145 CORE_PUBLIC bool IsDebugBuild(); 146 #endif 147 /** @} */ 148 CORE_END_NAMESPACE() 149 150 #endif // API_CORE_IENGINE_H 151