From 0afe8cacab876c9c95ad551468f5d6c41eb8720d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Apr 2013 00:38:49 +0300 Subject: add command for test perfomance in sdlfont calculation. --- src/commands.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/commands.h | 2 ++ src/localconsts.h | 1 + 3 files changed, 45 insertions(+) diff --git a/src/commands.cpp b/src/commands.cpp index 9044a83a5..9dd4267fe 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -30,6 +30,7 @@ #include "guildmanager.h" #include "localplayer.h" #include "main.h" +#include "nullopenglgraphics.h" #include "party.h" #include "gui/chatwindow.h" @@ -1065,6 +1066,47 @@ impHandler1(execute) execFile(name, name, params, ""); } +impHandler0(testsdlfont) +{ +#if defined USE_OPENGL && defined DEBUG_SDLFONT + SDLFont *font = new SDLFont("fonts/dejavusans.ttf", 18); + timespec time1; + timespec time2; + NullOpenGLGraphics *nullGraphics = new NullOpenGLGraphics; + std::vector data; + int width = 0; + + for (int f = 0; f < 300; f ++) + data.push_back("test " + toString(f) + "string"); + nullGraphics->_beginDraw(); + + clock_gettime(CLOCK_MONOTONIC, &time1); + for (int f = 0; f < 500; f ++) + { + FOR_EACH (std::vector::const_iterator, it, data) + { + width += font->getWidth(*it); + font->drawString(nullGraphics, *it, 10, 10); + } + FOR_EACH (std::vector::const_iterator, it, data) + font->drawString(nullGraphics, *it, 10, 10); + } + + clock_gettime(CLOCK_MONOTONIC, &time2); + + delete nullGraphics; + delete font; + + long int diff = (static_cast( + time2.tv_sec) * 1000000000LL + static_cast( + time2.tv_nsec)) / 100000 - (static_cast( + time1.tv_sec) * 1000000000LL + static_cast( + time1.tv_nsec)) / 100000; + if (debugChatTab) + debugChatTab->chatLog("sdlfont time: " + toString(diff)); +#endif +} + #ifdef DEBUG_DUMP_LEAKS1 void showRes(std::string str, ResourceManager::Resources *res); diff --git a/src/commands.h b/src/commands.h index 1e1e10d65..bc45bf837 100644 --- a/src/commands.h +++ b/src/commands.h @@ -113,6 +113,7 @@ namespace Commands decHandler(dumpOGL); decHandler(cacheInfo); decHandler(execute); + decHandler(testsdlfont); void replaceVars(std::string &str); } // namespace Commands @@ -190,6 +191,7 @@ static const CommandInfo commands[] = {"url", &Commands::url}, {"open", &Commands::open}, {"execute", &Commands::execute}, + {"testsdlfont", &Commands::testsdlfont}, {"hack", &Commands::hack} }; diff --git a/src/localconsts.h b/src/localconsts.h index 2253fbf1f..53fec1625 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -68,6 +68,7 @@ // #define DISABLE_RESOURCE_CACHING 1 #define DUMP_LEAKED_RESOURCES 1 // #define DEBUG_DUMP_LEAKS1 1 +#define DEBUG_SDLFONT 1 // Android logging // #define ANDROID_LOG 1 -- cgit v1.2.3-60-g2f50