GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/mapdebugtab.cpp Lines: 35 87 40.2 %
Date: 2021-03-17 Branches: 46 167 27.5 %

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-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "gui/widgets/tabs/mapdebugtab.h"
25
26
#include "game.h"
27
28
#include "being/localplayer.h"
29
30
#include "particle/particleengine.h"
31
32
#include "gui/viewport.h"
33
34
#include "gui/widgets/containerplacer.h"
35
#include "gui/widgets/label.h"
36
#include "gui/widgets/layouthelper.h"
37
38
#ifdef USE_OPENGL
39
#include "resources/imagehelper.h"
40
#endif  // USE_OPENGL
41
42
#include "resources/map/map.h"
43
44
#include "utils/gettext.h"
45
#include "utils/stringutils.h"
46
#include "utils/timer.h"
47
48
#include "debug.h"
49
50
2
MapDebugTab::MapDebugTab(const Widget2 *const widget) :
51
    DebugTab(widget),
52
    // TRANSLATORS: debug window label
53

4
    mMusicFileLabel(new Label(this, _("Music:"))),
54
    // TRANSLATORS: debug window label
55

4
    mMapLabel(new Label(this, _("Map:"))),
56
    // TRANSLATORS: debug window label
57

4
    mMapNameLabel(new Label(this, _("Map name:"))),
58
    // TRANSLATORS: debug window label
59

4
    mMinimapLabel(new Label(this, _("Minimap:"))),
60
4
    mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
61
        // TRANSLATORS: debug window label
62

2
        _("Cursor:"), 0, 0))),
63
4
    mParticleCountLabel(new Label(this, strprintf("%s %d",
64
        // TRANSLATORS: debug window label
65

2
        _("Particle count:"), 88888))),
66
4
    mMapActorCountLabel(new Label(this, strprintf("%s %d",
67
        // TRANSLATORS: debug window label
68

2
        _("Map actors count:"), 88888))),
69
#ifdef USE_OPENGL
70
4
    mMapAtlasCountLabel(new Label(this, strprintf("%s %d",
71
        // TRANSLATORS: debug window label
72

2
        _("Map atlas count:"), 88888))),
73
#endif  // USE_OPENGL
74
    // TRANSLATORS: debug window label
75

4
    mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
76
    mTexturesLabel(nullptr),
77
    mUpdateTime(0),
78
#ifdef DEBUG_DRAW_CALLS
79
    mDrawCallsLabel(new Label(this, strprintf("%s %s",
80
        // TRANSLATORS: debug window label
81
        _("Draw calls:"), "?"))),
82
#endif  // DEBUG_DRAW_CALLS
83
#ifdef DEBUG_BIND_TEXTURE
84
    mBindsLabel(new Label(this, strprintf("%s %s",
85
        // TRANSLATORS: debug window label
86
        _("Texture binds:"), "?"))),
87
#endif  // DEBUG_BIND_TEXTURE
88
    // TRANSLATORS: debug window label, frames per second
89

4
    mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
90


54
    mFPSText()
