Skip to content

Commit

Permalink
SCI32: Clean up scriptWidth/scriptHeight/screenWidth/screenHeight
Browse files Browse the repository at this point in the history
This removes the unnecessary Buffer subclass and stops most places
where the output buffer was being interrogated about dimensions
instead of GfxFrameout.
  • Loading branch information
csnover committed Oct 7, 2017
1 parent d53e778 commit c7c5f28
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 184 deletions.
31 changes: 16 additions & 15 deletions engines/sci/engine/kgraphics32.cpp
Expand Up @@ -77,7 +77,7 @@ reg_t kBaseSetter32(EngineState *s, int argc, reg_t *argv) {

Ratio scaleX;
if (getSciVersion() < SCI_VERSION_2_1_LATE) {
const int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
scaleX = Ratio(scriptWidth, celObj._xResolution);
}

Expand Down Expand Up @@ -160,11 +160,12 @@ reg_t kShakeScreen32(EngineState *s, int argc, reg_t *argv) {
}

reg_t kIsHiRes(EngineState *s, int argc, reg_t *argv) {
const Buffer &buffer = g_sci->_gfxFrameout->getCurrentBuffer();
if (buffer.screenWidth < 640 || buffer.screenHeight < 400)
return make_reg(0, 0);
const GfxFrameout *gfxFrameout = g_sci->_gfxFrameout;
if (gfxFrameout->getScreenWidth() < 640 || gfxFrameout->getScreenHeight() < 400) {
return NULL_REG;
}

return make_reg(0, 1);
return TRUE_REG;
}

reg_t kAddScreenItem(EngineState *s, int argc, reg_t *argv) {
Expand Down Expand Up @@ -412,25 +413,25 @@ reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv) {
}

reg_t kCelHigh32(EngineState *s, int argc, reg_t *argv) {
GuiResourceId resourceId = argv[0].toUint16();
int16 loopNo = argv[1].toSint16();
int16 celNo = argv[2].toSint16();
CelObjView celObj(resourceId, loopNo, celNo);
const GuiResourceId resourceId = argv[0].toUint16();
const int16 loopNo = argv[1].toSint16();
const int16 celNo = argv[2].toSint16();
const CelObjView celObj(resourceId, loopNo, celNo);
int16 height = celObj._height;
if (getSciVersion() < SCI_VERSION_2_1_LATE) {
height = mulru(height, Ratio(g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight, celObj._yResolution));
height = mulru(height, Ratio(g_sci->_gfxFrameout->getScriptHeight(), celObj._yResolution));
}
return make_reg(0, height);
}

reg_t kCelWide32(EngineState *s, int argc, reg_t *argv) {
GuiResourceId resourceId = argv[0].toUint16();
int16 loopNo = argv[1].toSint16();
int16 celNo = argv[2].toSint16();
CelObjView celObj(resourceId, loopNo, celNo);
const GuiResourceId resourceId = argv[0].toUint16();
const int16 loopNo = argv[1].toSint16();
const int16 celNo = argv[2].toSint16();
const CelObjView celObj(resourceId, loopNo, celNo);
int16 width = celObj._width;
if (getSciVersion() < SCI_VERSION_2_1_LATE) {
width = mulru(width, Ratio(g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth, celObj._xResolution));
width = mulru(width, Ratio(g_sci->_gfxFrameout->getScriptWidth(), celObj._xResolution));
}
return make_reg(0, width);
}
Expand Down
4 changes: 2 additions & 2 deletions engines/sci/engine/kvideo.cpp
Expand Up @@ -460,8 +460,8 @@ reg_t kPlayVMDShowCursor(EngineState *s, int argc, reg_t *argv) {
}

reg_t kPlayVMDSetBlackoutArea(EngineState *s, int argc, reg_t *argv) {
const int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
const int16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;
const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
const int16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();

Common::Rect blackoutArea;
blackoutArea.left = MAX<int16>(0, argv[0].toSint16());
Expand Down
2 changes: 1 addition & 1 deletion engines/sci/engine/savegame.cpp
Expand Up @@ -801,7 +801,7 @@ void SciBitmap::saveLoadWithSerializer(Common::Serializer &s) {
s.syncBytes(_data, _dataSize);

if (s.isLoading()) {
_buffer = Buffer(getWidth(), getHeight(), getPixels());
_buffer.init(getWidth(), getHeight(), getWidth(), getPixels(), Graphics::PixelFormat::createFormatCLUT8());
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions engines/sci/engine/segment.h
Expand Up @@ -977,7 +977,7 @@ class SciBitmap : public Common::Serializable {
_data = (byte *)malloc(other._dataSize);
memcpy(_data, other._data, other._dataSize);
if (_dataSize) {
_buffer = Buffer(getWidth(), getHeight(), getPixels());
_buffer.init(getWidth(), getHeight(), getWidth(), getPixels(), Graphics::PixelFormat::createFormatCLUT8());
}
_gc = other._gc;
}
Expand All @@ -998,7 +998,7 @@ class SciBitmap : public Common::Serializable {
_data = (byte *)malloc(other._dataSize);
memcpy(_data, other._data, _dataSize);
if (_dataSize) {
_buffer = Buffer(getWidth(), getHeight(), getPixels());
_buffer.init(getWidth(), getHeight(), getWidth(), getPixels(), Graphics::PixelFormat::createFormatCLUT8());
}
_gc = other._gc;

Expand Down Expand Up @@ -1032,7 +1032,7 @@ class SciBitmap : public Common::Serializable {
setXResolution(xResolution);
setYResolution(yResolution);

_buffer = Buffer(getWidth(), getHeight(), getPixels());
_buffer.init(getWidth(), getHeight(), getWidth(), getPixels(), Graphics::PixelFormat::createFormatCLUT8());
}

inline int getRawSize() const {
Expand Down
4 changes: 2 additions & 2 deletions engines/sci/event.cpp
Expand Up @@ -164,15 +164,15 @@ SciEvent EventManager::getScummVMEvent() {

#if ENABLE_SCI32
if (getSciVersion() >= SCI_VERSION_2) {
const Buffer &screen = g_sci->_gfxFrameout->getCurrentBuffer();
const GfxFrameout *gfxFrameout = g_sci->_gfxFrameout;

// This will clamp `mousePos` according to the restricted zone,
// so any cursor or screen item associated with the mouse position
// does not bounce when it hits the edge (or ignore the edge)
g_sci->_gfxCursor32->deviceMoved(mousePos);

Common::Point mousePosSci = mousePos;
mulru(mousePosSci, Ratio(screen.scriptWidth, screen.screenWidth), Ratio(screen.scriptHeight, screen.screenHeight));
mulru(mousePosSci, Ratio(gfxFrameout->getScriptWidth(), gfxFrameout->getScreenWidth()), Ratio(gfxFrameout->getScriptHeight(), gfxFrameout->getScreenHeight()));
noEvent.mousePosSci = input.mousePosSci = mousePosSci;

if (_hotRectanglesActive) {
Expand Down
8 changes: 4 additions & 4 deletions engines/sci/graphics/celobj32.cpp
Expand Up @@ -658,9 +658,9 @@ struct RENDERER {
_skipColor(skipColor) {}

inline void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const {
byte *targetPixel = (byte *)target.getPixels() + target.screenWidth * targetRect.top + targetRect.left;
byte *targetPixel = (byte *)target.getPixels() + target.w * targetRect.top + targetRect.left;

const int16 skipStride = target.screenWidth - targetRect.width();
const int16 skipStride = target.w - targetRect.width();
const int16 targetWidth = targetRect.width();
const int16 targetHeight = targetRect.height();
for (int16 y = 0; y < targetHeight; ++y) {
Expand Down Expand Up @@ -1265,8 +1265,8 @@ CelObjColor::CelObjColor(const uint8 color, const int16 width, const int16 heigh
_info.color = color;
_origin.x = 0;
_origin.y = 0;
_xResolution = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
_yResolution = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;
_xResolution = g_sci->_gfxFrameout->getScriptWidth();
_yResolution = g_sci->_gfxFrameout->getScriptHeight();
_hunkPaletteOffset = 0;
_mirrorX = false;
_remap = false;
Expand Down
4 changes: 2 additions & 2 deletions engines/sci/graphics/controls32.cpp
Expand Up @@ -391,8 +391,8 @@ ScrollWindow::ScrollWindow(SegManager *segMan, const Common::Rect &gameRect, con
_gfxText32.setFont(_fontId);
_pointSize = _gfxText32._font->getHeight();

const uint16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
const uint16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;
const uint16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
const uint16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();

Common::Rect bitmapRect(gameRect);
mulinc(bitmapRect, Ratio(_gfxText32._xResolution, scriptWidth), Ratio(_gfxText32._yResolution, scriptHeight));
Expand Down
23 changes: 12 additions & 11 deletions engines/sci/graphics/cursor32.cpp
Expand Up @@ -39,7 +39,7 @@ GfxCursor32::GfxCursor32() :

void GfxCursor32::init(const Buffer &outputBuffer) {
_screen = outputBuffer;
_screenRegion.rect = Common::Rect(_screen.screenWidth, _screen.screenHeight);
_screenRegion.rect = Common::Rect(_screen.w, _screen.h);
_screenRegion.data = static_cast<byte *>(_screen.getPixels());
_restrictedArea = _screenRegion.rect;
}
Expand Down Expand Up @@ -151,10 +151,10 @@ void GfxCursor32::show() {
void GfxCursor32::setRestrictedArea(const Common::Rect &rect) {
_restrictedArea = rect;

const int16 screenWidth = g_sci->_gfxFrameout->getCurrentBuffer().screenWidth;
const int16 screenHeight = g_sci->_gfxFrameout->getCurrentBuffer().screenHeight;
const int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
const int16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;
const int16 screenWidth = g_sci->_gfxFrameout->getScreenWidth();
const int16 screenHeight = g_sci->_gfxFrameout->getScreenHeight();
const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
const int16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();

mulru(_restrictedArea, Ratio(screenWidth, scriptWidth), Ratio(screenHeight, scriptHeight), 0);

Expand Down Expand Up @@ -259,7 +259,7 @@ void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const
// threshold size because inventory items usually have a
// high-resolution cursor representation.
bool pixelDouble = false;
if (g_sci->_gfxFrameout->_isHiRes &&
if (g_sci->_gfxFrameout->isHiRes() &&
(g_sci->getGameId() == GID_GK1 ||
(g_sci->getGameId() == GID_PQ4 && _width <= 22 && _height <= 22))) {

Expand All @@ -275,7 +275,8 @@ void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const
memset(_cursor.data, 255, _width * _height);
_cursor.skipColor = 255;

Buffer target(_width, _height, _cursor.data);
Buffer target;
target.init(_width, _height, _width, _cursor.data, Graphics::PixelFormat::createFormatCLUT8());
if (pixelDouble) {
view.draw(target, _cursor.rect, Common::Point(0, 0), false, 2, 2);
} else {
Expand Down Expand Up @@ -314,10 +315,10 @@ void GfxCursor32::copyFromScreen(DrawRegion &target) {
}

void GfxCursor32::setPosition(const Common::Point &position) {
const int16 scriptWidth = g_sci->_gfxFrameout->getCurrentBuffer().scriptWidth;
const int16 scriptHeight = g_sci->_gfxFrameout->getCurrentBuffer().scriptHeight;
const int16 screenWidth = g_sci->_gfxFrameout->getCurrentBuffer().screenWidth;
const int16 screenHeight = g_sci->_gfxFrameout->getCurrentBuffer().screenHeight;
const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
const int16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();
const int16 screenWidth = g_sci->_gfxFrameout->getScreenWidth();
const int16 screenHeight = g_sci->_gfxFrameout->getScreenHeight();

Common::Point newPosition;
newPosition.x = (position.x * Ratio(screenWidth, scriptWidth)).toInt();
Expand Down

0 comments on commit c7c5f28

Please sign in to comment.