From 4efd40e41eb44e13c28b73c4eb06b3d2105f88e0 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 2 Dec 2012 07:25:12 +0100 Subject: WINTERMUTE: Make the TTF-cache actually use LRU. --- engines/wintermute/base/font/base_font_truetype.cpp | 12 ++++++------ engines/wintermute/base/font/base_font_truetype.h | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp index f236329fcd..85844b5080 100644 --- a/engines/wintermute/base/font/base_font_truetype.cpp +++ b/engines/wintermute/base/font/base_font_truetype.cpp @@ -173,25 +173,25 @@ void BaseFontTT::drawText(const byte *text, int x, int y, int width, TTextAlign BaseRenderer *renderer = _gameRef->_renderer; // find cached surface, if exists - int minPriority = INT_MAX; + int minUseTime = INT_MAX; int minIndex = -1; BaseSurface *surface = NULL; int textOffset = 0; for (int i = 0; i < NUM_CACHED_TEXTS; i++) { if (_cachedTexts[i] == NULL) { - minPriority = 0; + minUseTime = 0; minIndex = i; } else { if (_cachedTexts[i]->_text == textStr && _cachedTexts[i]->_align == align && _cachedTexts[i]->_width == width && _cachedTexts[i]->_maxHeight == maxHeight && _cachedTexts[i]->_maxLength == maxLength) { surface = _cachedTexts[i]->_surface; textOffset = _cachedTexts[i]->_textOffset; - _cachedTexts[i]->_priority++; _cachedTexts[i]->_marked = true; + _cachedTexts[i]->_lastUsed = g_system->getMillis(); break; } else { - if (_cachedTexts[i]->_priority < minPriority) { - minPriority = _cachedTexts[i]->_priority; + if (_cachedTexts[i]->_lastUsed < minUseTime) { + minUseTime = _cachedTexts[i]->_lastUsed; minIndex = i; } } @@ -214,10 +214,10 @@ void BaseFontTT::drawText(const byte *text, int x, int y, int width, TTextAlign _cachedTexts[minIndex]->_width = width; _cachedTexts[minIndex]->_maxHeight = maxHeight; _cachedTexts[minIndex]->_maxLength = maxLength; - _cachedTexts[minIndex]->_priority = 1; _cachedTexts[minIndex]->_text = textStr; _cachedTexts[minIndex]->_textOffset = textOffset; _cachedTexts[minIndex]->_marked = true; + _cachedTexts[minIndex]->_lastUsed = g_system->getMillis(); } } diff --git a/engines/wintermute/base/font/base_font_truetype.h b/engines/wintermute/base/font/base_font_truetype.h index 02dca7439f..2b69d1655d 100644 --- a/engines/wintermute/base/font/base_font_truetype.h +++ b/engines/wintermute/base/font/base_font_truetype.h @@ -54,6 +54,7 @@ private: int _priority; int _textOffset; bool _marked; + uint32 _lastUsed; BaseCachedTTFontText() { //_text = L""; @@ -61,8 +62,8 @@ private: _width = _maxHeight = _maxLength = -1; _align = TAL_LEFT; _surface = NULL; - _priority = -1; _textOffset = 0; + _lastUsed = 0; _marked = false; } -- cgit v1.2.3