Skip to content

Commit

Permalink
SCI: Implementation of kCelInfo subop 4
Browse files Browse the repository at this point in the history
kCelInfo subop 4 returns the pixel color at the
passed in x,y coordinates for the passed in view,
loop, cel.  Shivers uses this function for the
red door puzzle, room 23601 to determine what
blocks on the puzzle board are already occupied
by pieces.
  • Loading branch information
heather162 authored and bluegr committed Oct 11, 2011
1 parent c5e6cde commit 084b2de
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
22 changes: 17 additions & 5 deletions engines/sci/engine/kgraphics.cpp
Expand Up @@ -1471,10 +1471,8 @@ reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv) {
}

reg_t kCelInfo(EngineState *s, int argc, reg_t *argv) {
// TODO: This is all a stub/skeleton, thus we're invoking kStub() for now
kStub(s, argc, argv);

// Used by Shivers 1, room 23601
// Used by Shivers 1, room 23601 to determine what blocks on the red door puzzle board
// are occupied by pieces already

// 6 arguments, all integers:
// argv[0] - subop (0 - 4). It's constantly called with 4 in Shivers 1
Expand All @@ -1490,7 +1488,21 @@ reg_t kCelInfo(EngineState *s, int argc, reg_t *argv) {
// 2, 3 - nop
// 4 - return value of pixel at x, y

return s->r_acc;
switch (argv[0].toUint16()) {
case 4: {
GuiResourceId viewId = argv[1].toSint16();
int16 loopNo = argv[2].toSint16();
int16 celNo = argv[3].toSint16();
int16 x = argv[4].toUint16();
int16 y = argv[5].toUint16();
byte color = g_sci->_gfxCache->kernelViewGetColorAtCoordinate(viewId, loopNo, celNo, x, y);
return make_reg(0, color);
}
default: {
kStub(s, argc, argv);
return s->r_acc;
}
}
}

reg_t kScrollWindow(EngineState *s, int argc, reg_t *argv) {
Expand Down
4 changes: 4 additions & 0 deletions engines/sci/graphics/cache.cpp
Expand Up @@ -102,4 +102,8 @@ int16 GfxCache::kernelViewGetCelCount(GuiResourceId viewId, int16 loopNo) {
return getView(viewId)->getCelCount(loopNo);
}

byte GfxCache::kernelViewGetColorAtCoordinate(GuiResourceId viewId, int16 loopNo, int16 celNo, int16 x, int16 y) {
return getView(viewId)->getColorAtCoordinate(loopNo, celNo, x, y);
}

} // End of namespace Sci
2 changes: 2 additions & 0 deletions engines/sci/graphics/cache.h
Expand Up @@ -49,6 +49,8 @@ class GfxCache {
int16 kernelViewGetLoopCount(GuiResourceId viewId);
int16 kernelViewGetCelCount(GuiResourceId viewId, int16 loopNo);

byte kernelViewGetColorAtCoordinate(GuiResourceId viewId, int16 loopNo, int16 celNo, int16 x, int16 y);

private:
void purgeFontCache();
void purgeViewCache();
Expand Down
9 changes: 9 additions & 0 deletions engines/sci/graphics/view.cpp
Expand Up @@ -837,4 +837,13 @@ void GfxView::adjustBackUpscaledCoordinates(int16 &y, int16 &x) {
_screen->adjustBackUpscaledCoordinates(y, x, _sci2ScaleRes);
}

byte GfxView::getColorAtCoordinate(int16 loopNo, int16 celNo, int16 x, int16 y) {
const CelInfo *celInfo = getCelInfo(loopNo, celNo);
const byte *bitmap = getBitmap(loopNo, celNo);
const int16 celWidth = celInfo->width;

bitmap += (celWidth * y);
return bitmap[x];
}

} // End of namespace Sci
2 changes: 2 additions & 0 deletions engines/sci/graphics/view.h
Expand Up @@ -85,6 +85,8 @@ class GfxView {
void adjustToUpscaledCoordinates(int16 &y, int16 &x);
void adjustBackUpscaledCoordinates(int16 &y, int16 &x);

byte getColorAtCoordinate(int16 loopNo, int16 celNo, int16 x, int16 y);

private:
void initData(GuiResourceId resourceId);
void unpackCel(int16 loopNo, int16 celNo, byte *outPtr, uint32 pixelCount);
Expand Down

0 comments on commit 084b2de

Please sign in to comment.