summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-08 05:04:05 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-08 19:05:18 +0300
commit73067138141ed121a4004538fd654e30e164c43c (patch)
tree44972eac4ac470c4fc0ce34d779cd50dd256f572
parent946c94cb1fc3273c437efb45f85b44b8ae48ab5f (diff)
downloadplus-73067138141ed121a4004538fd654e30e164c43c.tar.gz
plus-73067138141ed121a4004538fd654e30e164c43c.tar.bz2
plus-73067138141ed121a4004538fd654e30e164c43c.tar.xz
plus-73067138141ed121a4004538fd654e30e164c43c.zip
Improved algorithm for cleaning sdltext cache.
Now cache using less memory, but possible some times working bit slower.
-rw-r--r--src/gui/sdlfont.cpp43
-rw-r--r--src/main.h1
2 files changed, 34 insertions, 10 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 862ec8434..655a00f05 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -36,8 +36,10 @@
#include <guichan/exception.hpp>
const unsigned int CACHE_SIZE = 256;
-const unsigned int CACHE_SIZE_SMALL1 = 90;
-const unsigned int CACHE_SIZE_SMALL2 = 150;
+const unsigned int CACHE_SIZE_SMALL1 = 2;
+const unsigned int CACHE_SIZE_SMALL2 = 50;
+const unsigned int CACHE_SIZE_SMALL3 = 170;
+const unsigned int CLEAN_TIME = 5;
char *strBuf;
@@ -127,7 +129,7 @@ SDLFont::SDLFont(const std::string &filename, int size, int style) :
}
TTF_SetFontStyle(mFont, style);
- mCleanTime = cur_time + 120;
+ mCleanTime = cur_time + CLEAN_TIME;
}
SDLFont::~SDLFont()
@@ -243,12 +245,12 @@ void SDLFont::drawString(gcn::Graphics *graphics,
if (!mCleanTime)
{
- mCleanTime = cur_time + 120;
+ mCleanTime = cur_time + CLEAN_TIME;
}
else if (mCleanTime < cur_time)
{
doClean();
- mCleanTime = cur_time + 120;
+ mCleanTime = cur_time + CLEAN_TIME;
}
}
@@ -321,20 +323,41 @@ void SDLFont::doClean()
for (int f = 0; f < CACHES_NUMBER; f ++)
{
std::list<SDLTextChunk> *cache = &mCache[f];
- if (cache->size() > CACHE_SIZE_SMALL2)
+ const unsigned size = cache->size();
+#ifdef DEBUG_FONT_COUNTERS
+ logger->log("ptr: %d, size: %d", f, size);
+#endif
+ if (size > CACHE_SIZE_SMALL3)
+ {
+#ifdef DEBUG_FONT_COUNTERS
+ mDeleteCounter += 100;
+#endif
+ for (int d = 0; d < 100; d ++)
+ cache->pop_back();
+#ifdef DEBUG_FONT_COUNTERS
+ logger->log("delete3");
+#endif
+ }
+ else if (size > CACHE_SIZE_SMALL2)
{
#ifdef DEBUG_FONT_COUNTERS
- mDeleteCounter += 10;
+ mDeleteCounter += 20;
#endif
- for (int d = 0; d < 10; d ++)
+ for (int d = 0; d < 20; d ++)
cache->pop_back();
+#ifdef DEBUG_FONT_COUNTERS
+ logger->log("delete2");
+#endif
}
- else if (cache->size() > CACHE_SIZE_SMALL1)
+ else if (size > CACHE_SIZE_SMALL1)
{
#ifdef DEBUG_FONT_COUNTERS
mDeleteCounter ++;
#endif
cache->pop_back();
+#ifdef DEBUG_FONT_COUNTERS
+ logger->log("delete1");
+#endif
}
}
-} \ No newline at end of file
+}
diff --git a/src/main.h b/src/main.h
index 883c7a9d5..0dd9374ad 100644
--- a/src/main.h
+++ b/src/main.h
@@ -88,6 +88,7 @@
//define DEBUG_FONT 1
//define DEBUG_FONT_COUNTERS 1
//define DEBUG_ALPHA_CACHE 1
+//define DEBUG_OPENGL_LEAKS 1
#define SMALL_VERSION "1.1.5.1"
#define CHECK_VERSION "01.01.05.01"