diff options
author | Filippos Karapetis | 2009-10-30 17:13:25 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-30 17:13:25 +0000 |
commit | 371097d27cca28c1d7163f288fe8b229841d9b8d (patch) | |
tree | c2cae7b12f865a28730c9ae03dc34f1dd39500b7 /engines/sci | |
parent | b2ab8fd77bff53cf8dffe705959e6d4abd2b0f5c (diff) | |
download | scummvm-rg350-371097d27cca28c1d7163f288fe8b229841d9b8d.tar.gz scummvm-rg350-371097d27cca28c1d7163f288fe8b229841d9b8d.tar.bz2 scummvm-rg350-371097d27cca28c1d7163f288fe8b229841d9b8d.zip |
Added caching for mouse cursor views
svn-id: r45541
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/gui/gui_cursor.cpp | 20 | ||||
-rw-r--r-- | engines/sci/gui/gui_cursor.h | 11 |
2 files changed, 28 insertions, 3 deletions
diff --git a/engines/sci/gui/gui_cursor.cpp b/engines/sci/gui/gui_cursor.cpp index 702c9447e6..db1ae1ca6d 100644 --- a/engines/sci/gui/gui_cursor.cpp +++ b/engines/sci/gui/gui_cursor.cpp @@ -44,6 +44,7 @@ SciGuiCursor::SciGuiCursor(ResourceManager *resMan, SciGuiPalette *palette, SciG } SciGuiCursor::~SciGuiCursor() { + purgeCache(); } void SciGuiCursor::show() { @@ -54,6 +55,15 @@ void SciGuiCursor::hide() { CursorMan.showMouse(false); } +void SciGuiCursor::purgeCache() { + for (CursorCache::iterator iter = _cachedCursors.begin(); iter != _cachedCursors.end(); ++iter) { + delete iter->_value; + iter->_value = 0; + } + + _cachedCursors.clear(); +} + void SciGuiCursor::setShape(GuiResourceId resourceId) { Resource *resource; byte *resourceData; @@ -114,7 +124,13 @@ void SciGuiCursor::setShape(GuiResourceId resourceId) { } void SciGuiCursor::setView(GuiResourceId viewNum, int loopNum, int celNum, Common::Point *hotspot) { - SciGuiView *cursorView = new SciGuiView(_resMan, _screen, _palette, viewNum); + if (_cachedCursors.size() >= MAX_CACHED_CURSORS) + purgeCache(); + + if (!_cachedCursors.contains(viewNum)) + _cachedCursors[viewNum] = new SciGuiView(_resMan, _screen, _palette, viewNum); + + SciGuiView *cursorView = _cachedCursors[viewNum]; sciViewCelInfo *celInfo = cursorView->getCelInfo(loopNum, celNum); int16 width = celInfo->width; @@ -129,7 +145,6 @@ void SciGuiCursor::setView(GuiResourceId viewNum, int loopNum, int celNum, Commo if (width < 2 || height < 2) { hide(); delete cursorHotspot; - delete cursorView; return; } @@ -139,7 +154,6 @@ void SciGuiCursor::setView(GuiResourceId viewNum, int loopNum, int celNum, Commo show(); delete cursorHotspot; - delete cursorView; } void SciGuiCursor::setPosition(Common::Point pos) { diff --git a/engines/sci/gui/gui_cursor.h b/engines/sci/gui/gui_cursor.h index 93527643f5..a594f8a6c7 100644 --- a/engines/sci/gui/gui_cursor.h +++ b/engines/sci/gui/gui_cursor.h @@ -26,6 +26,8 @@ #ifndef SCI_GUI_CURSOR_H #define SCI_GUI_CURSOR_H +#include "common/hashmap.h" + namespace Sci { #define SCI_CURSOR_SCI0_HEIGHTWIDTH 16 @@ -33,8 +35,13 @@ namespace Sci { #define SCI_CURSOR_SCI0_TRANSPARENCYCOLOR 1 +#define MAX_CACHED_CURSORS 10 + class SciGuiView; class SciGuiPalette; + +typedef Common::HashMap<int, SciGuiView *> CursorCache; + class SciGuiCursor { public: SciGuiCursor(ResourceManager *resMan, SciGuiPalette *palette, SciGuiScreen *screen); @@ -56,11 +63,15 @@ public: void setMoveZone(Common::Rect zone) { _moveZone = zone; } private: + void purgeCache(); + ResourceManager *_resMan; SciGuiScreen *_screen; SciGuiPalette *_palette; Common::Rect _moveZone; // Rectangle in which the pointer can move + + CursorCache _cachedCursors; }; } // End of namespace Sci |