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  // TRANSLATORS: debug window label
71  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  mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
86  // TRANSLATORS: debug window label, logic per second
87  mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0))),
88  mFPSText()
89 {
90  LayoutHelper h(this);
92 
93 #ifdef USE_OPENGL
94  switch (imageHelper->useOpenGL())
95  {
96  case RENDER_SOFTWARE:
97  // TRANSLATORS: debug window label
98  mFPSText = _("%d FPS (Software)");
99  break;
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;
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  place(0, 0, mFPSLabel, 2, 1);
135  place(0, 1, mLPSLabel, 2, 1);
136  place(0, 2, mMusicFileLabel, 2, 1);
137  place(0, 3, mMapLabel, 2, 1);
138  place(0, 4, mMapNameLabel, 2, 1);
139  place(0, 5, mMinimapLabel, 2, 1);
140  place(0, 6, mXYLabel, 2, 1);
141  place(0, 7, mTileMouseLabel, 2, 1);
142  place(0, 8, mParticleCountLabel, 2, 1);
143  place(0, 9, mMapActorCountLabel, 2, 1);
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, 1);
155  n ++;
156 #endif // DEBUG_OPENGL_LEAKS
157 #ifdef DEBUG_DRAW_CALLS
158  place(0, n, mDrawCallsLabel, 2, 1);
159  n ++;
160 #endif // DEBUG_DRAW_CALLS
161 #ifdef DEBUG_BIND_TEXTURE
162  place(0, n, mBindsLabel, 2, 1);
163 #endif // DEBUG_BIND_TEXTURE
164 #endif // USE_OPENGL
165 
166  place.getCell().matchColWidth(0, 0);
167  place = h.getPlacer(0, 1);
168  setDimension(Rect(0, 0, 600, 300));
169 }
170 
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:"),
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", std::string()).c_str()));
203  // TRANSLATORS: debug window label
204  mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
205  map->getProperty("minimap", std::string()).c_str()));
206  // TRANSLATORS: debug window label
207  mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
208  map->getProperty("_realfilename", std::string()).c_str()));
209  // TRANSLATORS: debug window label
210  mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
211  map->getProperty("name", std::string()).c_str()));
212 
213  if (mUpdateTime != cur_time)
214  {
216  // TRANSLATORS: debug window label
217  mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
219 
221  // TRANSLATORS: debug window label
222  strprintf("%s %d", _("Map actors count:"),
223  map->getActorsCount()));
224 #ifdef USE_OPENGL
225 #ifdef DEBUG_OPENGL_LEAKS
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 
263  // TRANSLATORS: debug window label
264  strprintf("%s ?", _("Map actors count:")));
265  }
266 
269 
271  // TRANSLATORS: debug window label, logic per second
272  mLPSLabel->setCaption(strprintf(_("%d LPS"), lps));
273  BLOCK_END("MapDebugTab::logic")
274 }
275 
277  DebugTab(widget),
278  // TRANSLATORS: debug window label
279  mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
280  // TRANSLATORS: debug window label
281  mTargetIdLabel(new Label(this, strprintf("%s ? ", _("Target Id:")))),
282  mTargetTypeLabel(new Label(this, strprintf(
283  // TRANSLATORS: debug window label
284  "%s ? ", _("Target type:")))),
285  // TRANSLATORS: debug window label
286  mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
287  // TRANSLATORS: debug window label
288  mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
289  // TRANSLATORS: debug window label
290  mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
291  // TRANSLATORS: debug window label
292  mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
293  // TRANSLATORS: debug window label
294  mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
295  // TRANSLATORS: debug window label
296  mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
297  // TRANSLATORS: debug window label
298  mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
299  // TRANSLATORS: debug window label
300  mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
301  // TRANSLATORS: debug window label
302  mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
303  // TRANSLATORS: debug window label
304  mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
305  // TRANSLATORS: debug window label
306  mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
307 {
308  LayoutHelper h(this);
309  ContainerPlacer place = h.getPlacer(0, 0);
310 
311  place(0, 0, mTargetLabel, 2, 1);
312  place(0, 1, mTargetIdLabel, 2, 1);
313  place(0, 2, mTargetTypeLabel, 2, 1);
314  place(0, 3, mTargetLevelLabel, 2, 1);
315  place(0, 4, mTargetRaceLabel, 2, 1);
316  place(0, 5, mAttackDelayLabel, 2, 1);
317  place(0, 6, mTargetPartyLabel, 2, 1);
318  place(0, 7, mTargetGuildLabel, 2, 1);
319  place(0, 8, mMinHitLabel, 2, 1);
320  place(0, 9, mMaxHitLabel, 2, 1);
321  place(0, 10, mCriticalHitLabel, 2, 1);
322  place(0, 11, mKarmaLabel, 2, 1);
323  place(0, 12, mMannerLabel, 2, 1);
324  place(0, 13, mEffectsLabel, 2, 1);
325 
326  place.getCell().matchColWidth(0, 0);
327  place = h.getPlacer(0, 1);
328  setDimension(Rect(0, 0, 600, 300));
329 }
330 
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 
344  // TRANSLATORS: debug window label
345  _("Target Id:"), toInt(target->getId(), int)));
347  // TRANSLATORS: debug window label
348  _("Target type:"), toInt(target->getSubType(), int)));
349  if (target->getLevel() != 0)
350  {
352  // TRANSLATORS: debug window label
353  _("Target Level:"), target->getLevel()));
354  }
355  else
356  {
358  // TRANSLATORS: debug window label
359  _("Target Level:")));
360  }
361 
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 
375  // TRANSLATORS: debug window label
376  _("Minimal hit:"), target->getMinHit()));
378  // TRANSLATORS: debug window label
379  _("Maximum hit:"), target->getMaxHit()));
381  // TRANSLATORS: debug window label
382  _("Critical hit:"), target->getCriticalHit()));
384  // TRANSLATORS: debug window label
385  _("Karma:"), target->getKarma()));
387  // TRANSLATORS: debug window label
388  _("Manner:"), target->getManner()));
390  // TRANSLATORS: debug window label
391  _("Effects:"), target->getStatusEffectsString().c_str()));
392 
393  const int delay = target->getAttackDelay();
394  if (delay != 0)
395  {
397  // TRANSLATORS: debug window label
398  _("Attack delay:"), delay));
399  }
400  else
401  {
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 
450  BLOCK_END("TargetDebugTab::logic")
451 }
452 
453 NetDebugTab::NetDebugTab(const Widget2 *const widget) :
454  DebugTab(widget),
455  mPingLabel(new Label(this, " ")),
456  mInPackets1Label(new Label(this, " ")),
457  mOutPackets1Label(new Label(this, " "))
458 {
459  LayoutHelper h(this);
460  ContainerPlacer place = h.getPlacer(0, 0);
461 
462  place(0, 0, mPingLabel, 2, 1);
463  place(0, 1, mInPackets1Label, 2, 1);
464  place(0, 2, mOutPackets1Label, 2, 1);
465 
466  place.getCell().matchColWidth(0, 0);
467  place = h.getPlacer(0, 1);
468  setDimension(Rect(0, 0, 600, 300));
469 }
470 
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"),
488  // TRANSLATORS: debug window label
489  mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
491  BLOCK_END("NetDebugTab::logic")
492 }
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:117
int getMaxHit() const
Definition: being.h:775
volatile int lps
Definition: timer.cpp:54
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1379
#define _(s)
Definition: gettext.h:34
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
const std::string & getPartyName() const
Definition: being.h:254
std::string getRaceName() const
Definition: being.h:854
int getTileY() const
Definition: being.h:173
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Label * mTargetTypeLabel
int getAttackDelay() const
Definition: being.h:766
Label * mMapActorCountLabel
int getTileHeight() const
Definition: map.h:180
int textures_count
Definition: client.cpp:129
Label * mFPSLabel
Label * mTargetGuildLabel
BeingId getId() const
Definition: actorsprite.h:63
int getManner() const
Definition: being.h:1037
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:769
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:283
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:68
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:174
Label * mTileMouseLabel
int getKarma() const
Definition: being.h:1031
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:597
static int getOutBytes()
std::string getPingTime() const
int getCriticalHit() const
Definition: being.h:781
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:393
Viewport * viewport
Definition: viewport.cpp:35
Label * mTargetLabel
Being * getTarget() const
const std::string & getGuildName() const
Definition: being.h:258
Label * mParticleCountLabel