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  *
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 "utils/gettext.h"
44 #include "utils/stringutils.h"
45 #include "utils/timer.h"
46 
47 #include "debug.h"
48 
49 MapDebugTab::MapDebugTab(const Widget2 *const widget) :
50  DebugTab(widget),
51  // TRANSLATORS: debug window label
52  mMusicFileLabel(new Label(this, _("Music:"))),
53  // TRANSLATORS: debug window label
54  mMapLabel(new Label(this, _("Map:"))),
55  // TRANSLATORS: debug window label
56  mMapNameLabel(new Label(this, _("Map name:"))),
57  // TRANSLATORS: debug window label
58  mMinimapLabel(new Label(this, _("Minimap:"))),
59  mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
60  // TRANSLATORS: debug window label
61  _("Cursor:"), 0, 0))),
62  mParticleCountLabel(new Label(this, strprintf("%s %d",
63  // TRANSLATORS: debug window label
64  _("Particle count:"), 88888))),
65  mMapActorCountLabel(new Label(this, strprintf("%s %d",
66  // TRANSLATORS: debug window label
67  _("Map actors count:"), 88888))),
68 #ifdef USE_OPENGL
69  mMapAtlasCountLabel(new Label(this, strprintf("%s %d",
70  // TRANSLATORS: debug window label
71  _("Map atlas count:"), 88888))),
72 #endif // USE_OPENGL
73  // TRANSLATORS: debug window label
74  mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
75  mTexturesLabel(nullptr),
76  mUpdateTime(0),
77 #ifdef DEBUG_DRAW_CALLS
78  mDrawCallsLabel(new Label(this, strprintf("%s %s",
79  // TRANSLATORS: debug window label
80  _("Draw calls:"), "?"))),
81 #endif // DEBUG_DRAW_CALLS
82 #ifdef DEBUG_BIND_TEXTURE
83  mBindsLabel(new Label(this, strprintf("%s %s",
84  // TRANSLATORS: debug window label
85  _("Texture binds:"), "?"))),
86 #endif // DEBUG_BIND_TEXTURE
87  // TRANSLATORS: debug window label, frames per second
88  mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
89  mFPSText()
90 {
91  LayoutHelper h(this);
93 
94 #ifdef USE_OPENGL
95  switch (imageHelper->useOpenGL())
96  {
97  case RENDER_SOFTWARE:
98  // TRANSLATORS: debug window label
99  mFPSText = _("%d FPS (Software)");
100  break;
102  case RENDER_NULL:
103  case RENDER_LAST:
104  default:
105  // TRANSLATORS: debug window label
106  mFPSText = _("%d FPS (normal OpenGL)");
107  break;
108  case RENDER_SAFE_OPENGL:
109  // TRANSLATORS: debug window label
110  mFPSText = _("%d FPS (safe OpenGL)");
111  break;
112  case RENDER_GLES_OPENGL:
113  // TRANSLATORS: debug window label
114  mFPSText = _("%d FPS (mobile OpenGL ES)");
115  break;
116  case RENDER_GLES2_OPENGL:
117  // TRANSLATORS: debug window label
118  mFPSText = _("%d FPS (mobile OpenGL ES 2)");
119  break;
121  // TRANSLATORS: debug window label
122  mFPSText = _("%d FPS (modern OpenGL)");
123  break;
124  case RENDER_SDL2_DEFAULT:
125  // TRANSLATORS: debug window label
126  mFPSText = _("%d FPS (SDL2 default)");
127  break;
128  }
129 #else // USE_OPENGL
130 
131  // TRANSLATORS: debug window label
132  mFPSText = _("%d FPS (Software)");
133 #endif // USE_OPENGL
134 
135  place(0, 0, mFPSLabel, 2, 1);
136  place(0, 1, mMusicFileLabel, 2, 1);
137  place(0, 2, mMapLabel, 2, 1);
138  place(0, 3, mMapNameLabel, 2, 1);
139  place(0, 4, mMinimapLabel, 2, 1);
140  place(0, 5, mXYLabel, 2, 1);
141  place(0, 6, mTileMouseLabel, 2, 1);
142  place(0, 7, mParticleCountLabel, 2, 1);
143  place(0, 8, mMapActorCountLabel, 2, 1);
144 #ifdef USE_OPENGL
145  place(0, 9, mMapAtlasCountLabel, 2, 1);
146 #if defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS) \
147  || defined(DEBUG_BIND_TEXTURE)
148  int n = 10;
149 #endif // defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS)
150  // || defined(DEBUG_BIND_TEXTURE)
151 #ifdef DEBUG_OPENGL_LEAKS
152  mTexturesLabel = new Label(this, strprintf("%s %s",
153  // TRANSLATORS: debug window label
154  _("Textures count:"), "?"));
155  place(0, n, mTexturesLabel, 2, 1);
156  n ++;
157 #endif // DEBUG_OPENGL_LEAKS
158 #ifdef DEBUG_DRAW_CALLS
159  place(0, n, mDrawCallsLabel, 2, 1);
160  n ++;
161 #endif // DEBUG_DRAW_CALLS
162 #ifdef DEBUG_BIND_TEXTURE
163  place(0, n, mBindsLabel, 2, 1);
164 #endif // DEBUG_BIND_TEXTURE
165 #endif // USE_OPENGL
166 
167  place.getCell().matchColWidth(0, 0);
168  place = h.getPlacer(0, 1);
169  setDimension(Rect(0, 0, 600, 300));
170 }
171 
173 {
174  BLOCK_START("MapDebugTab::logic")
175  if (localPlayer != nullptr)
176  {
177  // TRANSLATORS: debug window label
178  mXYLabel->setCaption(strprintf("%s (%d, %d)", _("Player Position:"),
180  }
181  else
182  {
183  // TRANSLATORS: debug window label
184  mXYLabel->setCaption(strprintf("%s (?, ?)", _("Player Position:")));
185  }
186 
187  Game *const game = Game::instance();
188  const Map *const map = game != nullptr ? game->getCurrentMap() : nullptr;
189  if (map != nullptr &&
190  viewport != nullptr)
191  {
192  // Get the current mouse position
193  const int mouseTileX = (viewport->mMouseX + viewport->getCameraX())
194  / map->getTileWidth();
195  const int mouseTileY = (viewport->mMouseY + viewport->getCameraY())
196  / map->getTileHeight();
197  mTileMouseLabel->setCaption(strprintf("%s (%d, %d)",
198  // TRANSLATORS: debug window label
199  _("Cursor:"), mouseTileX, mouseTileY));
200 
201  // TRANSLATORS: debug window label
202  mMusicFileLabel->setCaption(strprintf("%s %s", _("Music:"),
203  map->getProperty("music", std::string()).c_str()));
204  // TRANSLATORS: debug window label
205  mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
206  map->getProperty("minimap", std::string()).c_str()));
207  // TRANSLATORS: debug window label
208  mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
209  map->getProperty("_realfilename", std::string()).c_str()));
210  // TRANSLATORS: debug window label
211  mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
212  map->getProperty("name", std::string()).c_str()));
213 
214  if (mUpdateTime != cur_time)
215  {
217  // TRANSLATORS: debug window label
218  mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
220 
222  // TRANSLATORS: debug window label
223  strprintf("%s %d", _("Map actors count:"),
224  map->getActorsCount()));
225 #ifdef USE_OPENGL
227  // TRANSLATORS: debug window label
228  strprintf("%s %d", _("Map atlas count:"),
229  map->getAtlasCount()));
230 #ifdef DEBUG_OPENGL_LEAKS
232  // TRANSLATORS: debug window label
233  _("Textures count:"), textures_count));
234 #endif // DEBUG_OPENGL_LEAKS
235 #ifdef DEBUG_DRAW_CALLS
236  if (mainGraphics)
237  {
238  mDrawCallsLabel->setCaption(strprintf("%s %d",
239  // TRANSLATORS: debug window label
240  _("Draw calls:"), mainGraphics->getDrawCalls()));
241  }
242 #endif // DEBUG_DRAW_CALLS
243 #ifdef DEBUG_BIND_TEXTURE
244  if (mainGraphics)
245  {
246  mBindsLabel->setCaption(strprintf("%s %d",
247  // TRANSLATORS: debug window label
248  _("Texture binds:"), mainGraphics->getBinds()));
249  }
250 #endif // DEBUG_BIND_TEXTURE
251 #endif // USE_OPENGL
252  }
253  }
254  else
255  {
256  // TRANSLATORS: debug window label
257  mTileMouseLabel->setCaption(strprintf("%s (?, ?)", _("Cursor:")));
258  // TRANSLATORS: debug window label
259  mMusicFileLabel->setCaption(strprintf("%s ?", _("Music:")));
260  // TRANSLATORS: debug window label
261  mMinimapLabel->setCaption(strprintf("%s ?", _("Minimap:")));
262  // TRANSLATORS: debug window label
263  mMapLabel->setCaption(strprintf("%s ?", _("Map:")));
264  // TRANSLATORS: debug window label
265  mMapNameLabel->setCaption(strprintf("%s ?", _("Map name:")));
267  // TRANSLATORS: debug window label
268  strprintf("%s ?", _("Map actors count:")));
269 #ifdef USE_OPENGL
271  // TRANSLATORS: debug window label
272  strprintf("%s ?", _("Map atlas count:")));
273 #endif // USE_OPENGL
274  }
275 
278 #ifdef USE_OPENGL
280 #endif // USE_OPENGL
281 
283  BLOCK_END("MapDebugTab::logic")
284 }
MapDebugTab::mMinimapLabel
Label * mMinimapLabel
Definition: mapdebugtab.h:45
fps
volatile int fps
Definition: timer.cpp:53
particleengine.h
imagehelper.h
Label::adjustSize
void adjustSize()
Definition: label.cpp:199
MapDebugTab::mTexturesLabel
Label * mTexturesLabel
Definition: mapdebugtab.h:53
Widget::setDimension
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
Label::setCaption
void setCaption(const std::string &caption)
Definition: label.cpp:263
Widget2
Definition: widget2.h:35
MapDebugTab::mMapAtlasCountLabel
Label * mMapAtlasCountLabel
Definition: mapdebugtab.h:50
imageHelper
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Map::getAtlasCount
int getAtlasCount() const
Definition: map.cpp:1820
RENDER_NORMAL_OPENGL
@ RENDER_NORMAL_OPENGL
Definition: rendertype.h:27
containerplacer.h
Game::instance
static Game * instance()
Definition: game.h:81
LayoutCell::matchColWidth
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:117
MapDebugTab::mMapActorCountLabel
Label * mMapActorCountLabel
Definition: mapdebugtab.h:48
Map::getActorsCount
int getActorsCount() const
Definition: map.h:286
ParticleEngine::particleCount
static int particleCount
Definition: particleengine.h:51
MapDebugTab::mFPSLabel
Label * mFPSLabel
Definition: mapdebugtab.h:62
cur_time
volatile time_t cur_time
Definition: timer.cpp:57
MapDebugTab::mMusicFileLabel
Label * mMusicFileLabel
Definition: mapdebugtab.h:42
Viewport::mMouseY
int mMouseY
Definition: viewport.h:154
RENDER_NULL
@ RENDER_NULL
Definition: rendertype.h:33
textures_count
int textures_count
Definition: client.cpp:137
MapDebugTab::mMapNameLabel
Label * mMapNameLabel
Definition: mapdebugtab.h:44
ContainerPlacer
Definition: containerplacer.h:35
Viewport::getCameraY
int getCameraY() const
Definition: viewport.h:120
LayoutHelper
Definition: layouthelper.h:38
MapDebugTab::logic
void logic()
Definition: mapdebugtab.cpp:172
LayoutHelper::getPlacer
ContainerPlacer getPlacer(const int x, const int y)
Definition: layouthelper.cpp:59
localplayer.h
RENDER_GLES_OPENGL
@ RENDER_GLES_OPENGL
Definition: rendertype.h:29
localPlayer
LocalPlayer * localPlayer
Definition: localplayer.cpp:108
nullptr
#define nullptr
Definition: localconsts.h:44
MapDebugTab::mXYLabel
Label * mXYLabel
Definition: mapdebugtab.h:52
strprintf
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Map::getTileWidth
int getTileWidth() const
Definition: map.h:177
mapdebugtab.h
MapDebugTab::mTileMouseLabel
Label * mTileMouseLabel
Definition: mapdebugtab.h:46
MapDebugTab::mMapLabel
Label * mMapLabel
Definition: mapdebugtab.h:43
RENDER_MODERN_OPENGL
@ RENDER_MODERN_OPENGL
Definition: rendertype.h:31
gettext.h
Viewport::mMouseX
int mMouseX
Definition: viewport.h:153
mainGraphics
Graphics * mainGraphics
Definition: graphics.cpp:108
RENDER_LAST
@ RENDER_LAST
Definition: rendertype.h:34
RENDER_SDL2_DEFAULT
@ RENDER_SDL2_DEFAULT
Definition: rendertype.h:30
RENDER_SOFTWARE
@ RENDER_SOFTWARE
Definition: rendertype.h:26
stringutils.h
Properties::getProperty
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
label.h
viewport
Viewport * viewport
Definition: viewport.cpp:35
layouthelper.h
Game::getCurrentMap
Map * getCurrentMap() const
Definition: game.h:106
MapDebugTab::mUpdateTime
time_t mUpdateTime
Definition: mapdebugtab.h:54
RENDER_SAFE_OPENGL
@ RENDER_SAFE_OPENGL
Definition: rendertype.h:28
MapDebugTab::mParticleCountLabel
Label * mParticleCountLabel
Definition: mapdebugtab.h:47
Rect
Definition: rect.h:72
Label
Definition: label.h:87
Map
Definition: map.h:71
Map::getTileHeight
int getTileHeight() const
Definition: map.h:183
Window::place
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
game.h
MapDebugTab::mFPSText
std::string mFPSText
Definition: mapdebugtab.h:63
new
#define new
Definition: debug_new.h:147
Viewport::getCameraX
int getCameraX() const
Definition: viewport.h:114
ImageHelper::useOpenGL
virtual RenderType useOpenGL() const
Definition: imagehelper.h:106
MapDebugTab::MapDebugTab
MapDebugTab(const Widget2 *const widget)
Definition: mapdebugtab.cpp:49
_
#define _(s)
Definition: gettext.h:34
Being::getTileY
int getTileY() const
Definition: being.h:173
Game
Definition: game.h:62
DebugTab
Definition: debugtab.h:28
RENDER_GLES2_OPENGL
@ RENDER_GLES2_OPENGL
Definition: rendertype.h:32
debug.h
Being::getTileX
int getTileX() const
Definition: being.h:167