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
This commit is contained in:
Max Horn 2010-06-28 11:20:33 +00:00
parent 9f48a37671
commit 2c01d10a36
3 changed files with 29 additions and 35 deletions

View File

@ -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

View File

@ -272,31 +272,37 @@ 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;
}
}
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;
@ -310,7 +316,6 @@ void GfxView::getCelScaledRect(int16 loopNo, int16 celNo, int16 x, int16 y, int1
outRect.bottom = y + scaledDisplaceY - z + 1;
outRect.top = outRect.bottom - scaledHeight;
}
}
void GfxView::unpackCel(int16 loopNo, int16 celNo, byte *outPtr, uint32 pixelCount) {
const CelInfo *celInfo = getCelInfo(loopNo, celNo);
@ -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

View File

@ -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);