diff options
author | Gregory Montoir | 2005-01-30 20:38:54 +0000 |
---|---|---|
committer | Gregory Montoir | 2005-01-30 20:38:54 +0000 |
commit | b9646d35d340627b47accfd1bc0f8c2da784a473 (patch) | |
tree | 7a4e2ec67b0b0e9fa97d120fa1bd97336cd625e8 /scumm | |
parent | 339df486e1a3d9ff5546c17e998521af504510cc (diff) | |
download | scummvm-rg350-b9646d35d340627b47accfd1bc0f8c2da784a473.tar.gz scummvm-rg350-b9646d35d340627b47accfd1bc0f8c2da784a473.tar.bz2 scummvm-rg350-b9646d35d340627b47accfd1bc0f8c2da784a473.zip |
added a basic cursor cache for win32 HE70+ games
svn-id: r16708
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/resource_v7he.cpp | 80 | ||||
-rw-r--r-- | scumm/resource_v7he.h | 17 |
2 files changed, 85 insertions, 12 deletions
diff --git a/scumm/resource_v7he.cpp b/scumm/resource_v7he.cpp index 0cc7de2d1d..b7de79be76 100644 --- a/scumm/resource_v7he.cpp +++ b/scumm/resource_v7he.cpp @@ -29,6 +29,7 @@ #include "scumm/resource.h" #include "scumm/resource_v7he.h" #include "common/stream.h" +#include "common/system.h" namespace Scumm { @@ -51,6 +52,49 @@ Win32ResExtractor::Win32ResExtractor(ScummEngine_v70he *scumm) { _vm = scumm; snprintf(_fileName, 256, "%s.he3", _vm->getGameName()); + memset(_cursorCache, 0, sizeof(_cursorCache)); +} + +Win32ResExtractor::~Win32ResExtractor() { + for (int i = 0; i < MAX_CACHED_CURSORS; ++i) { + CachedCursor *cc = &_cursorCache[i]; + if (cc->valid) { + free(cc->bitmap); + cc->bitmap = NULL; + cc->valid = false; + } + } +} + +Win32ResExtractor::CachedCursor *Win32ResExtractor::findCachedCursor(int id) { + for (int i = 0; i < MAX_CACHED_CURSORS; ++i) { + CachedCursor *cc = &_cursorCache[i]; + if (cc->valid && cc->id == id) { + return cc; + } + } + return NULL; +} + +Win32ResExtractor::CachedCursor *Win32ResExtractor::getCachedCursorSlot() { + uint32 min_last_used = 0; + CachedCursor *r = NULL; + for (int i = 0; i < MAX_CACHED_CURSORS; ++i) { + CachedCursor *cc = &_cursorCache[i]; + if (!cc->valid) { + return cc; + } else { + if (min_last_used == 0 || cc->last_used < min_last_used) { + min_last_used = cc->last_used; + r = cc; + } + } + } + assert(r); + free(r->bitmap); + r->bitmap = NULL; + r->valid = false; + return r; } void Win32ResExtractor::setCursor(int id) { @@ -58,18 +102,30 @@ void Win32ResExtractor::setCursor(int id) { byte *cursorRes = 0, *cursor = 0; int cursorsize; int w = 0, h = 0, hotspot_x = 0, hotspot_y = 0, keycolor = 0; - - snprintf(buf, 20, "%d", id); - - cursorsize = extractResource("group_cursor", buf, &cursorRes); - - convertIcons(cursorRes, cursorsize, &cursor, &w, &h, &hotspot_x, &hotspot_y, - &keycolor); - - _vm->setCursorHotspot(hotspot_x, hotspot_y); - _vm->setCursorFromBuffer(cursor, w, h, w); - free(cursorRes); - free(cursor); + CachedCursor *cc = findCachedCursor(id); + if (cc != NULL) { + debug(7, "Found cursor %d in cache slot %d", id, cc - _cursorCache); + _vm->setCursorHotspot(cc->hotspot_x, cc->hotspot_y); + _vm->setCursorFromBuffer(cc->bitmap, cc->w, cc->h, cc->w); + } else { + snprintf(buf, 20, "%d", id); + cursorsize = extractResource("group_cursor", buf, &cursorRes); + convertIcons(cursorRes, cursorsize, &cursor, &w, &h, &hotspot_x, &hotspot_y, &keycolor); + cc = getCachedCursorSlot(); + assert(cc && !cc->valid); + debug(7, "Adding cursor %d to cache slot %d", id, cc - _cursorCache); + _vm->setCursorHotspot(hotspot_x, hotspot_y); + _vm->setCursorFromBuffer(cursor, w, h, w); + free(cursorRes); + cc->valid = true; + cc->id = id; + cc->bitmap = cursor; + cc->w = w; + cc->h = h; + cc->hotspot_x = hotspot_x; + cc->hotspot_y = hotspot_y; + cc->last_used = g_system->getMillis(); + } } int Win32ResExtractor::extractResource(const char *resType, char *resName, byte **data) { diff --git a/scumm/resource_v7he.h b/scumm/resource_v7he.h index b492372cc9..3aef799933 100644 --- a/scumm/resource_v7he.h +++ b/scumm/resource_v7he.h @@ -123,10 +123,27 @@ class Win32ResExtractor { int convertIcons(byte *data, int datasize, byte **cursor, int *w, int *h, int *hotspot_x, int *hotspot_y, int *keycolor); + enum { + MAX_CACHED_CURSORS = 10 + }; + + struct CachedCursor { + bool valid; + int id; + byte *bitmap; + int w, h; + int hotspot_x, hotspot_y; + uint32 last_used; + }; + private: + Win32ResExtractor::CachedCursor *findCachedCursor(int id); + Win32ResExtractor::CachedCursor *getCachedCursorSlot(); + bool _arg_raw; ScummEngine_v70he *_vm; char _fileName[256]; + CachedCursor _cursorCache[MAX_CACHED_CURSORS]; typedef Common::MemoryReadStream MemoryReadStream; |