Kiwano Engine v1.3.x
Runner.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 <kiwano/core/Common.h>
23#include <kiwano/core/Time.h>
24#include <kiwano/platform/Window.h>
25#include <kiwano/render/Color.h>
26#include <kiwano/utils/Ticker.h>
27
28namespace kiwano
29{
30
31class Application;
32
38{
44
45 Settings()
46 : bg_color(Color::Black)
48 , vsync_enabled(true)
49 , debug_mode(false)
50 {
51 }
52};
53
58class KGE_API Runner : public ObjectBase
59{
60public:
61 Runner();
62
66 Runner(const Settings& settings);
67
68 virtual ~Runner();
69
73 virtual void OnReady();
74
78 virtual void OnDestroy();
79
84 virtual bool OnClose();
85
91 bool MainLoop(Duration dt);
92
95 RefPtr<Window> GetWindow() const;
96
99 Settings GetSettings() const;
100
103 RefPtr<Ticker> GetFrameTicker() const;
104
107 void SetFrameTicker(RefPtr<Ticker> ticker);
108
109protected:
112 void SetSettings(Settings settings);
113
116 void SetWindow(RefPtr<Window> window);
117
118private:
119 friend class Application;
120
121 void InitSettings();
122
123private:
124 Settings settings_;
125 RefPtr<Window> main_window_;
126 RefPtr<Ticker> frame_ticker_;
127};
128
129inline void Runner::OnReady() {}
130
131inline void Runner::OnDestroy() {}
132
133inline bool Runner::OnClose()
134{
135 return true;
136}
137
139{
140 return main_window_;
141}
142
144{
145 main_window_ = window;
146}
147
149{
150 return settings_;
151}
152
153inline void Runner::SetSettings(Settings settings)
154{
155 settings_ = settings;
156}
157
159{
160 return frame_ticker_;
161}
162
164{
165 frame_ticker_ = ticker;
166}
167
168} // namespace kiwano
应用程序,控制游戏的整个生命周期,包括初始化、启动、结束以及事件分发等
Definition: Application.h:46
Definition: Color.h:41
基础对象
Definition: ObjectBase.h:138
引用计数智能指针
Definition: RefBasePtr.hpp:35
程序运行器
Definition: Runner.h:59
virtual void OnDestroy()
应用程序销毁处理
Definition: Runner.h:131
RefPtr< Ticker > GetFrameTicker() const
获取帧报时器
Definition: Runner.h:158
virtual void OnReady()
初始化完成处理
Definition: Runner.h:129
virtual bool OnClose()
应用程序关闭处理
Definition: Runner.h:133
void SetFrameTicker(RefPtr< Ticker > ticker)
设置帧报时器
Definition: Runner.h:163
void SetWindow(RefPtr< Window > window)
设置窗口
Definition: Runner.h:143
Settings GetSettings() const
获取设置
Definition: Runner.h:148
void SetSettings(Settings settings)
修改设置
Definition: Runner.h:153
RefPtr< Window > GetWindow() const
获取窗口
Definition: Runner.h:138
时间段
Definition: Duration.h:48
游戏设置
Definition: Runner.h:38
Duration frame_interval
帧间隔
Definition: Runner.h:41
Color bg_color
背景色
Definition: Runner.h:40
bool vsync_enabled
垂直同步
Definition: Runner.h:42
bool debug_mode
调试模式
Definition: Runner.h:43
WindowConfig window
窗口设置
Definition: Runner.h:39
窗口设置
Definition: Window.h:97