From d812d9fac7bae4eff66a5ce8275be19d0ca77a32 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Nov 2012 21:13:16 +0300 Subject: Add own profiler and profiler info to some code. --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/actorsprite.cpp | 3 ++ src/actorspritemanager.cpp | 7 +++ src/animatedsprite.cpp | 1 + src/being.cpp | 7 +++ src/client.cpp | 77 ++++++++++++++++++++++++++- src/compoundsprite.cpp | 1 + src/flooritem.cpp | 2 + src/game.cpp | 9 ++++ src/graphics.cpp | 10 ++++ src/gui/botcheckerwindow.cpp | 2 + src/gui/chatwindow.cpp | 2 + src/gui/connectiondialog.cpp | 2 + src/gui/debugwindow.cpp | 7 +++ src/gui/equipmentwindow.cpp | 5 ++ src/gui/gui.cpp | 13 +++++ src/gui/killstats.cpp | 4 ++ src/gui/minimap.cpp | 8 +++ src/gui/ministatuswindow.cpp | 4 ++ src/gui/npcdialog.cpp | 2 + src/gui/outfitwindow.cpp | 2 + src/gui/sdlfont.cpp | 11 +++- src/gui/serverdialog.cpp | 2 + src/gui/shopwindow.cpp | 2 + src/gui/socialwindow.cpp | 2 + src/gui/updaterwindow.cpp | 2 + src/gui/viewport.cpp | 5 ++ src/gui/whoisonline.cpp | 2 + src/gui/widgets/avatarlistbox.cpp | 5 ++ src/gui/widgets/browserbox.cpp | 3 +- src/gui/widgets/button.cpp | 5 ++ src/gui/widgets/checkbox.cpp | 2 + src/gui/widgets/desktop.cpp | 2 + src/gui/widgets/dropdown.cpp | 4 ++ src/gui/widgets/dropshortcutcontainer.cpp | 5 ++ src/gui/widgets/emoteshortcutcontainer.cpp | 2 + src/gui/widgets/extendedlistbox.cpp | 2 + src/gui/widgets/guitable.cpp | 2 + src/gui/widgets/icon.cpp | 2 + src/gui/widgets/itemcontainer.cpp | 7 +++ src/gui/widgets/itemshortcutcontainer.cpp | 8 +++ src/gui/widgets/label.cpp | 2 + src/gui/widgets/listbox.cpp | 4 ++ src/gui/widgets/passwordfield.cpp | 2 + src/gui/widgets/playerbox.cpp | 4 ++ src/gui/widgets/popup.cpp | 2 + src/gui/widgets/progressbar.cpp | 6 ++- src/gui/widgets/progressindicator.cpp | 2 + src/gui/widgets/radiobutton.cpp | 2 + src/gui/widgets/scrollarea.cpp | 9 ++++ src/gui/widgets/shoplistbox.cpp | 5 ++ src/gui/widgets/slider.cpp | 3 ++ src/gui/widgets/sliderlist.cpp | 2 + src/gui/widgets/spellshortcutcontainer.cpp | 3 +- src/gui/widgets/tab.cpp | 5 ++ src/gui/widgets/tabbedarea.cpp | 7 +++ src/gui/widgets/textfield.cpp | 4 ++ src/gui/widgets/textpreview.cpp | 2 + src/gui/widgets/window.cpp | 2 + src/gui/widgets/windowcontainer.cpp | 11 ++++ src/gui/widgets/windowcontainer.h | 4 ++ src/guichan/basiccontainer.cpp | 9 ++++ src/guichan/graphics.cpp | 1 + src/guichan/gui.cpp | 6 +++ src/guichan/widget.cpp | 2 + src/guichan/widgets/container.cpp | 2 + src/guichan/widgets/scrollarea.cpp | 2 + src/guichan/widgets/textbox.cpp | 2 + src/imageparticle.cpp | 1 + src/imagesprite.cpp | 1 + src/localconsts.h | 5 ++ src/localplayer.cpp | 4 ++ src/map.cpp | 11 ++++ src/maplayer.cpp | 22 ++++++++ src/mobileopenglgraphics.cpp | 7 +++ src/net/packetcounters.cpp | 2 + src/net/tmwa/adminhandler.cpp | 2 + src/net/tmwa/beinghandler.cpp | 2 + src/net/tmwa/buysellhandler.cpp | 3 +- src/net/tmwa/charserverhandler.cpp | 2 + src/net/tmwa/chathandler.cpp | 2 + src/net/tmwa/gamehandler.cpp | 2 + src/net/tmwa/generalhandler.cpp | 6 +++ src/net/tmwa/guildhandler.cpp | 2 + src/net/tmwa/inventoryhandler.cpp | 2 + src/net/tmwa/itemhandler.cpp | 2 + src/net/tmwa/loginhandler.cpp | 2 + src/net/tmwa/network.cpp | 4 ++ src/net/tmwa/npchandler.cpp | 2 + src/net/tmwa/partyhandler.cpp | 2 + src/net/tmwa/playerhandler.cpp | 2 + src/net/tmwa/questhandler.cpp | 2 + src/net/tmwa/specialhandler.cpp | 2 + src/net/tmwa/tradehandler.cpp | 2 + src/normalopenglgraphics.cpp | 7 +++ src/resources/resourcemanager.cpp | 4 ++ src/safeopenglgraphics.cpp | 7 +++ src/simpleanimation.cpp | 1 + src/sound.cpp | 2 + src/text.cpp | 7 +++ src/textmanager.cpp | 2 + src/textparticle.cpp | 5 ++ src/utils/perfomance.cpp | 85 ++++++++++++++++++++++++++++++ src/utils/perfomance.h | 76 ++++++++++++++++++++++++++ 105 files changed, 637 insertions(+), 7 deletions(-) create mode 100644 src/utils/perfomance.cpp create mode 100644 src/utils/perfomance.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77b9792b6..f25ae995d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -478,6 +478,8 @@ SET(SRCS utils/mathutils.h utils/paths.cpp utils/paths.h + utils/perfomance.cpp + utils/perfomance.h utils/physfsrwops.cpp utils/physfsrwops.h utils/process.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 09c47c21e..2140f85cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -482,6 +482,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ utils/mkdir.h \ utils/paths.cpp \ utils/paths.h \ + utils/perfomance.cpp \ + utils/perfomance.h \ utils/physfsrwops.cpp \ utils/physfsrwops.h \ utils/process.cpp \ diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index bb612c674..edc954d28 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -80,6 +80,7 @@ ActorSprite::~ActorSprite() bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const { + FUNC_BLOCK("ActorSprite::draw", 1) // TODO: Eventually, we probably should fix all sprite offsets so that // these translations aren't necessary anymore. The sprites know // best where their base point should be. @@ -111,6 +112,7 @@ bool ActorSprite::drawSpriteAt(Graphics *const graphics, void ActorSprite::logic() { + BLOCK_START("ActorSprite::logic") // Update sprite animations update(tick_time * MILLISECONDS_IN_A_TICK); @@ -130,6 +132,7 @@ void ActorSprite::logic() // Update particle effects mChildParticleEffects.moveTo(mPos.x, mPos.y); + BLOCK_END("ActorSprite::logic") } void ActorSprite::actorLogic() diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 4cbf157ff..4ccb2e347 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -746,6 +746,7 @@ const ActorSprites &ActorSpriteManager::getAll() const void ActorSpriteManager::logic() { + BLOCK_START("ActorSpriteManager::logic") for_actors { if (*it) @@ -753,8 +754,12 @@ void ActorSpriteManager::logic() } if (mDeleteActors.empty()) + { + BLOCK_END("ActorSpriteManager::logic") return; + } + BLOCK_START("ActorSpriteManager::logic 1") for (ActorSpritesConstIterator it = mDeleteActors.begin(), it_end = mDeleteActors.end(); it != it_end; ++it) @@ -789,6 +794,8 @@ void ActorSpriteManager::logic() } mDeleteActors.clear(); + BLOCK_END("ActorSpriteManager::logic 1") + BLOCK_END("ActorSpriteManager::logic") } void ActorSpriteManager::clear() diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 2446e19dc..7fc8b2782 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -266,6 +266,7 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) bool AnimatedSprite::draw(Graphics *graphics, int posX, int posY) const { + FUNC_BLOCK("AnimatedSprite::draw", 1) if (!mFrame || !mFrame->image) return false; diff --git a/src/being.cpp b/src/being.cpp index 210736117..fe84cdaaf 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1243,6 +1243,7 @@ void Being::nextTile() void Being::logic() { + BLOCK_START("Being::logic") // Reduce the time that speech is still displayed if (mSpeechTime > 0) mSpeechTime--; @@ -1264,7 +1265,10 @@ void Being::logic() // This is a hack that stops NPCs from running off the map... if (mDest.x <= 0 && mDest.y <= 0) + { + BLOCK_END("Being::logic") return; + } // The Vector representing the difference between current position // and the next destination path node. @@ -1449,6 +1453,7 @@ void Being::logic() if (mType != PLAYER && actorSpriteManager) actorSpriteManager->destroy(this); } + BLOCK_END("Being::logic") } void Being::drawEmotion(Graphics *const graphics, const int offsetX, @@ -1878,6 +1883,7 @@ void Being::updateName() void Being::reReadConfig() { + BLOCK_START("Being::reReadConfig") if (mUpdateConfigTime + 1 < cur_time) { mHighlightMapPortals = config.getBoolValue("highlightMapPortals"); @@ -1898,6 +1904,7 @@ void Being::reReadConfig() mUpdateConfigTime = cur_time; } + BLOCK_END("Being::reReadConfig") } bool Being::updateFromCache() diff --git a/src/client.cpp b/src/client.cpp index 2e135fc6a..a73dc6806 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -809,6 +809,10 @@ void Client::gameClear() if (logger) logger->log1("Quitting11"); +#ifdef USE_PROFILER + Perfomance::clear(); +#endif + #ifdef DEBUG_OPENGL_LEAKS if (logger) logger->log("textures left: %d", textures_count); @@ -862,6 +866,8 @@ int Client::gameExec() while (mState != STATE_EXIT) { + PROFILER_START(); + BLOCK_START("Client::gameExec 1") if (mGame) { // Let the game handle the events while it is active @@ -869,6 +875,7 @@ int Client::gameExec() } else { + BLOCK_START("Client::gameExec 2") // Handle SDL events while (SDL_PollEvent(&event)) { @@ -917,11 +924,15 @@ int Client::gameExec() } #endif } + BLOCK_END("Client::gameExec 2") } + BLOCK_START("Client::gameExec 3") if (Net::getGeneralHandler()) Net::getGeneralHandler()->flushNetwork(); + BLOCK_END("Client::gameExec 3") + BLOCK_START("Client::gameExec 4") int k = 0; while (lastTickTime != tick_time && k < 40) { @@ -942,6 +953,7 @@ int Client::gameExec() gui->slowLogic(); if (mGame) mGame->slowLogic(); + BLOCK_END("Client::gameExec 4") // This is done because at some point tick_time will wrap. lastTickTime = tick_time; @@ -961,9 +973,12 @@ int Client::gameExec() SDL_Delay(100); } + BLOCK_START("Client::SDL_framerateDelay") if (mLimitFps) SDL_framerateDelay(&mFpsManager); + BLOCK_END("Client::SDL_framerateDelay") + BLOCK_START("Client::gameExec 6") // TODO: Add connect timeouts if (mState == STATE_CONNECT_GAME && Net::getGameHandler()->isConnected()) @@ -1048,12 +1063,14 @@ int Client::gameExec() mDesktop->setSize(mainGraphics->getWidth(), mainGraphics->getHeight()); } + BLOCK_END("Client::gameExec 6") if (mState == STATE_SWITCH_LOGIN && mOldState == STATE_GAME) Net::getGameHandler()->disconnect(); if (mState != mOldState) { + BLOCK_START("Client::gameExec 7") DepricatedEvent evt(EVENT_STATECHANGE); evt.setInt("oldState", mOldState); evt.setInt("newState", mState); @@ -1088,10 +1105,13 @@ int Client::gameExec() mQuitDialog->scheduleDelete(); mQuitDialog = nullptr; } + BLOCK_END("Client::gameExec 7") + BLOCK_START("Client::gameExec 8") switch (mState) { case STATE_CHOOSE_SERVER: + BLOCK_START("Client::gameExec STATE_CHOOSE_SERVER") logger->log1("State: CHOOSE SERVER"); loginData.clearUpdateHost(); @@ -1119,14 +1139,17 @@ int Client::gameExec() mOptions.serverName.clear(); mOptions.serverPort = 0; } + BLOCK_END("Client::gameExec STATE_CHOOSE_SERVER") break; case STATE_CONNECT_SERVER: + BLOCK_START("Client::gameExec STATE_CONNECT_SERVER") logger->log1("State: CONNECT SERVER"); loginData.updateHosts.clear(); mCurrentDialog = new ConnectionDialog( _("Connecting to server"), STATE_SWITCH_SERVER); TranslationManager::loadCurrentLang(); + BLOCK_END("Client::gameExec STATE_CONNECT_SERVER") break; case STATE_PRE_LOGIN: @@ -1136,6 +1159,7 @@ int Client::gameExec() break; case STATE_LOGIN: + BLOCK_START("Client::gameExec STATE_LOGIN") logger->log1("State: LOGIN"); // Don't allow an alpha opacity // lower than the default value @@ -1157,16 +1181,20 @@ int Client::gameExec() // dialog will show up next time. mOptions.password.clear(); } + BLOCK_END("Client::gameExec STATE_LOGIN") break; case STATE_LOGIN_ATTEMPT: + BLOCK_START("Client::gameExec STATE_LOGIN_ATTEMPT") logger->log1("State: LOGIN ATTEMPT"); accountLogin(&loginData); mCurrentDialog = new ConnectionDialog( _("Logging in"), STATE_SWITCH_SERVER); + BLOCK_END("Client::gameExec STATE_LOGIN_ATTEMPT") break; case STATE_WORLD_SELECT: + BLOCK_START("Client::gameExec STATE_WORLD_SELECT") logger->log1("State: WORLD SELECT"); { TranslationManager::loadCurrentLang(); @@ -1192,15 +1220,19 @@ int Client::gameExec() } } } + BLOCK_END("Client::gameExec STATE_WORLD_SELECT") break; case STATE_WORLD_SELECT_ATTEMPT: + BLOCK_START("Client::gameExec STATE_WORLD_SELECT_ATTEMPT") logger->log1("State: WORLD SELECT ATTEMPT"); mCurrentDialog = new ConnectionDialog( _("Entering game world"), STATE_WORLD_SELECT); + BLOCK_END("Client::gameExec STATE_WORLD_SELECT_ATTEMPT") break; case STATE_UPDATE: + BLOCK_START("Client::gameExec STATE_UPDATE") // Determine which source to use for the update host if (!mOptions.updateHost.empty()) mUpdateHost = mOptions.updateHost; @@ -1226,10 +1258,12 @@ int Client::gameExec() + mUpdatesDir, mOptions.dataPath.empty(), loginData.updateType); } + BLOCK_END("Client::gameExec STATE_UPDATE") break; case STATE_LOAD_DATA: { + BLOCK_START("Client::gameExec STATE_LOAD_DATA") logger->log1("State: LOAD DATA"); const ResourceManager *const resman @@ -1298,17 +1332,21 @@ int Client::gameExec() mDesktop->reloadWallpaper(); mState = STATE_GET_CHARACTERS; + BLOCK_END("Client::gameExec STATE_LOAD_DATA") break; } case STATE_GET_CHARACTERS: + BLOCK_START("Client::gameExec STATE_GET_CHARACTERS") logger->log1("State: GET CHARACTERS"); Net::getCharHandler()->requestCharacters(); mCurrentDialog = new ConnectionDialog( _("Requesting characters"), STATE_SWITCH_SERVER); + BLOCK_END("Client::gameExec STATE_GET_CHARACTERS") break; case STATE_CHAR_SELECT: + BLOCK_START("Client::gameExec STATE_CHAR_SELECT") logger->log1("State: CHAR SELECT"); // Don't allow an alpha opacity // lower than the default value @@ -1331,10 +1369,11 @@ int Client::gameExec() // Choosing character on the command line should work only // once, clear it so that 'switch character' works. mOptions.character.clear(); - + BLOCK_END("Client::gameExec STATE_CHAR_SELECT") break; case STATE_CONNECT_GAME: + BLOCK_START("Client::gameExec STATE_CONNECT_GAME") logger->log1("State: CONNECT GAME"); Net::getGameHandler()->connect(); @@ -1342,18 +1381,22 @@ int Client::gameExec() _("Connecting to the game server"), Net::getNetworkType() != ServerInfo::MANASERV ? STATE_CHOOSE_SERVER : STATE_SWITCH_CHARACTER); + BLOCK_END("Client::gameExec STATE_CONNECT_GAME") break; case STATE_CHANGE_MAP: + BLOCK_START("Client::gameExec STATE_CHANGE_MAP") logger->log1("State: CHANGE_MAP"); Net::getGameHandler()->connect(); mCurrentDialog = new ConnectionDialog( _("Changing game servers"), STATE_SWITCH_CHARACTER); + BLOCK_END("Client::gameExec STATE_CHANGE_MAP") break; case STATE_GAME: + BLOCK_START("Client::gameExec STATE_GAME") if (player_node) { logger->log("Memorizing selected character %s", @@ -1397,29 +1440,36 @@ int Client::gameExec() if (Net::getGeneralHandler()) Net::getGeneralHandler()->reloadPartially(); mGame = new Game; + BLOCK_END("Client::gameExec STATE_GAME") break; case STATE_LOGIN_ERROR: + BLOCK_START("Client::gameExec STATE_LOGIN_ERROR") logger->log1("State: LOGIN ERROR"); mCurrentDialog = new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&loginListener); mCurrentDialog = nullptr; // OkDialog deletes itself + BLOCK_END("Client::gameExec STATE_LOGIN_ERROR") break; case STATE_ACCOUNTCHANGE_ERROR: + BLOCK_START("Client::gameExec STATE_ACCOUNTCHANGE_ERROR") logger->log1("State: ACCOUNT CHANGE ERROR"); mCurrentDialog = new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself + BLOCK_END("Client::gameExec STATE_ACCOUNTCHANGE_ERROR") break; case STATE_REGISTER_PREP: + BLOCK_START("Client::gameExec STATE_REGISTER_PREP") logger->log1("State: REGISTER_PREP"); Net::getLoginHandler()->getRegistrationDetails(); mCurrentDialog = new ConnectionDialog( _("Requesting registration details"), STATE_LOGIN); + BLOCK_END("Client::gameExec STATE_REGISTER_PREP") break; case STATE_REGISTER: @@ -1428,22 +1478,29 @@ int Client::gameExec() break; case STATE_REGISTER_ATTEMPT: + BLOCK_START("Client::gameExec STATE_REGISTER_ATTEMPT") logger->log("Username is %s", loginData.username.c_str()); Net::getLoginHandler()->registerAccount(&loginData); + BLOCK_END("Client::gameExec STATE_REGISTER_ATTEMPT") break; case STATE_CHANGEPASSWORD: + BLOCK_START("Client::gameExec STATE_CHANGEPASSWORD") logger->log1("State: CHANGE PASSWORD"); mCurrentDialog = new ChangePasswordDialog(&loginData); + BLOCK_END("Client::gameExec STATE_CHANGEPASSWORD") break; case STATE_CHANGEPASSWORD_ATTEMPT: + BLOCK_START("Client::gameExec STATE_CHANGEPASSWORD_ATTEMPT") logger->log1("State: CHANGE PASSWORD ATTEMPT"); Net::getLoginHandler()->changePassword(loginData.username, loginData.password, loginData.newPassword); + BLOCK_END("Client::gameExec STATE_CHANGEPASSWORD_ATTEMPT") break; case STATE_CHANGEPASSWORD_SUCCESS: + BLOCK_START("Client::gameExec STATE_CHANGEPASSWORD_SUCCESS") logger->log1("State: CHANGE PASSWORD SUCCESS"); mCurrentDialog = new OkDialog(_("Password Change"), _("Password changed successfully!"), DIALOG_ERROR); @@ -1451,6 +1508,7 @@ int Client::gameExec() mCurrentDialog = nullptr; // OkDialog deletes itself loginData.password = loginData.newPassword; loginData.newPassword = ""; + BLOCK_END("Client::gameExec STATE_CHANGEPASSWORD_SUCCESS") break; case STATE_CHANGEEMAIL: @@ -1495,29 +1553,35 @@ int Client::gameExec() break; case STATE_SWITCH_SERVER: + BLOCK_START("Client::gameExec STATE_SWITCH_SERVER") logger->log1("State: SWITCH SERVER"); Net::getLoginHandler()->disconnect(); Net::getGameHandler()->disconnect(); mState = STATE_CHOOSE_SERVER; + BLOCK_END("Client::gameExec STATE_SWITCH_SERVER") break; case STATE_SWITCH_LOGIN: + BLOCK_START("Client::gameExec STATE_SWITCH_LOGIN") logger->log1("State: SWITCH LOGIN"); Net::getLoginHandler()->logout(); mState = STATE_LOGIN; + BLOCK_END("Client::gameExec STATE_SWITCH_LOGIN") break; case STATE_SWITCH_CHARACTER: + BLOCK_START("Client::gameExec STATE_SWITCH_CHARACTER") logger->log1("State: SWITCH CHARACTER"); // Done with game Net::getGameHandler()->disconnect(); mState = STATE_GET_CHARACTERS; + BLOCK_END("Client::gameExec STATE_SWITCH_CHARACTER") break; case STATE_LOGOUT_ATTEMPT: @@ -1530,18 +1594,23 @@ int Client::gameExec() break; case STATE_EXIT: + BLOCK_START("Client::gameExec STATE_EXIT") logger->log1("State: EXIT"); Net::unload(); + BLOCK_END("Client::gameExec STATE_EXIT") break; case STATE_FORCE_QUIT: + BLOCK_START("Client::gameExec STATE_FORCE_QUIT") logger->log1("State: FORCE QUIT"); if (Net::getGeneralHandler()) Net::getGeneralHandler()->unload(); mState = STATE_EXIT; + BLOCK_END("Client::gameExec STATE_FORCE_QUIT") break; case STATE_ERROR: + BLOCK_START("Client::gameExec STATE_ERROR") logger->log1("State: ERROR"); logger->log("Error: %s\n", errorMessage.c_str()); mCurrentDialog = new OkDialog(_("Error"), @@ -1549,6 +1618,7 @@ int Client::gameExec() mCurrentDialog->addActionListener(&errorListener); mCurrentDialog = nullptr; // OkDialog deletes itself Net::getGameHandler()->disconnect(); + BLOCK_END("Client::gameExec STATE_ERROR") break; case STATE_AUTORECONNECT_SERVER: @@ -1560,7 +1630,9 @@ int Client::gameExec() mState = STATE_FORCE_QUIT; break; } + BLOCK_END("Client::gameExec 8") } + BLOCK_END("Client::gameExec 1") } return 0; @@ -1722,6 +1794,9 @@ void Client::initLocalDataDir() logger->error(strprintf(_("%s doesn't exist and can't be created! " "Exiting."), mLocalDataDir.c_str())); } +#ifdef USE_PROFILER + Perfomance::init(mLocalDataDir + "/profiler.log"); +#endif } void Client::initTempDir() diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index f22e927f0..146ce9a1a 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -120,6 +120,7 @@ bool CompoundSprite::update(int time) bool CompoundSprite::draw(Graphics *graphics, int posX, int posY) const { + FUNC_BLOCK("CompoundSprite::draw", 1) if (mNeedsRedraw) updateImages(); diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 2a7ca5aed..cb9f2829f 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -98,6 +98,7 @@ bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const if (!mMap) return false; + BLOCK_START("FloorItem::draw") const int x = mX * mMap->getTileWidth() + offsetX; const int y = mY * mMap->getTileHeight() + offsetY; gcn::Font *font = nullptr; @@ -145,5 +146,6 @@ bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const font->drawString(graphics, toString(mAmount), x, y); } } + BLOCK_END("FloorItem::draw") return res; } diff --git a/src/game.cpp b/src/game.cpp index 7993fa25c..3cf000229 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -557,6 +557,7 @@ bool Game::saveScreenshot(SDL_Surface *const screenshot) void Game::logic() { + BLOCK_START("Game::logic") handleInput(); // Handle all necessary game logic @@ -569,10 +570,12 @@ void Game::logic() mCurrentMap->update(); cur_time = static_cast(time(nullptr)); + BLOCK_END("Game::logic") } void Game::slowLogic() { + BLOCK_START("Game::slowLogic") if (player_node) player_node->slowLogic(); if (botCheckerWindow) @@ -645,10 +648,12 @@ void Game::slowLogic() disconnectedDialog = nullptr; } } + BLOCK_END("Game::slowLogic") } void Game::adjustPerfomance() { + FUNC_BLOCK("Game::adjustPerfomance", 1) if (mNextAdjustTime <= adjustDelay) { mNextAdjustTime = cur_time + adjustDelay; @@ -907,6 +912,7 @@ void Game::handleActive(const SDL_Event &event) */ void Game::handleInput() { + BLOCK_START("Game::handleInput 1") if (joystick) joystick->logic(); @@ -914,6 +920,7 @@ void Game::handleInput() SDL_Event event; while (SDL_PollEvent(&event)) { + BLOCK_START("Game::handleInput 2") updateHistory(event); checkKeys(); @@ -935,6 +942,7 @@ void Game::handleInput() { Client::setState(STATE_EXIT); } + BLOCK_END("Game::handleInput 2") } // End while // If the user is configuring the keys then don't respond. @@ -951,6 +959,7 @@ void Game::handleInput() handleMove(); inputManager.handleRepeat(); + BLOCK_END("Game::handleInput 1") } /** diff --git a/src/graphics.cpp b/src/graphics.cpp index 4c1d4e832..a0a9a9c12 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -376,6 +376,7 @@ bool Graphics::drawRescaledImage(Image *const image, int srcX, int srcY, const int desiredHeight, const bool useColor A_UNUSED) { + FUNC_BLOCK("Graphics::drawRescaledImage", 1) // Check that preconditions for blitting are met. if (!mTarget || !image) return false; @@ -416,6 +417,7 @@ bool Graphics::drawImage2(const Image *const image, int srcX, int srcY, int dstX, int dstY, const int width, const int height, const bool useColor A_UNUSED) { + FUNC_BLOCK("Graphics::drawImage2", 1) // Check that preconditions for blitting are met. if (!mTarget || !image || !image->mSDLSurface) return false; @@ -451,6 +453,7 @@ void Graphics::drawImagePattern(const Image *const image, const int x, const int y, const int w, const int h) { + FUNC_BLOCK("Graphics::drawImagePattern", 1) // Check that preconditions for blitting are met. if (!mTarget || !image) return; @@ -555,6 +558,7 @@ void Graphics::drawImageRect(const int x, const int y, const Image *const left, const Image *const center) { + BLOCK_START("Graphics::drawImageRect") const bool drawMain = center && topLeft && topRight && bottomLeft && bottomRight; @@ -597,6 +601,7 @@ void Graphics::drawImageRect(const int x, const int y, x + w - bottomRight->getWidth(), y + h - bottomRight->getHeight()); } + BLOCK_END("Graphics::drawImageRect") } void Graphics::drawImageRect(int x, int y, int w, int h, @@ -685,6 +690,7 @@ bool Graphics::calcImageRect(GraphicsVertexes *const vert, if (!vert) return false; + BLOCK_START("Graphics::calcImageRect") const bool drawMain = center && topLeft && topRight && bottomLeft && bottomRight; @@ -729,6 +735,7 @@ bool Graphics::calcImageRect(GraphicsVertexes *const vert, } popClipArea(); + BLOCK_END("Graphics::calcImageRect") return 0; } @@ -837,6 +844,7 @@ void Graphics::drawTile(ImageVertexes *const vert) void Graphics::updateScreen() { + BLOCK_START("Graphics::updateScreen") if (mDoubleBuffer) { SDL_Flip(mTarget); @@ -846,6 +854,7 @@ void Graphics::updateScreen() SDL_UpdateRects(mTarget, 1, &mRect); // SDL_UpdateRect(mTarget, 0, 0, 0, 0); } + BLOCK_END("Graphics::updateScreen") } SDL_Surface *Graphics::getScreenshot() @@ -998,6 +1007,7 @@ int Graphics::SDL_FakeUpperBlit(const SDL_Surface *const src, void Graphics::fillRectangle(const gcn::Rectangle& rectangle) { + FUNC_BLOCK("Graphics::fillRectangle", 1) if (mClipStack.empty()) return; diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 4f3381dec..3164ca7c5 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -351,6 +351,7 @@ BotCheckerWindow::~BotCheckerWindow() void BotCheckerWindow::slowLogic() { + BLOCK_START("BotCheckerWindow::slowLogic") if (mEnabled && mTableModel) { const unsigned int nowTime = cur_time; @@ -367,6 +368,7 @@ void BotCheckerWindow::slowLogic() mLastUpdateTime = nowTime; } } + BLOCK_END("BotCheckerWindow::slowLogic") } void BotCheckerWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 47f6be680..2e78c048c 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -1693,8 +1693,10 @@ void ChatWindow::mouseExited(gcn::MouseEvent& mouseEvent) void ChatWindow::draw(gcn::Graphics* graphics) { + BLOCK_START("ChatWindow::draw") if (!mAutoHide || mHaveMouse) Window::draw(graphics); + BLOCK_END("ChatWindow::draw") } void ChatWindow::updateVisibility() diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 770507c38..c92f5f53e 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -63,6 +63,8 @@ void ConnectionDialog::action(const gcn::ActionEvent &) void ConnectionDialog::draw(gcn::Graphics *graphics) { + BLOCK_START("ConnectionDialog::draw") // Don't draw the window background, only draw the children drawChildren(graphics); + BLOCK_END("ConnectionDialog::draw") } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 08ea48dd3..11a8ca3c0 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -90,8 +90,12 @@ DebugWindow::~DebugWindow() void DebugWindow::slowLogic() { + BLOCK_START("DebugWindow::slowLogic") if (!isVisible() || !mTabs) + { + BLOCK_END("DebugWindow::slowLogic") return; + } switch (mTabs->getSelectedTabIndex()) { @@ -109,10 +113,12 @@ void DebugWindow::slowLogic() if (player_node) player_node->tryPingRequest(); + BLOCK_END("DebugWindow::slowLogic") } void DebugWindow::draw(gcn::Graphics *g) { + BLOCK_START("DebugWindow::draw") Window::draw(g); if (player_node) @@ -125,6 +131,7 @@ void DebugWindow::draw(gcn::Graphics *g) -target->getPixelY() + 32 + getHeight() / 2); } } + BLOCK_END("DebugWindow::draw") } void DebugWindow::widgetResized(const gcn::Event &event) diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 6d7baff40..e05e1cc50 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -141,6 +141,7 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { + BLOCK_START("EquipmentWindow::draw") // Draw window graphics Window::draw(graphics); Graphics *const g = static_cast(graphics); @@ -162,7 +163,10 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } if (!mEquipment) + { + BLOCK_END("EquipmentWindow::draw") return; + } i = 0; for (std::vector::const_iterator it = mBoxes.begin(), @@ -197,6 +201,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) box->y + mItemPadding); } } + BLOCK_END("EquipmentWindow::draw") } void EquipmentWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6e78e3ac8..956b9e8b3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -258,11 +258,15 @@ Gui::~Gui() void Gui::logic() { + BLOCK_START("Gui::logic") ResourceManager *const resman = ResourceManager::getInstance(); resman->clearScheduled(); if (!mTop) + { + BLOCK_END("Gui::logic") return; + } handleModalFocus(); handleModalMouseInputFocus(); @@ -271,10 +275,12 @@ void Gui::logic() handleMouseInput(); mTop->logic(); + BLOCK_END("Gui::logic") } void Gui::slowLogic() { + BLOCK_START("Gui::slowLogic") Palette::advanceGradients(); // Fade out mouse cursor after extended inactivity @@ -297,14 +303,17 @@ void Gui::slowLogic() mSecureFont->slowLogic(); if (boldFont) boldFont->slowLogic(); + BLOCK_END("Gui::slowLogic") } bool Gui::handleInput() { + BLOCK_START("Gui::handleInput") if (mInput) return handleKeyInput2(); else return false; + BLOCK_END("Gui::handleInput") } bool Gui::handleKeyInput2() @@ -312,6 +321,7 @@ bool Gui::handleKeyInput2() if (!guiInput) return false; + BLOCK_START("Gui::handleKeyInput2") bool consumed(false); while (!mInput->isKeyQueueEmpty()) @@ -376,11 +386,13 @@ bool Gui::handleKeyInput2() } } } // end while + BLOCK_END("Gui::handleKeyInput2") return consumed; } void Gui::draw() { + BLOCK_START("Gui::draw 1") mGraphics->pushClipArea(getTop()->getDimension()); getTop()->draw(mGraphics); @@ -403,6 +415,7 @@ void Gui::draw() } mGraphics->popClipArea(); + BLOCK_END("Gui::draw 1") } void Gui::videoResized() const diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index b591e6c51..d8da5c1e8 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -259,6 +259,7 @@ void KillStats::gainXp(int xp) void KillStats::recalcStats() { + BLOCK_START("KillStats::recalcStats") const int curTime = cur_time; // Need Update Exp Counter @@ -295,10 +296,12 @@ void KillStats::recalcStats() m15minExpNum = newExp; } validateJacko(); + BLOCK_END("KillStats::recalcStats") } void KillStats::update() { + BLOCK_START("KillStats::update") mExpSpeed1Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s", "Exp speed per %d min: %s", 1), 1, toString(m1minSpeed).c_str())); @@ -355,6 +358,7 @@ void KillStats::update() validateJacko(); updateJackoLabel(); + BLOCK_END("KillStats::update") } void KillStats::draw(gcn::Graphics *g) { diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index b773976c3..f155faaea 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -206,10 +206,14 @@ void Minimap::toggle() void Minimap::draw(gcn::Graphics *graphics) { + BLOCK_START("Minimap::draw") Window::draw(graphics); if (!userPalette || !player_node || !viewport) + { + BLOCK_END("Minimap::draw") return; + } Graphics *const graph = static_cast(graphics); @@ -218,7 +222,10 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->pushClipArea(a); if (!actorSpriteManager) + { + BLOCK_END("Minimap::draw") return; + } mMapOriginX = 0; mMapOriginY = 0; @@ -396,6 +403,7 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->setColor(userPalette->getColor(UserPalette::PC)); graphics->drawRectangle(gcn::Rectangle(x, y, w, h)); graphics->popClipArea(); + BLOCK_END("Minimap::draw") } void Minimap::mouseReleased(gcn::MouseEvent &event) diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp index 234218e8c..835c0b250 100644 --- a/src/gui/ministatuswindow.cpp +++ b/src/gui/ministatuswindow.cpp @@ -255,6 +255,7 @@ void MiniStatusWindow::updateStatus() void MiniStatusWindow::logic() { + BLOCK_START("MiniStatusWindow::logic") Popup::logic(); for (size_t i = 0, sz = mIcons.size(); i < sz; i++) @@ -262,11 +263,14 @@ void MiniStatusWindow::logic() if (mIcons[i]) mIcons[i]->update(tick_time * 10); } + BLOCK_END("MiniStatusWindow::logic") } void MiniStatusWindow::draw(gcn::Graphics *graphics) { + BLOCK_START("MiniStatusWindow::draw") drawChildren(graphics); + BLOCK_END("MiniStatusWindow::draw") } void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event) diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index ab05a3b49..1eb5e9800 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -745,6 +745,7 @@ void NpcDialog::setAvatarAction(const int actionId) void NpcDialog::logic() { + BLOCK_START("NpcDialog::logic") Window::logic(); if (mShowAvatar && mAvatarBeing) { @@ -760,6 +761,7 @@ void NpcDialog::logic() } } } + BLOCK_END("NpcDialog::logic") } void NpcDialog::clearRows() diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index b5e5757ca..a79fd5fbc 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -308,6 +308,7 @@ void OutfitWindow::copyOutfit(const int src, const int dst) void OutfitWindow::draw(gcn::Graphics *graphics) { + BLOCK_START("OutfitWindow::draw") Window::draw(graphics); Graphics *const g = static_cast(graphics); @@ -364,6 +365,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics) g->drawImage(image, tPosX, tPosY); } } + BLOCK_END("OutfitWindow::draw") } diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 33581767d..7ecf7cb4f 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -66,6 +66,7 @@ class SDLTextChunk final void generate(TTF_Font *const font, const float alpha) { + BLOCK_START("SDLTextChunk::generate") SDL_Color sdlCol; sdlCol.b = static_cast(color.b); sdlCol.r = static_cast(color.r); @@ -80,11 +81,13 @@ class SDLTextChunk final if (!surface) { img = nullptr; + BLOCK_END("SDLTextChunk::generate") return; } img = imageHelper->createTextSurface(surface, alpha); SDL_FreeSurface(surface); + BLOCK_END("SDLTextChunk::generate") } Image *img; @@ -192,8 +195,12 @@ void SDLFont::drawString(gcn::Graphics *const graphics, const std::string &text, const int x, const int y) { + BLOCK_START("SDLFont::drawString") if (text.empty()) + { + BLOCK_END("SDLFont::drawString") return; + } Graphics *const g = dynamic_cast(graphics); @@ -260,11 +267,12 @@ void SDLFont::drawString(gcn::Graphics *const graphics, image->setAlpha(alpha); g->drawImage(image, x, y); } - + BLOCK_END("SDLFont::drawString") } void SDLFont::slowLogic() { + BLOCK_START("SDLFont::slowLogic") if (!mCleanTime) { mCleanTime = cur_time + CLEAN_TIME; @@ -274,6 +282,7 @@ void SDLFont::slowLogic() doClean(); mCleanTime = cur_time + CLEAN_TIME; } + BLOCK_END("SDLFont::slowLogic") } void SDLFont::createSDLTextChunk(SDLTextChunk *const chunk) diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 306c0534f..5cc1c2acb 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -492,6 +492,7 @@ void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent) void ServerDialog::logic() { + BLOCK_START("ServerDialog::logic") { MutexLocker tempLock(&mMutex); if (mDownloadStatus == DOWNLOADING_COMPLETE) @@ -520,6 +521,7 @@ void ServerDialog::logic() } Window::logic(); + BLOCK_END("ServerDialog::logic") } void ServerDialog::downloadServerList() diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index acc3f3948..a9afab262 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -776,12 +776,14 @@ void ShopWindow::processRequest(std::string nick, std::string data, void ShopWindow::updateTimes() { + BLOCK_START("ShopWindow::updateTimes") if (mAnnonceTime + (2 * 60) < cur_time || mAnnonceTime > cur_time) { mBuyAnnounceButton->setEnabled(true); mSellAnnounceButton->setEnabled(true); } + BLOCK_END("ShopWindow::updateTimes") } bool ShopWindow::checkFloodCounter(int &counterTime) const diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 0fc926009..bb59517e5 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1666,6 +1666,7 @@ void SocialWindow::updateActiveList() void SocialWindow::slowLogic() { + BLOCK_START("SocialWindow::slowLogic") const unsigned int nowTime = cur_time; if (mNeedUpdate && nowTime - mLastUpdateTime > 1) { @@ -1680,6 +1681,7 @@ void SocialWindow::slowLogic() mNeedUpdate = false; mLastUpdateTime = nowTime; } + BLOCK_END("SocialWindow::slowLogic") } void SocialWindow::updateAvatar(std::string name) diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index e156f98be..2abb8979c 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -605,6 +605,7 @@ void UpdaterWindow::addUpdateFile(const ResourceManager *const resman, void UpdaterWindow::logic() { + BLOCK_START("UpdaterWindow::logic") // Update Scroll logic mScrollArea->logic(); @@ -826,6 +827,7 @@ void UpdaterWindow::logic() + toString(static_cast(mDownloadStatus))); break; } + BLOCK_END("UpdaterWindow::logic") } bool UpdaterWindow::validateFile(const std::string &filePath, diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index e7d7ab85d..3fb487811 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -116,6 +116,7 @@ extern MiniStatusWindow *miniStatusWindow; void Viewport::draw(gcn::Graphics *gcnGraphics) { + BLOCK_START("Viewport::draw 1") static int lastTick = tick_time; if (!mMap || !player_node) @@ -123,6 +124,7 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) gcnGraphics->setColor(gcn::Color(64, 64, 64)); gcnGraphics->fillRectangle( gcn::Rectangle(0, 0, getWidth(), getHeight())); + BLOCK_END("Viewport::draw 1") return; } @@ -265,15 +267,18 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) // Draw contained widgets WindowContainer::draw(gcnGraphics); + BLOCK_END("Viewport::draw 1") } void Viewport::logic() { + BLOCK_START("Viewport::logic") WindowContainer::logic(); // Make the player follow the mouse position // if the mouse is dragged elsewhere than in a window. _followMouse(); + BLOCK_END("Viewport::logic") } void Viewport::_followMouse() diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 425d5fbd8..fa3980024 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -606,6 +606,7 @@ void WhoIsOnline::slowLogic() if (!mAllowUpdate) return; + BLOCK_START("WhoIsOnline::slowLogic") if (mUpdateTimer == 0) mUpdateTimer = cur_time; @@ -658,6 +659,7 @@ void WhoIsOnline::slowLogic() default: break; } + BLOCK_END("WhoIsOnline::slowLogic") } void WhoIsOnline::action(const gcn::ActionEvent &event) diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 1f5556a5d..dcb280596 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -89,8 +89,12 @@ AvatarListBox::~AvatarListBox() void AvatarListBox::draw(gcn::Graphics *gcnGraphics) { + BLOCK_START("AvatarListBox::draw") if (!mListModel || !player_node) + { + BLOCK_END("AvatarListBox::draw") return; + } AvatarListModel *const model = static_cast( mListModel); @@ -276,6 +280,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } setWidth(parent->getWidth() - 10); + BLOCK_END("AvatarListBox::draw") } void AvatarListBox::mousePressed(gcn::MouseEvent &event) diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 4d0e5e32c..1fa563915 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -335,6 +335,7 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event) void BrowserBox::draw(gcn::Graphics *graphics) { + BLOCK_START("BrowserBox::draw") const gcn::ClipRectangle cr = graphics->getCurrentClipArea(); Graphics *const graphics2 = static_cast(graphics); mYStart = cr.y - cr.yOffset; @@ -400,7 +401,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) } } - return; + BLOCK_END("BrowserBox::draw") } int BrowserBox::calcHeight() diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 31bde646f..5a12893a6 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -276,6 +276,7 @@ void Button::updateAlpha() void Button::draw(gcn::Graphics *graphics) { + BLOCK_START("Button::draw") int mode; if (!isEnabled()) @@ -289,7 +290,10 @@ void Button::draw(gcn::Graphics *graphics) const Skin *const skin = button[mode]; if (!skin) + { + BLOCK_END("Button::draw") return; + } updateAlpha(); @@ -409,6 +413,7 @@ void Button::draw(gcn::Graphics *graphics) g2->drawImage(mImages[mode], imageX, imageY); g2->drawText(getCaption(), textX, textY, getAlignment()); } + BLOCK_END("Button::draw") } void Button::mouseReleased(gcn::MouseEvent& mouseEvent) diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 0c2b7ca14..786c77fd2 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -91,6 +91,7 @@ CheckBox::~CheckBox() void CheckBox::draw(gcn::Graphics* graphics) { + BLOCK_START("CheckBox::draw") drawBox(graphics); graphics->setFont(getFont()); @@ -98,6 +99,7 @@ void CheckBox::draw(gcn::Graphics* graphics) graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing, mPadding); + BLOCK_END("CheckBox::draw") } void CheckBox::updateAlpha() diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 0a6657d3e..6079d33a8 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -82,6 +82,7 @@ void Desktop::widgetResized(const gcn::Event &event A_UNUSED) void Desktop::draw(gcn::Graphics *graphics) { + BLOCK_START("Desktop::draw") Graphics *const g = static_cast(graphics); if (!mWallpaper || (getWidth() > mWallpaper->getWidth() || @@ -112,6 +113,7 @@ void Desktop::draw(gcn::Graphics *graphics) g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); Container::draw(graphics); + BLOCK_END("Desktop::draw") } void Desktop::setBestFittingWallpaper() diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index a896b4698..bde16760b 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -186,6 +186,7 @@ void DropDown::updateAlpha() void DropDown::draw(gcn::Graphics* graphics) { + BLOCK_START("DropDown::draw") int h; if (mDroppedDown) @@ -227,15 +228,18 @@ void DropDown::draw(gcn::Graphics* graphics) graphics->setColor(mShadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); } + BLOCK_END("DropDown::draw") } void DropDown::drawFrame(gcn::Graphics *graphics) { + BLOCK_START("DropDown::drawFrame") const int bs = getFrameSize(); const int w = getWidth() + bs * 2; const int h = getHeight() + bs * 2; static_cast(graphics)->drawImageRect(0, 0, w, h, skinRect); + BLOCK_END("DropDown::drawFrame") } void DropDown::drawButton(gcn::Graphics *graphics) diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 95a09533e..756738eb0 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -91,6 +91,7 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) if (!dropShortcut) return; + BLOCK_START("DropShortcutContainer::draw") if (Client::getGuiAlpha() != mAlpha) { mAlpha = Client::getGuiAlpha(); @@ -113,7 +114,10 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) const Inventory *const inv = PlayerInfo::getInventory(); if (!inv) + { + BLOCK_END("DropShortcutContainer::draw") return; + } for (unsigned i = 0; i < mMaxItems; i++) { @@ -166,6 +170,7 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) gcn::Graphics::CENTER); } } + BLOCK_END("DropShortcutContainer::draw") } void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 79abadf9c..1d1a5a60b 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -104,6 +104,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (!emoteShortcut) return; + BLOCK_START("EmoteShortcutContainer::draw") mAlpha = Client::getGuiAlpha(); if (Client::getGuiAlpha() != mAlpha && mBackgroundImg) mBackgroundImg->setAlpha(mAlpha); @@ -157,6 +158,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) spr->draw(g, tPosX, tPosY); } } + BLOCK_END("EmoteShortcutContainer::draw") } void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event A_UNUSED) diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index f1b41c03f..bb138b456 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -54,6 +54,7 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) if (!mListModel) return; + BLOCK_START("ExtendedListBox::draw") ExtendedListModel *const model = static_cast( mListModel); Graphics *const g = static_cast(graphics); @@ -95,4 +96,5 @@ void ExtendedListBox::draw(gcn::Graphics *graphics) image->getWidth() + mImagePadding + mSpacing, y + textPos); } } + BLOCK_END("ExtendedListBox::draw") } diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index 39f08340d..935fa833d 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -293,6 +293,7 @@ void GuiTable::draw(gcn::Graphics* graphics) if (!mModel || !getRowHeight()) return; + BLOCK_START("GuiTable::draw") if (Client::getGuiAlpha() != mAlpha) mAlpha = Client::getGuiAlpha(); @@ -386,6 +387,7 @@ void GuiTable::draw(gcn::Graphics* graphics) mTopWidget->draw(graphics); graphics->popClipArea(); } + BLOCK_END("GuiTable::draw") } void GuiTable::moveToTop(gcn::Widget *widget) diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index e152d3c4b..7b4f4857e 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -54,10 +54,12 @@ void Icon::setImage(Image *const image) void Icon::draw(gcn::Graphics *g) { + BLOCK_START("Icon::draw") if (mImage) { Graphics *const graphics = static_cast(g); graphics->drawImage(mImage, (getWidth() - mImage->mBounds.w) / 2, (getHeight() - mImage->mBounds.h) / 2); } + BLOCK_END("Icon::draw") } diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 616c5caa2..6e9ce1657 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -208,10 +208,14 @@ ItemContainer::~ItemContainer() void ItemContainer::logic() { + BLOCK_START("ItemContainer::logic") gcn::Widget::logic(); if (!mInventory) + { + BLOCK_END("ItemContainer::logic") return; + } const int lastUsedSlot = mInventory->getLastUsedSlot(); @@ -220,6 +224,7 @@ void ItemContainer::logic() mLastUsedSlot = lastUsedSlot; adjustHeight(); } + BLOCK_END("ItemContainer::logic") } void ItemContainer::draw(gcn::Graphics *graphics) @@ -227,6 +232,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (!mInventory || !mShowMatrix) return; + BLOCK_START("ItemContainer::draw") Graphics *const g = static_cast(graphics); g->setFont(getFont()); @@ -313,6 +319,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) itemY + mEquippedTextPadding, gcn::Graphics::CENTER); } } + BLOCK_END("ItemContainer::draw") } void ItemContainer::selectNone() diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index ccc8cb4c3..44248258c 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -100,9 +100,13 @@ void ItemShortcutContainer::setWidget2(const Widget2 *const widget) void ItemShortcutContainer::draw(gcn::Graphics *graphics) { + BLOCK_START("ItemShortcutContainer::draw") const ItemShortcut *const selShortcut = itemShortcut[mNumber]; if (!selShortcut) + { + BLOCK_END("ItemShortcutContainer::draw") return; + } mAlpha = Client::getGuiAlpha(); if (Client::getGuiAlpha() != mAlpha) @@ -126,7 +130,10 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) const Inventory *const inv = PlayerInfo::getInventory(); if (!inv) + { + BLOCK_END("ItemShortcutContainer::draw") return; + } for (unsigned i = 0; i < mMaxItems; i++) { @@ -231,6 +238,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) gcn::Graphics::CENTER); } } + BLOCK_END("ItemShortcutContainer::draw") } void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 0286caa7f..2d565a571 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -69,6 +69,7 @@ void Label::init() void Label::draw(gcn::Graphics* graphics) { + BLOCK_START("Label::draw") int textX; const int textY = getHeight() / 2 - getFont()->getHeight() / 2; @@ -92,6 +93,7 @@ void Label::draw(gcn::Graphics* graphics) graphics->setFont(getFont()); graphics->setColor(mForegroundColor); graphics->drawText(getCaption(), textX, textY, getAlignment()); + BLOCK_END("Label::draw") } void Label::adjustSize() diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index b90522229..4de4e360f 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -86,6 +86,7 @@ void ListBox::draw(gcn::Graphics *graphics) if (!mListModel) return; + BLOCK_START("ListBox::draw") updateAlpha(); mHighlightColor.a = static_cast(mAlpha * 255.0f); @@ -109,6 +110,7 @@ void ListBox::draw(gcn::Graphics *graphics) graphics->drawText(mListModel->getElementAt(i), mPadding, y + mPadding); } + BLOCK_END("ListBox::draw") } void ListBox::keyPressed(gcn::KeyEvent &keyEvent) @@ -225,11 +227,13 @@ void ListBox::refocus() void ListBox::adjustSize() { + BLOCK_START("ListBox::adjustSize") if (mListModel) { setHeight(getRowHeight() * mListModel->getNumberOfElements() + 2 * mPadding); } + BLOCK_END("ListBox::adjustSize") } void ListBox::logic() diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp index f301f2fe7..512c12761 100644 --- a/src/gui/widgets/passwordfield.cpp +++ b/src/gui/widgets/passwordfield.cpp @@ -33,6 +33,7 @@ PasswordField::PasswordField(const Widget2 *const widget, void PasswordField::draw(gcn::Graphics *graphics) { + BLOCK_START("PasswordField::draw") // std::string uses cow, thus cheap copy const std::string original = mText; if (mPasswordChar) @@ -41,4 +42,5 @@ void PasswordField::draw(gcn::Graphics *graphics) mText = ""; TextField::draw(graphics); mText = original; + BLOCK_END("PasswordField::draw") } diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 747cd91ab..f378373b2 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -97,6 +97,7 @@ void PlayerBox::init(std::string skin) void PlayerBox::draw(gcn::Graphics *graphics) { + BLOCK_START("PlayerBox::draw") if (mBeing) { // Draw character @@ -114,10 +115,12 @@ void PlayerBox::draw(gcn::Graphics *graphics) mBackground.grid[a]->setAlpha(Client::getGuiAlpha()); } } + BLOCK_END("PlayerBox::draw") } void PlayerBox::drawFrame(gcn::Graphics *graphics) { + BLOCK_START("PlayerBox::drawFrame") if (mDrawBackground) { int w, h, bs; @@ -128,4 +131,5 @@ void PlayerBox::drawFrame(gcn::Graphics *graphics) static_cast(graphics)->drawImageRect( 0, 0, w, h, mBackground); } + BLOCK_END("PlayerBox::drawFrame") } diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index b870d2eb1..03beec766 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -102,6 +102,7 @@ void Popup::setWindowContainer(WindowContainer *const wc) void Popup::draw(gcn::Graphics *graphics) { + BLOCK_START("Popup::draw") Graphics *const g = static_cast(graphics); if (mRedraw) @@ -116,6 +117,7 @@ void Popup::draw(gcn::Graphics *graphics) // g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); drawChildren(graphics); + BLOCK_END("Popup::draw") } gcn::Rectangle Popup::getChildrenArea() diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 590447b89..ef3aa19a0 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -90,6 +90,7 @@ ProgressBar::~ProgressBar() void ProgressBar::logic() { + BLOCK_START("ProgressBar::logic") if (mSmoothColorChange && mColorToGo != mColor) { // Smoothly changing the color for a nicer effect. @@ -115,6 +116,7 @@ void ProgressBar::logic() if (mProgressToGo < mProgress) mProgress = std::max(0.0f, mProgress - 0.005f); } + BLOCK_END("ProgressBar::logic") } void ProgressBar::updateAlpha() @@ -139,11 +141,11 @@ void ProgressBar::updateAlpha() void ProgressBar::draw(gcn::Graphics *graphics) { + BLOCK_START("ProgressBar::draw") updateAlpha(); - mColor.a = static_cast(mAlpha * 255); - render(static_cast(graphics)); + BLOCK_END("ProgressBar::draw") } void ProgressBar::setProgress(const float progress) diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index 936e357ab..10b2bba88 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -65,6 +65,7 @@ void ProgressIndicator::logic() void ProgressIndicator::draw(gcn::Graphics *graphics) { + BLOCK_START("ProgressIndicator::draw") if (mIndicator) { // Draw the indicator centered on the widget @@ -72,4 +73,5 @@ void ProgressIndicator::draw(gcn::Graphics *graphics) const int y = (getHeight() - 32) / 2; mIndicator->draw(static_cast(graphics), x, y); } + BLOCK_END("ProgressIndicator::draw") } diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 98e1182e1..1c56f787e 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -149,6 +149,7 @@ void RadioButton::drawBox(gcn::Graphics* graphics) void RadioButton::draw(gcn::Graphics* graphics) { + BLOCK_START("RadioButton::draw") drawBox(graphics); graphics->setFont(getFont()); @@ -156,6 +157,7 @@ void RadioButton::draw(gcn::Graphics* graphics) graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing, mPadding); + BLOCK_END("RadioButton::draw") } void RadioButton::mouseEntered(gcn::MouseEvent& event A_UNUSED) diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 0b7b73e6e..5658c6a8f 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -177,8 +177,12 @@ void ScrollArea::init(std::string skinName) void ScrollArea::logic() { + BLOCK_START("ScrollArea::logic") if (!isVisible()) + { + BLOCK_END("ScrollArea::logic") return; + } gcn::ScrollArea::logic(); gcn::Widget *const content = getContent(); @@ -208,6 +212,7 @@ void ScrollArea::logic() setHorizontalScrollAmount(mHScroll - mLeftButtonScrollAmount); else if (mRightButtonPressed) setHorizontalScrollAmount(mHScroll + mRightButtonScrollAmount); + BLOCK_END("ScrollArea::logic") } void ScrollArea::updateAlpha() @@ -236,6 +241,7 @@ void ScrollArea::updateAlpha() void ScrollArea::draw(gcn::Graphics *graphics) { + BLOCK_START("ScrollArea::draw") if (mVBarVisible) { drawUpButton(graphics); @@ -254,10 +260,12 @@ void ScrollArea::draw(gcn::Graphics *graphics) updateAlpha(); drawChildren(graphics); + BLOCK_END("ScrollArea::draw") } void ScrollArea::drawFrame(gcn::Graphics *graphics) { + BLOCK_START("ScrollArea::drawFrame") if (mOpaque) { const int bs = getFrameSize(); @@ -307,6 +315,7 @@ void ScrollArea::drawFrame(gcn::Graphics *graphics) // static_cast(graphics)-> // drawImageRect(0, 0, w, h, background); } + BLOCK_END("ScrollArea::drawFrame") } void ScrollArea::setOpaque(bool opaque) diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 0134a64c9..86c2e2e67 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -84,8 +84,12 @@ void ShopListBox::setPlayersMoney(const int money) void ShopListBox::draw(gcn::Graphics *gcnGraphics) { + BLOCK_START("ShopListBox::draw") if (!mListModel || !mShopItems) + { + BLOCK_END("ShopListBox::draw") return; + } if (Client::getGuiAlpha() != mAlpha) mAlpha = Client::getGuiAlpha(); @@ -156,6 +160,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) ITEM_ICON_SIZE + mPadding, y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2 + mPadding); } + BLOCK_END("ShopListBox::draw") } void ShopListBox::adjustSize() diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 4ba57b257..1f6a68be9 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -112,9 +112,11 @@ void Slider::updateAlpha() void Slider::draw(gcn::Graphics *graphics) { + BLOCK_START("Slider::draw") if (!buttons[0].grid[HSTART] || !buttons[1].grid[HSTART] || !buttons[0].grid[HEND]) { + BLOCK_END("Slider::draw") return; } @@ -174,6 +176,7 @@ void Slider::draw(gcn::Graphics *graphics) } drawMarker(graphics); + BLOCK_END("Slider::draw") } void Slider::drawMarker(gcn::Graphics *const graphics) const diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp index c108930d1..d57b1a092 100644 --- a/src/gui/widgets/sliderlist.cpp +++ b/src/gui/widgets/sliderlist.cpp @@ -108,12 +108,14 @@ void SliderList::resize() void SliderList::draw(gcn::Graphics *graphics) { + BLOCK_START("SliderList::draw") if (mOldWidth != getWidth()) { resize(); mOldWidth = getWidth(); } Container::draw(graphics); + BLOCK_END("SliderList::draw") } void SliderList::updateLabel() diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index cfc3863eb..10e82676e 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -93,6 +93,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) if (!spellShortcut) return; + BLOCK_START("SpellShortcutContainer::draw") if (Client::getGuiAlpha() != mAlpha) { mAlpha = Client::getGuiAlpha(); @@ -155,7 +156,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) { // Draw the item image being dragged by the cursor. } - + BLOCK_END("SpellShortcutContainer::draw") } void SpellShortcutContainer::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index aea8efb37..6747b19e0 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -147,6 +147,7 @@ void Tab::updateAlpha() void Tab::draw(gcn::Graphics *graphics) { + BLOCK_START("Tab::draw") int mode = TAB_STANDARD; // check which type of tab to draw @@ -184,7 +185,10 @@ void Tab::draw(gcn::Graphics *graphics) const Skin *const skin = tabImg[mode]; if (!skin) + { + BLOCK_END("Tab::draw") return; + } updateAlpha(); @@ -206,6 +210,7 @@ void Tab::draw(gcn::Graphics *graphics) // draw label drawChildren(graphics); + BLOCK_END("Tab::draw") } void Tab::widgetResized(const gcn::Event &event A_UNUSED) diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 0321e5044..ded2986d3 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -129,10 +129,15 @@ Tab *TabbedArea::getTab(const std::string &name) const void TabbedArea::draw(gcn::Graphics *graphics) { + BLOCK_START("TabbedArea::draw") if (mTabs.empty()) + { + BLOCK_END("TabbedArea::draw") return; + } drawChildren(graphics); + BLOCK_END("TabbedArea::draw") } gcn::Widget *TabbedArea::getWidget(const std::string &name) const @@ -274,7 +279,9 @@ void TabbedArea::removeTab(Tab *tab) void TabbedArea::logic() { + BLOCK_START("TabbedArea::logic") logicChildren(); + BLOCK_END("TabbedArea::logic") } void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent) diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index a31ae59fe..fc9c73a68 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -119,6 +119,7 @@ void TextField::updateAlpha() void TextField::draw(gcn::Graphics *graphics) { + BLOCK_START("TextField::draw") updateAlpha(); if (isFocused()) @@ -131,13 +132,16 @@ void TextField::draw(gcn::Graphics *graphics) graphics->setColor(mForegroundColor); graphics->setFont(getFont()); graphics->drawText(mText, mPadding - mXScroll, mPadding); + BLOCK_END("TextField::draw") } void TextField::drawFrame(gcn::Graphics *graphics) { + BLOCK_START("TextField::drawFrame") const int bs = 2 * getFrameSize(); static_cast(graphics)->drawImageRect(0, 0, getWidth() + bs, getHeight() + bs, skin); + BLOCK_END("TextField::drawFrame") } void TextField::setNumeric(const bool numeric) diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index f9f0269c0..8468da782 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -78,6 +78,7 @@ TextPreview::~TextPreview() void TextPreview::draw(gcn::Graphics* graphics) { + BLOCK_START("TextPreview::draw") if (Client::getGuiAlpha() != mAlpha) mAlpha = Client::getGuiAlpha(); @@ -112,6 +113,7 @@ void TextPreview::draw(gcn::Graphics* graphics) TextRenderer::renderText(graphics, mText, mPadding + 1, mPadding + 1, gcn::Graphics::LEFT, gcn::Color(mTextColor->r, mTextColor->g, mTextColor->b, alpha), mFont, mOutline, mShadow); + BLOCK_END("TextPreview::draw") } void TextPreview::adjustSize() diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index e4a279e6c..ecf8f0f99 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -186,6 +186,7 @@ void Window::draw(gcn::Graphics *graphics) if (!mSkin) return; + BLOCK_START("Window::draw") Graphics *const g = static_cast(graphics); bool update = false; @@ -237,6 +238,7 @@ void Window::draw(gcn::Graphics *graphics) { drawChildren(graphics); } + BLOCK_END("Window::draw") } void Window::setContentSize(int width, int height) diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp index 9acba77b2..8c985737c 100644 --- a/src/gui/widgets/windowcontainer.cpp +++ b/src/gui/widgets/windowcontainer.cpp @@ -37,10 +37,12 @@ WindowContainer::WindowContainer(const Widget2 *const widget) : void WindowContainer::logic() { + BLOCK_START("WindowContainer::logic") delete_all(mDeathList); mDeathList.clear(); gcn::Container::logic(); + BLOCK_END("WindowContainer::logic") } void WindowContainer::scheduleDelete(gcn::Widget *const widget) @@ -59,3 +61,12 @@ void WindowContainer::adjustAfterResize(const int oldScreenWidth, window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight); } } + +#ifdef USE_PROFILER +void WindowContainer::draw(gcn::Graphics* graphics) +{ + BLOCK_START("WindowContainer::draw") + Container::draw(graphics); + BLOCK_END("WindowContainer::draw") +} +#endif diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index 7a7b77fe1..fd25a1162 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -57,6 +57,10 @@ class WindowContainer : public Container void adjustAfterResize(const int oldScreenWidth, const int oldScreenHeight); +#ifdef USE_PROFILER + void draw(gcn::Graphics* graphics); +#endif + private: /** * List of widgets that are scheduled to be deleted. diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp index f3f61b65a..fb69bb53a 100644 --- a/src/guichan/basiccontainer.cpp +++ b/src/guichan/basiccontainer.cpp @@ -257,6 +257,8 @@ namespace gcn void BasicContainer::drawChildren(Graphics* graphics) { + BLOCK_START("BasicContainer::drawChildren") + graphics->pushClipArea(getChildrenArea()); for (WidgetListConstIterator iter = mWidgets.begin(); @@ -274,26 +276,33 @@ namespace gcn rec.width += 2 * (*iter)->getFrameSize(); rec.height += 2 * (*iter)->getFrameSize(); graphics->pushClipArea(rec); + BLOCK_START("BasicContainer::drawChildren 1") (*iter)->drawFrame(graphics); + BLOCK_END("BasicContainer::drawChildren 1") graphics->popClipArea(); } graphics->pushClipArea((*iter)->getDimension()); + BLOCK_START("BasicContainer::drawChildren 2") (*iter)->draw(graphics); + BLOCK_END("BasicContainer::drawChildren 2") graphics->popClipArea(); } } graphics->popClipArea(); + BLOCK_END("BasicContainer::drawChildren") } void BasicContainer::logicChildren() { + BLOCK_START("BasicContainer::logicChildren") for (WidgetListConstIterator iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { (*iter)->logic(); } + BLOCK_END("BasicContainer::logicChildren") } void BasicContainer::showWidgetPart(Widget* widget, Rectangle area) diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp index 52e183591..756b5a9b5 100644 --- a/src/guichan/graphics.cpp +++ b/src/guichan/graphics.cpp @@ -155,6 +155,7 @@ namespace gcn void Graphics::drawText(const std::string& text, int x, int y, Alignment alignment) { + FUNC_BLOCK("Graphics::drawText", 1) if (!mFont) throw GCN_EXCEPTION("No font set."); diff --git a/src/guichan/gui.cpp b/src/guichan/gui.cpp index 41b9fe30f..ed4417650 100644 --- a/src/guichan/gui.cpp +++ b/src/guichan/gui.cpp @@ -161,6 +161,7 @@ namespace gcn void Gui::handleMouseInput() { + BLOCK_START("Gui::handleMouseInput") while (!mInput->isMouseQueueEmpty()) { const MouseInput mouseInput = mInput->dequeueMouseInput(); @@ -192,6 +193,7 @@ namespace gcn break; } } + BLOCK_END("Gui::handleMouseInput") } void Gui::handleKeyInput() @@ -748,6 +750,7 @@ namespace gcn void Gui::handleModalMouseInputFocus() { + BLOCK_START("Gui::handleModalMouseInputFocus") // Check if modal mouse input focus has been gained by a widget. if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() != mFocusHandler->getModalMouseInputFocused()) @@ -765,10 +768,12 @@ namespace gcn handleModalFocusReleased(); mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr); } + BLOCK_END("Gui::handleModalMouseInputFocus") } void Gui::handleModalFocus() { + BLOCK_START("Gui::handleModalFocus") // Check if modal focus has been gained by a widget. if ((mFocusHandler->getLastWidgetWithModalFocus() != mFocusHandler->getModalFocused()) @@ -786,6 +791,7 @@ namespace gcn handleModalFocusReleased(); mFocusHandler->setLastWidgetWithModalFocus(nullptr); } + BLOCK_END("Gui::handleModalFocus") } void Gui::handleModalFocusGained() diff --git a/src/guichan/widget.cpp b/src/guichan/widget.cpp index e9e846e76..fbc0cfef9 100644 --- a/src/guichan/widget.cpp +++ b/src/guichan/widget.cpp @@ -108,6 +108,7 @@ namespace gcn void Widget::drawFrame(Graphics* graphics) { + BLOCK_START("Widget::drawFrame") const Color &faceColor = getBaseColor(); Color highlightColor = faceColor + 0x303030; Color shadowColor = faceColor - 0x303030; @@ -126,6 +127,7 @@ namespace gcn graphics->drawLine(width - i, i + 1, width - i, height - i); graphics->drawLine(i, height - i, width - i - 1, height - i); } + BLOCK_END("Widget::drawFrame") } void Widget::_setParent(Widget* parent) diff --git a/src/guichan/widgets/container.cpp b/src/guichan/widgets/container.cpp index ec61338c8..64f1ee8cb 100644 --- a/src/guichan/widgets/container.cpp +++ b/src/guichan/widgets/container.cpp @@ -69,6 +69,7 @@ namespace gcn void Container::draw(Graphics* graphics) { + BLOCK_START("Container::draw") if (isOpaque()) { graphics->setColor(getBaseColor()); @@ -76,6 +77,7 @@ namespace gcn } drawChildren(graphics); + BLOCK_END("Container::draw") } void Container::setOpaque(bool opaque) diff --git a/src/guichan/widgets/scrollarea.cpp b/src/guichan/widgets/scrollarea.cpp index f79bd32eb..59e909258 100644 --- a/src/guichan/widgets/scrollarea.cpp +++ b/src/guichan/widgets/scrollarea.cpp @@ -455,6 +455,7 @@ namespace gcn void ScrollArea::logic() { + BLOCK_START("ScrollArea::logic") checkPolicies(); setVerticalScrollAmount(getVerticalScrollAmount()); @@ -466,6 +467,7 @@ namespace gcn -mVScroll + getContent()->getFrameSize()); getContent()->logic(); } + BLOCK_END("ScrollArea::logic") } void ScrollArea::checkPolicies() diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp index 0c8f4451a..66441894b 100644 --- a/src/guichan/widgets/textbox.cpp +++ b/src/guichan/widgets/textbox.cpp @@ -120,6 +120,7 @@ namespace gcn void TextBox::draw(Graphics* graphics) { + BLOCK_START("TextBox::draw") if (mOpaque) { graphics->setColor(mBackgroundColor); @@ -142,6 +143,7 @@ namespace gcn graphics->drawText(mTextRows[i], 1, static_cast(i * getFont()->getHeight())); } + BLOCK_END("TextBox::draw") } void TextBox::drawCaret(Graphics* graphics, int x, int y) diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index 863cb8ba8..a4ae38a84 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -67,6 +67,7 @@ ImageParticle::~ImageParticle() bool ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const { + FUNC_BLOCK("ImageParticle::draw", 1) if (!isAlive() || !mImage) return false; diff --git a/src/imagesprite.cpp b/src/imagesprite.cpp index e827476db..aef932b20 100644 --- a/src/imagesprite.cpp +++ b/src/imagesprite.cpp @@ -50,6 +50,7 @@ ImageSprite::~ImageSprite() bool ImageSprite::draw(Graphics* graphics, int posX, int posY) const { + FUNC_BLOCK("ImageSprite::draw", 1) if (!mImage) return false; diff --git a/src/localconsts.h b/src/localconsts.h index 7db758697..7fa4fc381 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -62,3 +62,8 @@ //Android logging #define ANDROID_LOG 1 + +//profiler +//#define USE_PROFILER 1 + +#include "utils/perfomance.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index ede9f412c..d387cdd40 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -208,6 +208,7 @@ LocalPlayer::~LocalPlayer() void LocalPlayer::logic() { + BLOCK_START("LocalPlayer::logic") #ifdef USE_MUMBLE if (mumbleManager) mumbleManager->setPos(mX, mY, mDirection); @@ -325,10 +326,12 @@ void LocalPlayer::logic() } Being::logic(); + BLOCK_END("LocalPlayer::logic") } void LocalPlayer::slowLogic() { + BLOCK_START("LocalPlayer::slowLogic") if (weightNotice && weightNoticeTime < cur_time) { weightNotice->scheduleDelete(); @@ -354,6 +357,7 @@ void LocalPlayer::slowLogic() else mAdvertTime = cur_time + 30; } + BLOCK_END("LocalPlayer::slowLogic") } void LocalPlayer::setAction(const Action &action, const int attackType) diff --git a/src/map.cpp b/src/map.cpp index c31356276..f0fae1a9c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -325,6 +325,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) if (!player_node) return; + BLOCK_START("Map::draw") // Calculate range of tiles which are on-screen const int endPixelY = graphics->mHeight + scrollY + mTileHeight - 1 + mMaxTileHeight - mTileHeight; @@ -338,7 +339,9 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) // so that they overlap correctly // if (mSpritesUpdated) // { + BLOCK_START("Map::draw sort") mActors.sort(actorCompare); + BLOCK_END("Map::draw sort") // mSpritesUpdated = false; // } @@ -475,6 +478,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } drawAmbientLayers(graphics, FOREGROUND_LAYERS, mOverlayDetail); + BLOCK_END("Map::draw") } #define fillCollision(collision, color) \ @@ -546,6 +550,7 @@ void Map::drawCollision(Graphics *const graphics, void Map::updateAmbientLayers(const float scrollX, const float scrollY) { + BLOCK_START("Map::updateAmbientLayers") static int lastTick = tick_time; // static = only initialized at first call if (mLastAScrollX == 0.0f && mLastAScrollY == 0.0f) @@ -575,14 +580,19 @@ void Map::updateAmbientLayers(const float scrollX, const float scrollY) mLastAScrollX = scrollX; mLastAScrollY = scrollY; lastTick = tick_time; + BLOCK_END("Map::updateAmbientLayers") } void Map::drawAmbientLayers(Graphics *const graphics, const LayerType type, const int detail) { + BLOCK_START("Map::drawAmbientLayers") // Detail 0 = no ambient effects except background image if (detail <= 0 && type != BACKGROUND_LAYERS) + { + BLOCK_END("Map::drawAmbientLayers") return; + } // find out which layer list to draw AmbientLayerVector *layers; @@ -609,6 +619,7 @@ void Map::drawAmbientLayers(Graphics *const graphics, const LayerType type, if (detail == 1) break; } + BLOCK_END("Map::drawAmbientLayers") } Tileset *Map::getTilesetWithGid(const int gid) const diff --git a/src/maplayer.cpp b/src/maplayer.cpp index 752ff593f..8980b4f47 100644 --- a/src/maplayer.cpp +++ b/src/maplayer.cpp @@ -86,6 +86,7 @@ void MapLayer::draw(Graphics *const graphics, if (!player_node) return; + BLOCK_START("MapLayer::draw") startX -= mX; startY -= mY; endX -= mX; @@ -145,10 +146,12 @@ void MapLayer::draw(Graphics *const graphics, x += c; } } + BLOCK_END("MapLayer::draw") } void MapLayer::drawSDL(Graphics *const graphics) { + BLOCK_START("MapLayer::drawSDL") MapRows::const_iterator rit = mTempRows.begin(); const MapRows::const_iterator rit_end = mTempRows.end(); while (rit != rit_end) @@ -163,6 +166,7 @@ void MapLayer::drawSDL(Graphics *const graphics) } ++ rit; } + BLOCK_END("MapLayer::drawSDL") } #ifdef USE_OPENGL @@ -171,6 +175,7 @@ void MapLayer::updateSDL(Graphics *const graphics, int startX, int startY, const int scrollX, const int scrollY, const int debugFlags) { + BLOCK_START("MapLayer::updateSDL") delete_all(mTempRows); mTempRows.clear(); @@ -226,6 +231,7 @@ void MapLayer::updateSDL(Graphics *const graphics, int startX, int startY, } } } + BLOCK_END("MapLayer::updateSDL") } void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY, @@ -233,6 +239,7 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY, const int scrollX, const int scrollY, const int debugFlags) { + BLOCK_START("MapLayer::updateOGL") delete_all(mTempRows); mTempRows.clear(); @@ -302,10 +309,12 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY, } } } + BLOCK_END("MapLayer::updateOGL") } void MapLayer::drawOGL(Graphics *const graphics) { + BLOCK_START("MapLayer::drawOGL") MapRows::const_iterator rit = mTempRows.begin(); const MapRows::const_iterator rit_end = mTempRows.end(); // int k = 0; @@ -322,6 +331,7 @@ void MapLayer::drawOGL(Graphics *const graphics) } ++ rit; } + BLOCK_END("MapLayer::drawOGL") // logger->log("draws: %d", k); } #endif @@ -332,8 +342,12 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY, const Actors *const actors, const int debugFlags, const int yFix) const { + BLOCK_START("MapLayer::drawFringe") if (!player_node || !mSpecialLayer || !mTempLayer) + { + BLOCK_END("MapLayer::drawFringe") return; + } startX -= mX; startY -= mY; @@ -512,16 +526,19 @@ void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY, } } } + BLOCK_END("MapLayer::drawFringe") } int MapLayer::getTileDrawWidth(const Image *img, const int endX, int &width) const { + BLOCK_START("MapLayer::getTileDrawWidth") const Image *const img1 = img; int c = 0; if (!img1) { width = 0; + BLOCK_END("MapLayer::getTileDrawWidth") return c; } width = img1->mBounds.w; @@ -534,6 +551,7 @@ int MapLayer::getTileDrawWidth(const Image *img, if (img) width += img->mBounds.w; } + BLOCK_END("MapLayer::getTileDrawWidth") return c; } @@ -634,6 +652,7 @@ void SpecialLayer::draw(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY) const { + BLOCK_START("SpecialLayer::draw") if (startX < 0) startX = 0; if (startY < 0) @@ -648,6 +667,7 @@ void SpecialLayer::draw(Graphics *const graphics, int startX, int startY, for (int x = startX; x < endX; x++) itemDraw(graphics, x, y, scrollX, scrollY); } + BLOCK_END("SpecialLayer::draw") } void SpecialLayer::itemDraw(Graphics *const graphics, const int x, const int y, @@ -742,6 +762,7 @@ void MapItem::setPos(const int x, const int y) void MapItem::draw(Graphics *const graphics, const int x, const int y, const int dx, const int dy) const { + BLOCK_START("MapItem::draw") if (mImage) graphics->drawImage(mImage, x, y); @@ -780,6 +801,7 @@ void MapItem::draw(Graphics *const graphics, const int x, const int y, font->drawString(graphics, mName, x, y); } } + BLOCK_END("MapItem::draw") } ObjectsLayer::ObjectsLayer(const unsigned width, const unsigned height) : diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp index 564f9be82..7cb445342 100644 --- a/src/mobileopenglgraphics.cpp +++ b/src/mobileopenglgraphics.cpp @@ -188,6 +188,7 @@ bool MobileOpenGLGraphics::drawImage2(const Image *const image, const int width, const int height, const bool useColor) { + FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; @@ -231,6 +232,7 @@ bool MobileOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, const bool useColor, bool smooth) { + FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; @@ -284,6 +286,7 @@ void MobileOpenGLGraphics::drawImagePattern(const Image *const image, const int x, const int y, const int w, const int h) { + FUNC_BLOCK("Graphics::drawImagePattern", 1) if (!image) return; @@ -739,11 +742,13 @@ void MobileOpenGLGraphics::drawTile(ImageVertexes *const vert) void MobileOpenGLGraphics::updateScreen() { + BLOCK_START("Graphics::updateScreen") // glFlush(); // glFinish(); SDL_GL_SwapBuffers(); // may be need clear? // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + BLOCK_END("Graphics::updateScreen") } void MobileOpenGLGraphics::_beginDraw() @@ -984,6 +989,7 @@ void MobileOpenGLGraphics::setTexturingAndBlending(bool enable) void MobileOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) { + BLOCK_START("Graphics::drawRectangle") setTexturingAndBlending(false); restoreColor(); @@ -1020,6 +1026,7 @@ void MobileOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, glVertexPointer(2, GL_SHORT, 0, &vert); glDrawArrays(GL_LINE_LOOP, 0, 4); } + BLOCK_END("Graphics::drawRectangle") } bool MobileOpenGLGraphics::drawNet(const int x1, const int y1, diff --git a/src/net/packetcounters.cpp b/src/net/packetcounters.cpp index 6fb8588fe..d2193895d 100644 --- a/src/net/packetcounters.cpp +++ b/src/net/packetcounters.cpp @@ -120,6 +120,7 @@ void PacketCounters::update() if (!runCounters) return; + BLOCK_START("PacketCounters::update") updateCounter(PacketCounters::mInCurrentSec, PacketCounters::mInBytesCalc, PacketCounters::mInBytes); updateCounter(PacketCounters::mInCurrentSec, @@ -128,4 +129,5 @@ void PacketCounters::update() PacketCounters::mOutBytesCalc, PacketCounters::mOutBytes); updateCounter(PacketCounters::mOutCurrentSec, PacketCounters::mOutPacketsCalc, PacketCounters::mOutPackets); + BLOCK_END("PacketCounters::update") } diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index d7fc78d1d..26abfc0cd 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -56,6 +56,7 @@ AdminHandler::AdminHandler() : void AdminHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("AdminHandler::handleMessage") int id; switch (msg.getId()) { @@ -68,6 +69,7 @@ void AdminHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("AdminHandler::handleMessage") } void AdminHandler::announce(const std::string &text) diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 5bf0bc1d6..9d9c82fce 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -107,6 +107,7 @@ void BeingHandler::requestNameById(int id) void BeingHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("BeingHandler::handleMessage") switch (msg.getId()) { case SMSG_BEING_VISIBLE: @@ -235,6 +236,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("BeingHandler::handleMessage") } void BeingHandler::undress(Being *being) diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index 6d94370c7..fcc6be2cf 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -73,6 +73,7 @@ BuySellHandler::BuySellHandler() : void BuySellHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("BuySellHandler::handleMessage") switch (msg.getId()) { case SMSG_NPC_BUY_SELL_CHOICE: @@ -98,7 +99,7 @@ void BuySellHandler::handleMessage(Net::MessageIn &msg) default: break; } - + BLOCK_END("BuySellHandler::handleMessage") } void BuySellHandler::processNpcBuy(Net::MessageIn &msg) diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 039010535..4d0fae108 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -73,6 +73,7 @@ CharServerHandler::CharServerHandler() : void CharServerHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("CharServerHandler::handleMessage") switch (msg.getId()) { case SMSG_CHAR_LOGIN: @@ -162,6 +163,7 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("CharServerHandler::handleMessage") } void CharServerHandler::readPlayerData(Net::MessageIn &msg, diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index ef6ff2847..07f95d5f9 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -69,6 +69,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) if (!localChatTab) return; + BLOCK_START("ChatHandler::handleMessage") switch (msg.getId()) { case SMSG_WHISPER_RESPONSE: @@ -100,6 +101,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("ChatHandler::handleMessage") } void ChatHandler::talk(const std::string &text) diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 2515a45d3..e09bb5436 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -58,6 +58,7 @@ GameHandler::GameHandler() : void GameHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("GameHandler::handleMessage") switch (msg.getId()) { case SMSG_MAP_LOGIN_SUCCESS: @@ -84,6 +85,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("GameHandler::handleMessage") } void GameHandler::mapLoadedEvent() diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 33ccfe819..b26a14daf 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -121,6 +121,7 @@ GeneralHandler::~GeneralHandler() void GeneralHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("GeneralHandler::handleMessage") int code; switch (msg.getId()) @@ -164,6 +165,7 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("GeneralHandler::handleMessage") } void GeneralHandler::load() @@ -220,9 +222,12 @@ void GeneralHandler::flushNetwork() if (!mNetwork) return; + BLOCK_START("GeneralHandler::flushNetwork 1") mNetwork->flush(); + BLOCK_END("GeneralHandler::flushNetwork 1") mNetwork->dispatchMessages(); + BLOCK_START("GeneralHandler::flushNetwork 3") if (mNetwork->getState() == Network::NET_ERROR) { if (!mNetwork->getError().empty()) @@ -232,6 +237,7 @@ void GeneralHandler::flushNetwork() Client::setState(STATE_ERROR); } + BLOCK_END("GeneralHandler::flushNetwork 3") } void GeneralHandler::clearHandlers() diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index 6b97c6020..5f148ebac 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -80,6 +80,7 @@ GuildHandler::~GuildHandler() void GuildHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("GuildHandler::handleMessage") switch (msg.getId()) { case SMSG_GUILD_CREATE_RESPONSE: @@ -189,6 +190,7 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("GuildHandler::handleMessage") } void GuildHandler::create(const std::string &name) diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index f5768f8c5..562e9c00b 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -67,6 +67,7 @@ InventoryHandler::~InventoryHandler() void InventoryHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("InventoryHandler::handleMessage") switch (msg.getId()) { case SMSG_PLAYER_INVENTORY: @@ -133,6 +134,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("InventoryHandler::handleMessage") } void InventoryHandler::equipItem(const Item *item) diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index 7612b638e..d1becafef 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -45,6 +45,7 @@ ItemHandler::ItemHandler() : void ItemHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("ItemHandler::handleMessage") switch (msg.getId()) { case SMSG_ITEM_VISIBLE: @@ -62,6 +63,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("ItemHandler::handleMessage") } } // namespace TmwAthena diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index eb0364d44..7e4eca95f 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -65,6 +65,7 @@ LoginHandler::~LoginHandler() void LoginHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("LoginHandler::handleMessage") switch (msg.getId()) { case SMSG_CHAR_PASSWORD_RESPONSE: @@ -94,6 +95,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("LoginHandler::handleMessage") } void LoginHandler::connect() diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index c8c28e0d2..e7e336d2d 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -135,6 +135,7 @@ void Network::clearHandlers() void Network::dispatchMessages() { + BLOCK_START("Network::dispatchMessages") while (messageReady()) { MessageIn *const msg = getNextMessage(); @@ -158,6 +159,7 @@ void Network::dispatchMessages() skip(msg->getLength()); delete msg; } + BLOCK_END("Network::dispatchMessages") } bool Network::messageReady() @@ -197,6 +199,7 @@ bool Network::messageReady() MessageIn *Network::getNextMessage() { + BLOCK_START("Network::getNextMessage") while (!messageReady()) { if (mState == NET_ERROR) @@ -224,6 +227,7 @@ MessageIn *Network::getNextMessage() MessageIn *const msg = new MessageIn(mInBuffer, len); SDL_mutexV(mMutex); + BLOCK_END("Network::getNextMessage") return msg; } diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 3e9fe3822..732fc7d06 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -63,6 +63,7 @@ NpcHandler::NpcHandler() : void NpcHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("NpcHandler::handleMessage") const int npcId = getNpc(msg, msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE); @@ -107,6 +108,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) } mDialog = nullptr; + BLOCK_END("NpcHandler::handleMessage") } void NpcHandler::talk(int npcId) diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index e23629bc2..7ff752252 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -65,6 +65,7 @@ PartyHandler::~PartyHandler() void PartyHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("PartyHandler::handleMessage") switch (msg.getId()) { case SMSG_PARTY_CREATE: @@ -101,6 +102,7 @@ void PartyHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("PartyHandler::handleMessage") } void PartyHandler::create(const std::string &name) diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 1067418e2..d5c48e387 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -62,6 +62,7 @@ PlayerHandler::PlayerHandler() : void PlayerHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("PlayerHandler::handleMessage") switch (msg.getId()) { case SMSG_WALK_RESPONSE: @@ -107,6 +108,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("PlayerHandler::handleMessage") } void PlayerHandler::attack(int id, bool keep) diff --git a/src/net/tmwa/questhandler.cpp b/src/net/tmwa/questhandler.cpp index bd03dc7a2..228e06ed0 100644 --- a/src/net/tmwa/questhandler.cpp +++ b/src/net/tmwa/questhandler.cpp @@ -52,6 +52,7 @@ QuestHandler::QuestHandler() : void QuestHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("QuestHandler::handleMessage") switch (msg.getId()) { case CMSG_QUEST_SET_VAR: @@ -65,6 +66,7 @@ void QuestHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("QuestHandler::handleMessage") } void QuestHandler::processSetQuestVar(Net::MessageIn &msg A_UNUSED) diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index ab37aba97..72838e052 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -50,6 +50,7 @@ SpecialHandler::SpecialHandler() : void SpecialHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("SpecialHandler::handleMessage") switch (msg.getId()) { case SMSG_PLAYER_SKILLS: @@ -67,6 +68,7 @@ void SpecialHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("SpecialHandler::handleMessage") } void SpecialHandler::useBeing(int id, int level, int beingId) diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 4fc099f27..727ca581a 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -58,6 +58,7 @@ TradeHandler::TradeHandler() : void TradeHandler::handleMessage(Net::MessageIn &msg) { + BLOCK_START("TradeHandler::handleMessage") switch (msg.getId()) { case SMSG_TRADE_REQUEST: @@ -91,6 +92,7 @@ void TradeHandler::handleMessage(Net::MessageIn &msg) default: break; } + BLOCK_END("TradeHandler::handleMessage") } void TradeHandler::request(Being *being) diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 7fb4a7786..40cd5226b 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -225,6 +225,7 @@ bool NormalOpenGLGraphics::drawImage2(const Image *const image, const int width, const int height, const bool useColor) { + FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; @@ -268,6 +269,7 @@ bool NormalOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, const bool useColor, bool smooth) { + FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; @@ -321,6 +323,7 @@ void NormalOpenGLGraphics::drawImagePattern(const Image *const image, const int x, const int y, const int w, const int h) { + FUNC_BLOCK("Graphics::drawImagePattern", 1) if (!image) return; @@ -928,11 +931,13 @@ void NormalOpenGLGraphics::drawTile(ImageVertexes *const vert) void NormalOpenGLGraphics::updateScreen() { + BLOCK_START("Graphics::updateScreen") // glFlush(); // glFinish(); SDL_GL_SwapBuffers(); // may be need clear? // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + BLOCK_END("Graphics::updateScreen") } void NormalOpenGLGraphics::_beginDraw() @@ -1173,6 +1178,7 @@ void NormalOpenGLGraphics::setTexturingAndBlending(bool enable) void NormalOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) { + BLOCK_START("Graphics::drawRectangle") const float offset = filled ? 0 : 0.5f; const float x = static_cast(rect.x); const float y = static_cast(rect.y); @@ -1192,6 +1198,7 @@ void NormalOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, glVertexPointer(2, GL_FLOAT, 0, &vert); glDrawArrays(filled ? GL_QUADS : GL_LINE_LOOP, 0, 4); + BLOCK_END("Graphics::drawRectangle") } bool NormalOpenGLGraphics::drawNet(const int x1, const int y1, diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 5bd4db3e4..6779419f1 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -1023,12 +1023,14 @@ void ResourceManager::scheduleDelete(SDL_Surface *const surface) void ResourceManager::clearScheduled() { + BLOCK_START("ResourceManager::clearScheduled") for (std::set::iterator i = deletedSurfaces.begin(), i_end = deletedSurfaces.end(); i != i_end; ++i) { SDL_FreeSurface(*i); } deletedSurfaces.clear(); + BLOCK_END("ResourceManager::clearScheduled") } struct RescaledLoader @@ -1069,6 +1071,7 @@ Image *ResourceManager::getRescaled(Image *const image, void ResourceManager::delayedLoad() { + BLOCK_START("ResourceManager::delayedLoad") static int loadTime = 0; if (loadTime < cur_time) { @@ -1091,6 +1094,7 @@ void ResourceManager::delayedLoad() else loadTime = time2 + 3; } + BLOCK_END("ResourceManager::delayedLoad") } void ResourceManager::removeDelayLoad(const AnimationDelayLoad diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index f4ae7ba93..9ca2340d0 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -147,6 +147,7 @@ bool SafeOpenGLGraphics::drawImage2(const Image *const image, const int width, const int height, const bool useColor) { + FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; @@ -190,6 +191,7 @@ bool SafeOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, const bool useColor, bool smooth) { + FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; @@ -245,6 +247,7 @@ void SafeOpenGLGraphics::drawImagePattern(const Image *const image, const int x, const int y, const int w, const int h) { + FUNC_BLOCK("Graphics::drawImagePattern", 1) if (!image) return; @@ -375,9 +378,11 @@ void SafeOpenGLGraphics::drawImageRect2(GraphicsVertexes* vert, void SafeOpenGLGraphics::updateScreen() { + BLOCK_START("Graphics::updateScreen") glFlush(); glFinish(); SDL_GL_SwapBuffers(); + BLOCK_END("Graphics::updateScreen") } void SafeOpenGLGraphics::_beginDraw() @@ -589,6 +594,7 @@ void SafeOpenGLGraphics::setTexturingAndBlending(bool enable) void SafeOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) { + BLOCK_START("Graphics::drawRectangle") const float offset = filled ? 0 : 0.5f; setTexturingAndBlending(false); @@ -604,6 +610,7 @@ void SafeOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) glVertex2f(static_cast(rect.x) + offset, static_cast(rect.y + rect.height) - offset); glEnd(); + BLOCK_END("Graphics::drawRectangle") } void SafeOpenGLGraphics::bindTexture(GLenum target, GLuint texture) diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index f9966d83f..63ec812a9 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -68,6 +68,7 @@ SimpleAnimation::~SimpleAnimation() bool SimpleAnimation::draw(Graphics *const graphics, const int posX, const int posY) const { + FUNC_BLOCK("SimpleAnimation::draw", 1) if (!mCurrentFrame || !mCurrentFrame->image) return false; diff --git a/src/sound.cpp b/src/sound.cpp index cb4b11770..82e7b2f6d 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -285,6 +285,7 @@ void Sound::fadeOutAndPlayMusic(const std::string &fileName, const int ms) void Sound::logic() { + BLOCK_START("Sound::logic") if (sFadingOutEnded) { if (mMusic) @@ -300,6 +301,7 @@ void Sound::logic() mNextMusicFile.clear(); } } + BLOCK_END("Sound::logic") } void Sound::playSfx(const std::string &path, const int x, const int y) const diff --git a/src/text.cpp b/src/text.cpp index 41b2b01ca..cf15590fe 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -125,6 +125,7 @@ void Text::adviseXY(const int x, const int y) void Text::draw(gcn::Graphics *const graphics, const int xOff, const int yOff) { + BLOCK_START("Text::draw") if (mIsSpeech) { static_cast(graphics)->drawImageRect( @@ -135,6 +136,7 @@ void Text::draw(gcn::Graphics *const graphics, const int xOff, const int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, *mColor, mFont, !mIsSpeech, true); + BLOCK_END("Text::draw") } FlashText::FlashText(const std::string &text, const int x, const int y, @@ -148,10 +150,15 @@ FlashText::FlashText(const std::string &text, const int x, const int y, void FlashText::draw(gcn::Graphics *const graphics, const int xOff, const int yOff) { + BLOCK_START("FlashText::draw") if (mTime) { if ((--mTime & 4) == 0) + { + BLOCK_END("FlashText::draw") return; + } } Text::draw(graphics, xOff, yOff); + BLOCK_END("FlashText::draw") } diff --git a/src/textmanager.cpp b/src/textmanager.cpp index 1bd8ebef8..f44f22383 100644 --- a/src/textmanager.cpp +++ b/src/textmanager.cpp @@ -66,12 +66,14 @@ TextManager::~TextManager() void TextManager::draw(gcn::Graphics *const graphics, const int xOff, const int yOff) { + BLOCK_START("TextManager::draw") for (TextList::const_iterator bPtr = mTextList.begin(), ePtr = mTextList.end(); bPtr != ePtr; ++ bPtr) { (*bPtr)->draw(graphics, xOff, yOff); } + BLOCK_END("TextManager::draw") } void TextManager::place(const Text *const textObj, const Text *const omit, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 4ee261f82..e3d3fc710 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -41,8 +41,12 @@ TextParticle::TextParticle(Map *const map, const std::string &text, bool TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const { + BLOCK_START("TextParticle::draw") if (!isAlive()) + { + BLOCK_END("TextParticle::draw") return false; + } const int screenX = static_cast(mPos.x) + offsetX; const int screenY = static_cast(mPos.y) - static_cast(mPos.z) @@ -69,5 +73,6 @@ bool TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const screenX, screenY, gcn::Graphics::CENTER, color, mTextFont, mOutline, false, static_cast(alpha)); + BLOCK_END("TextParticle::draw") return true; } diff --git a/src/utils/perfomance.cpp b/src/utils/perfomance.cpp new file mode 100644 index 000000000..db25b4fe7 --- /dev/null +++ b/src/utils/perfomance.cpp @@ -0,0 +1,85 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "localconsts.h" + +#ifdef USE_PROFILER + +#include "utils/perfomance.h" + +#include "configuration.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "debug.h" + +//static const clockid_t clockType = CLOCK_PROCESS_CPUTIME_ID; +static const clockid_t clockType = CLOCK_MONOTONIC; + +namespace Perfomance +{ + std::ofstream file; + + void init(const std::string &path) + { + file.open(path.c_str(), std::ios_base::trunc); + } + + void clear() + { + if (file.is_open()) + file.close(); + } + + void start() + { + timespec time; + clock_gettime(clockType, &time); + file << static_cast(time.tv_sec) * 1000000000LL + + static_cast(time.tv_nsec) + << " __init__" << std::endl; + } + + void blockStart(const std::string &name) + { + timespec time; + clock_gettime(clockType, &time); + file << static_cast(time.tv_sec) * 1000000000LL + + static_cast(time.tv_nsec) + << " start: " << name << std::endl; + } + + void blockEnd(const std::string &name) + { + timespec time; + clock_gettime(clockType, &time); + file << static_cast(time.tv_sec) * 1000000000LL + + static_cast(time.tv_nsec) + << " end: " << name << std::endl; + } +} + +#endif diff --git a/src/utils/perfomance.h b/src/utils/perfomance.h new file mode 100644 index 000000000..ddca355c1 --- /dev/null +++ b/src/utils/perfomance.h @@ -0,0 +1,76 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef UTILS_PEFOMANCE_H +#define UTILS_PEFOMANCE_H + +#ifdef USE_PROFILER +#include +#include +#include +#include +#include + +#include "localconsts.h" + +#define PROFILER_START() Perfomance::start(); +#define BLOCK_START(name) Perfomance::blockStart(name); +#define BLOCK_END(name) Perfomance::blockEnd(name); +#define FUNC_BLOCK(name, id) Perfomance::Func PerfomanceFunc##id(name); + +namespace Perfomance +{ + void start(); + + void init(const std::string &path); + + void clear(); + + void blockStart(const std::string &name); + + void blockEnd(const std::string &name); + + class Func + { + public: + Func(const std::string &str) : + name(str) + { + blockStart(str); + } + + ~Func() + { + blockEnd(name); + } + + std::string name; + }; +} + +#else // USE_PROFILER + +#define PROFILER_START() +#define BLOCK_START(name) +#define BLOCK_END(name) +#define FUNC_BLOCK(name, id) + +#endif // USE_PROFILER +#endif // UTILS_PEFOMANCE_H -- cgit v1.2.3-70-g09d2