diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-06-27 23:36:53 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-06-27 23:36:53 +0300 |
commit | b2e94802333247f64369c1164215d26583abda20 (patch) | |
tree | 1721dc1f97f6c27f8b3d2bcae81a854573a281c5 /src/utils | |
parent | 610b13d188cd3faf99b971eea58594b336a57edd (diff) | |
download | manaverse-b2e94802333247f64369c1164215d26583abda20.tar.gz manaverse-b2e94802333247f64369c1164215d26583abda20.tar.bz2 manaverse-b2e94802333247f64369c1164215d26583abda20.tar.xz manaverse-b2e94802333247f64369c1164215d26583abda20.zip |
Move environment functions into separate file.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/env.cpp | 79 | ||||
-rw-r--r-- | src/utils/env.h | 30 | ||||
-rw-r--r-- | src/utils/gettexthelper.cpp | 5 |
3 files changed, 112 insertions, 2 deletions
diff --git a/src/utils/env.cpp b/src/utils/env.cpp new file mode 100644 index 000000000..9ef3d67d0 --- /dev/null +++ b/src/utils/env.cpp @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "utils/env.h" + +#include "configuration.h" +#include "logger.h" +#include "settings.h" + +#include <stdlib.h> + +#include "debug.h" + +void updateEnv() +{ +#if defined(WIN32) || defined(__APPLE__) + if (config.getBoolValue("centerwindow")) + setEnv("SDL_VIDEO_CENTERED", "1"); + else + setEnv("SDL_VIDEO_CENTERED", "0"); +#endif + + if (config.getBoolValue("allowscreensaver")) + setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1"); + else + setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0"); + +#ifndef WIN32 + const int vsync = settings.options.test.empty() + ? config.getIntValue("vsync") : 1; + // __GL_SYNC_TO_VBLANK is nvidia variable. + // vblank_mode is MESA variable. + switch (vsync) + { + case 1: + setEnv("__GL_SYNC_TO_VBLANK", "0"); + setEnv("vblank_mode", "0"); + break; + case 2: + setEnv("__GL_SYNC_TO_VBLANK", "1"); + setEnv("vblank_mode", "1"); + break; + default: + break; + } +#endif +} + +void setEnv(const char *const name, const char *const value) +{ + if (!name || !value) + return; +#ifdef WIN32 + if (putenv(const_cast<char*>((std::string(name) + + "=" + value).c_str()))) +#else + if (setenv(name, value, 1)) +#endif + { + logger->log("setenv failed: %s=%s", name, value); + } +} diff --git a/src/utils/env.h b/src/utils/env.h new file mode 100644 index 000000000..8619ee375 --- /dev/null +++ b/src/utils/env.h @@ -0,0 +1,30 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef UTILS_ENV_H +#define UTILS_ENV_H + +#include "localconsts.h" + +void setEnv(const char *const name, const char *const value); + +void updateEnv(); + +#endif // UTILS_ENV_H diff --git a/src/utils/gettexthelper.cpp b/src/utils/gettexthelper.cpp index 9fa1dc3e0..b4cb8af57 100644 --- a/src/utils/gettexthelper.cpp +++ b/src/utils/gettexthelper.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include "logger.h" +#include "utils/env.h" #include "utils/physfstools.h" #include <libintl.h> @@ -54,8 +55,8 @@ void GettextHelper::initLang() if (!lang.empty()) { - Client::setEnv("LANG", lang.c_str()); - Client::setEnv("LANGUAGE", lang.c_str()); + setEnv("LANG", lang.c_str()); + setEnv("LANGUAGE", lang.c_str()); } #ifdef ANDROID #ifdef USE_SDL2 |