summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-27 23:36:53 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-27 23:36:53 +0300
commitb2e94802333247f64369c1164215d26583abda20 (patch)
tree1721dc1f97f6c27f8b3d2bcae81a854573a281c5
parent610b13d188cd3faf99b971eea58594b336a57edd (diff)
downloadmv-b2e94802333247f64369c1164215d26583abda20.tar.gz
mv-b2e94802333247f64369c1164215d26583abda20.tar.bz2
mv-b2e94802333247f64369c1164215d26583abda20.tar.xz
mv-b2e94802333247f64369c1164215d26583abda20.zip
Move environment functions into separate file.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp51
-rw-r--r--src/client.h4
-rw-r--r--src/utils/env.cpp79
-rw-r--r--src/utils/env.h30
-rw-r--r--src/utils/gettexthelper.cpp5
7 files changed, 117 insertions, 56 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 53024f542..4535fa97a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -732,6 +732,8 @@ SET(SRCS
utils/cpu.h
utils/delete2.h
utils/dtor.h
+ utils/env.cpp
+ utils/env.h
utils/files.cpp
utils/files.h
utils/fuzzer.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index daab0c9ad..094d25a33 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -872,6 +872,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
utils/cpu.h \
utils/delete2.h \
utils/dtor.h \
+ utils/env.cpp \
+ utils/env.h \
utils/files.cpp \
utils/files.h \
utils/fuzzer.cpp \
diff --git a/src/client.cpp b/src/client.cpp
index d23ec9586..4028856bf 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -118,6 +118,7 @@
#include "utils/cpu.h"
#include "utils/delete2.h"
+#include "utils/env.h"
#include "utils/fuzzer.h"
#include "utils/gettext.h"
#include "utils/gettexthelper.h"
@@ -505,41 +506,6 @@ void Client::initSoundManager()
"loginMusic", "Magick - Real.ogg"));
}
-void Client::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:
- Client::setEnv("__GL_SYNC_TO_VBLANK", "0");
- Client::setEnv("vblank_mode", "0");
- break;
- case 2:
- Client::setEnv("__GL_SYNC_TO_VBLANK", "1");
- Client::setEnv("vblank_mode", "1");
- break;
- default:
- break;
- }
-#endif
-}
-
void Client::initGraphics()
{
WindowManager::applyVSync();
@@ -555,21 +521,6 @@ void Client::initGraphics()
mainGraphics->beginDraw();
}
-void Client::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);
- }
-}
-
void Client::testsClear()
{
if (!settings.options.test.empty())
diff --git a/src/client.h b/src/client.h
index 791425ae5..880a11fb7 100644
--- a/src/client.h
+++ b/src/client.h
@@ -97,8 +97,6 @@ class Client final : public ConfigListener,
void slowLogic();
- static void setEnv(const char *const name, const char *const value);
-
private:
void initSoundManager();
@@ -106,8 +104,6 @@ class Client final : public ConfigListener,
static void initGraphics();
- static void updateEnv();
-
static void initFeatures();
void gameClear();
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