PETKA: optimize drawing

This commit is contained in:
Andrei Prykhodko 2020-10-04 01:21:50 +03:00
parent 9590eed4b4
commit 301bd3e115
7 changed files with 38 additions and 65 deletions

View File

@ -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<Common::Rect> &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

View File

@ -35,7 +35,6 @@ public:
uint getDelay() const;
const Common::Rect &getBounds() const;
Common::Point getPos() const;
const Common::Array<Common::Rect> &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<Common::Rect> &getMskRects() const;
const Graphics::Surface *getSurface() const;
private:
Common::Rect _bounds;
Common::Point _pos;
Common::Array<Common::Array<Common::Rect> > _msk;
};
};

View File

@ -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<Common::Rect> &dirtyRects = g_vm->videoSystem()->rects();
for (Common::List<Common::Rect>::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<Common::Rect> rects = flc->getMskRects();
const Common::Array<Common::Rect> &rects = flc->getMskRects();
for (uint i = 0; i < rects.size(); ++i) {
if (_y + rects[i].bottom > _z)
_z = _y + rects[i].bottom;

View File

@ -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));
}
}

View File

@ -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

View File

@ -62,8 +62,8 @@ void VideoSystem::update() {
xOff = MAX<int>(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<Common::Rect> VideoSystem::rects() const {
const Common::List<Common::Rect> &VideoSystem::rects() const {
return _dirtyRects;
}

View File

@ -47,7 +47,7 @@ public:
void setShake(bool shake);
const Common::List<Common::Rect> rects() const;
const Common::List<Common::Rect> &rects() const;
private:
void sort();