18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef CORE_ENGINE_H 178bf80f4bSopenharmony_ci#define CORE_ENGINE_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <cstdint> 208bf80f4bSopenharmony_ci 218bf80f4bSopenharmony_ci#include <base/containers/array_view.h> 228bf80f4bSopenharmony_ci#include <base/containers/string.h> 238bf80f4bSopenharmony_ci#include <base/containers/string_view.h> 248bf80f4bSopenharmony_ci#include <base/containers/unique_ptr.h> 258bf80f4bSopenharmony_ci#include <base/containers/vector.h> 268bf80f4bSopenharmony_ci#include <base/namespace.h> 278bf80f4bSopenharmony_ci#include <core/ecs/intf_ecs.h> 288bf80f4bSopenharmony_ci#include <core/engine_info.h> 298bf80f4bSopenharmony_ci#include <core/intf_engine.h> 308bf80f4bSopenharmony_ci#include <core/io/intf_file_manager.h> 318bf80f4bSopenharmony_ci#include <core/namespace.h> 328bf80f4bSopenharmony_ci#include <core/plugin/intf_class_register.h> 338bf80f4bSopenharmony_ci#include <core/plugin/intf_interface.h> 348bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h> 358bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin_register.h> 368bf80f4bSopenharmony_ci 378bf80f4bSopenharmony_ciBASE_BEGIN_NAMESPACE() 388bf80f4bSopenharmony_cistruct Uid; 398bf80f4bSopenharmony_citemplate<class T1, class T2> 408bf80f4bSopenharmony_cistruct pair; 418bf80f4bSopenharmony_ciBASE_END_NAMESPACE() 428bf80f4bSopenharmony_ci 438bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE() 448bf80f4bSopenharmony_ciclass IImageLoaderManager; 458bf80f4bSopenharmony_ciclass IPlatform; 468bf80f4bSopenharmony_ciclass IThreadPool; 478bf80f4bSopenharmony_ci 488bf80f4bSopenharmony_ciclass Engine final : public IEngine, virtual public IClassRegister, IPluginRegister::ITypeInfoListener { 498bf80f4bSopenharmony_cipublic: 508bf80f4bSopenharmony_ci explicit Engine(EngineCreateInfo const& createInfo); 518bf80f4bSopenharmony_ci ~Engine() override; 528bf80f4bSopenharmony_ci 538bf80f4bSopenharmony_ci void Init() override; 548bf80f4bSopenharmony_ci bool TickFrame() override; 558bf80f4bSopenharmony_ci bool TickFrame(const BASE_NS::array_view<IEcs*>& ecsInputs) override; 568bf80f4bSopenharmony_ci IFileManager& GetFileManager() override; 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci IImageLoaderManager& GetImageLoaderManager() override; 598bf80f4bSopenharmony_ci 608bf80f4bSopenharmony_ci const IPlatform& GetPlatform() const override; 618bf80f4bSopenharmony_ci 628bf80f4bSopenharmony_ci EngineTime GetEngineTime() const override; 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ci IEcs::Ptr CreateEcs() override; 658bf80f4bSopenharmony_ci IEcs::Ptr CreateEcs(IThreadPool& threadPool) override; 668bf80f4bSopenharmony_ci 678bf80f4bSopenharmony_ci BASE_NS::string_view GetVersion() override; 688bf80f4bSopenharmony_ci bool IsDebugBuild() override; 698bf80f4bSopenharmony_ci 708bf80f4bSopenharmony_ci // IInterface 718bf80f4bSopenharmony_ci const IInterface* GetInterface(const BASE_NS::Uid& uid) const override; 728bf80f4bSopenharmony_ci IInterface* GetInterface(const BASE_NS::Uid& uid) override; 738bf80f4bSopenharmony_ci void Ref() override; 748bf80f4bSopenharmony_ci void Unref() override; 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci // IClassFactory 778bf80f4bSopenharmony_ci IInterface::Ptr CreateInstance(const BASE_NS::Uid& uid) override; 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ci // IClassRegister 808bf80f4bSopenharmony_ci void RegisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override; 818bf80f4bSopenharmony_ci void UnregisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override; 828bf80f4bSopenharmony_ci BASE_NS::array_view<const InterfaceTypeInfo* const> GetInterfaceMetadata() const override; 838bf80f4bSopenharmony_ci const InterfaceTypeInfo& GetInterfaceMetadata(const BASE_NS::Uid& uid) const override; 848bf80f4bSopenharmony_ci IInterface* GetInstance(const BASE_NS::Uid& uid) const override; 858bf80f4bSopenharmony_ci 868bf80f4bSopenharmony_ci // IPluginRegister::ITypeInfoListener 878bf80f4bSopenharmony_ci void OnTypeInfoEvent(EventType type, BASE_NS::array_view<const ITypeInfo* const> typeInfos) override; 888bf80f4bSopenharmony_ci 898bf80f4bSopenharmony_ciprivate: 908bf80f4bSopenharmony_ci void RegisterDefaultPaths(); 918bf80f4bSopenharmony_ci void LoadPlugins(); 928bf80f4bSopenharmony_ci void UnloadPlugins(); 938bf80f4bSopenharmony_ci static bool TickFrame(IEcs& ecs, uint64_t totalTime, uint64_t deltaTime); 948bf80f4bSopenharmony_ci 958bf80f4bSopenharmony_ci uint64_t firstTime_ { ~0u }; 968bf80f4bSopenharmony_ci uint64_t previousFrameTime_ { ~0u }; 978bf80f4bSopenharmony_ci uint64_t deltaTime_ { 1 }; 988bf80f4bSopenharmony_ci 998bf80f4bSopenharmony_ci BASE_NS::unique_ptr<IPlatform> platform_; 1008bf80f4bSopenharmony_ci ContextInfo applicationContext_; 1018bf80f4bSopenharmony_ci 1028bf80f4bSopenharmony_ci IFileManager::Ptr fileManager_; 1038bf80f4bSopenharmony_ci 1048bf80f4bSopenharmony_ci BASE_NS::unique_ptr<class ImageLoaderManager> imageManager_; 1058bf80f4bSopenharmony_ci uint32_t refCount_ { 0 }; 1068bf80f4bSopenharmony_ci 1078bf80f4bSopenharmony_ci BASE_NS::vector<BASE_NS::pair<PluginToken, const IEnginePlugin*>> plugins_; 1088bf80f4bSopenharmony_ci BASE_NS::vector<const InterfaceTypeInfo*> interfaceTypeInfos_; 1098bf80f4bSopenharmony_ci}; 1108bf80f4bSopenharmony_ciCORE_END_NAMESPACE() 1118bf80f4bSopenharmony_ci 1128bf80f4bSopenharmony_ci#endif // CORE_ENGINE_H 113