ManaPlus
mapdebugtab.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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "game.h"
27 
28 #include "being/localplayer.h"
29 
31 
32 #include "gui/viewport.h"
33 
35 #include "gui/widgets/label.h"
37 
38 #ifdef USE_OPENGL
39 #include "resources/imagehelper.h"
40 #endif // USE_OPENGL
41 
42 #include "resources/map/map.h"
43 
44 #include "utils/gettext.h"
45 #include "utils/stringutils.h"
46 #include "utils/timer.h"
47 
48 #include "debug.h"
49 
50 MapDebugTab::MapDebugTab(const Widget2 *const widget) :
51  DebugTab(widget),
52  // TRANSLATORS: debug window label
53  mMusicFileLabel(new Label(this, _("Music:"))),
54  // TRANSLATORS: debug window label
55  mMapLabel(new Label(this, _("Map:"))),
56  // TRANSLATORS: debug window label
57  mMapNameLabel(new Label(this, _("Map name:"))),
58  // TRANSLATORS: debug window label
59  mMinimapLabel(new Label(this, _("Minimap:"))),
60  mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
61  // TRANSLATORS: debug window label
62  _("Cursor:"), 0, 0))),
63  mParticleCountLabel(new Label(this, strprintf("%s %d",
64  // TRANSLATORS: debug window label
65  _("Particle count:"), 88888))),
66  mMapActorCountLabel(new Label(this, strprintf("%s %d",
67  // TRANSLATORS: debug window label
68  _("Map actors count:"), 88888))),
69 #ifdef USE_OPENGL
70  mMapAtlasCountLabel(new Label(this, strprintf("%s %d",
71  // TRANSLATORS: debug window label
72  _("Map atlas count:"), 88888))),
73 #endif // USE_OPENGL
74  // TRANSLATORS: debug window label
75  mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
76  mTexturesLabel(nullptr),
77  mUpdateTime(0),
78 #ifdef DEBUG_DRAW_CALLS
79  mDrawCallsLabel(new Label(this, strprintf("%s %s",
80  // TRANSLATORS: debug window label
81  _("Draw calls:"), "?"))),
82 #endif // DEBUG_DRAW_CALLS
83 #ifdef DEBUG_BIND_TEXTURE
84  mBindsLabel(new Label(this, strprintf("%s %s",
85  // TRANSLATORS: debug window label
86  _("Texture binds:"), "?"))),
87 #endif // DEBUG_BIND_TEXTURE
88  // TRANSLATORS: debug window label, frames per second
89  mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
90  mFPSText()
91 {
92  LayoutHelper h(this);
93  ContainerPlacer place = h.getPlacer(0, 0);
94 
95 #ifdef USE_OPENGL
96  switch (imageHelper->useOpenGL())
97  {
98  case RENDER_SOFTWARE:
99  // TRANSLATORS: debug window label
100  mFPSText = _("%d FPS (Software)");
101  break;
103  case RENDER_NULL:
104  case RENDER_LAST:
105  default:
106  // TRANSLATORS: debug window label
107  mFPSText = _("%d FPS (normal OpenGL)");
108  break;
109  case RENDER_SAFE_OPENGL:
110  // TRANSLATORS: debug window label
111  mFPSText = _("%d FPS (safe OpenGL)");
112  break;
113  case RENDER_GLES_OPENGL:
114  // TRANSLATORS: debug window label
115  mFPSText = _("%d FPS (mobile OpenGL ES)");
116  break;
117  case RENDER_GLES2_OPENGL:
118  // TRANSLATORS: debug window label
119  mFPSText = _("%d FPS (mobile OpenGL ES 2)");
120  break;
122  // TRANSLATORS: debug window label
123  mFPSText = _("%d FPS (modern OpenGL)");
124  break;
125  case RENDER_SDL2_DEFAULT:
126  // TRANSLATORS: debug window label
127  mFPSText = _("%d FPS (SDL2 default)");
128  break;
129  }
130 #else // USE_OPENGL
131 
132  // TRANSLATORS: debug window label
133  mFPSText = _("%d FPS (Software)");
134 #endif // USE_OPENGL
135 
136  place(0, 0, mFPSLabel, 2, 1);
137  place(0, 1, mMusicFileLabel, 2, 1);
138  place(0, 2, mMapLabel, 2, 1);
139  place(0, 3, mMapNameLabel, 2, 1);
140  place(0, 4, mMinimapLabel, 2, 1);
141  place(0, 5, mXYLabel, 2, 1);
142  place(0, 6, mTileMouseLabel, 2, 1);
143  place(0, 7, mParticleCountLabel, 2, 1);
144  place(0, 8, mMapActorCountLabel, 2, 1);
145 #ifdef USE_OPENGL
146  place(0, 9, mMapAtlasCountLabel, 2, 1);
147 #if defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS) \
148  || defined(DEBUG_BIND_TEXTURE)
149  int n = 10;
150 #endif // defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS)
151  // || defined(DEBUG_BIND_TEXTURE)
152 #ifdef DEBUG_OPENGL_LEAKS
153  mTexturesLabel = new Label(this, strprintf("%s %s",
154  // TRANSLATORS: debug window label
155  _("Textures count:"), "?"));
156  place(0, n, mTexturesLabel, 2, 1);
157  n ++;
158 #endif // DEBUG_OPENGL_LEAKS
159 #ifdef DEBUG_DRAW_CALLS
160  place(0, n, mDrawCallsLabel, 2, 1);
161  n ++;
162 #endif // DEBUG_DRAW_CALLS
163 #ifdef DEBUG_BIND_TEXTURE
164  place(0, n, mBindsLabel, 2, 1);
165 #endif // DEBUG_BIND_TEXTURE
166 #endif // USE_OPENGL
167 
168  place.getCell().matchColWidth(0, 0);
169  place = h.getPlacer(0, 1);
170  setDimension(Rect(0, 0, 600, 300));
171 }
172 
174 {
175  BLOCK_START("MapDebugTab::logic")
176  if (localPlayer != nullptr)
177  {
178  // TRANSLATORS: debug window label
179  mXYLabel->setCaption(strprintf("%s (%d, %d)", _("Player Position:"),
181  }
182  else
183  {
184  // TRANSLATORS: debug window label
185  mXYLabel->setCaption(strprintf("%s (?, ?)", _("Player Position:")));
186  }
187 
188  Game *const game = Game::instance();
189  const Map *const map = game != nullptr ? game->getCurrentMap() : nullptr;
190  if (map != nullptr &&
191  viewport != nullptr)
192  {
193  // Get the current mouse position
194  const int mouseTileX = (viewport->mMouseX + viewport->getCameraX())
195  / map->getTileWidth();
196  const int mouseTileY = (viewport->mMouseY + viewport->getCameraY())
197  / map->getTileHeight();
198  mTileMouseLabel->setCaption(strprintf("%s (%d, %d)",
199  // TRANSLATORS: debug window label
200  _("Cursor:"), mouseTileX, mouseTileY));
201 
202  // TRANSLATORS: debug window label
203  mMusicFileLabel->setCaption(strprintf("%s %s", _("Music:"),
204  map->getProperty("music", std::string()).c_str()));
205  // TRANSLATORS: debug window label
206  mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
207  map->getProperty("minimap", std::string()).c_str()));
208  // TRANSLATORS: debug window label
209  mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
210  map->getProperty("_realfilename", std::string()).c_str()));
211  // TRANSLATORS: debug window label
212  mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
213  map->getProperty("name", std::string()).c_str()));
214 
215  if (mUpdateTime != cur_time)
216  {
218  // TRANSLATORS: debug window label
219  mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
221 
223  // TRANSLATORS: debug window label
224  strprintf("%s %d", _("Map actors count:"),
225  map->getActorsCount()));
226 #ifdef USE_OPENGL
228  // TRANSLATORS: debug window label
229  strprintf("%s %d", _("Map atlas count:"),
230  map->getAtlasCount()));
231 #ifdef DEBUG_OPENGL_LEAKS
233  // TRANSLATORS: debug window label
234  _("Textures count:"), textures_count));
235 #endif // DEBUG_OPENGL_LEAKS
236 #ifdef DEBUG_DRAW_CALLS
237  if (mainGraphics)
238  {
239  mDrawCallsLabel->setCaption(strprintf("%s %d",
240  // TRANSLATORS: debug window label
241  _("Draw calls:"), mainGraphics->getDrawCalls()));
242  }
243 #endif // DEBUG_DRAW_CALLS
244 #ifdef DEBUG_BIND_TEXTURE
245  if (mainGraphics)
246  {
247  mBindsLabel->setCaption(strprintf("%s %d",
248  // TRANSLATORS: debug window label
249  _("Texture binds:"), mainGraphics->getBinds()));
250  }
251 #endif // DEBUG_BIND_TEXTURE
252 #endif // USE_OPENGL
253  }
254  }
255  else
256  {
257  // TRANSLATORS: debug window label
258  mTileMouseLabel->setCaption(strprintf("%s (?, ?)", _("Cursor:")));
259  // TRANSLATORS: debug window label
260  mMusicFileLabel->setCaption(strprintf("%s ?", _("Music:")));
261  // TRANSLATORS: debug window label
262  mMinimapLabel->setCaption(strprintf("%s ?", _("Minimap:")));
263  // TRANSLATORS: debug window label
264  mMapLabel->setCaption(strprintf("%s ?", _("Map:")));
265  // TRANSLATORS: debug window label
266  mMapNameLabel->setCaption(strprintf("%s ?", _("Map name:")));
268  // TRANSLATORS: debug window label
269  strprintf("%s ?", _("Map actors count:")));
270 #ifdef USE_OPENGL
272  // TRANSLATORS: debug window label
273  strprintf("%s ?", _("Map atlas count:")));
274 #endif // USE_OPENGL
275  }
276 
279 #ifdef USE_OPENGL
281 #endif // USE_OPENGL
282 
284  BLOCK_END("MapDebugTab::logic")
285 }
volatile time_t cur_time
Definition: timer.cpp:58
int getTileX() const
Definition: being.h:168
int getTileY() const
Definition: being.h:174
LayoutCell & getCell()
Definition: game.h:64
Map * getCurrentMap() const
Definition: game.h:107
static Game * instance()
Definition: game.h:82
virtual RenderType useOpenGL() const
Definition: imagehelper.h:107
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:118
ContainerPlacer getPlacer(const int x, const int y)
Label * mMapLabel
Definition: mapdebugtab.h:44
Label * mMapNameLabel
Definition: mapdebugtab.h:45
Label * mXYLabel
Definition: mapdebugtab.h:53
Label * mFPSLabel
Definition: mapdebugtab.h:63
time_t mUpdateTime
Definition: mapdebugtab.h:55
Label * mMapActorCountLabel
Definition: mapdebugtab.h:49
Label * mMinimapLabel
Definition: mapdebugtab.h:46
Label * mMapAtlasCountLabel
Definition: mapdebugtab.h:51
Label * mMusicFileLabel
Definition: mapdebugtab.h:43
std::string mFPSText
Definition: mapdebugtab.h:64
Label * mParticleCountLabel
Definition: mapdebugtab.h:48
Label * mTexturesLabel
Definition: mapdebugtab.h:54
MapDebugTab(const Widget2 *const widget)
Definition: mapdebugtab.cpp:50
Label * mTileMouseLabel
Definition: mapdebugtab.h:47
Definition: map.h:75
int getTileHeight() const
Definition: map.h:184
int getActorsCount() const
Definition: map.h:287
int getTileWidth() const
Definition: map.h:178
int getAtlasCount() const
Definition: map.cpp:1821
static int particleCount
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:59
Definition: rect.h:74
int mMouseX
Definition: viewport.h:154
int getCameraY() const
Definition: viewport.h:121
int getCameraX() const
Definition: viewport.h:115
int mMouseY
Definition: viewport.h:155
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
#define new
Definition: debug_new.h:147
int textures_count
Definition: client.cpp:138
Viewport * viewport
Definition: viewport.cpp:36
#define _(s)
Definition: gettext.h:35
Graphics * mainGraphics
Definition: graphics.cpp:109
ImageHelper * imageHelper
Definition: imagehelper.cpp:44
#define nullptr
Definition: localconsts.h:45
LocalPlayer * localPlayer
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
@ RENDER_SAFE_OPENGL
Definition: rendertype.h:29
@ RENDER_GLES2_OPENGL
Definition: rendertype.h:33
@ RENDER_GLES_OPENGL
Definition: rendertype.h:30
@ RENDER_MODERN_OPENGL
Definition: rendertype.h:32
@ RENDER_LAST
Definition: rendertype.h:35
@ RENDER_NORMAL_OPENGL
Definition: rendertype.h:28
@ RENDER_SDL2_DEFAULT
Definition: rendertype.h:31
@ RENDER_NULL
Definition: rendertype.h:34
@ RENDER_SOFTWARE
Definition: rendertype.h:27
std::string strprintf(const char *const format,...)
volatile int fps
Definition: timer.cpp:54