diff options
author | Colin Snover | 2016-05-27 14:49:03 -0500 |
---|---|---|
committer | Colin Snover | 2016-05-27 15:54:14 -0500 |
commit | 746c4e7b03bee53d5db708dece2b490cc1f84c2b (patch) | |
tree | 9aab6010d743a9457a17fa4a90ffb113bcf1c0ee /engines/sci | |
parent | 4ee5b0f910ff46c386141cc72a627ac6aeb3ef03 (diff) | |
download | scummvm-rg350-746c4e7b03bee53d5db708dece2b490cc1f84c2b.tar.gz scummvm-rg350-746c4e7b03bee53d5db708dece2b490cc1f84c2b.tar.bz2 scummvm-rg350-746c4e7b03bee53d5db708dece2b490cc1f84c2b.zip |
SCI32: Fix CelObj cache
The previous implementation did not work properly, assigning the
next insertion index to the oldest object instead of filling empty
cache slots on a cache miss.
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/graphics/celobj32.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/engines/sci/graphics/celobj32.cpp b/engines/sci/graphics/celobj32.cpp index 693bc5f196..3e09d0f495 100644 --- a/engines/sci/graphics/celobj32.cpp +++ b/engines/sci/graphics/celobj32.cpp @@ -525,30 +525,30 @@ int CelObj::_nextCacheId = 1; CelCache *CelObj::_cache = nullptr; int CelObj::searchCache(const CelInfo32 &celInfo, int *nextInsertIndex) const { + *nextInsertIndex = -1; int oldestId = _nextCacheId + 1; - int oldestIndex = -1; + int oldestIndex = 0; for (int i = 0, len = _cache->size(); i < len; ++i) { CelCacheEntry &entry = (*_cache)[i]; - if (entry.celObj != nullptr) { - if (entry.celObj->_info == celInfo) { - entry.id = ++_nextCacheId; - return i; + if (entry.celObj == nullptr) { + if (*nextInsertIndex == -1) { + *nextInsertIndex = i; } - - if (oldestId > entry.id) { - oldestId = entry.id; - oldestIndex = i; - } - } else if (oldestIndex == -1) { + } else if (entry.celObj->_info == celInfo) { + entry.id = ++_nextCacheId; + return i; + } else if (oldestId > entry.id) { + oldestId = entry.id; oldestIndex = i; } } - // NOTE: Unlike the original SCI engine code, the out-param - // here is only updated if there was not a cache hit. - *nextInsertIndex = oldestIndex; + if (*nextInsertIndex == -1) { + *nextInsertIndex = oldestIndex; + } + return -1; } |