ManaPlus
debugwindowtabs.cpp
Go to the documentation of this file.
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 
24 
25 #include "game.h"
26 
27 #include "being/localplayer.h"
28 
30 
31 #include "gui/viewport.h"
32 
34 #include "gui/widgets/label.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 MapDebugTab::MapDebugTab(const Widget2 *const widget) :
52  DebugTab(widget),
53  // TRANSLATORS: debug window label
54  mMusicFileLabel(new Label(this, _("Music:"))),
55  // TRANSLATORS: debug window label
56  mMapLabel(new Label(this, _("Map:"))),
57  // TRANSLATORS: debug window label
58  mMapNameLabel(new Label(this, _("Map name:"))),
59  // TRANSLATORS: debug window label
60  mMinimapLabel(new Label(this, _("Minimap:"))),
61  mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
62  // TRANSLATORS: debug window label
63  _("Cursor:"), 0, 0))),
64  mParticleCountLabel(new Label(this, strprintf("%s %d",
65  // TRANSLATORS: debug window label
66  _("Particle count:"), 88888))),
67  mMapActorCountLabel(new Label(this, strprintf("%s %d",
68  // TRANSLATORS: debug window label
69  _("Map actors count:"), 88888))),
70 #ifdef USE_OPENGL
71  mMapAtlasCountLabel(new Label(this, strprintf("%s %d",
72  // TRANSLATORS: debug window label
73  _("Map atlas count:"), 88888))),
74 #endif // USE_OPENGL
75  // TRANSLATORS: debug window label
76  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  mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
91  // TRANSLATORS: debug window label, logic per second
92  mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0))),
93  mFPSText()
94 {
95  LayoutHelper h(this);
96  ContainerPlacer place = h.getPlacer(0, 0);
97 
98 #ifdef USE_OPENGL
99  switch (imageHelper->useOpenGL())
100  {
101  case RENDER_SOFTWARE:
102  // TRANSLATORS: debug window label
103  mFPSText = _("%d FPS (Software)");
104  break;
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;
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  place(0, 0, mFPSLabel, 2, 1);
140  place(0, 1, mLPSLabel, 2, 1);
141  place(0, 2, mMusicFileLabel, 2, 1);
142  place(0, 3, mMapLabel, 2, 1);
143  place(0, 4, mMapNameLabel, 2, 1);
144  place(0, 5, mMinimapLabel, 2, 1);
145  place(0, 6, mXYLabel, 2, 1);
146  place(0, 7, mTileMouseLabel, 2, 1);
147  place(0, 8, mParticleCountLabel, 2, 1);
148  place(0, 9, mMapActorCountLabel, 2, 1);
149 #ifdef USE_OPENGL
150  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  place.getCell().matchColWidth(0, 0);
173  place = h.getPlacer(0, 1);
174  setDimension(Rect(0, 0, 600, 300));
175 }
176 
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:"),
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  {
222  // TRANSLATORS: debug window label
223  mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
225 
227  // TRANSLATORS: debug window label
228  strprintf("%s %d", _("Map actors count:"),
229  map->getActorsCount()));
230 #ifdef USE_OPENGL
232  // TRANSLATORS: debug window label
233  strprintf("%s %d", _("Map atlas count:"),
234  map->getAtlasCount()));
235 #ifdef DEBUG_OPENGL_LEAKS
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:")));
272  // TRANSLATORS: debug window label
273  strprintf("%s ?", _("Map actors count:")));
274 #ifdef USE_OPENGL
276  // TRANSLATORS: debug window label
277  strprintf("%s ?", _("Map atlas count:")));
278 #endif // USE_OPENGL
279  }
280 
283 #ifdef USE_OPENGL
285 #endif // USE_OPENGL
286 
288  // TRANSLATORS: debug window label, logic per second
289  mLPSLabel->setCaption(strprintf(_("%d LPS"), lps));
290  BLOCK_END("MapDebugTab::logic")
291 }
292 
294  DebugTab(widget),
295  // TRANSLATORS: debug window label
296  mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
297  // TRANSLATORS: debug window label
298  mTargetIdLabel(new Label(this, strprintf("%s ? ", _("Target Id:")))),
299  mTargetTypeLabel(new Label(this, strprintf(
300  // TRANSLATORS: debug window label
301  "%s ? ", _("Target type:")))),
302  // TRANSLATORS: debug window label
303  mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
304  // TRANSLATORS: debug window label
305  mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
306  // TRANSLATORS: debug window label
307  mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
308  // TRANSLATORS: debug window label
309  mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
310  // TRANSLATORS: debug window label
311  mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
312  // TRANSLATORS: debug window label
313  mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
314  // TRANSLATORS: debug window label
315  mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
316  // TRANSLATORS: debug window label
317  mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
318  // TRANSLATORS: debug window label
319  mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
320  // TRANSLATORS: debug window label
321  mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
322  // TRANSLATORS: debug window label
323  mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
324 {
325  LayoutHelper h(this);
326  ContainerPlacer place = h.getPlacer(0, 0);
327 
328  place(0, 0, mTargetLabel, 2, 1);
329  place(0, 1, mTargetIdLabel, 2, 1);
330  place(0, 2, mTargetTypeLabel, 2, 1);
331  place(0, 3, mTargetLevelLabel, 2, 1);
332  place(0, 4, mTargetRaceLabel, 2, 1);
333  place(0, 5, mAttackDelayLabel, 2, 1);
334  place(0, 6, mTargetPartyLabel, 2, 1);
335  place(0, 7, mTargetGuildLabel, 2, 1);
336  place(0, 8, mMinHitLabel, 2, 1);
337  place(0, 9, mMaxHitLabel, 2, 1);
338  place(0, 10, mCriticalHitLabel, 2, 1);
339  place(0, 11, mKarmaLabel, 2, 1);
340  place(0, 12, mMannerLabel, 2, 1);
341  place(0, 13, mEffectsLabel, 2, 1);
342 
343  place.getCell().matchColWidth(0, 0);
344  place = h.getPlacer(0, 1);
345  setDimension(Rect(0, 0, 600, 300));
346 }
347 
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 
361  // TRANSLATORS: debug window label
362  _("Target Id:"), toInt(target->getId(), int)));
364  // TRANSLATORS: debug window label
365  _("Target type:"), toInt(target->getSubType(), int)));
366  if (target->getLevel() != 0)
367  {
369  // TRANSLATORS: debug window label
370  _("Target Level:"), target->getLevel()));
371  }
372  else
373  {
375  // TRANSLATORS: debug window label
376  _("Target Level:")));
377  }
378 
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 
392  // TRANSLATORS: debug window label
393  _("Minimal hit:"), target->getMinHit()));
395  // TRANSLATORS: debug window label
396  _("Maximum hit:"), target->getMaxHit()));
398  // TRANSLATORS: debug window label
399  _("Critical hit:"), target->getCriticalHit()));
401  // TRANSLATORS: debug window label
402  _("Karma:"), target->getKarma()));
404  // TRANSLATORS: debug window label
405  _("Manner:"), target->getManner()));
407  // TRANSLATORS: debug window label
408  _("Effects:"), target->getStatusEffectsString().c_str()));
409 
410  const int delay = target->getAttackDelay();
411  if (delay != 0)
412  {
414  // TRANSLATORS: debug window label
415  _("Attack delay:"), delay));
416  }
417  else
418  {
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 
467  BLOCK_END("TargetDebugTab::logic")
468 }
469 
470 NetDebugTab::NetDebugTab(const Widget2 *const widget) :
471  DebugTab(widget),
472  mPingLabel(new Label(this, " ")),
473  mInPackets1Label(new Label(this, " ")),
474  mOutPackets1Label(new Label(this, " "))
475 {
476  LayoutHelper h(this);
477  ContainerPlacer place = h.getPlacer(0, 0);
478 
479  place(0, 0, mPingLabel, 2, 1);
480  place(0, 1, mInPackets1Label, 2, 1);
481  place(0, 2, mOutPackets1Label, 2, 1);
482 
483  place.getCell().matchColWidth(0, 0);
484  place = h.getPlacer(0, 1);
485  setDimension(Rect(0, 0, 600, 300));
486 }
487 
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"),
505  // TRANSLATORS: debug window label
506  mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
508  BLOCK_END("NetDebugTab::logic")
509 }
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:117
int getMaxHit() const
Definition: being.h:781
volatile int lps
Definition: timer.cpp:54
#define _(s)
Definition: gettext.h:34
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
const std::string & getPartyName() const
Definition: being.h:254
Label * mMapAtlasCountLabel
std::string getRaceName() const
Definition: being.h:860
int getTileY() const
Definition: being.h:173
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Label * mTargetTypeLabel
int getAttackDelay() const
Definition: being.h:772
Label * mMapActorCountLabel
int getAtlasCount() const
Definition: map.cpp:1804
int getTileHeight() const
Definition: map.h:183
int textures_count
Definition: client.cpp:137
Label * mFPSLabel
Label * mTargetGuildLabel
BeingId getId() const
Definition: actorsprite.h:63
int getManner() const
Definition: being.h:1043
Definition: rect.h:72
Label * mLPSLabel
#define BLOCK_START(name)
Definition: perfomance.h:78
std::string getStatusEffectsString() const
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
Label * mTexturesLabel
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
Label * mTargetPartyLabel
Label * mTargetIdLabel
#define BLOCK_END(name)
Definition: perfomance.h:79
int getMinHit() const
Definition: being.h:775
int mMouseX
Definition: viewport.h:153
volatile int fps
Definition: timer.cpp:53
Label * mTargetLevelLabel
Map * getCurrentMap() const
Definition: game.h:106
LayoutCell & getCell()
Label * mMapLabel
#define new
Definition: debug_new.h:147
#define toInt(val, name)
Definition: intdefines.h:46
static int particleCount
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
Definition: label.h:87
Label * mCriticalHitLabel
Definition: game.h:62
Label * mMusicFileLabel
int getActorsCount() const
Definition: map.h:286
LocalPlayer * localPlayer
int getCameraY() const
Definition: viewport.h:120
Label * mMapNameLabel
time_t mUpdateTime
#define nullptr
Definition: localconsts.h:44
Graphics * mainGraphics
Definition: graphics.cpp:108
Label * mAttackDelayLabel
std::string mFPSText
volatile time_t cur_time
Definition: timer.cpp:57
const std::string & getName() const
Definition: being.h:231
ContainerPlacer getPlacer(const int x, const int y)
Label * mOutPackets1Label
Definition: map.h:71
Label * mXYLabel
int mMouseY
Definition: viewport.h:154
int getCameraX() const
Definition: viewport.h:114
Label * mPingLabel
MapDebugTab(const Widget2 *const widget)
Label * mMinimapLabel
int getTileWidth() const
Definition: map.h:177
Label * mTileMouseLabel
int getKarma() const
Definition: being.h:1037
static Game * instance()
Definition: game.h:81
TargetDebugTab(const Widget2 *const widget)
int getTileX() const
Definition: being.h:167
static int getInBytes()
virtual int getLevel() const
Definition: being.h:603
static int getOutBytes()
std::string getPingTime() const
int getCriticalHit() const
Definition: being.h:787
Label * mInPackets1Label
NetDebugTab(const Widget2 *const widget)
Definition: being.h:93
Label * mTargetRaceLabel
void adjustSize()
Definition: label.cpp:197
BeingTypeId getSubType() const
Definition: being.h:399
Viewport * viewport
Definition: viewport.cpp:35
Label * mTargetLabel
Being * getTarget() const
const std::string & getGuildName() const
Definition: being.h:258
Label * mParticleCountLabel