aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kiewitz2010-01-31 17:45:22 +0000
committerMartin Kiewitz2010-01-31 17:45:22 +0000
commitaaf756e7364658bcde053932907bbf009e1762ab (patch)
tree1f5ac575c4e5c97de6a28fd8b1856c42a6336328
parent3b411f65767256f3d55fd361a253d06f6426654c (diff)
downloadscummvm-rg350-aaf756e7364658bcde053932907bbf009e1762ab.tar.gz
scummvm-rg350-aaf756e7364658bcde053932907bbf009e1762ab.tar.bz2
scummvm-rg350-aaf756e7364658bcde053932907bbf009e1762ab.zip
SCI: implemented font caching
svn-id: r47762
-rw-r--r--engines/sci/graphics/cache.cpp26
-rw-r--r--engines/sci/graphics/cache.h9
-rw-r--r--engines/sci/graphics/gui.cpp2
-rw-r--r--engines/sci/graphics/helpers.h1
-rw-r--r--engines/sci/graphics/text.cpp17
-rw-r--r--engines/sci/graphics/text.h3
6 files changed, 41 insertions, 17 deletions
diff --git a/engines/sci/graphics/cache.cpp b/engines/sci/graphics/cache.cpp
index 8d153e8472..a1330797d4 100644
--- a/engines/sci/graphics/cache.cpp
+++ b/engines/sci/graphics/cache.cpp
@@ -41,10 +41,20 @@ GfxCache::GfxCache(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palet
}
GfxCache::~GfxCache() {
- purgeCache();
+ purgeFontCache();
+ purgeViewCache();
}
-void GfxCache::purgeCache() {
+void GfxCache::purgeFontCache() {
+ for (FontCache::iterator iter = _cachedFonts.begin(); iter != _cachedFonts.end(); ++iter) {
+ delete iter->_value;
+ iter->_value = 0;
+ }
+
+ _cachedFonts.clear();
+}
+
+void GfxCache::purgeViewCache() {
for (ViewCache::iterator iter = _cachedViews.begin(); iter != _cachedViews.end(); ++iter) {
delete iter->_value;
iter->_value = 0;
@@ -53,9 +63,19 @@ void GfxCache::purgeCache() {
_cachedViews.clear();
}
+Font *GfxCache::getFont(GuiResourceId fontId) {
+ if (_cachedFonts.size() >= MAX_CACHED_FONTS)
+ purgeFontCache();
+
+ if (!_cachedViews.contains(fontId))
+ _cachedFonts[fontId] = new Font(_resMan, _screen, fontId);
+
+ return _cachedFonts[fontId];
+}
+
View *GfxCache::getView(GuiResourceId viewId) {
if (_cachedViews.size() >= MAX_CACHED_VIEWS)
- purgeCache();
+ purgeViewCache();
if (!_cachedViews.contains(viewId))
_cachedViews[viewId] = new View(_resMan, _screen, _palette, viewId);
diff --git a/engines/sci/graphics/cache.h b/engines/sci/graphics/cache.h
index a8c3dd5a13..d15d5b25c3 100644
--- a/engines/sci/graphics/cache.h
+++ b/engines/sci/graphics/cache.h
@@ -35,6 +35,7 @@ namespace Sci {
class Font;
class View;
+typedef Common::HashMap<int, Font *> FontCache;
typedef Common::HashMap<int, View *> ViewCache;
class GfxCache {
@@ -42,19 +43,23 @@ public:
GfxCache(ResourceManager *resMan, GfxScreen *screen, GfxPalette *palette);
~GfxCache();
- View *getView(GuiResourceId viewNum);
+ Font *getFont(GuiResourceId fontId);
+
+ View *getView(GuiResourceId viewId);
int16 kernelViewGetCelWidth(GuiResourceId viewId, int16 loopNo, int16 celNo);
int16 kernelViewGetCelHeight(GuiResourceId viewId, int16 loopNo, int16 celNo);
int16 kernelViewGetLoopCount(GuiResourceId viewId);
int16 kernelViewGetCelCount(GuiResourceId viewId, int16 loopNo);
private:
- void purgeCache();
+ void purgeFontCache();
+ void purgeViewCache();
ResourceManager *_resMan;
GfxScreen *_screen;
GfxPalette *_palette;
+ FontCache _cachedFonts;
ViewCache _cachedViews;
};
diff --git a/engines/sci/graphics/gui.cpp b/engines/sci/graphics/gui.cpp
index ae14a7e73b..c8ebb1380f 100644
--- a/engines/sci/graphics/gui.cpp
+++ b/engines/sci/graphics/gui.cpp
@@ -58,7 +58,7 @@ SciGui::SciGui(EngineState *state, GfxScreen *screen, GfxPalette *palette, GfxCa
_transitions = new Transitions(this, _screen, _palette, _s->resMan->isVGA());
_animate = new GfxAnimate(_s, _cache, _ports, _paint16, _screen, _palette, _cursor, _transitions);
_s->_gfxAnimate = _animate;
- _text = new Text(_s->resMan, _ports, _paint16, _screen);
+ _text = new Text(_s->resMan, _cache, _ports, _paint16, _screen);
_controls = new Controls(_s->_segMan, _ports, _paint16, _text);
_menu = new Menu(_s->_event, _s->_segMan, this, _ports, _paint16, _text, _screen, _cursor);
}
diff --git a/engines/sci/graphics/helpers.h b/engines/sci/graphics/helpers.h
index 2d7239f975..7db6fa0d4a 100644
--- a/engines/sci/graphics/helpers.h
+++ b/engines/sci/graphics/helpers.h
@@ -34,6 +34,7 @@ namespace Sci {
// Cache limits
#define MAX_CACHED_CURSORS 10
+#define MAX_CACHED_FONTS 20
#define MAX_CACHED_VIEWS 50
#define SCI_SHAKE_DIRECTION_VERTICAL 1
diff --git a/engines/sci/graphics/text.cpp b/engines/sci/graphics/text.cpp
index 8d0e64b759..aa97e858ab 100644
--- a/engines/sci/graphics/text.cpp
+++ b/engines/sci/graphics/text.cpp
@@ -29,6 +29,7 @@
#include "sci/sci.h"
#include "sci/engine/state.h"
+#include "sci/graphics/cache.h"
#include "sci/graphics/ports.h"
#include "sci/graphics/paint16.h"
#include "sci/graphics/font.h"
@@ -36,8 +37,8 @@
namespace Sci {
-Text::Text(ResourceManager *resMan, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen)
- : _resMan(resMan), _ports(ports), _paint16(paint16), _screen(screen) {
+Text::Text(ResourceManager *resMan, GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen)
+ : _resMan(resMan), _cache(cache), _ports(ports), _paint16(paint16), _screen(screen) {
init();
}
@@ -58,19 +59,15 @@ GuiResourceId Text::GetFontId() {
}
Font *Text::GetFont() {
- if ((_font == NULL) || (_font->getResourceId() != _ports->_curPort->fontId)) {
- delete _font;
- _font = new Font(_resMan, _screen, _ports->_curPort->fontId);
- }
+ if ((_font == NULL) || (_font->getResourceId() != _ports->_curPort->fontId))
+ _font = _cache->getFont(_ports->_curPort->fontId);
return _font;
}
void Text::SetFont(GuiResourceId fontId) {
- if ((_font == NULL) || (_font->getResourceId() != fontId)) {
- delete _font;
- _font = new Font(_resMan, _screen, fontId);
- }
+ if ((_font == NULL) || (_font->getResourceId() != fontId))
+ _font = _cache->getFont(fontId);
_ports->_curPort->fontId = _font->getResourceId();
_ports->_curPort->fontHeight = _font->getHeight();
diff --git a/engines/sci/graphics/text.h b/engines/sci/graphics/text.h
index 65ca413ef9..bf6d771c79 100644
--- a/engines/sci/graphics/text.h
+++ b/engines/sci/graphics/text.h
@@ -38,7 +38,7 @@ class Screen;
class Font;
class Text {
public:
- Text(ResourceManager *_resMan, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen);
+ Text(ResourceManager *_resMan, GfxCache *fonts, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen);
~Text();
GuiResourceId GetFontId();
@@ -70,6 +70,7 @@ private:
void init();
ResourceManager *_resMan;
+ GfxCache *_cache;
GfxPorts *_ports;
GfxPaint16 *_paint16;
GfxScreen *_screen;