1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "test/testmain.h" |
23 |
|
|
|
24 |
|
|
#ifdef USE_OPENGL |
25 |
|
|
|
26 |
|
|
#include "logger.h" |
27 |
|
|
#include "settings.h" |
28 |
|
|
|
29 |
|
|
#include "fs/paths.h" |
30 |
|
|
|
31 |
|
|
#include "utils/cast.h" |
32 |
|
|
#include "utils/delete2.h" |
33 |
|
|
#include "utils/process.h" |
34 |
|
|
|
35 |
|
|
#include <fstream> |
36 |
|
|
|
37 |
|
|
#include "debug.h" |
38 |
|
|
|
39 |
|
1 |
std::string fileName; |
40 |
|
|
extern char *selfName; |
41 |
|
|
|
42 |
|
|
TestMain::TestMain() : |
43 |
|
|
log(new Logger), |
44 |
|
|
mConfig() |
45 |
|
|
{ |
46 |
|
|
fileName = getSelfName(); |
47 |
|
|
log->setLogFile(pathJoin(settings.localDataDir, "manaplustest.log")); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
TestMain::~TestMain() |
51 |
|
|
{ |
52 |
|
|
delete2(log) |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
void TestMain::initConfig() |
56 |
|
|
{ |
57 |
|
|
mConfig.init(settings.configDir + "/test.xml", |
58 |
|
|
UseVirtFs_false, |
59 |
|
|
SkipError_false); |
60 |
|
|
mConfig.clear(); |
61 |
|
|
// setConfigDefaults(mConfig); |
62 |
|
|
|
63 |
|
|
mConfig.setValue("hwaccel", false); |
64 |
|
|
mConfig.setValue("screen", false); |
65 |
|
|
mConfig.setValue("sound", false); |
66 |
|
|
mConfig.setValue("guialpha", 0.8F); |
67 |
|
|
// mConfig.setValue("remember", true); |
68 |
|
|
mConfig.setValue("sfxVolume", 50); |
69 |
|
|
mConfig.setValue("musicVolume", 60); |
70 |
|
|
mConfig.setValue("fpslimit", 0); |
71 |
|
|
mConfig.setValue("customcursor", true); |
72 |
|
|
mConfig.setValue("useScreenshotDirectorySuffix", true); |
73 |
|
|
mConfig.setValue("ChatLogLength", 128); |
74 |
|
|
mConfig.setValue("screenwidth", 800); |
75 |
|
|
mConfig.setValue("screenheight", 600); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
int TestMain::exec(const bool testAudio) |
79 |
|
|
{ |
80 |
|
|
initConfig(); |
81 |
|
|
int softwareTest = invokeSoftwareRenderTest("1"); |
82 |
|
|
int soundTest = -1; |
83 |
|
|
int rescaleTest[6]; |
84 |
|
|
int softFps = 0; |
85 |
|
|
int normalOpenGLFps = 0; |
86 |
|
|
int safeOpenGLFps = 0; |
87 |
|
|
int modernOpenGLFps = 0; |
88 |
|
|
int textureSize[6]; |
89 |
|
|
std::string textureSizeStr; |
90 |
|
|
|
91 |
|
|
RenderType openGLMode = RENDER_SOFTWARE; |
92 |
|
|
int detectMode = 0; |
93 |
|
|
for (int f = 0; f < 6; f ++) |
94 |
|
|
{ |
95 |
|
|
rescaleTest[f] = -1; |
96 |
|
|
textureSize[f] = 1024; |
97 |
|
|
} |
98 |
|
|
std::string info; |
99 |
|
|
|
100 |
|
|
const int videoDetectTest = invokeTest("99"); |
101 |
|
|
if (videoDetectTest == 0) |
102 |
|
|
detectMode = readValue2(99); |
103 |
|
|
|
104 |
|
|
int normalOpenGLTest = invokeNormalOpenGLRenderTest("2"); |
105 |
|
|
int safeOpenGLTest = invokeSafeOpenGLRenderTest("3"); |
106 |
|
|
int modernOpenGLTest = invokeModernOpenGLRenderTest("19"); |
107 |
|
|
if (testAudio) |
108 |
|
|
soundTest = invokeTest4(); |
109 |
|
|
else |
110 |
|
|
soundTest = 0; |
111 |
|
|
|
112 |
|
|
info.append(strprintf("%d.%d,%d,%d,%d.", soundTest, softwareTest, |
113 |
|
|
normalOpenGLTest, safeOpenGLTest, modernOpenGLTest)); |
114 |
|
|
|
115 |
|
|
if (softwareTest == 0) |
116 |
|
|
{ |
117 |
|
|
int softFpsTest = invokeSoftwareRenderTest("8"); |
118 |
|
|
info.append(strprintf("%d", softFpsTest)); |
119 |
|
|
if (softFpsTest == 0) |
120 |
|
|
{ |
121 |
|
|
softFps = readValue2(8); |
122 |
|
|
info.append(strprintf(",%d", softFps)); |
123 |
|
|
if (softFps == 0) |
124 |
|
|
{ |
125 |
|
|
softwareTest = -1; |
126 |
|
|
softFpsTest = -1; |
127 |
|
|
} |
128 |
|
|
else |
129 |
|
|
{ |
130 |
|
|
rescaleTest[0] = invokeSoftwareRenderTest("5"); |
131 |
|
|
info.append(strprintf(",%d", rescaleTest[0])); |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
else |
135 |
|
|
{ |
136 |
|
|
softwareTest = -1; |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
info.append("."); |
140 |
|
|
if (modernOpenGLTest == 0) |
141 |
|
|
{ |
142 |
|
|
int modernOpenGLFpsTest = invokeModernOpenGLRenderTest("17"); |
143 |
|
|
info.append(strprintf("%d", modernOpenGLFpsTest)); |
144 |
|
|
if (modernOpenGLFpsTest == 0) |
145 |
|
|
{ |
146 |
|
|
modernOpenGLFps = readValue2(17); |
147 |
|
|
info.append(strprintf(",%d", modernOpenGLFps)); |
148 |
|
|
if (modernOpenGLFps == 0) |
149 |
|
|
{ |
150 |
|
|
modernOpenGLTest = -1; |
151 |
|
|
modernOpenGLFpsTest = -1; |
152 |
|
|
} |
153 |
|
|
else |
154 |
|
|
{ |
155 |
|
|
rescaleTest[3] = invokeModernOpenGLRenderTest("18"); |
156 |
|
|
info.append(strprintf(",%d", rescaleTest[3])); |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
|
else |
160 |
|
|
{ |
161 |
|
|
modernOpenGLTest = -1; |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
info.append("."); |
165 |
|
|
if (normalOpenGLTest == 0) |
166 |
|
|
{ |
167 |
|
|
int normalOpenGLFpsTest = invokeNormalOpenGLRenderTest("9"); |
168 |
|
|
info.append(strprintf("%d", normalOpenGLFpsTest)); |
169 |
|
|
if (normalOpenGLFpsTest == 0) |
170 |
|
|
{ |
171 |
|
|
normalOpenGLFps = readValue2(9); |
172 |
|
|
info.append(strprintf(",%d", normalOpenGLFps)); |
173 |
|
|
if (normalOpenGLFps == 0) |
174 |
|
|
{ |
175 |
|
|
normalOpenGLTest = -1; |
176 |
|
|
normalOpenGLFpsTest = -1; |
177 |
|
|
} |
178 |
|
|
else |
179 |
|
|
{ |
180 |
|
|
rescaleTest[1] = invokeNormalOpenGLRenderTest("6"); |
181 |
|
|
info.append(strprintf(",%d", rescaleTest[1])); |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
else |
185 |
|
|
{ |
186 |
|
|
normalOpenGLTest = -1; |
187 |
|
|
} |
188 |
|
|
} |
189 |
|
|
info.append("."); |
190 |
|
|
if (safeOpenGLTest == 0) |
191 |
|
|
{ |
192 |
|
|
int safeOpenGLFpsTest = invokeSafeOpenGLRenderTest("10"); |
193 |
|
|
info.append(strprintf("%d", safeOpenGLFpsTest)); |
194 |
|
|
if (safeOpenGLFpsTest == 0) |
195 |
|
|
{ |
196 |
|
|
safeOpenGLFps = readValue2(10); |
197 |
|
|
info.append(strprintf(",%d", safeOpenGLFps)); |
198 |
|
|
if (safeOpenGLFps == 0) |
199 |
|
|
{ |
200 |
|
|
safeOpenGLTest = -1; |
201 |
|
|
safeOpenGLFpsTest = -1; |
202 |
|
|
} |
203 |
|
|
else |
204 |
|
|
{ |
205 |
|
|
rescaleTest[2] = invokeSafeOpenGLRenderTest("7"); |
206 |
|
|
info.append(strprintf(",%d", rescaleTest[2])); |
207 |
|
|
} |
208 |
|
|
} |
209 |
|
|
else |
210 |
|
|
{ |
211 |
|
|
safeOpenGLTest = -1; |
212 |
|
|
} |
213 |
|
|
} |
214 |
|
|
info.append("."); |
215 |
|
|
|
216 |
|
|
int maxFps = softFps; |
217 |
|
|
if (maxFps < normalOpenGLFps) |
218 |
|
|
{ |
219 |
|
|
openGLMode = RENDER_NORMAL_OPENGL; |
220 |
|
|
maxFps = normalOpenGLFps; |
221 |
|
|
} |
222 |
|
|
if (maxFps < modernOpenGLFps) |
223 |
|
|
{ |
224 |
|
|
openGLMode = RENDER_MODERN_OPENGL; |
225 |
|
|
maxFps = modernOpenGLFps; |
226 |
|
|
} |
227 |
|
|
if (maxFps < safeOpenGLFps) |
228 |
|
|
{ |
229 |
|
|
openGLMode = RENDER_SAFE_OPENGL; |
230 |
|
|
maxFps = safeOpenGLFps; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
int batchSize = 256; |
234 |
|
|
|
235 |
|
|
if (invokeNormalOpenBatchTest("11") == 0) |
236 |
|
|
batchSize = readValue2(11); |
237 |
|
|
if (batchSize < 256) |
238 |
|
|
batchSize = 256; |
239 |
|
|
|
240 |
|
|
if (invokeNormalOpenBatchTest("14") == 0) |
241 |
|
|
{ |
242 |
|
|
textureSize[CAST_SIZE(RENDER_NORMAL_OPENGL)] |
243 |
|
|
= readValue2(14); |
244 |
|
|
} |
245 |
|
|
if (invokeModernOpenBatchTest("15") == 0) |
246 |
|
|
{ |
247 |
|
|
textureSize[CAST_SIZE(RENDER_MODERN_OPENGL)] |
248 |
|
|
= readValue2(15); |
249 |
|
|
} |
250 |
|
|
if (invokeSafeOpenBatchTest("16") == 0) |
251 |
|
|
{ |
252 |
|
|
textureSize[CAST_SIZE(RENDER_SAFE_OPENGL)] |
253 |
|
|
= readValue2(16); |
254 |
|
|
} |
255 |
|
|
if (invokeMobileOpenBatchTest("20") == 0) |
256 |
|
|
{ |
257 |
|
|
textureSize[CAST_SIZE(RENDER_GLES_OPENGL)] |
258 |
|
|
= readValue2(20); |
259 |
|
|
} |
260 |
|
|
for (int f = 0; f < 6; f ++) |
261 |
|
|
info.append(strprintf(",%d", textureSize[f])); |
262 |
|
|
info.append(",-"); |
263 |
|
|
|
264 |
|
|
textureSizeStr = toString(textureSize[0]); |
265 |
|
|
for (int f = 1; f < 6; f ++) |
266 |
|
|
textureSizeStr.append(strprintf(",%d", textureSize[f])); |
267 |
|
|
|
268 |
|
|
// if OpenGL implimentation is not good, disable it. |
269 |
|
|
if ((detectMode & 15) == 0) |
270 |
|
|
openGLMode = RENDER_SOFTWARE; |
271 |
|
|
|
272 |
|
|
writeConfig(openGLMode, rescaleTest[CAST_SIZE(openGLMode)], |
273 |
|
|
soundTest, info, batchSize, textureSizeStr, detectMode); |
274 |
|
|
return 0; |
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
void TestMain::writeConfig(const RenderType openGLMode, |
278 |
|
|
const int rescale, |
279 |
|
|
const int sound, |
280 |
|
|
const std::string &info, |
281 |
|
|
const int batchSize A_UNUSED, |
282 |
|
|
const std::string &textureSize, |
283 |
|
|
const int detectMode) |
284 |
|
|
{ |
285 |
|
|
mConfig.init(settings.configDir + "/config.xml", |
286 |
|
|
UseVirtFs_false, |
287 |
|
|
SkipError_false); |
288 |
|
|
|
289 |
|
|
log->log("set mode to %d", CAST_S32(openGLMode)); |
290 |
|
|
|
291 |
|
|
// searched values |
292 |
|
|
mConfig.setValue("opengl", CAST_S32(openGLMode)); |
293 |
|
|
mConfig.setValue("showBackground", rescale == 0); |
294 |
|
|
mConfig.setValue("sound", sound == 0); |
295 |
|
|
|
296 |
|
|
// better performance |
297 |
|
|
mConfig.setValue("hwaccel", true); |
298 |
|
|
mConfig.setValue("fpslimit", 60); |
299 |
|
|
mConfig.setValue("altfpslimit", 2); |
300 |
|
|
mConfig.setValue("safemode", false); |
301 |
|
|
mConfig.setValue("enableMapReduce", true); |
302 |
|
|
mConfig.setValue("textureSize", textureSize); |
303 |
|
|
|
304 |
|
|
// max batch size |
305 |
|
|
// mConfig.setValue("batchsize", batchSize); |
306 |
|
|
|
307 |
|
|
// additional modes |
308 |
|
|
mConfig.setValue("useTextureSampler", |
309 |
|
|
static_cast<bool>(detectMode & 1024)); |
310 |
|
|
mConfig.setValue("compresstextures", |
311 |
|
|
static_cast<bool>(detectMode & 2048)); |
312 |
|
|
|
313 |
|
|
// stats |
314 |
|
|
mConfig.setValue("testInfo", info); |
315 |
|
|
|
316 |
|
|
mConfig.write(); |
317 |
|
|
} |
318 |
|
|
|
319 |
|
|
int TestMain::readValue2(const int ver) |
320 |
|
|
{ |
321 |
|
|
const int def = readValue(ver, 0); |
322 |
|
|
log->log("value for %d = %d", ver, def); |
323 |
|
|
return def; |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
int TestMain::readValue(const int ver, int def) |
327 |
|
|
{ |
328 |
|
|
std::string tmp; |
329 |
|
|
int var; |
330 |
|
|
std::ifstream file; |
331 |
|
|
file.open(pathJoin(settings.localDataDir, "test.log").c_str(), |
332 |
|
|
std::ios::in); |
333 |
|
|
if (!getline(file, tmp)) |
334 |
|
|
{ |
335 |
|
|
file.close(); |
336 |
|
|
return def; |
337 |
|
|
} |
338 |
|
|
var = atoi(tmp.c_str()); |
339 |
|
|
if (ver != var || !getline(file, tmp)) |
340 |
|
|
{ |
341 |
|
|
file.close(); |
342 |
|
|
return def; |
343 |
|
|
} |
344 |
|
|
def = atoi(tmp.c_str()); |
345 |
|
|
file.close(); |
346 |
|
|
return def; |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
int TestMain::invokeTest(const std::string &test) |
350 |
|
|
{ |
351 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_SOFTWARE)); |
352 |
|
|
|
353 |
|
|
mConfig.write(); |
354 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 0); |
355 |
|
|
return ret; |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
int TestMain::invokeTest4() |
359 |
|
|
{ |
360 |
|
|
mConfig.setValue("sound", true); |
361 |
|
|
const int ret = invokeTest("4"); |
362 |
|
|
|
363 |
|
|
log->log("4: %d", ret); |
364 |
|
|
return ret; |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
int TestMain::invokeSoftwareRenderTest(const std::string &test) |
368 |
|
|
{ |
369 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_SOFTWARE)); |
370 |
|
|
mConfig.write(); |
371 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
372 |
|
|
log->log("%s: %d", test.c_str(), ret); |
373 |
|
|
return ret; |
374 |
|
|
} |
375 |
|
|
|
376 |
|
|
int TestMain::invokeNormalOpenGLRenderTest(const std::string &test) |
377 |
|
|
{ |
378 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL)); |
379 |
|
|
mConfig.write(); |
380 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
381 |
|
|
log->log("%s: %d", test.c_str(), ret); |
382 |
|
|
return ret; |
383 |
|
|
} |
384 |
|
|
|
385 |
|
|
int TestMain::invokeModernOpenGLRenderTest(const std::string &test) |
386 |
|
|
{ |
387 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_MODERN_OPENGL)); |
388 |
|
|
mConfig.write(); |
389 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
390 |
|
|
log->log("%s: %d", test.c_str(), ret); |
391 |
|
|
return ret; |
392 |
|
|
} |
393 |
|
|
|
394 |
|
|
int TestMain::invokeNormalOpenBatchTest(const std::string &test) |
395 |
|
|
{ |
396 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_NORMAL_OPENGL)); |
397 |
|
|
mConfig.write(); |
398 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
399 |
|
|
// log->log("%s: %d", test.c_str(), ret); |
400 |
|
|
return ret; |
401 |
|
|
} |
402 |
|
|
|
403 |
|
|
int TestMain::invokeModernOpenBatchTest(const std::string &test) |
404 |
|
|
{ |
405 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_MODERN_OPENGL)); |
406 |
|
|
mConfig.write(); |
407 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
408 |
|
|
// log->log("%s: %d", test.c_str(), ret); |
409 |
|
|
return ret; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
int TestMain::invokeMobileOpenBatchTest(const std::string &test) |
413 |
|
|
{ |
414 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_GLES_OPENGL)); |
415 |
|
|
mConfig.write(); |
416 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
417 |
|
|
// log->log("%s: %d", test.c_str(), ret); |
418 |
|
|
return ret; |
419 |
|
|
} |
420 |
|
|
|
421 |
|
|
int TestMain::invokeSafeOpenBatchTest(const std::string &test) |
422 |
|
|
{ |
423 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_SAFE_OPENGL)); |
424 |
|
|
mConfig.write(); |
425 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
426 |
|
|
// log->log("%s: %d", test.c_str(), ret); |
427 |
|
|
return ret; |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
int TestMain::invokeSafeOpenGLRenderTest(const std::string &test) |
431 |
|
|
{ |
432 |
|
|
mConfig.setValue("opengl", CAST_S32(RENDER_SAFE_OPENGL)); |
433 |
|
|
mConfig.write(); |
434 |
|
|
const int ret = execFileWait(fileName, fileName, "-t", test, 30); |
435 |
|
|
log->log("%s: %d", test.c_str(), ret); |
436 |
|
|
return ret; |
437 |
|
2 |
} |
438 |
|
|
#endif // USE_OPENGL |