diff options
author | Max Horn | 2010-06-28 11:20:33 +0000 |
---|---|---|
committer | Max Horn | 2010-06-28 11:20:33 +0000 |
commit | 2c01d10a36f50da6c8bdcfe70558f7d9a2e56324 (patch) | |
tree | 5b33d3bbc12602e069fb84f962cfa341c5c69ae7 /engines/sci/graphics | |
parent | 9f48a37671737229e76cd38cf766d855fd2e7318 (diff) | |
download | scummvm-rg350-2c01d10a36f50da6c8bdcfe70558f7d9a2e56324.tar.gz scummvm-rg350-2c01d10a36f50da6c8bdcfe70558f7d9a2e56324.tar.bz2 scummvm-rg350-2c01d10a36f50da6c8bdcfe70558f7d9a2e56324.zip |
SCI: Remove GfxView::getLoopInfo; add assert to GfxView::getCelInfo
The return value of GfxView::getCelInfo was used virtually everywhere
without a check for it being non-NULL. Hence instead of returning
NULL when the loop count is zero, it makes more sense to assert out
(instead of a segfault, or worse, random data being used).
svn-id: r50422
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r-- | engines/sci/graphics/cache.cpp | 2 | ||||
-rw-r--r-- | engines/sci/graphics/view.cpp | 63 | ||||
-rw-r--r-- | engines/sci/graphics/view.h | 1 |
3 files changed, 30 insertions, 36 deletions
diff --git a/engines/sci/graphics/cache.cpp b/engines/sci/graphics/cache.cpp index 81bdab80ea..8caa28b3a1 100644 --- a/engines/sci/graphics/cache.cpp +++ b/engines/sci/graphics/cache.cpp @@ -102,7 +102,7 @@ int16 GfxCache::kernelViewGetLoopCount(GuiResourceId viewId) { } int16 GfxCache::kernelViewGetCelCount(GuiResourceId viewId, int16 loopNo) { - return getView(viewId)->getLoopInfo(loopNo)->celCount; + return getView(viewId)->getCelCount(loopNo); } } // End of namespace Sci diff --git a/engines/sci/graphics/view.cpp b/engines/sci/graphics/view.cpp index 0749d958a0..b255b18adc 100644 --- a/engines/sci/graphics/view.cpp +++ b/engines/sci/graphics/view.cpp @@ -272,44 +272,49 @@ int16 GfxView::getHeight(int16 loopNo, int16 celNo) const { } const CelInfo *GfxView::getCelInfo(int16 loopNo, int16 celNo) const { + assert(_loopCount); loopNo = CLIP<int16>(loopNo, 0, _loopCount - 1); celNo = CLIP<int16>(celNo, 0, _loop[loopNo].celCount - 1); - return _loopCount ? &_loop[loopNo].cel[celNo] : NULL; + return &_loop[loopNo].cel[celNo]; } -const LoopInfo *GfxView::getLoopInfo(int16 loopNo) const { - loopNo = CLIP<int16>(loopNo, 0, _loopCount - 1); - return _loopCount ? &_loop[loopNo] : NULL; +uint16 GfxView::getCelCount(int16 loopNo) const { +// assert(_loopCount); +// loopNo = CLIP<int16>(loopNo, 0, _loopCount - 1); + if ((loopNo < 0) || (loopNo >= _loopCount)) + return 0; + return _loop[loopNo].celCount; +} + +Palette *GfxView::getPalette() { + return _embeddedPal ? &_viewPalette : NULL; } void GfxView::getCelRect(int16 loopNo, int16 celNo, int16 x, int16 y, int16 z, Common::Rect &outRect) const { const CelInfo *celInfo = getCelInfo(loopNo, celNo); - if (celInfo) { - outRect.left = x + celInfo->displaceX - (celInfo->width >> 1); - outRect.right = outRect.left + celInfo->width; - outRect.bottom = y + celInfo->displaceY - z + 1; - outRect.top = outRect.bottom - celInfo->height; - } + outRect.left = x + celInfo->displaceX - (celInfo->width >> 1); + outRect.right = outRect.left + celInfo->width; + outRect.bottom = y + celInfo->displaceY - z + 1; + outRect.top = outRect.bottom - celInfo->height; } void GfxView::getCelScaledRect(int16 loopNo, int16 celNo, int16 x, int16 y, int16 z, int16 scaleX, int16 scaleY, Common::Rect &outRect) const { int16 scaledDisplaceX, scaledDisplaceY; int16 scaledWidth, scaledHeight; const CelInfo *celInfo = getCelInfo(loopNo, celNo); - if (celInfo) { - // Scaling displaceX/Y, Width/Height - scaledDisplaceX = (celInfo->displaceX * scaleX) >> 7; - scaledDisplaceY = (celInfo->displaceY * scaleY) >> 7; - scaledWidth = (celInfo->width * scaleX) >> 7; - scaledHeight = (celInfo->height * scaleY) >> 7; - scaledWidth = CLIP<int16>(scaledWidth, 0, _screen->getWidth()); - scaledHeight = CLIP<int16>(scaledHeight, 0, _screen->getHeight()); - - outRect.left = x + scaledDisplaceX - (scaledWidth >> 1); - outRect.right = outRect.left + scaledWidth; - outRect.bottom = y + scaledDisplaceY - z + 1; - outRect.top = outRect.bottom - scaledHeight; - } + + // Scaling displaceX/Y, Width/Height + scaledDisplaceX = (celInfo->displaceX * scaleX) >> 7; + scaledDisplaceY = (celInfo->displaceY * scaleY) >> 7; + scaledWidth = (celInfo->width * scaleX) >> 7; + scaledHeight = (celInfo->height * scaleY) >> 7; + scaledWidth = CLIP<int16>(scaledWidth, 0, _screen->getWidth()); + scaledHeight = CLIP<int16>(scaledHeight, 0, _screen->getHeight()); + + outRect.left = x + scaledDisplaceX - (scaledWidth >> 1); + outRect.right = outRect.left + scaledWidth; + outRect.bottom = y + scaledDisplaceY - z + 1; + outRect.top = outRect.bottom - scaledHeight; } void GfxView::unpackCel(int16 loopNo, int16 celNo, byte *outPtr, uint32 pixelCount) { @@ -660,14 +665,4 @@ void GfxView::drawScaled(const Common::Rect &rect, const Common::Rect &clipRect, } } -uint16 GfxView::getCelCount(int16 loopNo) const { - if ((loopNo < 0) || (loopNo >= _loopCount)) - return 0; - return _loop[loopNo].celCount; -} - -Palette *GfxView::getPalette() { - return _embeddedPal ? &_viewPalette : NULL; -} - } // End of namespace Sci diff --git a/engines/sci/graphics/view.h b/engines/sci/graphics/view.h index dd25bde3f2..93239e7586 100644 --- a/engines/sci/graphics/view.h +++ b/engines/sci/graphics/view.h @@ -64,7 +64,6 @@ public: int16 getWidth(int16 loopNo, int16 celNo) const; int16 getHeight(int16 loopNo, int16 celNo) const; const CelInfo *getCelInfo(int16 loopNo, int16 celNo) const; - const LoopInfo *getLoopInfo(int16 loopNo) const; void getCelRect(int16 loopNo, int16 celNo, int16 x, int16 y, int16 z, Common::Rect &outRect) const; void getCelScaledRect(int16 loopNo, int16 celNo, int16 x, int16 y, int16 z, int16 scaleX, int16 scaleY, Common::Rect &outRect) const; const byte *getBitmap(int16 loopNo, int16 celNo); |