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