YSTest: Shells.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
Shells.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2010 - 2013.
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
28 #include "Shells.h"
29 #include "ShlExplorer.h"
30 #include "ShlReader.h"
31 #include <ytest/timing.hpp>
32
34 //测试用声明：全局资源定义。
35 //extern char gstr[128];
36
37 using namespace ystdex;
38
39 YSL_BEGIN_NAMESPACE(YReader)
40
41 namespace
42 {
43
44 ResourceMap GlobalResourceMap;
46 double gfx_init_time;
47
48 } // unnamed namespace;
49
50 DeclResource(GR_BGs)
51
52 namespace
53 {
54
55 using namespace YReader;
56
57 //测试函数。
58
59 template<typename _tTarget>
60 _tTarget&
61 FetchGlobalResource(ResourceIndex idx)
62 {
63 if(!GlobalResourceMap[idx])
64 GlobalResourceMap[idx] = MakeValueObjectByPtr(new _tTarget());
65 return GlobalResourceMap[GR_BGs].GetObject<_tTarget>();
66 }
67
68 shared_ptr<Image>&
69 FetchGlobalImage(size_t idx)
70 {
71 auto& spi(FetchGlobalResource<array<shared_ptr<Image>, 10>>(GR_BGs));
72
73 YAssert(IsInInterval(idx, 10u), "Index is out of range.");
74 return spi[idx];
75 }
76
77 } // unnamed namespace;
78
79 using namespace Shells;
80 using namespace Drawing::ColorSpace;
81
82 void
83 Cleanup()
84 {
85 for(size_t i(0); i != 10; ++i)
86 FetchGlobalImage(i).reset();
87 GlobalResourceMap.clear();
88 ReleaseStored<ShlReader>();
89 ReleaseStored<ShlExplorer>();
90 }
91
92 shared_ptr<Image>&
93 FetchImage(size_t i)
94 {
95 static Color(*const p_bg[10])(SDst, SDst){nullptr,
96 [](SDst x, SDst y)->Color{
97 return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
98 },
99 [](SDst x, SDst y)->Color{
100 return {(x << 4) / (y | 1), (x | y << 1) % (y + 2),
101 (~y | x << 1) % 27 + 3};
102 },
103 [](SDst x, SDst y)->Color{
104 return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
105 },
106 [](SDst x, SDst y)->Color{
107 return {x + y * y, (x & y) ^ (x | y), x * x + y};
108 },
109 [](SDst x, SDst y)->Color{
110 return {(x << 4) / ((y & 1) | 1), ~x % 101 + y,
111 (x + y) % (((y - 2) & 1) | 129) + (x << 2)};
112 },
113 [](SDst x, SDst y)->Color{
114 return {(x | y) % (y + 2), (~y | x) % 27 + 3, (x << 6) / (y | 1)};
115 }
116 };
117
118 if(!FetchGlobalImage(i) && p_bg[i])
119 {
120 auto& h(FetchGlobalImage(i));
121
122 if(!h)
123 h = make_shared<Image>(nullptr, MainScreenWidth, MainScreenHeight);
124 gfx_init_time += ytest::timing::once(Timers::HighResolutionClock::now,
125 ScrDraw<BitmapPtr, decltype(*p_bg)>,
126 h->GetBufferPtr(), p_bg[i]).count() / 1e9;
127 }
128 return FetchGlobalImage(i);
129 }
130
131 double
132 FetchImageLoadTime()
133 {
134 return gfx_init_time;
135 }
136
137 YSL_END_NAMESPACE(YReader)
138