GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/maingui.cpp Lines: 8 8 100.0 %
Date: 2017-11-29 Branches: 6 12 50.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "maingui.h"
24
25
#include "client.h"
26
#include "commandline.h"
27
#include "settings.h"
28
29
#include "fs/virtfs/fs.h"
30
31
#include "utils/delete2.h"
32
#ifdef ANDROID
33
#include "fs/mkdir.h"
34
#include "fs/paths.h"
35
#endif  // ANDROID
36
#include "utils/process.h"
37
38
#ifdef __MINGW32__
39
#include <windows.h>
40
#endif  // __MINGW32__
41
42
#include <iostream>
43
44
PRAGMA48(GCC diagnostic push)
45
PRAGMA48(GCC diagnostic ignored "-Wshadow")
46
#include <SDL_image.h>
47
#include <SDL_mixer.h>
48
PRAGMA48(GCC diagnostic pop)
49
50
#ifndef SDL_VERSIONNUM
51
#error missing <SDL_version.h>
52
#endif  // SDL_VERSIONNUM
53
54
#ifdef UNITTESTS
55
#include "logger.h"
56
57
#include "utils/cpu.h"
58
#include "utils/sdlhelper.h"
59
#include "resources/dye/dyepalette.h"
60
#ifdef UNITTESTS_CATCH
61
#define CATCH_CONFIG_RUNNER
62
#ifdef UNITTESTS_EMBED
63
#include "unittests/catch.hpp"
64
#else  // UNITTESTS_EMBED
65
#include <catch.hpp>
66
#endif  // UNITTESTS_EMBED
67
#endif  // UNITTESTS_CATCH
68
#ifdef UNITTESTS_DOCTEST
69
#define DOCTEST_CONFIG_IMPLEMENT
70
#ifdef UNITTESTS_EMBED
71
#include "unittests/doctest.h"
72
#else  // UNITTESTS_EMBED
73
#include <doctest/doctest.h>
74
#endif  // UNITTESTS_EMBED
75
#endif  // UNITTESTS_DOCTEST
76
#else  // UNITTESTS
77
#include "utils/xml.h"
78
#endif  // UNITTESTS
79
80
#define SDL_IMAGE_COMPILEDVERSION \
81
    SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, \
82
    SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL)
83
84
#define SDL_IMAGE_VERSION_ATLEAST(X, Y, Z) \
85
    (SDL_IMAGE_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
86
87
#ifndef SDL_MIXER_COMPILEDVERSION
88
#define SDL_MIXER_COMPILEDVERSION \
89
    SDL_VERSIONNUM(SDL_MIXER_MAJOR_VERSION, \
90
    SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL)
91
#endif  // SDL_MIXER_COMPILEDVERSION
92
93
#ifndef SDL_MIXER_VERSION_ATLEAST
94
#define SDL_MIXER_VERSION_ATLEAST(X, Y, Z) \
95
    (SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
96
#endif  // SDL_MIXER_VERSION_ATLEAST
97
98
#include "debug.h"
99
100
char *selfName = nullptr;
101
102
#ifndef UNITTESTS
103
#ifdef ANDROID
104
int main(int argc, char *argv[])
105
#else  // ANDROID
106
107
int mainGui(int argc, char *argv[])
108
#endif  // ANDROID
109
{
110
#if defined(__MINGW32__)
111
    // load mingw crash handler. Won't fail if dll is not present.
112
    // may load libray from current dir, it may not same as program dir
113
    LoadLibrary("exchndl.dll");
114
#endif  // defined(__MINGW32__)
115
116
    selfName = argv[0];
117
118
    parseOptions(argc, argv);
119
120
    std::ios::sync_with_stdio(false);
121
122
#ifdef ANDROID
123
    mkdir_r(getSdStoragePath().c_str());
124
#endif  // ANDROID
125
126
    VirtFs::init(argv[0]);
127
    XML::initXML();
128
#if SDL_IMAGE_VERSION_ATLEAST(1, 2, 11)
129
    IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
130
#endif  // SDL_IMAGE_VERSION_ATLEAST(1, 2, 11)
131
#if SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
132
    Mix_Init(MIX_INIT_OGG);
133
#endif  // SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
134
135
#ifdef WIN32
136
    SetCurrentDirectory(VirtFs::getBaseDir());
137
#endif  // WIN32
138
139
    setPriority(true);
140
    client = new Client;
141
    int ret = 0;
142
    if (!settings.options.testMode)
143
    {
144
        client->gameInit();
145
        ret = client->gameExec();
146
    }
147
    else
148
    {
149
        client->testsInit();
150
        ret = Client::testsExec();
151
    }
152
    delete2(client);
153
    VirtFs::deinit();
154
155
#if SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
156
    Mix_Quit();
157
#endif  // SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
158
#if SDL_IMAGE_VERSION_ATLEAST(1, 2, 11)
159
    IMG_Quit();
160
#endif  // SDL_IMAGE_VERSION_ATLEAST(1, 2, 11)
161
162
    return ret;
163
}
164
#else  // UNITTESTS
165
166
2
int main(int argc, char *argv[])
167
{
168
2
    logger = new Logger;
169
2
    SDL::initLogger();
170

8
    VirtFs::init(argv[0]);
171
2
    Cpu::detect();
172
2
    DyePalette::initFunctions();
173
#ifdef UNITTESTS_CATCH
174
2
    return Catch::Session().run(argc, argv);
175
#elif defined(UNITTESTS_DOCTEST)
176
    doctest::Context context;
177
    context.applyCommandLine(argc, argv);
178
    return context.run();
179
#else  // UNITTESTS_CATCH
180
    return 1;
181
#endif  // UNITTESTS_CATCH
182

6
}
183
184
#endif  // UNITTESTS