ZVISION: Remove duplicate blitting code for images and animations

This commit is contained in:
Filippos Karapetis 2014-12-26 22:30:32 +02:00
parent 2becc76d5c
commit db37cfb1b0
5 changed files with 37 additions and 72 deletions

View File

@ -104,7 +104,8 @@ void RenderManager::renderSceneToScreen() {
post = (*it)->draw(_currentBackgroundImage.getSubArea(rect));
else
post = (*it)->draw(_effectSurface.getSubArea(rect));
blitSurfaceToSurface(*post, _effectSurface, screenSpaceLocation.left, screenSpaceLocation.top);
Common::Rect empty;
blitSurfaceToSurface(*post, empty, _effectSurface, screenSpaceLocation.left, screenSpaceLocation.top);
screenSpaceLocation.clip(windowRect);
if (_backgroundSurfaceDirtyRect .isEmpty()) {
_backgroundSurfaceDirtyRect = screenSpaceLocation;
@ -511,19 +512,12 @@ void RenderManager::blitSurfaceToSurface(const Graphics::Surface &src, const Com
delete srcAdapted;
}
void RenderManager::blitSurfaceToSurface(const Graphics::Surface &src, Graphics::Surface &dst, int x, int y) {
void RenderManager::blitSurfaceToBkg(const Graphics::Surface &src, int x, int y, int32 colorkey) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, dst, x, y);
}
void RenderManager::blitSurfaceToSurface(const Graphics::Surface &src, Graphics::Surface &dst, int x, int y, uint32 colorkey) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, dst, x, y, colorkey);
}
void RenderManager::blitSurfaceToBkg(const Graphics::Surface &src, int x, int y) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, _currentBackgroundImage, x, y);
if (colorkey >= 0)
blitSurfaceToSurface(src, empt, _currentBackgroundImage, x, y, colorkey);
else
blitSurfaceToSurface(src, empt, _currentBackgroundImage, x, y);
Common::Rect dirty(src.w, src.h);
dirty.translate(x, y);
if (_backgroundDirtyRect.isEmpty())
@ -532,34 +526,10 @@ void RenderManager::blitSurfaceToBkg(const Graphics::Surface &src, int x, int y)
_backgroundDirtyRect.extend(dirty);
}
void RenderManager::blitSurfaceToBkg(const Graphics::Surface &src, int x, int y, uint32 colorkey) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, _currentBackgroundImage, x, y, colorkey);
Common::Rect dirty(src.w, src.h);
dirty.translate(x, y);
if (_backgroundDirtyRect.isEmpty())
_backgroundDirtyRect = dirty;
else
_backgroundDirtyRect.extend(dirty);
}
void RenderManager::blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect) {
if (src.w == _dstRect.width() && src.h == _dstRect.height())
blitSurfaceToBkg(src, _dstRect.left, _dstRect.top);
else {
Graphics::Surface *tmp = new Graphics::Surface;
tmp->create(_dstRect.width(), _dstRect.height(), src.format);
scaleBuffer(src.getPixels(), tmp->getPixels(), src.w, src.h, src.format.bytesPerPixel, _dstRect.width(), _dstRect.height());
blitSurfaceToBkg(*tmp, _dstRect.left, _dstRect.top);
tmp->free();
delete tmp;
}
}
void RenderManager::blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect, uint32 colorkey) {
if (src.w == _dstRect.width() && src.h == _dstRect.height())
void RenderManager::blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect, int32 colorkey) {
if (src.w == _dstRect.width() && src.h == _dstRect.height()) {
blitSurfaceToBkg(src, _dstRect.left, _dstRect.top, colorkey);
else {
} else {
Graphics::Surface *tmp = new Graphics::Surface;
tmp->create(_dstRect.width(), _dstRect.height(), src.format);
scaleBuffer(src.getPixels(), tmp->getPixels(), src.w, src.h, src.format.bytesPerPixel, _dstRect.width(), _dstRect.height());
@ -569,20 +539,12 @@ void RenderManager::blitSurfaceToBkgScaled(const Graphics::Surface &src, const C
}
}
void RenderManager::blitSurfaceToMenu(const Graphics::Surface &src, int x, int y) {
void RenderManager::blitSurfaceToMenu(const Graphics::Surface &src, int x, int y, int32 colorkey) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, _menuSurface, x, y);
Common::Rect dirty(src.w, src.h);
dirty.translate(x, y);
if (_menuSurfaceDirtyRect.isEmpty())
_menuSurfaceDirtyRect = dirty;
if (colorkey >= 0)
blitSurfaceToSurface(src, empt, _menuSurface, x, y, colorkey);
else
_menuSurfaceDirtyRect.extend(dirty);
}
void RenderManager::blitSurfaceToMenu(const Graphics::Surface &src, int x, int y, uint32 colorkey) {
Common::Rect empt;
blitSurfaceToSurface(src, empt, _menuSurface, x, y, colorkey);
blitSurfaceToSurface(src, empt, _menuSurface, x, y);
Common::Rect dirty(src.w, src.h);
dirty.translate(x, y);
if (_menuSurfaceDirtyRect.isEmpty())
@ -803,7 +765,8 @@ void RenderManager::processSubs(uint16 deltatime) {
Graphics::Surface *rndr = new Graphics::Surface();
rndr->create(sub->r.width(), sub->r.height(), _engine->_resourcePixelFormat);
_engine->getTextRenderer()->drawTxtInOneLine(sub->txt, *rndr);
blitSurfaceToSurface(*rndr, _subtitleSurface, sub->r.left - _subtitleArea.left + _workingWindow.left, sub->r.top - _subtitleArea.top + _workingWindow.top);
Common::Rect empty;
blitSurfaceToSurface(*rndr, empty, _subtitleSurface, sub->r.left - _subtitleArea.left + _workingWindow.left, sub->r.top - _subtitleArea.top + _workingWindow.top);
rndr->free();
delete rndr;
}

View File

@ -230,20 +230,15 @@ public:
// Blitting surface-to-surface methods
void blitSurfaceToSurface(const Graphics::Surface &src, const Common::Rect &_srcRect , Graphics::Surface &dst, int x, int y);
void blitSurfaceToSurface(const Graphics::Surface &src, const Common::Rect &_srcRect , Graphics::Surface &dst, int _x, int _y, uint32 colorkey);
void blitSurfaceToSurface(const Graphics::Surface &src, Graphics::Surface &dst, int x, int y);
void blitSurfaceToSurface(const Graphics::Surface &src, Graphics::Surface &dst, int x, int y, uint32 colorkey);
// Blitting surface-to-background methods
void blitSurfaceToBkg(const Graphics::Surface &src, int x, int y);
void blitSurfaceToBkg(const Graphics::Surface &src, int x, int y, uint32 colorkey);
void blitSurfaceToBkg(const Graphics::Surface &src, int x, int y, int32 colorkey = -1);
// Blitting surface-to-background methods with scale
void blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect);
void blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect, uint32 colorkey);
void blitSurfaceToBkgScaled(const Graphics::Surface &src, const Common::Rect &_dstRect, int32 colorkey = -1);
// Blitting surface-to-menu methods
void blitSurfaceToMenu(const Graphics::Surface &src, int x, int y);
void blitSurfaceToMenu(const Graphics::Surface &src, int x, int y, uint32 colorkey);
void blitSurfaceToMenu(const Graphics::Surface &src, int x, int y, int32 colorkey = -1);
// Subtitles methods

