GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/env.cpp Lines: 3 16 18.8 %
Date: 2017-11-29 Branches: 2 13 15.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "utils/env.h"
22
23
#include "configuration.h"
24
#include "logger.h"
25
#include "settings.h"
26
27
#include "debug.h"
28
29
void updateEnv()
30
{
31
#if defined(WIN32) || defined(__APPLE__)
32
    if (config.getBoolValue("centerwindow"))
33
        setEnv("SDL_VIDEO_CENTERED", "1");
34
    else
35
        setEnv("SDL_VIDEO_CENTERED", "0");
36
#endif  // defined(WIN32) || defined(__APPLE__)
37
38
#ifndef WIN32
39
    const int vsync = settings.options.test.empty()
40
        ? config.getIntValue("vsync") : 1;
41
    // __GL_SYNC_TO_VBLANK is nvidia variable.
42
    // vblank_mode is MESA variable.
43
    switch (vsync)
44
    {
45
        case 1:
46
            setEnv("__GL_SYNC_TO_VBLANK", "0");
47
            setEnv("vblank_mode", "0");
48
            break;
49
        case 2:
50
            setEnv("__GL_SYNC_TO_VBLANK", "1");
51
            setEnv("vblank_mode", "2");
52
            break;
53
        default:
54
            break;
55
    }
56
#endif  // WIN32
57
}
58
59
462
void setEnv(const char *const name, const char *const value)
60
{
61
462
    if ((name == nullptr) || (value == nullptr))
62
        return;
63
#ifdef WIN32
64
    if (putenv(const_cast<char*>((std::string(name)
65
        + "=" + value).c_str())))
66
#else  // WIN32
67
68
462
    if (setenv(name, value, 1) != 0)
69
#endif  // WIN32
70
    {
71
        logger->log("setenv failed: %s=%s", name, value);
72
    }
73
}