diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-05-18 01:57:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-05-19 00:31:16 +0300 |
commit | 804154afbee8843dde358837ec18ab7bfb785088 (patch) | |
tree | d0b58bea9b13e37dc44c7bf9487d3cde2a7991f6 /src | |
parent | f35d6cd35d92ad16a55bf49f61f19153949497c0 (diff) | |
download | manaverse-804154afbee8843dde358837ec18ab7bfb785088.tar.gz manaverse-804154afbee8843dde358837ec18ab7bfb785088.tar.bz2 manaverse-804154afbee8843dde358837ec18ab7bfb785088.tar.xz manaverse-804154afbee8843dde358837ec18ab7bfb785088.zip |
Add button "detect best video mode" in video settings (windows only).
Diffstat (limited to 'src')
-rw-r--r-- | src/graphicsmanager.cpp | 11 | ||||
-rw-r--r-- | src/graphicsmanager.h | 2 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 45 | ||||
-rw-r--r-- | src/gui/setup_video.h | 2 | ||||
-rw-r--r-- | src/test/testlauncher.cpp | 1 | ||||
-rw-r--r-- | src/test/testmain.cpp | 101 | ||||
-rw-r--r-- | src/test/testmain.h | 14 | ||||
-rw-r--r-- | src/utils/paths.cpp | 11 |
8 files changed, 111 insertions, 76 deletions
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 68a2ac48d..e9360d88c 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -20,6 +20,7 @@ #include "graphicsmanager.h" +#include "client.h" #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" @@ -31,6 +32,8 @@ #include "utils/process.h" #include "utils/stringutils.h" +#include "test/testmain.h" + #include "debug.h" GraphicsManager graphicsManager; @@ -43,6 +46,14 @@ GraphicsManager::~GraphicsManager() { } +bool GraphicsManager::startDetection() +{ + std::string fileName = getSelfName(); + TestMain *test = new TestMain(); + test->exec(false); + return test->getConfig().getValueInt("opengl", -1); +} + bool GraphicsManager::detectGraphics() { #ifdef USE_OPENGL diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index 9c892b80d..91af198a5 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -35,6 +35,8 @@ class GraphicsManager void initGraphics(bool noOpenGL); + bool startDetection(); + bool detectGraphics(); void updateExtensions(const char *extensions); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index a416b2027..466c04e6c 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -25,6 +25,11 @@ #include "configuration.h" #include "game.h" #include "graphics.h" + +#ifdef WIN32 +#include "graphicsmanager.h" +#endif + #include "localplayer.h" #include "logger.h" #include "main.h" @@ -33,6 +38,7 @@ #include "gui/okdialog.h" #include "gui/textdialog.h" +#include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" @@ -51,6 +57,8 @@ #include <guichan/key.hpp> #include <guichan/listmodel.hpp> +#include <guichan/widgets/button.hpp> + #include <SDL.h> #include <algorithm> @@ -232,6 +240,11 @@ Setup_Video::Setup_Video(): mFpsLabel(new Label), mAltFpsSlider(new Slider(2, 160)), mAltFpsLabel(new Label(_("Alt FPS limit: "))), +#ifdef WIN32 + mDetectButton(new Button(_("Dettect best mode"), "detect", this)), +#else + mDetectButton(nullptr), +#endif mDialog(nullptr) { setName(_("Video")); @@ -298,14 +311,6 @@ Setup_Video::Setup_Video(): place(1, 2, mEnableResizeCheckBox, 2); place(1, 3, mNoFrameCheckBox, 2); - -// place(1, 5, mPickupNotifyLabel, 4); -// place(1, 6, mPickupChatCheckBox, 1); -// place(2, 6, mPickupParticleCheckBox, 2); - -// place(0, 7, mAlphaSlider); -// place(1, 7, alphaLabel, 3); - place(0, 6, mFpsSlider); place(1, 6, mFpsCheckBox).setPadding(3); place(2, 6, mFpsLabel).setPadding(1); @@ -313,19 +318,9 @@ Setup_Video::Setup_Video(): place(0, 7, mAltFpsSlider); place(1, 7, mAltFpsLabel).setPadding(3); -// place(0, 11, mSpeechSlider); -// place(1, 11, speechLabel); -// place(2, 11, mSpeechLabel, 3).setPadding(2); - -// place(0, 12, mOverlayDetailSlider); -// place(1, 12, overlayDetailLabel); -// place(2, 12, mOverlayDetailField, 3).setPadding(2); - -// place(0, 13, mParticleEffectsCheckBox, 5); - -// place(0, 14, mParticleDetailSlider); -// place(1, 14, particleDetailLabel); -// place(2, 14, mParticleDetailField, 3).setPadding(2); +#ifdef WIN32 + place(0, 8, mDetectButton); +#endif int width = 600; @@ -560,6 +555,14 @@ void Setup_Video::action(const gcn::ActionEvent &event) { config.setValue("noframe", mNoFrameCheckBox->isSelected()); } +#ifdef WIN32 + else if (id == "detect") + { + int val = graphicsManager.startDetection(); + if (val >= 0 && val <= 2) + mOpenGLDropDown->setSelected(val); + } +#endif } void Setup_Video::externalUpdated() diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 7443087f7..84b1084c7 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -36,6 +36,7 @@ class TextDialog; namespace gcn { + class Button; class CheckBox; class DropDown; class Label; @@ -86,6 +87,7 @@ class Setup_Video : public SetupTab, public gcn::KeyListener gcn::Slider *mAltFpsSlider; gcn::Label *mAltFpsLabel; + gcn::Button *mDetectButton; TextDialog *mDialog; }; diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index b3fa729a0..84caf5afd 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -215,6 +215,7 @@ int TestLauncher::testVideoDetection() graphicsManager.detectGraphics(); file << mTest << std::endl; file << config.getIntValue("opengl") << std::endl; + return 0; } int TestLauncher::calcFps(timeval *start, timeval *end, int calls) diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp index 8ec48e6e2..57c5ac45f 100644 --- a/src/test/testmain.cpp +++ b/src/test/testmain.cpp @@ -23,7 +23,6 @@ #include "utils/gettext.h" #include "client.h" -#include "configuration.h" #include "localconsts.h" #include "utils/gettext.h" @@ -41,11 +40,7 @@ extern char *selfName; TestMain::TestMain() { -#ifdef WIN32 - fileName = "manaplus.exe"; -#else fileName = getSelfName(); -#endif log = new Logger; // log->setLogFile(Client::getLocalDataDirectory() @@ -56,25 +51,25 @@ TestMain::TestMain() void TestMain::initConfig() { - config.init(Client::getConfigDirectory() + "/test.xml"); -// config.setDefaultValues(getConfigDefaults()); - - config.setValue("hwaccel", false); - config.setValue("screen", false); - config.setValue("sound", false); - config.setValue("guialpha", 0.8f); -// config.setValue("remember", true); - config.setValue("sfxVolume", 50); - config.setValue("musicVolume", 60); - config.setValue("fpslimit", 0); - config.setValue("customcursor", true); - config.setValue("useScreenshotDirectorySuffix", true); - config.setValue("ChatLogLength", 128); - config.setValue("screenwidth", 800); - config.setValue("screenheight", 600); + mConfig.init(Client::getConfigDirectory() + "/test.xml"); +// mConfig.setDefaultValues(getConfigDefaults()); + + mConfig.setValue("hwaccel", false); + mConfig.setValue("screen", false); + mConfig.setValue("sound", false); + mConfig.setValue("guialpha", 0.8f); +// mConfig.setValue("remember", true); + mConfig.setValue("sfxVolume", 50); + mConfig.setValue("musicVolume", 60); + mConfig.setValue("fpslimit", 0); + mConfig.setValue("customcursor", true); + mConfig.setValue("useScreenshotDirectorySuffix", true); + mConfig.setValue("ChatLogLength", 128); + mConfig.setValue("screenwidth", 800); + mConfig.setValue("screenheight", 600); } -int TestMain::exec() +int TestMain::exec(bool testAudio) { initConfig(); int softwareTest = invokeSoftwareRenderTest("1"); @@ -97,11 +92,14 @@ int TestMain::exec() videoDetectTest = invokeTest("99"); if (!videoDetectTest) - detectMode = readValue(99); + detectMode = readValue2(99); fastOpenGLTest = invokeFastOpenGLRenderTest("2"); safeOpenGLTest = invokeSafeOpenGLRenderTest("3"); - soundTest = invokeTest4(); + if (testAudio) + soundTest = invokeTest4(); + else + soundTest = true; info += strprintf("%d.%d,%d,%d.", soundTest, softwareTest, fastOpenGLTest, safeOpenGLTest); @@ -112,7 +110,7 @@ int TestMain::exec() info += strprintf ("%d", softFpsTest); if (!softFpsTest) { - softFps = readValue(8); + softFps = readValue2(8); info += strprintf (",%d", softFps); if (!softFps) { @@ -137,7 +135,7 @@ int TestMain::exec() info += strprintf ("%d", fastOpenGLFpsTest); if (!fastOpenGLFpsTest) { - fastOpenGLFps = readValue(9); + fastOpenGLFps = readValue2(9); info += strprintf (",%d", fastOpenGLFps); if (!fastOpenGLFps) { @@ -162,7 +160,7 @@ int TestMain::exec() info += strprintf ("%d", safeOpenGLFpsTest); if (!safeOpenGLFpsTest) { - safeOpenGLFps = readValue(10); + safeOpenGLFps = readValue2(10); info += strprintf (",%d", safeOpenGLFps); if (!safeOpenGLFps) { @@ -205,30 +203,38 @@ int TestMain::exec() void TestMain::writeConfig(int openGLMode, int rescale, int sound, std::string info) { - config.init(Client::getConfigDirectory() + "/config.xml"); + mConfig.init(Client::getConfigDirectory() + "/config.xml"); // searched values - config.setValue("opengl", openGLMode); - config.setValue("showBackground", !rescale); - config.setValue("sound", !sound); + mConfig.setValue("opengl", openGLMode); + mConfig.setValue("showBackground", !rescale); + mConfig.setValue("sound", !sound); // better perfomance - config.setValue("hwaccel", true); - config.setValue("fpslimit", 60); - config.setValue("altfpslimit", 2); - config.setValue("safemode", false); - config.setValue("enableMapReduce", true); + mConfig.setValue("hwaccel", true); + mConfig.setValue("fpslimit", 60); + mConfig.setValue("altfpslimit", 2); + mConfig.setValue("safemode", false); + mConfig.setValue("enableMapReduce", true); // stats - config.setValue("testInfo", info); + mConfig.setValue("testInfo", info); + + mConfig.write(); +} - config.write(); +int TestMain::readValue2(int ver) +{ + int def = readValue(ver, 0); + log->log("value for %d = %d", ver, def); + return 0; } int TestMain::readValue(int ver, int def) { std::string tmp; int var; + std::ifstream file; file.open((Client::getLocalDataDirectory() + std::string("/test.log")).c_str(), std::ios::in); if (!getline(file, tmp)) @@ -244,22 +250,21 @@ int TestMain::readValue(int ver, int def) } def = atoi(tmp.c_str()); file.close(); - log->log("value for %d = %d", ver, def); return def; } int TestMain::invokeTest(std::string test) { - config.setValue("opengl", 0); + mConfig.setValue("opengl", 0); - config.write(); + mConfig.write(); int ret = execFile(fileName, fileName, "-t", test); return ret; } int TestMain::invokeTest4() { - config.setValue("sound", true); + mConfig.setValue("sound", true); int ret = invokeTest("4"); log->log("4: %d", ret); @@ -268,8 +273,8 @@ int TestMain::invokeTest4() int TestMain::invokeSoftwareRenderTest(std::string test) { - config.setValue("opengl", 0); - config.write(); + mConfig.setValue("opengl", 0); + mConfig.write(); int ret = execFile(fileName, fileName, "-t", test, 30); log->log("%s: %d", test.c_str(), ret); return ret; @@ -278,8 +283,8 @@ int TestMain::invokeSoftwareRenderTest(std::string test) int TestMain::invokeFastOpenGLRenderTest(std::string test) { #if defined USE_OPENGL - config.setValue("opengl", 1); - config.write(); + mConfig.setValue("opengl", 1); + mConfig.write(); int ret = execFile(fileName, fileName, "-t", test, 30); log->log("%s: %d", test.c_str(), ret); return ret; @@ -291,8 +296,8 @@ int TestMain::invokeFastOpenGLRenderTest(std::string test) int TestMain::invokeSafeOpenGLRenderTest(std::string test) { #if defined USE_OPENGL - config.setValue("opengl", 2); - config.write(); + mConfig.setValue("opengl", 2); + mConfig.write(); int ret = execFile(fileName, fileName, "-t", test, 30); log->log("%s: %d", test.c_str(), ret); return ret; diff --git a/src/test/testmain.h b/src/test/testmain.h index 8e5ce162f..281cdab3a 100644 --- a/src/test/testmain.h +++ b/src/test/testmain.h @@ -21,6 +21,7 @@ #ifndef TEST_TESTMAIN_H #define TEST_TESTMAIN_H +#include "configuration.h" #include "logger.h" #include <string> @@ -30,13 +31,16 @@ class TestMain public: TestMain(); - int exec(); + int exec(bool testAudio = true); + + static int readValue(int ver, int def); + + Configuration &getConfig() + { return mConfig; } private: void initConfig(); - int readValue(int ver, int def = 0); - int invokeTest(std::string test); int invokeTest3(); @@ -56,9 +60,11 @@ class TestMain void writeConfig(int openGLMode, int rescale, int sound, std::string info); + int readValue2(int ver); + Logger *log; - std::ifstream file; + Configuration mConfig; }; #endif // TEST_TESTMAIN_H diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 306955cb3..c00a3f39d 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -96,14 +96,13 @@ std::string removeLast(std::string str) #ifdef WIN32 std::string getSelfName() { - // GetModuleFileName(nullptr) - return ""; + return "manaplus.exe"; } #elif defined(__APPLE__) std::string getSelfName() { - return ""; + return "manaplus.exe"; } #elif defined __linux__ || defined __linux @@ -124,4 +123,10 @@ std::string getSelfName() } } +#else +std::string getSelfName() +{ + return ""; +} + #endif |