[Scummvm-cvs-logs] SF.net SVN: scummvm:[47762] scummvm/trunk/engines/sci/graphics

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Sun Jan 31 18:45:22 CET 2010


Revision: 47762
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47762&view=rev
Author:   m_kiewitz
Date:     2010-01-31 17:45:22 +0000 (Sun, 31 Jan 2010)

Log Message:
-----------
SCI: implemented font caching

Modified Paths:
--------------
    scummvm/trunk/engines/sci/graphics/cache.cpp
    scummvm/trunk/engines/sci/graphics/cache.h
    scummvm/trunk/engines/sci/graphics/gui.cpp
    scummvm/trunk/engines/sci/graphics/helpers.h
    scummvm/trunk/engines/sci/graphics/text.cpp
    scummvm/trunk/engines/sci/graphics/text.h

Modified: scummvm/trunk/engines/sci/graphics/cache.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/cache.cpp	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/cache.cpp	2010-01-31 17:45:22 UTC (rev 47762)
@@ -41,10 +41,20 @@
 }
 
 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 @@
 	_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);

Modified: scummvm/trunk/engines/sci/graphics/cache.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/cache.h	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/cache.h	2010-01-31 17:45:22 UTC (rev 47762)
@@ -35,6 +35,7 @@
 class Font;
 class View;
 
+typedef Common::HashMap<int, Font *> FontCache;
 typedef Common::HashMap<int, View *> ViewCache;
 
 class GfxCache {
@@ -42,19 +43,23 @@
 	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;
 };
 

Modified: scummvm/trunk/engines/sci/graphics/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/gui.cpp	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/gui.cpp	2010-01-31 17:45:22 UTC (rev 47762)
@@ -58,7 +58,7 @@
 	_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);
 }

Modified: scummvm/trunk/engines/sci/graphics/helpers.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/helpers.h	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/helpers.h	2010-01-31 17:45:22 UTC (rev 47762)
@@ -34,6 +34,7 @@
 
 // Cache limits
 #define MAX_CACHED_CURSORS 10
+#define MAX_CACHED_FONTS 20
 #define MAX_CACHED_VIEWS 50
 
 #define SCI_SHAKE_DIRECTION_VERTICAL 1

Modified: scummvm/trunk/engines/sci/graphics/text.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/text.cpp	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/text.cpp	2010-01-31 17:45:22 UTC (rev 47762)
@@ -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 @@
 }
 
 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();

Modified: scummvm/trunk/engines/sci/graphics/text.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/text.h	2010-01-31 17:30:58 UTC (rev 47761)
+++ scummvm/trunk/engines/sci/graphics/text.h	2010-01-31 17:45:22 UTC (rev 47762)
@@ -38,7 +38,7 @@
 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 @@
 	void init();
 
 	ResourceManager *_resMan;
+	GfxCache *_cache;
 	GfxPorts *_ports;
 	GfxPaint16 *_paint16;
 	GfxScreen *_screen;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list