91
{
92
4
    LayoutHelper h(this);
93
2
    ContainerPlacer place = h.getPlacer(0, 0);
94
95
#ifdef USE_OPENGL
96

2
    switch (imageHelper->useOpenGL())
97
    {
98
        case RENDER_SOFTWARE:
99
            // TRANSLATORS: debug window label
100
2
            mFPSText = _("%d FPS (Software)");
101
            break;
102
        case RENDER_NORMAL_OPENGL:
103
        case RENDER_NULL:
104
        case RENDER_LAST:
105
        default:
106
            // TRANSLATORS: debug window label
107
            mFPSText = _("%d FPS (normal OpenGL)");
108
            break;
109
        case RENDER_SAFE_OPENGL:
110
            // TRANSLATORS: debug window label
111
            mFPSText = _("%d FPS (safe OpenGL)");
112
            break;
113
        case RENDER_GLES_OPENGL:
114
            // TRANSLATORS: debug window label
115
            mFPSText = _("%d FPS (mobile OpenGL ES)");
116
            break;
117
        case RENDER_GLES2_OPENGL:
118
            // TRANSLATORS: debug window label
119
            mFPSText = _("%d FPS (mobile OpenGL ES 2)");
120
            break;
121
        case RENDER_MODERN_OPENGL:
122
            // TRANSLATORS: debug window label
123
            mFPSText = _("%d FPS (modern OpenGL)");
124
            break;
125
        case RENDER_SDL2_DEFAULT:
126
            // TRANSLATORS: debug window label
127
            mFPSText = _("%d FPS (SDL2 default)");
128
            break;
129
    }
130
#else  // USE_OPENGL
131
132
    // TRANSLATORS: debug window label
133
    mFPSText = _("%d FPS (Software)");
134
#endif  // USE_OPENGL
135
136
2
    place(0, 0, mFPSLabel, 2, 1);
137
2
    place(0, 1, mMusicFileLabel, 2, 1);
138
2
    place(0, 2, mMapLabel, 2, 1);
139
2
    place(0, 3, mMapNameLabel, 2, 1);
140
2
    place(0, 4, mMinimapLabel, 2, 1);
141
2
    place(0, 5, mXYLabel, 2, 1);
142
2
    place(0, 6, mTileMouseLabel, 2, 1);
143
2
    place(0, 7, mParticleCountLabel, 2, 1);
144
2
    place(0, 8, mMapActorCountLabel, 2, 1);
145
#ifdef USE_OPENGL
146
2
    place(0, 9, mMapAtlasCountLabel, 2, 1);
147
#if defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS) \
148
    || defined(DEBUG_BIND_TEXTURE)
149
    int n = 10;
150
#endif  // defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS)
151
        // || defined(DEBUG_BIND_TEXTURE)
152
#ifdef DEBUG_OPENGL_LEAKS
153
    mTexturesLabel = new Label(this, strprintf("%s %s",
154
        // TRANSLATORS: debug window label
155
        _("Textures count:"), "?"));
156
    place(0, n, mTexturesLabel, 2, 1);
157
    n ++;
158
#endif  // DEBUG_OPENGL_LEAKS
159
#ifdef DEBUG_DRAW_CALLS
160
    place(0, n, mDrawCallsLabel, 2, 1);
161
    n ++;
162
#endif  // DEBUG_DRAW_CALLS
163
#ifdef DEBUG_BIND_TEXTURE
164
    place(0, n, mBindsLabel, 2, 1);
165
#endif  // DEBUG_BIND_TEXTURE
166
#endif  // USE_OPENGL
167
168
2
    place.getCell().matchColWidth(0, 0);
169
2
    place = h.getPlacer(0, 1);
170
2
    setDimension(Rect(0, 0, 600, 300));
171
2
}
172
173
void MapDebugTab::logic()
174
{
175
    BLOCK_START("MapDebugTab::logic")
176
    if (localPlayer != nullptr)
177
    {
178
        // TRANSLATORS: debug window label
179
        mXYLabel->setCaption(strprintf("%s (%d, %d)", _("Player Position:"),
180
            localPlayer->getTileX(), localPlayer->getTileY()));
181
    }
182
    else
183
    {
184
        // TRANSLATORS: debug window label
185
        mXYLabel->setCaption(strprintf("%s (?, ?)", _("Player Position:")));
186
    }
187
188
    Game *const game = Game::instance();
189
    const Map *const map = game != nullptr ? game->getCurrentMap() : nullptr;
190
    if (map != nullptr &&
191
        viewport != nullptr)
192
    {
193
          // Get the current mouse position
194
        const int mouseTileX = (viewport->mMouseX + viewport->getCameraX())
195
                         / map->getTileWidth();
196
        const int mouseTileY = (viewport->mMouseY + viewport->getCameraY())
197
                         / map->getTileHeight();
198
        mTileMouseLabel->setCaption(strprintf("%s (%d, %d)",
199
            // TRANSLATORS: debug window label
200
            _("Cursor:"), mouseTileX, mouseTileY));
201
202
        // TRANSLATORS: debug window label
203
        mMusicFileLabel->setCaption(strprintf("%s %s", _("Music:"),
204
            map->getProperty("music", std::string()).c_str()));
205
        // TRANSLATORS: debug window label
206
        mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
207
            map->getProperty("minimap", std::string()).c_str()));
