GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/env.cpp Lines: 3 14 21.4 %
Date: 2021-03-17 Branches: 2 17 11.8 %

Line Branch Exec Source
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 "utils/env.h"
23
24
#include "configuration.h"
25
#include "logger.h"
26
#include "settings.h"
27
28
#include "debug.h"
29
30
void updateEnv()
31
{
32
#if defined(WIN32) || defined(__APPLE__)
33
    if (config.getBoolValue("centerwindow"))
34
        setEnv("SDL_VIDEO_CENTERED", "1");
35
    else
36
        setEnv("SDL_VIDEO_CENTERED", "0");
37
#endif  // defined(WIN32) || defined(__APPLE__)
38
39
#ifndef WIN32
40
    const int vsync = settings.options.test.empty()
41
        ? config.getIntValue("vsync") : 1;
42
    // __GL_SYNC_TO_VBLANK is nvidia variable.
43
    // vblank_mode is MESA variable.
44
    switch (vsync)
45
    {
46
        case 1:
47
            setEnv("__GL_SYNC_TO_VBLANK", "0");
48
            setEnv("vblank_mode", "0");
49
            break;
50
        case 2:
51
            setEnv("__GL_SYNC_TO_VBLANK", "1");
52
            setEnv("vblank_mode", "2");
53
            break;
54
        default:
55
            break;
56
    }
57
#endif  // WIN32
58
}
59
60
254
void setEnv(const char *const name, const char *const value)
61
{
62
254
    if ((name == nullptr) || (value == nullptr))
63
        return;
64
#ifdef WIN32
65
    if (putenv(const_cast<char*>((std::string(name)
66
        + "=" + value).c_str())))
67
#else  // WIN32
68
69
254
    if (setenv(name, value, 1) != 0)
70
#endif  // WIN32
71
    {
72
        logger->log("setenv failed: %s=%s", name, value);
73
    }
74
}