aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_sub_frame.cpp
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-07-29 03:41:45 +0200
committerEinar Johan Trøan Sømåen2012-07-29 03:41:45 +0200
commit3a218180017e97e4b9dceca3bf25a232f271c6b9 (patch)
tree254a7cf172388ddc6506ebb990649a9a67b24a8f /engines/wintermute/base/base_sub_frame.cpp
parent482a5fb467e6694fb54c75f718563992657edf97 (diff)
downloadscummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.tar.gz
scummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.tar.bz2
scummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.zip
WINTERMUTE: Make BaseSubFrame load lazily.
Diffstat (limited to 'engines/wintermute/base/base_sub_frame.cpp')
-rw-r--r--engines/wintermute/base/base_sub_frame.cpp43
1 files changed, 32 insertions, 11 deletions
diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp
index 333e2f4f9c..006f15fa2c 100644
--- a/engines/wintermute/base/base_sub_frame.cpp
+++ b/engines/wintermute/base/base_sub_frame.cpp
@@ -48,6 +48,7 @@ BaseSubFrame::BaseSubFrame(BaseGame *inGame) : BaseScriptable(inGame, true) {
_alpha = 0xFFFFFFFF;
_transparent = 0xFFFF00FF;
+ _wantsDefaultRect = false;
BasePlatform::setRectEmpty(&_rect);
_editorSelected = false;
@@ -205,12 +206,25 @@ bool BaseSubFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) {
if (BasePlatform::isRectEmpty(&rect)) {
setDefaultRect();
} else {
- _rect = rect;
+ setRect(rect);
}
return STATUS_OK;
}
+Rect32 BaseSubFrame::getRect() {
+ if (_wantsDefaultRect && _surface) {
+ BasePlatform::setRect(&_rect, 0, 0, _surface->getWidth(), _surface->getHeight());
+ _wantsDefaultRect = false;
+ }
+ return _rect;
+}
+
+void BaseSubFrame::setRect(Rect32 rect) {
+ _wantsDefaultRect = false;
+ _rect = rect;
+}
+
//////////////////////////////////////////////////////////////////////
bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, bool precise, uint32 alpha, float rotate, TSpriteBlendMode blendMode) {
@@ -220,9 +234,9 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl
if (registerOwner != NULL && !_decoration) {
if (zoomX == 100 && zoomY == 100) {
- _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, x - _hotspotX + _rect.left, y - _hotspotY + _rect.top, _rect.right - _rect.left, _rect.bottom - _rect.top, zoomX, zoomY, precise));
+ _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, x - _hotspotX + getRect().left, y - _hotspotY + getRect().top, getRect().right - getRect().left, getRect().bottom - getRect().top, zoomX, zoomY, precise));
} else {
- _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, (int)(x - (_hotspotX + _rect.left) * (zoomX / 100)), (int)(y - (_hotspotY + _rect.top) * (zoomY / 100)), (int)((_rect.right - _rect.left) * (zoomX / 100)), (int)((_rect.bottom - _rect.top) * (zoomY / 100)), zoomX, zoomY, precise));
+ _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, (int)(x - (_hotspotX + getRect().left) * (zoomX / 100)), (int)(y - (_hotspotY + getRect().top) * (zoomY / 100)), (int)((getRect().right - getRect().left) * (zoomX / 100)), (int)((getRect().bottom - getRect().top) * (zoomY / 100)), zoomX, zoomY, precise));
}
}
if (_gameRef->_suspendedRendering) {
@@ -237,12 +251,12 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl
}
if (rotate != 0.0f) {
- res = _surface->displayTransform((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _hotspotX, _hotspotY, _rect, zoomX, zoomY, alpha, rotate, blendMode, _mirrorX, _mirrorY);
+ res = _surface->displayTransform((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _hotspotX, _hotspotY, getRect(), zoomX, zoomY, alpha, rotate, blendMode, _mirrorX, _mirrorY);
} else {
if (zoomX == 100 && zoomY == 100) {
- res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, _rect, alpha, blendMode, _mirrorX, _mirrorY);
+ res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, getRect(), alpha, blendMode, _mirrorX, _mirrorY);
} else {
- res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _rect, zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY);
+ res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), getRect(), zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY);
}
}
@@ -262,8 +276,8 @@ bool BaseSubFrame::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, flo
BasePlatform::setRect(rect,
(int)(x - _hotspotX * ratioX),
(int)(y - _hotspotY * ratioY),
- (int)(x - _hotspotX * ratioX + (_rect.right - _rect.left) * ratioX),
- (int)(y - _hotspotY * ratioY + (_rect.bottom - _rect.top) * ratioY));
+ (int)(x - _hotspotX * ratioX + (getRect().right - getRect().left) * ratioX),
+ (int)(y - _hotspotY * ratioY + (getRect().bottom - getRect().top) * ratioY));
return true;
}
@@ -287,8 +301,8 @@ bool BaseSubFrame::saveAsText(BaseDynamicBuffer *buffer, int indent, bool comple
if (_surface) {
BasePlatform::setRect(&rect, 0, 0, _surface->getWidth(), _surface->getHeight());
}
- if (!(rect == _rect)) {
- buffer->putTextIndent(indent + 2, "RECT { %d,%d,%d,%d }\n", _rect.left, _rect.top, _rect.right, _rect.bottom);
+ if (!(rect == getRect())) {
+ buffer->putTextIndent(indent + 2, "RECT { %d,%d,%d,%d }\n", getRect().left, getRect().top, getRect().right, getRect().bottom);
}
if (_hotspotX != 0 || _hotspotY != 0) {
@@ -338,8 +352,9 @@ bool BaseSubFrame::saveAsText(BaseDynamicBuffer *buffer, int indent, bool comple
//////////////////////////////////////////////////////////////////////////
void BaseSubFrame::setDefaultRect() {
if (_surface) {
- BasePlatform::setRect(&_rect, 0, 0, _surface->getWidth(), _surface->getHeight());
+ _wantsDefaultRect = true;
} else {
+ _wantsDefaultRect = false;
BasePlatform::setRectEmpty(&_rect);
}
}
@@ -350,6 +365,12 @@ bool BaseSubFrame::persist(BasePersistenceManager *persistMgr) {
BaseScriptable::persist(persistMgr);
+ if (persistMgr->getIsSaving()) {
+ getRect(); // To make sure it gets updated if it was never loaded.
+ } else {
+ _wantsDefaultRect = false;
+ }
+
persistMgr->transfer(TMEMBER(_2DOnly));
persistMgr->transfer(TMEMBER(_3DOnly));
persistMgr->transfer(TMEMBER(_alpha));