GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/debugwindowtabs.cpp Lines: 84 198 42.4 %
Date: 2017-11-29 Branches: 124 411 30.2 %

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 "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
    // TRANSLATORS: debug window label
71

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

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

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


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

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

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

8
    mTargetIdLabel(new Label(this, strprintf("%s ?     ", _("Target Id:")))),
282
8
    mTargetTypeLabel(new Label(this, strprintf(
283
        // TRANSLATORS: debug window label
284

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

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

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

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

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

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

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

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

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

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

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

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

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

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


52
    mOutPackets1Label(new Label(this, "                "))
458
{
459
8
    LayoutHelper h(this);
460
4
    ContainerPlacer place = h.getPlacer(0, 0);
461
462
4
    place(0, 0, mPingLabel, 2);
463
4
    place(0, 1, mInPackets1Label, 2);
464
4
    place(0, 2, mOutPackets1Label, 2);
465
466
4
    place.getCell().matchColWidth(0, 0);
467
4
    place = h.getPlacer(0, 1);
468
8
    setDimension(Rect(0, 0, 600, 300));
469
4
}
470
471
void NetDebugTab::logic()
472
{
473
    BLOCK_START("NetDebugTab::logic")
474
    if (localPlayer != nullptr)
475
    {
476
        // TRANSLATORS: debug window label
477
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
478
            localPlayer->getPingTime().c_str()));
479
    }
480
    else
481
    {
482
        // TRANSLATORS: debug window label
483
        mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
484
    }
485
    // TRANSLATORS: debug window label
486
    mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
487
        PacketCounters::getInBytes()));
488
    // TRANSLATORS: debug window label
489
    mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
490
        PacketCounters::getOutBytes()));
491
    BLOCK_END("NetDebugTab::logic")
492
4
}