Ticket #8935: bs1-subtitles.diff

File bs1-subtitles.diff, 3.7 KB (added by eriktorbjorn, 15 years ago)

Patch against current SVN

  • engines/sword1/animation.h

     
    9292        Audio::Mixer *_snd;
    9393        OSystem *_system;
    9494        Common::Array<MovieText *> _movieTexts;
    95         byte *_textSpriteBuf;
    9695        int _textX, _textY, _textWidth, _textHeight;
    9796        byte _black, _white;
    9897
  • engines/sword1/animation.cpp

     
    3636#include "common/str.h"
    3737#include "common/events.h"
    3838#include "common/system.h"
     39#include "graphics/surface.h"
    3940
    4041namespace Sword1 {
    4142
     
    7071        : _vm(vm), _screen(screen), _textMan(textMan), _snd(snd), _system(system) {
    7172        _bgSoundStream = NULL;
    7273        _ticks = 0;
    73         _textSpriteBuf = NULL;
    7474        _black = 1;
    7575        _white = 255;
    7676        _currentFrame = 0;
     
    275275                                _textHeight = frame->height;
    276276                                _textX = 320 - _textWidth / 2;
    277277                                _textY = 420 - _textHeight;
    278                                 _textSpriteBuf = (byte *)calloc(_textHeight, _textWidth);
    279278                        }
    280279                        if (_currentFrame == _movieTexts[0]->_endFrame) {
    281280                                _textMan->releaseText(2, false);
    282                                 free(_textSpriteBuf);
    283                                 _textSpriteBuf = NULL;
    284281                                delete _movieTexts.remove_at(0);
    285282                        }
    286283                }
     
    309306        if (terminated)
    310307                _snd->stopHandle(_bgSoundHandle);
    311308
    312         if (_textSpriteBuf) {
    313                 _textMan->releaseText(2, false);
    314                 free(_textSpriteBuf);
    315                 _textSpriteBuf = NULL;
    316         }
     309        _textMan->releaseText(2, false);
    317310
    318311        while (!_movieTexts.empty())
    319312                delete _movieTexts.remove_at(_movieTexts.size() - 1);
     
    444437}
    445438
    446439void MoviePlayerDXA::processFrame(void) {
     440}
     441
     442void MoviePlayerDXA::updateScreen(void) {
     443        _system->copyRectToScreen(_drawBuffer, _frameWidth, _frameX, _frameY, _frameWidth, _frameHeight);
     444
    447445        // TODO: Handle the advanced cutscene packs. Do they really exist?
    448446
    449447        // We cannot draw the text to _drawBuffer, since that's one of the
    450         // decoder's internal buffers. Instead, we copy part of _drawBuffer
    451         // to the text sprite.
     448        // decoder's internal buffers, and besides it may be much smaller than
     449        // the screen, so it's possible that the subtitles don't fit on it.
     450        // Instead, we get the frame buffer from the backend, after copying the
     451        // frame to it, and draw on that.
    452452
    453         if (_textSpriteBuf) {
    454                 memset(_textSpriteBuf, 0, _textWidth * _textHeight);
    455 
    456                 // FIXME: This is inefficient
    457                 int x, y;
    458 
    459                 for (y = _textY; y < _textY + _textHeight; y++) {
    460                         for (x = _textX; x < _textX + _textWidth; x++) {
    461                                 if (x >= _frameX && x <= _frameX + _frameWidth && y >= _frameY && y <= _frameY + _frameHeight) {
    462                                         _textSpriteBuf[(y - _textY) * _textWidth + x - _textX] = _drawBuffer[(y - _frameY) * _frameWidth + x - _frameX];
    463                                 }
    464                         }
    465                 }
    466 
     453        if (_textMan->giveSpriteData(2)) {
     454                Graphics::Surface *frameBuffer = _system->lockScreen();
    467455                byte *src = (byte *)_textMan->giveSpriteData(2) + sizeof(FrameHeader);
    468                 byte *dst = _textSpriteBuf;
     456                byte *dst = (byte *)frameBuffer->getBasePtr(_textX, _textY);
    469457
    470                 for (y = 0; y < _textHeight; y++) {
    471                         for (x = 0; x < _textWidth; x++) {
     458                for (int y = 0; y < _textHeight; y++) {
     459                        for (int x = 0; x < _textWidth; x++) {
    472460                                switch (src[x]) {
    473461                                case BORDER_COL:
    474462                                        dst[x] = _black;
     
    479467                                }
    480468                        }
    481469                        src += _textWidth;
    482                         dst += _textWidth;
     470                        dst += frameBuffer->pitch;
    483471                }
    484         }
    485 }
    486472
    487 void MoviePlayerDXA::updateScreen(void) {
    488         _system->copyRectToScreen(_drawBuffer, _frameWidth, _frameX, _frameY, _frameWidth, _frameHeight);
    489         if (_textSpriteBuf) {
    490                 _system->copyRectToScreen(_textSpriteBuf, _textWidth, _textX, _textY, _textWidth, _textHeight);
     473                _system->unlockScreen();
    491474        }
     475
    492476        _system->updateScreen();
    493477}
    494478