View File

@ -566,6 +566,12 @@ ActionPreloadAnimation::ActionPreloadAnimation(ZVision *engine, int32 slotkey, c
// The two %*u are usually 0 and dont seem to have a use
sscanf(line.c_str(), "%24s %*u %*u %d %d", fileName, &_mask, &_framerate);
// Mask 0 means "no transparency" in this case. Since we use a common blitting
// code for images and animations, we set it to -1 to avoid confusion with
// color 0, which is used as a mask in some images
if (_mask == 0)
_mask = -1;
_fileName = Common::String(fileName);
}
@ -628,6 +634,12 @@ ActionPlayAnimation::ActionPlayAnimation(ZVision *engine, int32 slotkey, const C
"%24s %u %u %u %u %u %u %d %*u %*u %d %d",
fileName, &_x, &_y, &_x2, &_y2, &_start, &_end, &_loopCount, &_mask, &_framerate);
// Mask 0 means "no transparency" in this case. Since we use a common blitting
// code for images and animations, we set it to -1 to avoid confusion with
// color 0, which is used as a mask in some images
if (_mask == 0)
_mask = -1;
_fileName = Common::String(fileName);
}

View File

@ -154,17 +154,11 @@ bool AnimationNode::process(uint32 deltaTimeInMillis) {
if (_engine->getRenderManager()->getRenderTable()->getRenderState() == RenderTable::PANORAMA) {
Graphics::Surface *transposed = RenderManager::tranposeSurface(frame);
if (_mask > 0)
_engine->getRenderManager()->blitSurfaceToBkg(*transposed, nod->pos.left, nod->pos.top, _mask);
else
_engine->getRenderManager()->blitSurfaceToBkg(*transposed, nod->pos.left, nod->pos.top);
_engine->getRenderManager()->blitSurfaceToBkg(*transposed, nod->pos.left, nod->pos.top, _mask);
transposed->free();
delete transposed;
} else {
if (_mask > 0)
_engine->getRenderManager()->blitSurfaceToBkg(*frame, nod->pos.left, nod->pos.top, _mask);
else
_engine->getRenderManager()->blitSurfaceToBkg(*frame, nod->pos.left, nod->pos.top);
_engine->getRenderManager()->blitSurfaceToBkg(*frame, nod->pos.left, nod->pos.top, _mask);
}
}
}

View File

@ -462,15 +462,16 @@ void TextRenderer::drawTxtInOneLine(const Common::String &text, Graphics::Surfac
j++;
}
dx = 0;
Common::Rect empty;
for (int32 jj = 0; jj < j; jj++) {
if (TxtJustify[i] == TXT_JUSTIFY_LEFT)
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], dst, dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], empty, dst, dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
else if (TxtJustify[i] == TXT_JUSTIFY_CENTER)
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], dst, ((dst.w - width) / 2) + dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], empty, dst, ((dst.w - width) / 2) + dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
else if (TxtJustify[i] == TXT_JUSTIFY_RIGHT)
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], dst, dst.w - width + dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
_engine->getRenderManager()->blitSurfaceToSurface(*TxtSurfaces[i][jj], empty, dst, dst.w - width + dx, dy + TxtPoint[i] - TxtSurfaces[i][jj]->h, 0);
dx += TxtSurfaces[i][jj]->w;
}