mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-04 01:46:42 +00:00
Added caching for mouse cursor views
svn-id: r45541
This commit is contained in:
parent
b2ab8fd77b
commit
371097d27c
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user