mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-18 23:57:32 +00:00
MOHAWK: Add subimage drawing/caching code
svn-id: r55038
This commit is contained in:
parent
1897e5e132
commit
64a8652cd6
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user