From f75a1e7af1db4be56430765e19a5aee75284dd3e Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Sat, 9 Feb 2013 22:03:05 +0300
Subject: Improve font cache cleaning.

Add missing font cache cleaning code.
---
 src/gui/gui.cpp     | 12 +++++++-----
 src/gui/sdlfont.cpp | 20 ++++++++++++--------
 src/gui/sdlfont.h   |  2 +-
 3 files changed, 20 insertions(+), 14 deletions(-)

(limited to 'src')

diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 3a459b55f..3a5964924 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -296,15 +296,17 @@ void Gui::slowLogic()
         mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f);
     }
     if (mGuiFont)
-        mGuiFont->slowLogic();
+        mGuiFont->slowLogic(0);
     if (mInfoParticleFont)
-        mInfoParticleFont->slowLogic();
+        mInfoParticleFont->slowLogic(1);
     if (mHelpFont)
-        mHelpFont->slowLogic();
+        mHelpFont->slowLogic(2);
     if (mSecureFont)
-        mSecureFont->slowLogic();
+        mSecureFont->slowLogic(3);
     if (boldFont)
-        boldFont->slowLogic();
+        boldFont->slowLogic(4);
+    if (mNpcFont)
+        mNpcFont->slowLogic(5);
     BLOCK_END("Gui::slowLogic")
 }
 
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 3a8f4a0b8..404e1d319 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -41,7 +41,7 @@ const unsigned int CACHE_SIZE = 256;
 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;
+const unsigned int CLEAN_TIME = 7;
 const int OUTLINE_SIZE = 1;
 
 char *strBuf;
@@ -327,17 +327,17 @@ void SDLFont::drawString(gcn::Graphics *const graphics,
     BLOCK_END("SDLFont::drawString")
 }
 
-void SDLFont::slowLogic()
+void SDLFont::slowLogic(const int rnd)
 {
     BLOCK_START("SDLFont::slowLogic")
     if (!mCleanTime)
     {
-        mCleanTime = cur_time + CLEAN_TIME;
+        mCleanTime = cur_time + CLEAN_TIME + rnd;
     }
     else if (mCleanTime < cur_time)
     {
         doClean();
-        mCleanTime = cur_time + CLEAN_TIME;
+        mCleanTime = cur_time + CLEAN_TIME + rnd;
     }
     BLOCK_END("SDLFont::slowLogic")
 }
@@ -410,8 +410,10 @@ void SDLFont::doClean()
 #ifdef DEBUG_FONT_COUNTERS
             mDeleteCounter += 100;
 #endif
-            for (int d = 0; d < 100; d ++)
-                cache->pop_back();
+            const std::list<SDLTextChunk>::iterator it_end = cache->end();
+            std::list<SDLTextChunk>::iterator it = cache->begin();
+            std::advance(it, -100);
+            cache->erase(it, it_end);
 #ifdef DEBUG_FONT_COUNTERS
             logger->log("delete3");
 #endif
@@ -421,8 +423,10 @@ void SDLFont::doClean()
 #ifdef DEBUG_FONT_COUNTERS
             mDeleteCounter += 20;
 #endif
-            for (int d = 0; d < 20; d ++)
-                cache->pop_back();
+            const std::list<SDLTextChunk>::iterator it_end = cache->end();
+            std::list<SDLTextChunk>::iterator it = cache->begin();
+            std::advance(it, -20);
+            cache->erase(it, it_end);
 #ifdef DEBUG_FONT_COUNTERS
             logger->log("delete2");
 #endif
diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h
index 22cbb53cb..4e77943f8 100644
--- a/src/gui/sdlfont.h
+++ b/src/gui/sdlfont.h
@@ -87,7 +87,7 @@ class SDLFont final : public gcn::Font
 
         void doClean();
 
-        void slowLogic();
+        void slowLogic(const int rnd);
 
         int getCreateCounter() const A_WARN_UNUSED
         { return mCreateCounter; }
-- 
cgit v1.2.3-70-g09d2