diff options
author | Einar Johan Trøan Sømåen | 2012-07-29 03:41:45 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-07-29 03:41:45 +0200 |
commit | 3a218180017e97e4b9dceca3bf25a232f271c6b9 (patch) | |
tree | 254a7cf172388ddc6506ebb990649a9a67b24a8f | |
parent | 482a5fb467e6694fb54c75f718563992657edf97 (diff) | |
download | scummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.tar.gz scummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.tar.bz2 scummvm-rg350-3a218180017e97e4b9dceca3bf25a232f271c6b9.zip |
WINTERMUTE: Make BaseSubFrame load lazily.
-rw-r--r-- | engines/wintermute/base/base_frame.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/base_sprite.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/base_sub_frame.cpp | 43 | ||||
-rw-r--r-- | engines/wintermute/base/base_sub_frame.h | 8 | ||||
-rw-r--r-- | engines/wintermute/base/gfx/base_renderer.cpp | 8 |
5 files changed, 45 insertions, 18 deletions
diff --git a/engines/wintermute/base/base_frame.cpp b/engines/wintermute/base/base_frame.cpp index 87213b1421..5473419f22 100644 --- a/engines/wintermute/base/base_frame.cpp +++ b/engines/wintermute/base/base_frame.cpp @@ -321,7 +321,7 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { if (BasePlatform::isRectEmpty(&rect)) {
sub->setDefaultRect();
} else {
- sub->_rect = rect;
+ sub->setRect(rect);
}
sub->_hotspotX = hotspotX;
diff --git a/engines/wintermute/base/base_sprite.cpp b/engines/wintermute/base/base_sprite.cpp index bc2167c618..bc42f81dd4 100644 --- a/engines/wintermute/base/base_sprite.cpp +++ b/engines/wintermute/base/base_sprite.cpp @@ -151,7 +151,7 @@ bool BaseSprite::loadFile(const Common::String &filename, int lifeTime, TSpriteC delete frame;
delete subframe;
} else {
- BasePlatform::setRect(&subframe->_rect, 0, 0, subframe->_surface->getWidth(), subframe->_surface->getHeight());
+ subframe->setDefaultRect();
frame->_subframes.add(subframe);
_frames.add(frame);
_currentFrame = 0;
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));
diff --git a/engines/wintermute/base/base_sub_frame.h b/engines/wintermute/base/base_sub_frame.h index 023e306706..d8027d3ce9 100644 --- a/engines/wintermute/base/base_sub_frame.h +++ b/engines/wintermute/base/base_sub_frame.h @@ -58,8 +58,14 @@ public: int _hotspotX;
int _hotspotY;
uint32 _alpha;
+ // These two setters and getters are rather usefull, as they allow _rect to be lazily defined
+ // Thus we don't need to load the actual graphics before the rect is actually needed.
+ Rect32 getRect();
+ void setRect(Rect32 rect);
+private:
+ bool _wantsDefaultRect;
Rect32 _rect;
-
+public:
bool _cKDefault;
byte _cKRed;
byte _cKGreen;
diff --git a/engines/wintermute/base/gfx/base_renderer.cpp b/engines/wintermute/base/gfx/base_renderer.cpp index ab5111332e..cc6167a749 100644 --- a/engines/wintermute/base/gfx/base_renderer.cpp +++ b/engines/wintermute/base/gfx/base_renderer.cpp @@ -76,16 +76,16 @@ BaseObject *BaseRenderer::getObjectAt(int x, int y) { if (_rectList[i]->_precise) {
// frame
if (_rectList[i]->_frame) {
- int xx = (int)((_rectList[i]->_frame->_rect.left + x - _rectList[i]->_rect.left + _rectList[i]->_offsetX) / (float)((float)_rectList[i]->_zoomX / (float)100));
- int yy = (int)((_rectList[i]->_frame->_rect.top + y - _rectList[i]->_rect.top + _rectList[i]->_offsetY) / (float)((float)_rectList[i]->_zoomY / (float)100));
+ int xx = (int)((_rectList[i]->_frame->getRect().left + x - _rectList[i]->_rect.left + _rectList[i]->_offsetX) / (float)((float)_rectList[i]->_zoomX / (float)100));
+ int yy = (int)((_rectList[i]->_frame->getRect().top + y - _rectList[i]->_rect.top + _rectList[i]->_offsetY) / (float)((float)_rectList[i]->_zoomY / (float)100));
if (_rectList[i]->_frame->_mirrorX) {
- int width = _rectList[i]->_frame->_rect.right - _rectList[i]->_frame->_rect.left;
+ int width = _rectList[i]->_frame->getRect().right - _rectList[i]->_frame->getRect().left;
xx = width - xx;
}
if (_rectList[i]->_frame->_mirrorY) {
- int height = _rectList[i]->_frame->_rect.bottom - _rectList[i]->_frame->_rect.top;
+ int height = _rectList[i]->_frame->getRect().bottom - _rectList[i]->_frame->getRect().top;
yy = height - yy;
}
|