aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/gui/gui_cursor.cpp20
-rw-r--r--engines/sci/gui/gui_cursor.h11
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