Skip to content

Commit

Permalink
SCI: Fix some rect off-by-ones
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Feb 18, 2016
1 parent 3c9b930 commit 03e3f2c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions engines/sci/engine/kgraphics32.cpp
Expand Up @@ -204,8 +204,8 @@ reg_t kCreateTextBitmap(EngineState *s, int argc, reg_t *argv) {
Common::Rect rect(
readSelectorValue(segMan, object, SELECTOR(textLeft)),
readSelectorValue(segMan, object, SELECTOR(textTop)),
readSelectorValue(segMan, object, SELECTOR(textRight)),
readSelectorValue(segMan, object, SELECTOR(textBottom))
readSelectorValue(segMan, object, SELECTOR(textRight)) + 1,
readSelectorValue(segMan, object, SELECTOR(textBottom)) + 1
);

if (subop == 0) {
Expand Down
2 changes: 1 addition & 1 deletion engines/sci/graphics/frameout.cpp
Expand Up @@ -144,7 +144,7 @@ void GfxFrameout::run() {
// NOTE: This happens in SCI::InitPlane in the actual engine,
// and is a background fill plane to ensure hidden planes
// (planes with a priority of -1) are never drawn
Plane *initPlane = new Plane(Common::Rect(_currentBuffer.scriptWidth - 1, _currentBuffer.scriptHeight - 1));
Plane *initPlane = new Plane(Common::Rect(_currentBuffer.scriptWidth, _currentBuffer.scriptHeight));
initPlane->_priority = 0;
_planes.add(initPlane);
}
Expand Down
19 changes: 13 additions & 6 deletions engines/sci/graphics/helpers.h
Expand Up @@ -142,13 +142,13 @@ inline void mul(Common::Rect &rect, const Common::Rational &ratioX, const Common
* Multiplies a number by a rational number, rounding up to
* the nearest whole number.
*/
inline int mulru(const int value, const Common::Rational &ratio, const int extra = 0) {
int num = (value + extra) * ratio.getNumerator();
inline int mulru(const int value, const Common::Rational &ratio) {
int num = value * ratio.getNumerator();
int result = num / ratio.getDenominator();
if (num > ratio.getDenominator() && num % ratio.getDenominator()) {
++result;
}
return result - extra;
return result;
}

/**
Expand All @@ -165,12 +165,19 @@ inline void mulru(Common::Point &point, const Common::Rational &ratioX, const Co
* Multiplies a point by two rational numbers for X and Y,
* rounding up to the nearest whole number. Modifies the
* rect directly.
*
* @note In SCI engine, the bottom-right corner of rects
* received an additional one pixel during the
* multiplication in order to round up to include the
* bottom-right corner. Since ScummVM rects do not include
* the bottom-right corner, doing this ends up making rects
* a pixel too wide/tall depending upon the remainder.
*/
inline void mulru(Common::Rect &rect, const Common::Rational &ratioX, const Common::Rational &ratioY, const int brExtra = 0) {
inline void mulru(Common::Rect &rect, const Common::Rational &ratioX, const Common::Rational &ratioY) {
rect.left = mulru(rect.left, ratioX);
rect.top = mulru(rect.top, ratioY);
rect.right = mulru(rect.right, ratioX, brExtra);
rect.bottom = mulru(rect.bottom, ratioY, brExtra);
rect.right = mulru(rect.right, ratioX);
rect.bottom = mulru(rect.bottom, ratioY);
}

struct Buffer : public Graphics::Surface {
Expand Down
10 changes: 5 additions & 5 deletions engines/sci/graphics/plane32.cpp
Expand Up @@ -78,8 +78,8 @@ _moved(0) {

_gameRect.left = readSelectorValue(segMan, object, SELECTOR(inLeft));
_gameRect.top = readSelectorValue(segMan, object, SELECTOR(inTop));
_gameRect.right = readSelectorValue(segMan, object, SELECTOR(inRight));
_gameRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom));
_gameRect.right = readSelectorValue(segMan, object, SELECTOR(inRight)) + 1;
_gameRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom)) + 1;
convertGameRectToPlaneRect();

_back = readSelectorValue(segMan, object, SELECTOR(back));
Expand Down Expand Up @@ -136,7 +136,7 @@ void Plane::convertGameRectToPlaneRect() {
const Ratio ratioY = Ratio(screenHeight, scriptHeight);

_planeRect = _gameRect;
mulru(_planeRect, ratioX, ratioY, 1);
mulru(_planeRect, ratioX, ratioY);
}

void Plane::printDebugInfo(Console *con) const {
Expand Down Expand Up @@ -752,8 +752,8 @@ void Plane::update(const reg_t object) {
_vanishingPoint.y = readSelectorValue(segMan, object, SELECTOR(vanishingY));
_gameRect.left = readSelectorValue(segMan, object, SELECTOR(inLeft));
_gameRect.top = readSelectorValue(segMan, object, SELECTOR(inTop));
_gameRect.right = readSelectorValue(segMan, object, SELECTOR(inRight));
_gameRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom));
_gameRect.right = readSelectorValue(segMan, object, SELECTOR(inRight)) + 1;
_gameRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom)) + 1;
convertGameRectToPlaneRect();

_priority = readSelectorValue(segMan, object, SELECTOR(priority));
Expand Down
6 changes: 3 additions & 3 deletions engines/sci/graphics/screen_item32.cpp
Expand Up @@ -209,8 +209,8 @@ void ScreenItem::setFromObject(SegManager *segMan, const reg_t object, const boo
_useInsetRect = true;
_insetRect.left = readSelectorValue(segMan, object, SELECTOR(inLeft));
_insetRect.top = readSelectorValue(segMan, object, SELECTOR(inTop));
_insetRect.right = readSelectorValue(segMan, object, SELECTOR(inRight));
_insetRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom));
_insetRect.right = readSelectorValue(segMan, object, SELECTOR(inRight)) + 1;
_insetRect.bottom = readSelectorValue(segMan, object, SELECTOR(inBottom)) + 1;
} else {
_useInsetRect = false;
}
Expand Down Expand Up @@ -376,7 +376,7 @@ void ScreenItem::calcRects(const Plane &plane) {
Ratio celXRatio(screenWidth, _celObj->_scaledWidth);
Ratio celYRatio(screenHeight, _celObj->_scaledHeight);
mulru(_scaledPosition, celXRatio, celYRatio);
mulru(_screenItemRect, celXRatio, celYRatio, 1);
mulru(_screenItemRect, celXRatio, celYRatio);
}

_ratioX = newRatioX * Ratio(screenWidth, _celObj->_scaledWidth);
Expand Down

0 comments on commit 03e3f2c

Please sign in to comment.