• 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 CORE_ENGINE_H
17 #define CORE_ENGINE_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/array_view.h>
22 #include <base/containers/string.h>
23 #include <base/containers/string_view.h>
24 #include <base/containers/unique_ptr.h>
25 #include <base/containers/vector.h>
26 #include <base/namespace.h>
27 #include <core/ecs/intf_ecs.h>
28 #include <core/engine_info.h>
29 #include <core/intf_engine.h>
30 #include <core/io/intf_file_manager.h>
31 #include <core/namespace.h>
32 #include <core/plugin/intf_class_register.h>
33 #include <core/plugin/intf_interface_helper.h>
34 #include <core/plugin/intf_plugin.h>
35 #include <core/plugin/intf_plugin_register.h>
36 
37 #include "resources/resource_manager.h"
38 
39 BASE_BEGIN_NAMESPACE()
40 template<class T1, class T2>
41 struct pair;
42 BASE_END_NAMESPACE()
43 
44 CORE_BEGIN_NAMESPACE()
45 class IImageLoaderManager;
46 class IPlatform;
47 class IThreadPool;
48 
49 class Engine final : public IInterfaceHelper<IEngine, IClassRegister, IClassFactory>,
50                      IPluginRegister::ITypeInfoListener {
51 public:
52     explicit Engine(EngineCreateInfo const& createInfo);
53     ~Engine() override;
54 
55     void Init() override;
56     bool TickFrame() override;
57     bool TickFrame(const BASE_NS::array_view<IEcs*>& ecsInputs) override;
58     IFileManager& GetFileManager() override;
59 
60     IImageLoaderManager& GetImageLoaderManager() override;
61 
62     const IPlatform& GetPlatform() const override;
63 
64     EngineTime GetEngineTime() const override;
65 
66     IEcs::Ptr CreateEcs() override;
67     IEcs::Ptr CreateEcs(IThreadPool& threadPool) override;
68 
69     BASE_NS::string_view GetVersion() override;
70     bool IsDebugBuild() override;
71 
72     const IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
73     IInterface* GetInterface(const BASE_NS::Uid& uid) override;
74 
75     // IClassFactory
76     IInterface::Ptr CreateInstance(const BASE_NS::Uid& uid) override;
77 
78     // IClassRegister
79     void RegisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override;
80     void UnregisterInterfaceType(const InterfaceTypeInfo& interfaceInfo) override;
81     BASE_NS::array_view<const InterfaceTypeInfo* const> GetInterfaceMetadata() const override;
82     const InterfaceTypeInfo& GetInterfaceMetadata(const BASE_NS::Uid& uid) const override;
83     IInterface* GetInstance(const BASE_NS::Uid& uid) const override;
84 
85     // IPluginRegister::ITypeInfoListener
86     void OnTypeInfoEvent(EventType type, BASE_NS::array_view<const ITypeInfo* const> typeInfos) override;
87 
88 private:
89     void RegisterDefaultPaths();
90     void LoadPlugins();
91     void UnloadPlugins();
92     static bool TickFrame(IEcs& ecs, uint64_t totalTime, uint64_t deltaTime);
93 
94     uint64_t firstTime_ { ~0u };
95     uint64_t previousFrameTime_ { ~0u };
96     uint64_t deltaTime_ { 1 };
97 
98     BASE_NS::unique_ptr<IPlatform> platform_;
99 
100     IFileManager::Ptr fileManager_;
101 
102     BASE_NS::unique_ptr<class ImageLoaderManager> imageManager_;
103 
104     BASE_NS::vector<BASE_NS::pair<PluginToken, const IEnginePlugin*>> plugins_;
105     BASE_NS::vector<const InterfaceTypeInfo*> interfaceTypeInfos_;
106 
107     ResourceManager resourceManager_;
108 };
109 CORE_END_NAMESPACE()
110 
111 #endif // CORE_ENGINE_H
112