Kiwano Engine v1.3.x
Application.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <mutex>
23#include <kiwano/core/Common.h>
24#include <kiwano/base/Module.h>
25#include <kiwano/core/Time.h>
26#include <kiwano/core/Singleton.h>
27#include <kiwano/event/Event.h>
28#include <kiwano/platform/Runner.h>
29#include <kiwano/platform/Window.h>
30#include <kiwano/utils/Timer.h>
31
32namespace kiwano
33{
34
39extern KGE_API int GetVersion();
40
45class KGE_API Application : public Singleton<Application>
46{
48
49public:
51
52 virtual ~Application();
53
61 void Run(const Settings& settings, const Function<void()>& setup, std::initializer_list<Module*> modules = {});
62
69 void Run(RefPtr<Runner> runner);
70
75 void Pause();
76
81 void Resume();
82
87 void Quit();
88
93 bool IsPaused() const;
94
100 void Use(Module& m);
101
106 RefPtr<Runner> GetRunner() const;
107
112 RefPtr<Window> GetWindow() const;
113
121 void SetTimeScale(float scale_factor);
122
129 void DispatchEvent(RefPtr<Event> evt);
130
137 void DispatchEvent(Event* evt);
138
145 void PerformInMainThread(Function<void()> func);
146
152 void UpdateFrame(Duration dt);
153
158 void Destroy();
159
160private:
166 void Update(Duration dt);
167
172 void Render();
173
174private:
175 bool running_;
176 bool is_paused_;
177 float time_scale_;
178 RefPtr<Runner> runner_;
179 RefPtr<Timer> timer_;
180 ModuleList modules_;
181 std::mutex perform_mutex_;
182 Queue<Function<void()>> functions_to_perform_;
183};
184
186{
187 return runner_;
188}
189
191{
192 if (runner_)
193 return runner_->GetWindow();
194 return nullptr;
195}
196
197inline bool Application::IsPaused() const
198{
199 return is_paused_;
200}
201
202} // namespace kiwano
应用程序,控制游戏的整个生命周期,包括初始化、启动、结束以及事件分发等
Definition: Application.h:46
RefPtr< Window > GetWindow() const
获取窗口
Definition: Application.h:190
RefPtr< Runner > GetRunner() const
获取程序运行器
Definition: Application.h:185
bool IsPaused() const
获取暂停状态
Definition: Application.h:197
事件
Definition: Event.h:43
Definition: Function.h:228
基础模块
Definition: Module.h:111
引用计数智能指针
Definition: RefBasePtr.hpp:35
Definition: Singleton.h:28
时间段
Definition: Duration.h:48
游戏设置
Definition: Runner.h:39