From 301bd3e1154d22411cd7c61ce5542335f356fbfd Mon Sep 17 00:00:00 2001 From: Andrei Prykhodko Date: Sun, 4 Oct 2020 01:21:50 +0300 Subject: [PATCH] PETKA: optimize drawing --- engines/petka/flc.cpp | 31 ----------------- engines/petka/flc.h | 3 -- engines/petka/objects/object.cpp | 48 ++++++++++++++++----------- engines/petka/objects/object_bg.cpp | 8 ++--- engines/petka/objects/object_case.cpp | 6 ++-- engines/petka/video.cpp | 5 ++- engines/petka/video.h | 2 +- 7 files changed, 38 insertions(+), 65 deletions(-) diff --git a/engines/petka/flc.cpp b/engines/petka/flc.cpp index 657cb906c98..02b457e0a21 100644 --- a/engines/petka/flc.cpp +++ b/engines/petka/flc.cpp @@ -74,14 +74,6 @@ const Common::Rect &FlicDecoder::getBounds() const { return *(new Common::Rect(0, 0)); } -Common::Point FlicDecoder::getPos() const { - const Track *track = getTrack(0); - if (track) - return ((const FlicVideoTrack *)track)->getPos(); - - return Common::Point(0, 0); -} - const Common::Array &FlicDecoder::getMskRects() const { const Track *track = getTrack(0); if (track) @@ -166,25 +158,6 @@ bool FlicDecoder::FlicVideoTrack::loadMsk(Common::SeekableReadStream &stream) { _bounds.right++; _bounds.bottom++; - _pos.x = 0; - _pos.y = 0; - - if (_frameCount == 1 && _surface->w > 630 && _surface->h > 470 && (_bounds.width() < 620 || _bounds.height() < 460)) { - Graphics::Surface *s = new Graphics::Surface(); - s->create(_bounds.width(), _bounds.height(), g_system->getScreenFormat()); - - _surface->convertToInPlace(s->format, _palette); - s->copyRectToSurface(*_surface, 0, 0, _bounds); - - _surface->free(); - delete _surface; - - _pos.x = _bounds.left; - _pos.y = _bounds.top; - - _surface = s; - } - return true; } @@ -205,8 +178,4 @@ uint FlicDecoder::FlicVideoTrack::getDelay() const { return _frameDelay; } -Common::Point FlicDecoder::FlicVideoTrack::getPos() const { - return _pos; -} - } // End of namespace Petka diff --git a/engines/petka/flc.h b/engines/petka/flc.h index feffe542a68..17b88c6492b 100644 --- a/engines/petka/flc.h +++ b/engines/petka/flc.h @@ -35,7 +35,6 @@ public: uint getDelay() const; const Common::Rect &getBounds() const; - Common::Point getPos() const; const Common::Array &getMskRects() const; const Graphics::Surface *getCurrentFrame() const; uint32 getTransColor(const Graphics::PixelFormat &fmt) const; @@ -49,13 +48,11 @@ protected: uint getDelay() const; const Common::Rect &getBounds() const; - Common::Point getPos() const; const Common::Array &getMskRects() const; const Graphics::Surface *getSurface() const; private: Common::Rect _bounds; - Common::Point _pos; Common::Array > _msk; }; }; diff --git a/engines/petka/objects/object.cpp b/engines/petka/objects/object.cpp index 561b48f48d8..aa355e7f145 100644 --- a/engines/petka/objects/object.cpp +++ b/engines/petka/objects/object.cpp @@ -428,13 +428,13 @@ bool QObject::isInPoint(Common::Point p) { return false; const Graphics::Surface *s = flc->getCurrentFrame(); if (s->format.bytesPerPixel == 1) { - byte index = *(const byte *) flc->getCurrentFrame()->getBasePtr(p.x - _x - flc->getPos().x, - p.y - _y - flc->getPos().y); + byte index = *(const byte *) flc->getCurrentFrame()->getBasePtr(p.x - _x, + p.y - _y); const byte *pal = flc->getPalette(); return (pal[0] != pal[index * 3] || pal[1] != pal[index * 3 + 1] || pal[2] != pal[index * 3 + 2]); } if (s->format.bytesPerPixel == 2) - return *(const uint16*)flc->getCurrentFrame()->getBasePtr(p.x - _x - flc->getPos().x, p.y - _y - flc->getPos().y) != flc->getTransColor(s->format); + return *(const uint16*)flc->getCurrentFrame()->getBasePtr(p.x - _x, p.y - _y) != flc->getTransColor(s->format); } return false; } @@ -457,31 +457,39 @@ void QObject::draw() { _startSound = false; } - QSystem *sys = g_vm->getQSystem(); - Common::Rect screen(640 + sys->_xOffset, 480); - Common::Rect dest(flc->getBounds()); - dest.translate(_x, _y); + int xOff = g_vm->getQSystem()->_xOffset; + VideoSystem *videoSys = g_vm->videoSystem(); - Common::Rect intersect(screen.findIntersectingRect(dest)); + Common::Rect screen(640 + xOff, 480); + Common::Rect flcBounds(flc->getBounds()); + Common::Rect objBounds(flcBounds); + + objBounds.translate(_x, _y); + + Common::Rect intersect(screen.findIntersectingRect(objBounds)); if (intersect.isEmpty()) return; - const Graphics::Surface *frame = flc->getCurrentFrame(); - Graphics::Surface *s = frame->convertTo(g_system->getScreenFormat(), flc->getPalette()); - const Common::List &dirtyRects = g_vm->videoSystem()->rects(); - for (Common::List::const_iterator it = dirtyRects.begin(); it != dirtyRects.end(); ++it) { - Common::Rect dirty = *it; - dirty.translate(sys->_xOffset, 0); + Graphics::Surface *surface = flc->getCurrentFrame()->getSubArea(flcBounds).convertTo(g_system->getScreenFormat(), flc->getPalette()); + + for (Common::Rect dirty : videoSys->rects()) { + dirty.translate(xOff, 0); + Common::Rect destRect(intersect.findIntersectingRect(dirty)); if (destRect.isEmpty()) continue; + Common::Rect srcRect(destRect); - srcRect.translate(-_x - flc->getPos().x, -_y - flc->getPos().y); - destRect.translate(-sys->_xOffset, 0); - g_vm->videoSystem()->transBlitFrom(*s, srcRect, destRect, flc->getTransColor(s->format)); + + srcRect.translate(-_x, -_y); + srcRect.translate(-flcBounds.left, -flcBounds.top); + + destRect.translate(-xOff, 0); + videoSys->transBlitFrom(*surface, srcRect, destRect, flc->getTransColor(surface->format)); } - s->free(); - delete s; + + surface->free(); + delete surface; } void QObject::updateZ() { @@ -490,7 +498,7 @@ void QObject::updateZ() { FlicDecoder *flc = g_vm->resMgr()->loadFlic(_resourceId); if (flc) { _z = 1; - const Common::Array rects = flc->getMskRects(); + const Common::Array &rects = flc->getMskRects(); for (uint i = 0; i < rects.size(); ++i) { if (_y + rects[i].bottom > _z) _z = _y + rects[i].bottom; diff --git a/engines/petka/objects/object_bg.cpp b/engines/petka/objects/object_bg.cpp index c9b55456be7..19ceff333a3 100644 --- a/engines/petka/objects/object_bg.cpp +++ b/engines/petka/objects/object_bg.cpp @@ -89,10 +89,10 @@ void QObjectBG::draw() { Graphics::Surface *s = g_vm->resMgr()->loadBitmap(_resourceId); if (!s) return; - for (auto r : g_vm->videoSystem()->rects()) { - Common::Rect srcRect = r; - srcRect.translate(g_vm->getQSystem()->_xOffset, 0); - g_vm->videoSystem()->blitFrom(*s, srcRect, Common::Point(r.left, r.top)); + int xOffset = g_vm->getQSystem()->_xOffset; + for (auto rect : g_vm->videoSystem()->rects()) { + rect.translate(xOffset, 0); + g_vm->videoSystem()->blitFrom(*s, rect, Common::Point(rect.left - xOffset, rect.top)); } } diff --git a/engines/petka/objects/object_case.cpp b/engines/petka/objects/object_case.cpp index b15d3aae66f..51e45bf01d5 100644 --- a/engines/petka/objects/object_case.cpp +++ b/engines/petka/objects/object_case.cpp @@ -111,7 +111,7 @@ void QObjectCase::draw() { for (uint i = 0; i < mskRects.size(); ++i) { Common::Rect destRect = mskRects[i].findIntersectingRect(*it); Common::Rect srcRect = destRect; - srcRect.translate(-flc->getPos().x - _x + sys->_xOffset, -flc->getPos().y - _y); + srcRect.translate(-_x + sys->_xOffset, -_y); g_vm->videoSystem()->transBlitFrom(*s, srcRect, destRect, flc->getTransColor(s->format)); } } @@ -146,7 +146,7 @@ bool QObjectCase::isInPoint(Common::Point p) { void QObjectCase::onMouseMove(Common::Point p) { p.x -= _x; FlicDecoder *flc = g_vm->resMgr()->loadFlic(kExitCaseResourceId); - if (*(const byte *)flc->getCurrentFrame()->getBasePtr(p.x - flc->getPos().x, p.y - flc->getPos().y) != 0) { + if (*(const byte *)flc->getCurrentFrame()->getBasePtr(p.x, p.y) != 0) { if (_clickedObjIndex != kCloseButton && _clickedObjIndex != kInvalidButton) { flc = g_vm->resMgr()->loadFlic(kFirstButtonResourceId + _clickedObjIndex); flc->setFrame(1); @@ -290,4 +290,4 @@ void QObjectCase::reshow() { } } -} +} // End of namespace Petka diff --git a/engines/petka/video.cpp b/engines/petka/video.cpp index 14669bb55c2..8ade8f7cb28 100644 --- a/engines/petka/video.cpp +++ b/engines/petka/video.cpp @@ -62,8 +62,8 @@ void VideoSystem::update() { xOff = MAX(xOff, reqOffset); } sys->_xOffset = CLIP(xOff, 0, sys->_sceneWidth - 640); + makeAllDirty(); } - makeAllDirty(); } @@ -76,7 +76,6 @@ void VideoSystem::update() { } sort(); - mergeDirtyRects(); _allowAddingRects = false; @@ -135,7 +134,7 @@ void VideoSystem::addDirtyMskRects(FlicDecoder &flc) { addDirtyMskRects(Common::Point(0, 0), flc); } -const Common::List VideoSystem::rects() const { +const Common::List &VideoSystem::rects() const { return _dirtyRects; } diff --git a/engines/petka/video.h b/engines/petka/video.h index 5e3b2afc8a5..b12f7aa6a2c 100644 --- a/engines/petka/video.h +++ b/engines/petka/video.h @@ -47,7 +47,7 @@ public: void setShake(bool shake); - const Common::List rects() const; + const Common::List &rects() const; private: void sort();