208
        // TRANSLATORS: debug window label
209
        mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
210
            map->getProperty("_realfilename", std::string()).c_str()));
211
        // TRANSLATORS: debug window label
212
        mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
213
            map->getProperty("name", std::string()).c_str()));
214
215
        if (mUpdateTime != cur_time)
216
        {
217
            mUpdateTime = cur_time;
218
            // TRANSLATORS: debug window label
219
            mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
220
                ParticleEngine::particleCount));
221
222
            mMapActorCountLabel->setCaption(
223
                // TRANSLATORS: debug window label
224
                strprintf("%s %d", _("Map actors count:"),
225
                map->getActorsCount()));
226
#ifdef USE_OPENGL
227
            mMapAtlasCountLabel->setCaption(
228
                // TRANSLATORS: debug window label
229
                strprintf("%s %d", _("Map atlas count:"),
230
                map->getAtlasCount()));
231
#ifdef DEBUG_OPENGL_LEAKS
232
            mTexturesLabel->setCaption(strprintf("%s %d",
233
                // TRANSLATORS: debug window label
234
                _("Textures count:"), textures_count));
235
#endif  // DEBUG_OPENGL_LEAKS
236
#ifdef DEBUG_DRAW_CALLS
237
            if (mainGraphics)
238
            {
239
                mDrawCallsLabel->setCaption(strprintf("%s %d",
240
                    // TRANSLATORS: debug window label
241
                    _("Draw calls:"), mainGraphics->getDrawCalls()));
242
            }
243
#endif  // DEBUG_DRAW_CALLS
244
#ifdef DEBUG_BIND_TEXTURE
245
            if (mainGraphics)
246
            {
247
                mBindsLabel->setCaption(strprintf("%s %d",
248
                    // TRANSLATORS: debug window label
249
                    _("Texture binds:"), mainGraphics->getBinds()));
250
            }
251
#endif  // DEBUG_BIND_TEXTURE
252
#endif  // USE_OPENGL
253
        }
254
    }
255
    else
256
    {
257
        // TRANSLATORS: debug window label
258
        mTileMouseLabel->setCaption(strprintf("%s (?, ?)", _("Cursor:")));
259
        // TRANSLATORS: debug window label
260
        mMusicFileLabel->setCaption(strprintf("%s ?", _("Music:")));
261
        // TRANSLATORS: debug window label
262
        mMinimapLabel->setCaption(strprintf("%s ?", _("Minimap:")));
263
        // TRANSLATORS: debug window label
264
        mMapLabel->setCaption(strprintf("%s ?", _("Map:")));
265
        // TRANSLATORS: debug window label
266
        mMapNameLabel->setCaption(strprintf("%s ?", _("Map name:")));
267
        mMapActorCountLabel->setCaption(
268
            // TRANSLATORS: debug window label
269
            strprintf("%s ?", _("Map actors count:")));
270
#ifdef USE_OPENGL
271
        mMapAtlasCountLabel->setCaption(
272
            // TRANSLATORS: debug window label
273
            strprintf("%s ?", _("Map atlas count:")));
274
#endif  // USE_OPENGL
275
    }
276
277
    mMapActorCountLabel->adjustSize();
278
    mParticleCountLabel->adjustSize();
279
#ifdef USE_OPENGL
280
    mMapAtlasCountLabel->adjustSize();
281
#endif  // USE_OPENGL
282
283
    mFPSLabel->setCaption(strprintf(mFPSText.c_str(), fps));
284
    BLOCK_END("MapDebugTab::logic")
285
2
}