GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/mapdebugtab.cpp Lines: 35 87 40.2 %
Date: 2019-10-15 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
 *
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 "gui/widgets/tabs/mapdebugtab.h"
24
25
#include "game.h"
26
27
#include "being/localplayer.h"
28
29
#include "particle/particleengine.h"
30
31
#include "gui/viewport.h"
32
33
#include "gui/widgets/containerplacer.h"
34
#include "gui/widgets/label.h"
35
#include "gui/widgets/layouthelper.h"
36
37
#ifdef USE_OPENGL
38
#include "resources/imagehelper.h"
39
#endif  // USE_OPENGL
40
41
#include "resources/map/map.h"
42
43
#include "utils/gettext.h"
44
#include "utils/stringutils.h"
45
#include "utils/timer.h"
46
47
#include "debug.h"
48
49
2
MapDebugTab::MapDebugTab(const Widget2 *const widget) :
50
    DebugTab(widget),
51
    // TRANSLATORS: debug window label
52

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

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

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

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

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

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

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

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

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

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


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

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