YSTest: DSMain.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

DSMain.cpp
浏览该文件的文档.
1 /*
2 © 2010-2017 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
29 #include "DSScreen.h"
30 #include YFM_Helper_HostRenderer // for Host::WindowThread;
31 #include YFM_Helper_Initialization
32 #include YFM_YSLib_Adaptor_Font
33 #include "DSWindow.h"
34 #if YCL_MULTITHREAD == 1
35 # include <thread> // for std::this_thread::*;
36 #endif
37 #ifdef YCL_DS
38 # include YFM_YSLib_Service_YBlit // for Drawing::FillPixels;
39 #elif YCL_Android
40 # include YFM_Android_Helper_AndroidHost // for
41 // Android::FetchNativeHostInstance, Android::FetchDefaultWindow;
42 #endif
43 #include YFM_YCLib_Debug
44 #include YFM_Helper_Environment
45
46 namespace YSLib
47 {
48
49 using namespace Drawing;
50
51 namespace
52 {
53
54 #if YCL_Win32
55 yconstexpr const double g_max_free_fps(1000);
56 std::chrono::nanoseconds host_sleep(std::uint64_t(1000000000 / g_max_free_fps));
57 #endif
58
59
61 DSApplication* ApplicationPtr;
62
63 } // unnamed namespace;
64
65
66 DSApplication::DSApplication()
67 : GUIApplication(), DSVideoState(),
68 scrs()
69 #if YCL_Win32
70 , p_wnd_thrd()
71 #endif
72 {
73 using Devices::DSScreen;
74
75 YAssert(!ApplicationPtr, "Duplicate instance found.");
76 ApplicationPtr = this;
77 #if YCL_DS
78 FetchDefaultFontCache();
79 InitVideo();
80 #endif
81 Devices::InitDSScreen(scrs[0], scrs[1]);
82
83 auto& scr0(Deref(scrs[0]));
84 auto& scr1(Deref(scrs[1]));
85
86 #if YCL_DS
87 FillPixels<Pixel>(scr0.GetCheckedBufferPtr(),
88 GetAreaOf(scr0.GetSize()), ColorSpace::Blue),
89 FillPixels<Pixel>(scr1.GetCheckedBufferPtr(),
90 GetAreaOf(scr1.GetSize()), ColorSpace::Green);
91 #elif YCL_Win32
92
93 using namespace Host;
94
95 p_wnd_thrd.reset(new WindowThread([this]{
96 return unique_ptr<Window>(new DSWindow(CreateNativeWindow(
97 WindowClassName, {256, 384}, L"YSTest", WS_TILED | WS_CAPTION
98 | WS_SYSMENU | WS_MINIMIZEBOX), Deref(scrs[0]), Deref(scrs[1]),
99 GetGUIHostRef()));
100 }));
101 while(!p_wnd_thrd->GetWindowPtr())
102 // TODO: Resolve magic sleep duration.
103 std::this_thread::sleep_for(host_sleep);
104
105 const auto h_wnd(p_wnd_thrd->GetWindowPtr()->GetNativeHandle());
106
107 GetGUIHostRef().MapPoint = [this](const Point& pt){
108 return GetGUIHostRef().MapTopLevelWindowPoint(pt);
109 };
110 #elif YCL_Android
111 const auto h_wnd(&Android::FetchDefaultWindow());
112 // auto& host(Android::FetchNativeHostInstance());
113
114 // host.ResizeScreen({MainScreenWidth, MainScreenHeight << 1}),
115 GetGUIHostRef().MapPoint = [](const Point& pt) ynothrow{
116 // XXX: Use alternative implementation rather than Win32's.
117 yconstexpr const Rect
118 bounds(0, MainScreenHeight, MainScreenWidth, MainScreenHeight << 1);
119
120 return bounds.Contains(pt) ? pt - bounds.GetPoint() : Point::Invalid;
121 };
122 #endif
123
124 // XXX: Only %YCL_Win32 and %YCL_Android are tested and supported.
125 #if YCL_Win32 || YCL_Android
126 yunseq(scr0.WindowHandle = h_wnd, scr1.WindowHandle = h_wnd);
127 #elif YF_Hosted
128 yunused(scr0), yunused(scr1);
129 #endif
130 }
131
132 DSApplication::~DSApplication()
133 {
134 #if YCL_Win32
135 p_wnd_thrd.reset();
136 YTraceDe(Notice, "Host thread dropped.");
137 #endif
138 // hShell = {};
139 reset(scrs[0]),
140 reset(scrs[1]);
141 ApplicationPtr = {};
142 }
143
144 Devices::DSScreen&
145 DSApplication::GetDSScreenUp() const ynothrow
146 {
147 return Deref(scrs[0]);
148 }
149 Devices::DSScreen&
150 DSApplication::GetDSScreenDown() const ynothrow
151 {
152 return Deref(scrs[1]);
153 }
154 Devices::Screen&
155 DSApplication::GetScreenUp() const ynothrow
156 {
157 return GetDSScreenUp();
158 }
159 Devices::Screen&
160 DSApplication::GetScreenDown() const ynothrow
161 {
162 return GetDSScreenDown();
163 }
164
165 void
166 DSApplication::SwapScreens()
167 {
168 UI::FetchGUIState().Reset();
169 SwapLCD();
170 #if YF_Hosted
171 std::swap(GetDSScreenUp().Offset, GetDSScreenDown().Offset);
172 # if !YCL_Android
173 if(const auto p_wnd = GetGUIHostRef().GetForegroundWindow())
174 p_wnd->Invalidate();
175 # endif
176 #endif
177 }
178
179
180 #if YCL_Win32
181 namespace Windows
182 {
183
184 void
185 TestFramework(size_t idx)
186 {
187 YTraceDe(Notice, "%s",
188 ("Test began, idx = " + to_string(idx) + " .").c_str());
189 YTraceDe(Notice, "Test ended.");
190 yunused(idx);
191 }
192
193 } // namespace Windows;
194 #endif
195
196 } // namespace YSLib;
197
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:313
ystdex::reset
bool reset(std::unique_ptr< _type, _tDeleter > &p)
Definition: memory.hpp:708
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:530
DSWindow.h
DS 宿主窗口。
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::Devices::InitDSScreen
void InitDSScreen(unique_ptr< DSScreen > &p_up, unique_ptr< DSScreen > &p_dn)
初始化 DS 屏幕。
Definition: DSScreen.h:135
YSLib::Drawing::Rect::Contains
bool Contains(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: YGDIBase.cpp:92
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:131
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:278
platform::KeyCodes::DS::L
Definition: Keys.h:227
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
YSLib::Consoles::Blue
Definition: YConsole.h:62
YSLib::UI::FetchGUIState
GUIState & FetchGUIState() ynothrow
Definition: YGUI.cpp:508
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:111
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
platform::if
if(!p) p
platform_ex::Windows::Invalid
Definition: MinGW32.h:471
Drawing
DSScreen.h
DS 屏幕。
platform::Descriptions::Notice
Definition: YCommon.h:168
yunused
#define yunused(...)
标记未使用的表达式。
Definition: ydef.h:968
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
YSLib::Consoles::Green
Definition: YConsole.h:63
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
platform::InitVideo
YF_API bool InitVideo()
初始化视频输出。
Definition: Video.cpp:43