YSTest: DSMain.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

DSMain.cpp
浏览该文件的文档.
1 /*
2 © 2010-2016 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 #if YF_Hosted
124
125 yunseq(scr0.WindowHandle = h_wnd, scr1.WindowHandle = h_wnd);
126 #endif
127 }
128
129 DSApplication::~DSApplication()
130 {
131 #if YCL_Win32
132 p_wnd_thrd.reset();
133 YTraceDe(Notice, "Host thread dropped.");
134 #endif
135 // hShell = {};
136 reset(scrs[0]),
137 reset(scrs[1]);
138 ApplicationPtr = {};
139 }
140
141 Devices::DSScreen&
142 DSApplication::GetDSScreenUp() const ynothrow
143 {
144 return Deref(scrs[0]);
145 }
146 Devices::DSScreen&
147 DSApplication::GetDSScreenDown() const ynothrow
148 {
149 return Deref(scrs[1]);
150 }
151 Devices::Screen&
152 DSApplication::GetScreenUp() const ynothrow
153 {
154 return GetDSScreenUp();
155 }
156 Devices::Screen&
157 DSApplication::GetScreenDown() const ynothrow
158 {
159 return GetDSScreenDown();
160 }
161
162 void
163 DSApplication::SwapScreens()
164 {
165 UI::FetchGUIState().Reset();
166 SwapLCD();
167 #if YF_Hosted
168 std::swap(GetDSScreenUp().Offset, GetDSScreenDown().Offset);
169 # if !YCL_Android
170 if(const auto p_wnd = GetGUIHostRef().GetForegroundWindow())
171 p_wnd->Invalidate();
172 # endif
173 #endif
174 }
175
176
177 #if YCL_Win32
178 namespace Windows
179 {
180
181 void
182 TestFramework(size_t idx)
183 {
184 YTraceDe(Notice, "%s",
185 ("Test began, idx = " + to_string(idx) + " .").c_str());
186 YTraceDe(Notice, "Test ended.");
187 yunused(idx);
188 }
189
190 } // namespace Windows;
191 #endif
192
193 } // namespace YSLib;
194
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
DSWindow.h
DS 宿主窗口。
YSLib::Consoles::Blue
Definition: YConsole.h:62
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
YSLib::Consoles::Green
Definition: YConsole.h:63
YSLib::Devices::InitDSScreen
void InitDSScreen(unique_ptr< DSScreen > &p_up, unique_ptr< DSScreen > &p_dn) ynothrow
初始化 DS 屏幕。
Definition: DSScreen.h:135
platform::InitVideo
YF_API bool InitVideo()
初始化视频输出。
Definition: Video.cpp:43
YSLib::Drawing::Rect::Contains
bool Contains(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: YGDIBase.cpp:92
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
YSLib::FetchDefaultFontCache
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。 字体缓存初始化失败。
Definition: Initialization.cpp:493
platform::KeyCodes::DS::L
Definition: Keys.h:227
YSLib::UI::FetchGUIState
GUIState & FetchGUIState() ynothrow
Definition: YGUI.cpp:508
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:105
ystdex::reset
bool reset(std::unique_ptr< _type > &p)
Definition: memory.hpp:584
yunused
#define yunused(...)
标记未使用的表达式。
Definition: ydef.h:942
platform_ex::Windows::Invalid
Definition: MinGW32.h:461
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:305
DSScreen.h
DS 屏幕。
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:440
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
Drawing
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:278
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
platform::if
if(!p) p
platform::Descriptions::Notice
Definition: YCommon.h:158