diff options
author | Alyssa Milburn | 2010-12-25 19:52:54 +0000 |
---|---|---|
committer | Alyssa Milburn | 2010-12-25 19:52:54 +0000 |
commit | 64a8652cd6786fc7c063c28c849be6b8bfdcc454 (patch) | |
tree | b0ad8c146c70f1f38ac5a17fc3605ba68ad20d48 /engines | |
parent | 1897e5e132bda062f84d38cbb0a3bef4d7087245 (diff) | |
download | scummvm-rg350-64a8652cd6786fc7c063c28c849be6b8bfdcc454.tar.gz scummvm-rg350-64a8652cd6786fc7c063c28c849be6b8bfdcc454.tar.bz2 scummvm-rg350-64a8652cd6786fc7c063c28c849be6b8bfdcc454.zip |
MOHAWK: Add subimage drawing/caching code
svn-id: r55038
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/graphics.cpp | 28 | ||||
-rw-r--r-- | engines/mohawk/graphics.h | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp index 47808e4c69..7f0e9a0a14 100644 --- a/engines/mohawk/graphics.cpp +++ b/engines/mohawk/graphics.cpp @@ -101,8 +101,14 @@ GraphicsManager::~GraphicsManager() { void GraphicsManager::clearCache() { for (Common::HashMap<uint16, MohawkSurface*>::iterator it = _cache.begin(); it != _cache.end(); it++) delete it->_value; + for (Common::HashMap<uint16, Common::Array<MohawkSurface*> >::iterator it = _subImageCache.begin(); it != _subImageCache.end(); it++) { + Common::Array<MohawkSurface *> &array = it->_value; + for (uint i = 0; i < array.size(); i++) + delete array[i]; + } _cache.clear(); + _subImageCache.clear(); } MohawkSurface *GraphicsManager::findImage(uint16 id) { @@ -117,6 +123,10 @@ MohawkSurface *GraphicsManager::findImage(uint16 id) { return _cache[id]; } +Common::Array<MohawkSurface *> GraphicsManager::decodeImages(uint16 id) { + error("decodeImages not implemented for this game"); +} + void GraphicsManager::preloadImage(uint16 image) { findImage(image); } @@ -150,6 +160,22 @@ void GraphicsManager::copyAnimImageToScreen(uint16 image, int left, int top) { } void GraphicsManager::copyAnimImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) { + copyAnimImageSectionToScreen(findImage(image), srcRect, dstRect); +} + +void GraphicsManager::copyAnimSubImageToScreen(uint16 image, uint16 subimage, int left, int top) { + if (!_subImageCache.contains(image)) + _subImageCache[image] = decodeImages(image); + Common::Array<MohawkSurface *> &images = _subImageCache[image]; + + Graphics::Surface *surface = images[subimage]->getSurface(); + + Common::Rect srcRect(0, 0, surface->w, surface->h); + Common::Rect dstRect(left, top, left + surface->w, top + surface->h); + copyAnimImageSectionToScreen(images[subimage], srcRect, dstRect); +} + +void GraphicsManager::copyAnimImageSectionToScreen(MohawkSurface *image, Common::Rect srcRect, Common::Rect dstRect) { uint16 startX = 0; uint16 startY = 0; @@ -172,7 +198,7 @@ void GraphicsManager::copyAnimImageSectionToScreen(uint16 image, Common::Rect sr if (dstRect.top >= getVM()->_system->getHeight()) return; - Graphics::Surface *surface = findImage(image)->getSurface(); + Graphics::Surface *surface = image->getSurface(); if (startX >= surface->w) return; if (startY >= surface->h) diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h index 0dc281c391..7c11692af3 100644 --- a/engines/mohawk/graphics.h +++ b/engines/mohawk/graphics.h @@ -88,20 +88,25 @@ public: virtual void setPalette(uint16 id); void copyAnimImageToScreen(uint16 image, int left = 0, int top = 0); void copyAnimImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest); + void copyAnimSubImageToScreen(uint16 image, uint16 subimage, int left = 0, int top = 0); protected: + void copyAnimImageSectionToScreen(MohawkSurface *image, Common::Rect src, Common::Rect dest); + // findImage will search the cache to find the image. // If not found, it will call decodeImage to get a new one. MohawkSurface *findImage(uint16 id); // decodeImage will always return a new image. virtual MohawkSurface *decodeImage(uint16 id) = 0; + virtual Common::Array<MohawkSurface *> decodeImages(uint16 id); virtual MohawkEngine *getVM() = 0; private: // An image cache that stores images until clearCache() is called Common::HashMap<uint16, MohawkSurface*> _cache; + Common::HashMap<uint16, Common::Array<MohawkSurface*> > _subImageCache; }; class MystGraphics : public GraphicsManager { |