GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/debugwindowtabs.cpp Lines: 87 206 42.2 %
Date: 2018-05-19 03:07:18 Branches: 128 415 30.8 %

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-2018  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/debugwindowtabs.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 "net/packetcounters.h"
44
45
#include "utils/gettext.h"
46
#include "utils/stringutils.h"
47
#include "utils/timer.h"
48
49
#include "debug.h"
50
51
4
MapDebugTab::MapDebugTab(const Widget2 *const widget) :
52
    DebugTab(widget),
53
    // TRANSLATORS: debug window label
54

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

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

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

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

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

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

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

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

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

8
    mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
91
    // TRANSLATORS: debug window label, logic per second
92

8
    mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0))),
93


112
    mFPSText()
94
{
95
8
    LayoutHelper h(this);
96
4
    ContainerPlacer place = h.getPlacer(0, 0);
97
98
#ifdef USE_OPENGL
99

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

8
    mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
297
    // TRANSLATORS: debug window label
298

8
    mTargetIdLabel(new Label(this, strprintf("%s ?     ", _("Target Id:")))),
299
8
    mTargetTypeLabel(new Label(this, strprintf(
300
        // TRANSLATORS: debug window label
301

4
        "%s ?     ", _("Target type:")))),
302
    // TRANSLATORS: debug window label
303

8
    mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
304
    // TRANSLATORS: debug window label
305

8
    mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
306
    // TRANSLATORS: debug window label
307

8
    mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
308
    // TRANSLATORS: debug window label
309

8
    mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
310
    // TRANSLATORS: debug window label
311

8
    mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
312
    // TRANSLATORS: debug window label
313

8
    mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
314
    // TRANSLATORS: debug window label
315

8
    mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
316
    // TRANSLATORS: debug window label
317

8
    mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
318
    // TRANSLATORS: debug window label
319

8
    mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
320
    // TRANSLATORS: debug window label
321

8
    mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
322
    // TRANSLATORS: debug window label
323

68
    mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
324
{
325
8
    LayoutHelper h(this);
326
4
    ContainerPlacer place = h.getPlacer(0, 0);
327
328
4
    place(0, 0, mTargetLabel, 2, 1);
329
4
    place(0, 1, mTargetIdLabel, 2, 1);
330
4
    place(0, 2, mTargetTypeLabel, 2, 1);
331
4
    place(0, 3, mTargetLevelLabel, 2, 1);
332
4
    place(0, 4, mTargetRaceLabel, 2, 1);
333
4
    place(0, 5, mAttackDelayLabel, 2, 1);
334
4
    place(0, 6, mTargetPartyLabel, 2, 1);
335
4
    place(0, 7, mTargetGuildLabel, 2, 1);
336
4
    place(0, 8, mMinHitLabel, 2, 1);
337
4
    place(0, 9, mMaxHitLabel, 2, 1);
338
4
    place(0, 10, mCriticalHitLabel, 2, 1);
339
4
    place(0, 11, mKarmaLabel, 2, 1);
340
4
    place(0, 12, mMannerLabel, 2, 1);
341
4
    place(0, 13, mEffectsLabel, 2, 1);
342
343
4
    place.getCell().matchColWidth(0, 0);
344
4
    place = h.getPlacer(0, 1);
345
8
    setDimension(Rect(0, 0, 600, 300));
346
4
}
347
348
void TargetDebugTab::logic()
349
{
350
    BLOCK_START("TargetDebugTab::logic")
351
    if ((localPlayer != nullptr) && (localPlayer->getTarget() != nullptr))
352
    {
353
        const Being *const target = localPlayer->getTarget();
354
355
        // TRANSLATORS: debug window label
356
        mTargetLabel->setCaption(strprintf("%s %s (%d, %d)", _("Target:"),
357
            target->getName().c_str(), target->getTileX(),
358
            target->getTileY()));
359
360
        mTargetIdLabel->setCaption(strprintf("%s %d",
361
            // TRANSLATORS: debug window label
362
            _("Target Id:"), toInt(target->getId(), int)));
363
        mTargetTypeLabel->setCaption(strprintf("%s %d",
364
            // TRANSLATORS: debug window label
365
            _("Target type:"), toInt(target->getSubType(), int)));
366
        if (target->getLevel() != 0)
367
        {
368
            mTargetLevelLabel->setCaption(strprintf("%s %d",
369
                // TRANSLATORS: debug window label
370
                _("Target Level:"), target->getLevel()));
371
        }
372
        else
373
        {
374
            mTargetLevelLabel->setCaption(strprintf("%s ?",
375
                // TRANSLATORS: debug window label
376
                _("Target Level:")));
377
        }
378
379
        mTargetRaceLabel->setCaption(strprintf("%s %s",
380
            // TRANSLATORS: debug window label
381
            _("Target race:"), target->getRaceName().c_str()));
382
383
        // TRANSLATORS: debug window label
384
        mTargetPartyLabel->setCaption(strprintf("%s %s", _("Target Party:"),
385
            target->getPartyName().c_str()));
386
387
        // TRANSLATORS: debug window label
388
        mTargetGuildLabel->setCaption(strprintf("%s %s", _("Target Guild:"),
389
            target->getGuildName().c_str()));
390
391
        mMinHitLabel->setCaption(strprintf("%s %d",
392
            // TRANSLATORS: debug window label
393
            _("Minimal hit:"), target->getMinHit()));
394
        mMaxHitLabel->setCaption(strprintf("%s %d",
395
            // TRANSLATORS: debug window label
396
            _("Maximum hit:"), target->getMaxHit()));
397
        mCriticalHitLabel->setCaption(strprintf("%s %d",
398
            // TRANSLATORS: debug window label
399
            _("Critical hit:"), target->getCriticalHit()));
400
        mKarmaLabel->setCaption(strprintf("%s %d",
401
            // TRANSLATORS: debug window label
402
            _("Karma:"), target->getKarma()));
403
        mMannerLabel->setCaption(strprintf("%s %d",
404
            // TRANSLATORS: debug window label
405
            _("Manner:"), target->getManner()));
406
        mEffectsLabel->setCaption(strprintf("%s %s",
407
            // TRANSLATORS: debug window label
408
            _("Effects:"), target->getStatusEffectsString().c_str()));
409
410
        const int delay = target->getAttackDelay();
411
        if (delay != 0)
412
        {
413
            mAttackDelayLabel->setCaption(strprintf("%s %d",
414
                // TRANSLATORS: debug window label
415
                _("Attack delay:"), delay));
416
        }
417
        else
418
        {
419
            mAttackDelayLabel->setCaption(strprintf(
420
                // TRANSLATORS: debug window label
421
                "%s ?", _("Attack delay:")));
422
        }
423
    }
424
    else
425
    {
426
        // TRANSLATORS: debug window label
427
        mTargetLabel->setCaption(strprintf("%s ?", _("Target:")));
428
        // TRANSLATORS: debug window label
429
        mTargetIdLabel->setCaption(strprintf("%s ?", _("Target Id:")));
430
        // TRANSLATORS: debug window label
431
        mTargetTypeLabel->setCaption(strprintf("%s ?", _("Target type:")));
432
        // TRANSLATORS: debug window label
433
        mTargetLevelLabel->setCaption(strprintf("%s ?", _("Target Level:")));
434
        // TRANSLATORS: debug window label
435
        mTargetPartyLabel->setCaption(strprintf("%s ?", _("Target Party:")));
436
        // TRANSLATORS: debug window label
437
        mTargetGuildLabel->setCaption(strprintf("%s ?", _("Target Guild:")));
438
        // TRANSLATORS: debug window label
439
        mAttackDelayLabel->setCaption(strprintf("%s ?", _("Attack delay:")));
440
        // TRANSLATORS: debug window label
441
        mMinHitLabel->setCaption(strprintf("%s ?", _("Minimal hit:")));
442
        // TRANSLATORS: debug window label
443
        mMaxHitLabel->setCaption(strprintf("%s ?", _("Maximum hit:")));
444
        // TRANSLATORS: debug window label
445
        mCriticalHitLabel->setCaption(strprintf("%s ?", _("Critical hit:")));
446
        // TRANSLATORS: debug window label
447
        mKarmaLabel->setCaption(strprintf("%s ?", _("Karma:")));
448
        // TRANSLATORS: debug window label
449
        mMannerLabel->setCaption(strprintf("%s ?", _("Manner:")));
450
        // TRANSLATORS: debug window label
451
        mEffectsLabel->setCaption(strprintf("%s ?", _("Effects:")));
452
    }
453
454
    mTargetLabel->adjustSize();
455
    mTargetIdLabel->adjustSize();
456
    mTargetTypeLabel->adjustSize();
457
    mTargetLevelLabel->adjustSize();
458
    mTargetPartyLabel->adjustSize();
459
    mTargetGuildLabel->adjustSize();
460
    mAttackDelayLabel->adjustSize();
461
    mMinHitLabel->adjustSize();
462
    mMaxHitLabel->adjustSize();
463
    mCriticalHitLabel->adjustSize();
464
    mKarmaLabel->adjustSize();
465
    mMannerLabel->adjustSize();
466
    mEffectsLabel->adjustSize();
467
    BLOCK_END("TargetDebugTab::logic")
468
}
469
470
4
NetDebugTab::NetDebugTab(const Widget2 *const widget) :
471
    DebugTab(widget),
472

4
    mPingLabel(new Label(this, "                ")),
473

4
    mInPackets1Label(new Label(this, "                ")),
474


52
    mOutPackets1Label(new Label(this, "                "))
475
{
476
8
    LayoutHelper h(this);
477
4
    ContainerPlacer place = h.getPlacer(0, 0);
478
479
4
    place(0, 0, mPingLabel, 2, 1);
480
4
    place(0, 1, mInPackets1Label, 2, 1);
481
4
    place(0, 2, mOutPackets1Label, 2, 1);
482
483
4
    place.getCell().matchColWidth(0, 0);
484
4
    place = h.getPlacer(0, 1);
485
8
    setDimension(Rect(0, 0, 600, 300));
486
4
}
487
488
void NetDebugTab::logic()
489
{
490
    BLOCK_START("NetDebugTab::logic")
491
    if (localPlayer != nullptr)
492
    {
493
        // TRANSLATORS: debug window label
494
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
495
            localPlayer->getPingTime().c_str()));
496
    }
497
    else
498
    {
499
        // TRANSLATORS: debug window label
500
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
501
    }
502
    // TRANSLATORS: debug window label
503
    mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
504
        PacketCounters::getInBytes()));
505
    // TRANSLATORS: debug window label
506
    mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
507
        PacketCounters::getOutBytes()));
508
    BLOCK_END("NetDebugTab::logic")
509
4
}