2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-02-11 12:54:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2006-02-11 12:54:56 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-02-11 12:54:56 +00:00
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2006-02-11 12:54:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lure/animseq.h"
|
|
|
|
#include "lure/decode.h"
|
|
|
|
#include "lure/events.h"
|
2008-01-01 12:58:04 +00:00
|
|
|
#include "lure/lure.h"
|
2007-11-18 05:10:56 +00:00
|
|
|
#include "lure/palette.h"
|
|
|
|
#include "lure/sound.h"
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
namespace Lure {
|
|
|
|
|
|
|
|
// delay
|
|
|
|
// Delays for a given number of milliseconds. If it returns true, it indicates that
|
|
|
|
// Escape has been pressed, and the introduction should be aborted.
|
|
|
|
|
|
|
|
AnimAbortType AnimationSequence::delay(uint32 milliseconds) {
|
|
|
|
Events &events = Events::getReference();
|
2007-11-18 05:10:56 +00:00
|
|
|
uint32 delayCtr = g_system->getMillis() + milliseconds;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-11-18 05:10:56 +00:00
|
|
|
while (g_system->getMillis() < delayCtr) {
|
2006-02-11 12:54:56 +00:00
|
|
|
while (events.pollEvent()) {
|
2007-12-16 08:10:47 +00:00
|
|
|
if ((events.type() == Common::EVENT_KEYDOWN) && (events.event().kbd.ascii != 0)) {
|
2008-09-01 20:18:17 +00:00
|
|
|
if (events.event().kbd.keycode == Common::KEYCODE_ESCAPE)
|
|
|
|
return ABORT_END_INTRO;
|
|
|
|
else
|
|
|
|
return ABORT_NEXT_SCENE;
|
|
|
|
} else if (events.type() == Common::EVENT_LBUTTONDOWN) {
|
2006-02-11 12:54:56 +00:00
|
|
|
return ABORT_NEXT_SCENE;
|
2008-09-01 20:18:17 +00:00
|
|
|
} else if ((events.type() == Common::EVENT_QUIT) || (events.type() == Common::EVENT_RTL)) {
|
2006-02-11 12:54:56 +00:00
|
|
|
return ABORT_END_INTRO;
|
2008-09-01 20:18:17 +00:00
|
|
|
} else if (events.type() == Common::EVENT_MAINMENU) {
|
|
|
|
return ABORT_NONE;
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 05:10:56 +00:00
|
|
|
uint32 delayAmount = delayCtr - g_system->getMillis();
|
2006-02-11 12:54:56 +00:00
|
|
|
if (delayAmount > 10) delayAmount = 10;
|
2007-11-18 05:10:56 +00:00
|
|
|
g_system->delayMillis(delayAmount);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
return ABORT_NONE;
|
|
|
|
}
|
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
// egaDecodeFrame
|
|
|
|
// Decodes a single frame of a EGA animation sequence
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
void AnimationSequence::egaDecodeFrame(byte *&pPixels) {
|
|
|
|
Screen &screen = Screen::getReference();
|
2008-01-27 19:47:41 +00:00
|
|
|
byte *screenData = screen.screen_raw();
|
2008-01-01 12:58:04 +00:00
|
|
|
|
|
|
|
// Skip over the list of blocks that are changed
|
|
|
|
int numBlocks = *pPixels++;
|
|
|
|
pPixels += numBlocks;
|
|
|
|
|
|
|
|
// Loop through the list of same/changed pixel ranges
|
|
|
|
int len = *pPixels++;
|
2008-01-27 19:47:41 +00:00
|
|
|
int offset = MENUBAR_Y_SIZE * FULL_SCREEN_WIDTH *
|
2008-01-01 12:58:04 +00:00
|
|
|
EGA_NUM_LAYERS / EGA_PIXELS_PER_BYTE;
|
|
|
|
while ((offset += len) < FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT / 2) {
|
|
|
|
|
|
|
|
int repeatLen = *pPixels++;
|
|
|
|
if (repeatLen > 0) {
|
|
|
|
byte *pDest = screenData + (offset / EGA_NUM_LAYERS) * EGA_PIXELS_PER_BYTE;
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
// Copy over the following bytes - each four bytes contain the four
|
2008-01-01 12:58:04 +00:00
|
|
|
// planes worth of data for 8 sequential pixels
|
|
|
|
while (repeatLen-- > 0) {
|
|
|
|
int planeNum = offset % EGA_NUM_LAYERS;
|
|
|
|
byte v = *pPixels++;
|
|
|
|
for (int bitCtr = 0; bitCtr < 8; ++bitCtr, v <<= 1) {
|
|
|
|
if ((v & 0x80) != 0)
|
|
|
|
*(pDest + bitCtr) |= 1 << planeNum;
|
|
|
|
else
|
|
|
|
*(pDest + bitCtr) &= ~(1 << planeNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((++offset % EGA_NUM_LAYERS) == 0)
|
|
|
|
pDest += EGA_PIXELS_PER_BYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get next skip bytes length
|
|
|
|
len = *pPixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vgaDecodeFrame
|
|
|
|
// Decodes a single frame of a VGA animation sequence
|
|
|
|
|
|
|
|
void AnimationSequence::vgaDecodeFrame(byte *&pPixels, byte *&pLines) {
|
2007-11-18 05:10:56 +00:00
|
|
|
Screen &screen = Screen::getReference();
|
2008-01-27 19:47:41 +00:00
|
|
|
byte *screenData = screen.screen_raw();
|
2006-02-11 12:54:56 +00:00
|
|
|
uint16 screenPos = 0;
|
|
|
|
uint16 len;
|
|
|
|
|
|
|
|
while (screenPos < SCREEN_SIZE) {
|
|
|
|
// Get line length
|
|
|
|
len = (uint16) *pLines++;
|
|
|
|
if (len == 0) {
|
2006-02-11 17:14:06 +00:00
|
|
|
len = READ_LE_UINT16(pLines);
|
2006-02-11 12:54:56 +00:00
|
|
|
pLines += 2;
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
// Move the splice over
|
2007-11-18 05:10:56 +00:00
|
|
|
memcpy(screenData, pPixels, len);
|
|
|
|
screenData += len;
|
2006-02-11 12:54:56 +00:00
|
|
|
screenPos += len;
|
|
|
|
pPixels += len;
|
|
|
|
|
|
|
|
// Get the offset inc amount
|
|
|
|
len = (uint16) *pLines++;
|
|
|
|
if (len == 0) {
|
2006-02-11 17:14:06 +00:00
|
|
|
len = READ_LE_UINT16(pLines);
|
2006-02-11 12:54:56 +00:00
|
|
|
pLines += 2;
|
|
|
|
}
|
|
|
|
|
2007-11-18 05:10:56 +00:00
|
|
|
screenData += len;
|
2006-02-11 12:54:56 +00:00
|
|
|
screenPos += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
AnimationSequence::AnimationSequence(uint16 screenId, Palette &palette, bool fadeIn, int frameDelay,
|
|
|
|
const AnimSoundSequence *soundList): _screenId(screenId), _palette(palette),
|
2007-11-18 05:10:56 +00:00
|
|
|
_frameDelay(frameDelay), _soundList(soundList) {
|
|
|
|
Screen &screen = Screen::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
PictureDecoder decoder;
|
|
|
|
Disk &d = Disk::getReference();
|
2008-01-01 12:58:04 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
// Get the data and decode it. Note that VGA decompression is used
|
2008-01-01 12:58:04 +00:00
|
|
|
// even if the decompressed contents is actually EGA data
|
2006-02-11 12:54:56 +00:00
|
|
|
MemoryBlock *data = d.getEntry(_screenId);
|
2008-01-01 12:58:04 +00:00
|
|
|
_decodedData = decoder.vgaDecode(data, MAX_ANIM_DECODER_BUFFER_SIZE);
|
2006-02-11 12:54:56 +00:00
|
|
|
delete data;
|
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
_isEGA = LureEngine::getReference().isEGA();
|
|
|
|
if (_isEGA) {
|
|
|
|
// Setup for EGA animation
|
|
|
|
_lineRefs = NULL;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
// Reset the palette and clear the screen for EGA decoding
|
|
|
|
screen.setPaletteEmpty(RES_PALETTE_ENTRIES);
|
|
|
|
screen.screen().empty();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
// Load the screen - each four bytes contain the four planes
|
|
|
|
// worth of data for 8 sequential pixels
|
|
|
|
byte *pSrc = _decodedData->data();
|
|
|
|
byte *pDest = screen.screen().data().data() +
|
|
|
|
(FULL_SCREEN_WIDTH * MENUBAR_Y_SIZE);
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
for (int ctr = 0; ctr < FULL_SCREEN_WIDTH * (FULL_SCREEN_HEIGHT -
|
2008-01-01 12:58:04 +00:00
|
|
|
MENUBAR_Y_SIZE) / 8; ++ctr, pDest += EGA_PIXELS_PER_BYTE) {
|
|
|
|
for (int planeCtr = 0; planeCtr < EGA_NUM_LAYERS; ++planeCtr, ++pSrc) {
|
|
|
|
byte v = *pSrc;
|
|
|
|
for (int bitCtr = 0; bitCtr < 8; ++bitCtr, v <<= 1) {
|
|
|
|
if ((v & 0x80) != 0)
|
|
|
|
*(pDest + bitCtr) |= 1 << planeCtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
screen.update();
|
|
|
|
screen.setPalette(&_palette, 0, _palette.numEntries());
|
|
|
|
|
|
|
|
// Set pointers for animation
|
|
|
|
_pPixels = pSrc;
|
|
|
|
_pPixelsEnd = _decodedData->data() + _decodedData->size() - 1;
|
|
|
|
_pLines = NULL;
|
|
|
|
_pLinesEnd = NULL;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
} else {
|
|
|
|
// Setup for VGA animation
|
|
|
|
_lineRefs = d.getEntry(_screenId + 1);
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-01 12:58:04 +00:00
|
|
|
// Reset the palette and set the initial starting screen
|
|
|
|
screen.setPaletteEmpty(RES_PALETTE_ENTRIES);
|
|
|
|
screen.screen().data().copyFrom(_decodedData, 0, 0, FULL_SCREEN_HEIGHT * FULL_SCREEN_WIDTH);
|
|
|
|
screen.update();
|
|
|
|
|
|
|
|
// Set the palette
|
|
|
|
if (fadeIn) screen.paletteFadeIn(&_palette);
|
|
|
|
else screen.setPalette(&_palette, 0, _palette.numEntries());
|
|
|
|
|
|
|
|
// Set up frame pointers
|
|
|
|
_pPixels = _decodedData->data() + SCREEN_SIZE;
|
|
|
|
_pPixelsEnd = _decodedData->data() + _decodedData->size() - 1;
|
|
|
|
_pLines = _lineRefs->data();
|
|
|
|
_pLinesEnd = _lineRefs->data() + _lineRefs->size() - 1;
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationSequence::~AnimationSequence() {
|
2010-01-03 19:37:43 +00:00
|
|
|
delete _lineRefs;
|
2006-02-11 12:54:56 +00:00
|
|
|
delete _decodedData;
|
2009-01-31 12:26:44 +00:00
|
|
|
|
|
|
|
// Renable GMM saving/loading now that the animation is done
|
|
|
|
LureEngine::getReference()._saveLoadAllowed = true;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// show
|
|
|
|
// Main method for displaying the animation
|
|
|
|
|
|
|
|
AnimAbortType AnimationSequence::show() {
|
2008-01-01 12:58:04 +00:00
|
|
|
Screen &screen = Screen::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
AnimAbortType result;
|
2007-11-18 05:10:56 +00:00
|
|
|
const AnimSoundSequence *soundFrame = _soundList;
|
|
|
|
int frameCtr = 0;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2009-01-31 12:26:44 +00:00
|
|
|
// Disable GMM saving/loading whilst animation is running
|
|
|
|
LureEngine::getReference()._saveLoadAllowed = false;
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
// Loop through displaying the animations
|
2008-01-01 12:58:04 +00:00
|
|
|
while (_pPixels < _pPixelsEnd) {
|
2007-11-18 05:10:56 +00:00
|
|
|
if ((soundFrame != NULL) && (frameCtr == 0))
|
2007-12-16 08:10:47 +00:00
|
|
|
Sound.musicInterface_Play(
|
2008-01-27 19:47:41 +00:00
|
|
|
Sound.isRoland() ? soundFrame->rolandSoundId : soundFrame->adlibSoundId,
|
2007-12-16 08:10:47 +00:00
|
|
|
soundFrame->channelNum);
|
2007-11-18 05:10:56 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if (_isEGA)
|
2008-01-01 12:58:04 +00:00
|
|
|
egaDecodeFrame(_pPixels);
|
|
|
|
else {
|
|
|
|
if (_pLines >= _pLinesEnd) break;
|
|
|
|
vgaDecodeFrame(_pPixels, _pLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the decoded frame visible
|
|
|
|
screen.update();
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-11-18 05:10:56 +00:00
|
|
|
result = delay(_frameDelay * 1000 / 50);
|
2006-02-11 12:54:56 +00:00
|
|
|
if (result != ABORT_NONE) return result;
|
2007-11-18 05:10:56 +00:00
|
|
|
|
|
|
|
if ((soundFrame != NULL) && (++frameCtr == soundFrame->numFrames)) {
|
|
|
|
frameCtr = 0;
|
|
|
|
++soundFrame;
|
|
|
|
if (soundFrame->numFrames == 0) soundFrame = NULL;
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ABORT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationSequence::step() {
|
2007-11-18 05:10:56 +00:00
|
|
|
Screen &screen = Screen::getReference();
|
2008-01-01 12:58:04 +00:00
|
|
|
if (_pPixels >= _pPixelsEnd) return false;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
if (_isEGA)
|
2008-01-01 12:58:04 +00:00
|
|
|
egaDecodeFrame(_pPixels);
|
|
|
|
else {
|
|
|
|
if (_pLines >= _pLinesEnd) return false;
|
|
|
|
vgaDecodeFrame(_pPixels, _pLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the decoded frame visible
|
|
|
|
screen.update();
|
2007-11-18 05:10:56 +00:00
|
|
|
screen.setPalette(&_palette);
|
2008-01-01 12:58:04 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Lure
|