-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
264 lines (264 loc) · 10.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>cocos2d-html5 benchmark</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<link rel="shortcut icon" href="res/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="res/Images/Icon.png">
<!-- MUST be the first style, due to hack code -->
<style type="text/css">
html body {
margin: 10px 0;
}
body > * {
width: 300px;
margin: 0 auto;
}
.menu_item_wrapper {
float: left;
display: table;
table-layout: fixed;
height: 100%;
font-size: 14px;
}
.menu_item_wrapper > div {
display: table-cell;
vertical-align: middle;
}
.menu_item_wrapper input[type="button"] {
margin: auto 10%;
width: 80%;
}
.menu_item_text {
margin: auto 5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#output {
border: 1px solid black;
background-color: rgba(0, 0, 0, 0.1);
font-size: 14px;
min-height: 100px;
}
</style>
<script type="text/javascript">
var BENCHMARK_VERSION = 'v1.0.4'; // Modify version in build.xml, when single file used
// append version to title
document.title = document.title + ' ' + BENCHMARK_VERSION;
// benchmark output to write test result
var BenchmarkOutput = function() {
this._format = function(args) {
var text = '', i, width = 0;
for (i=0; i<args.length; ++i) {
var arg = args[i];
if (typeof args[i] === 'string') {
if (0 === arg.indexOf('%')) {
width = Number(arg.substr(1));
if (width) {
continue;
}
}
}
if (width) {
var j = 0;
var paddingLength = width - arg.length - text.length;
for (j=0; j<paddingLength; ++j) {
text += ' ';
}
width = 0;
}
text += arg;
}
return text;
};
this._write = function(text) {
var output = document.getElementById('output');
if (1 === output.firstChild.length) {
output.firstChild.deleteData(0, output.firstChild.length);
}
output.firstChild.appendData(text);
};
this.write = function() {
this._write(this._format(arguments));
};
this.writeln = function() {
this._write(this._format(arguments) + '\n');
};
this.clear = function() {
var output = document.getElementById('output');
output.firstChild.deleteData(0, output.firstChild.length);
}
};
BenchmarkOutput._instance = null;
BenchmarkOutput.getInstance = function() {
if (!this._instance) {
this._instance = new BenchmarkOutput();
}
return this._instance;
};
BenchmarkQueryParameters = (function() {
var result = {};
if (window.location.search)
{
var params = window.location.search.substr(1).split("&");
for (var i=0; i < params.length; ++i)
{
var tmp = params[i].split("=");
result[tmp[0]] = decodeURI(tmp[1]);
}
result['__length'] = params.length;
}
result.toString = function() {
var ret = '', key, i = 0;
if (result['__length']) {
ret += '?';
}
for(key in result) {
if (key !== 'toString' && key !== '__length') {
if (0 < i) {
ret += '&';
}
++i;
ret += key;
ret += '=';
ret += result[key];
}
}
return ret;
};
return result;
}());
function BenchmarkOnActionButtonClick(button) {
if (typeof BenchmarkController !== 'undefined') { // loaded
if (button.id === 'action') {
if (button.value === 'start') {
BenchmarkController.getInstance().startBenchmark();
}
else if (button.value === 'stop') {
BenchmarkController.getInstance().stopBenchmark();
}
}
else if (button.id === 'clear') {
BenchmarkOutput.getInstance().clear();
BenchmarkShowResultActions(false);
}
else if (button.id === 'submit') {
var errno = BenchmarkController.getInstance().submitBenchmark();
if (errno == BenchmarkController.E_SUCCESS) {
BenchmarkEnableSubmitAction(false);
alert('Submitted, thanks for your contribution.');
window.location = 'rank.php'
}
else if (errno == BenchmarkController.E_ALREADY_SUBMITTED) {
alert('Data already submitted');
}
else {
alert('Failed to submit, errno: ' + errno);
}
}
else if (button.id === 'share') {
}
}
}
function BenchmarkOnEngineChange(select) {
var selectOption = select.options[select.selectedIndex];
BenchmarkQueryParameters.engine = selectOption.value;
window.location.search = BenchmarkQueryParameters.toString();
}
function BenchmarkShowResultActions(show) {
var display = 'none';
if (show) {
display = 'block';
}
document.getElementById('result_actions').style.display = display;
}
function BenchmarkEnableSubmitAction(enable) {
document.getElementById('submit').disabled = !enable;
}
function BenchmarkOnControllerLoadEnd(controller) {
var controllerDelegate = {
_setAction: function(action) {
document.getElementById('action').value = action;
},
onBeginTestCase: function(testInfo) {
if (testInfo.firstInCategory) {
BenchmarkOutput.getInstance().writeln(testInfo.category);
}
},
onEndTestCase: function(testID, testInfo) {
var name = ' ' + testInfo.name + ': ';
var FPS = '', score = '';
if (testInfo.duration) {
FPS = controller.getTestFPS(testID);
score = '(' + controller.getTestScore(testID) + ')';
}
BenchmarkOutput.getInstance().writeln(name, '%25', FPS, score);
},
onStartBenchmark: function() {
this._setAction('stop');
BenchmarkEnableSubmitAction(false);
},
onStopBenchmark: function() {
cc.Director.getInstance().replaceScene(BenchmarkEntryScene.getInstance());
this._setAction('start');
},
onBenchmarkDone: function() {
BenchmarkOutput.getInstance().writeln('Score: ' + controller.getFinalScore() + ', Time used: ' + controller.getTimeUsed() + 'ms');
BenchmarkOutput.getInstance().writeln('####################################');
BenchmarkShowResultActions(true);
BenchmarkEnableSubmitAction(true);
},
onError: function(e) {
BenchmarkOutput.getInstance().writeln('Exception occurred, stopped:\n' + e);
}
};
controller.setDelegate(controllerDelegate);
}
</script>
<script src="cocos2d.js"></script>
</head>
<body>
<div id="Cocos2dGameContainer" style="background-color:rgba(0,0,0,0.1); width: 300px; height: 300px">
</div>
<div style="height: 50px">
<div class="menu_item_wrapper" style="width: 56%">
<div>
<div class="menu_item_text">
<span style="float: left">version: </span>
<span id="benchmark_version"><script>document.write(BENCHMARK_VERSION)</script></span>
</div>
<div class="menu_item_text" id="engine_menu" style="display: none">
<span style="float: left">engine: </span>
<span id="engine_version" style="display: none"></span>
<select id="engine_select" style="display: none" onchange="BenchmarkOnEngineChange(this)">
</select>
</div>
</div>
</div>
<div class="menu_item_wrapper" style="width: 22%">
<div>
<input id="action" type="button" onclick="BenchmarkOnActionButtonClick(this)" value=start />
</div>
</div>
<div class="menu_item_wrapper" style="width: 22%">
<div>
<input id="clear" type="button" onclick="BenchmarkOnActionButtonClick(this)" value=clear />
</div>
</div>
</div>
<div id="result_actions" style="height: 40px; display: none; border-top:1px solid black;">
<div class="menu_item_wrapper" style="width: 50%">
<div>
<input id="submit" type="button" onclick="BenchmarkOnActionButtonClick(this)" value=submit />
</div>
</div>
<div class="menu_item_wrapper" style="width: 50%">
<div>
<input id="share" type="button" disabled=true onclick="BenchmarkOnActionButtonClick(this)" value=share />
</div>
</div>
</div>
<pre id="output"> <!--   MUST NOT be deleted, to simplify javascript code --></pre>
</body>
</html>