2015-12-01 20:10:42 +01: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on Labyrinth of Time code with assistance of
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993 Terra Nova Development
|
|
|
|
* Copyright (c) 2004 The Wyrmkeep Entertainment Co.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lab/lab.h"
|
2015-12-08 21:19:41 +01:00
|
|
|
|
2015-12-08 21:28:45 +01:00
|
|
|
#include "lab/anim.h"
|
2015-12-08 21:19:41 +01:00
|
|
|
#include "lab/dispman.h"
|
|
|
|
#include "lab/eventman.h"
|
2015-12-08 20:36:05 +01:00
|
|
|
#include "lab/music.h"
|
2015-12-08 21:00:50 +01:00
|
|
|
#include "lab/utils.h"
|
2015-12-01 20:10:42 +01:00
|
|
|
|
|
|
|
namespace Lab {
|
|
|
|
|
|
|
|
Anim::Anim(LabEngine *vm) : _vm(vm) {
|
2015-12-02 00:34:51 +01:00
|
|
|
_header = 0;
|
|
|
|
_curBit = 0;
|
|
|
|
_numChunks = 1;
|
|
|
|
_headerdata._width = 0;
|
|
|
|
_headerdata._height = 0;
|
|
|
|
_headerdata._fps = 0;
|
|
|
|
_headerdata._flags = 0;
|
|
|
|
_delayMicros = 0;
|
|
|
|
_continuous = false;
|
|
|
|
_isPlaying = false;
|
|
|
|
_isAnim = false;
|
|
|
|
_isPal = false;
|
|
|
|
_noPalChange = false;
|
|
|
|
_donePal = false;
|
|
|
|
_frameNum = 0;
|
|
|
|
_playOnce = false;
|
|
|
|
_buffer = nullptr;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile = nullptr;
|
2015-12-02 00:34:51 +01:00
|
|
|
_size = 0;
|
|
|
|
_rawDiffBM._bytesPerRow = 0;
|
2015-12-10 10:53:15 +02:00
|
|
|
_rawDiffBM._drawOnScreen = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
for (int i = 0; i < 16; i++)
|
2015-12-02 00:34:51 +01:00
|
|
|
_rawDiffBM._planes[i] = nullptr;
|
|
|
|
_rawDiffBM._rows = 0;
|
|
|
|
_waitForEffect = false;
|
|
|
|
_stopPlayingEnd = false;
|
|
|
|
_sampleSpeed = 0;
|
|
|
|
_doBlack = false;
|
|
|
|
_diffWidth = 0;
|
|
|
|
_diffHeight = 0;
|
2015-12-08 21:33:03 +01:00
|
|
|
DrawBitMap = _vm->_graphics->_dispBitMap;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 3 * 256; i++)
|
2015-12-02 00:34:51 +01:00
|
|
|
_diffPalette[i] = 0;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 11:29:23 +02:00
|
|
|
void Anim::diffNextFrame(bool onlyDiffData) {
|
2015-12-08 11:27:34 +01:00
|
|
|
if (_header == 65535)
|
|
|
|
// Already done.
|
2015-12-01 20:10:42 +01:00
|
|
|
return;
|
|
|
|
|
2015-12-10 12:45:21 +02:00
|
|
|
if (_vm->_graphics->_dispBitMap->_drawOnScreen)
|
2015-12-10 12:47:05 +02:00
|
|
|
_vm->_graphics->_dispBitMap->_planes[0] = _vm->_graphics->getCurrentDrawingBuffer();
|
2015-12-10 12:45:21 +02:00
|
|
|
|
|
|
|
_vm->_graphics->_dispBitMap->_planes[1] = _vm->_graphics->_dispBitMap->_planes[0] + 0x10000;
|
|
|
|
_vm->_graphics->_dispBitMap->_planes[2] = _vm->_graphics->_dispBitMap->_planes[1] + 0x10000;
|
|
|
|
_vm->_graphics->_dispBitMap->_planes[3] = _vm->_graphics->_dispBitMap->_planes[2] + 0x10000;
|
|
|
|
_vm->_graphics->_dispBitMap->_planes[4] = _vm->_graphics->_dispBitMap->_planes[3] + 0x10000;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
|
|
|
_vm->_event->mouseHide();
|
|
|
|
|
|
|
|
while (1) {
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_curBit >= _numChunks) {
|
2015-12-01 20:10:42 +01:00
|
|
|
_vm->_event->mouseShow();
|
|
|
|
|
2015-12-08 11:29:23 +02:00
|
|
|
if (!onlyDiffData) {
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_headerdata._fps) {
|
2015-12-13 04:53:12 +02:00
|
|
|
uint32 targetMillis = g_system->getMillis() + _delayMicros;
|
|
|
|
while (g_system->getMillis() < targetMillis)
|
|
|
|
g_system->delayMillis(10);
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_isPal && !_noPalChange) {
|
2015-12-06 14:36:49 +01:00
|
|
|
_vm->_graphics->setPalette(_diffPalette, 256);
|
2015-12-02 00:34:51 +01:00
|
|
|
_isPal = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_donePal = true;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 11:29:23 +02:00
|
|
|
if (_isPal && !_noPalChange && !onlyDiffData && !_donePal) {
|
2015-12-06 14:36:49 +01:00
|
|
|
_vm->_graphics->setPalette(_diffPalette, 256);
|
2015-12-02 00:34:51 +01:00
|
|
|
_isPal = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_donePal = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_frameNum++;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if ((_frameNum == 1) && (_continuous || (!_playOnce)))
|
2015-12-07 01:06:04 +02:00
|
|
|
_buffer = _diffFile;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_isAnim = (_frameNum >= 3) && (!_playOnce);
|
|
|
|
_curBit = 0;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-10 10:53:15 +02:00
|
|
|
if (_vm->_graphics->_dispBitMap->_drawOnScreen)
|
2015-12-04 13:32:08 +01:00
|
|
|
_vm->_graphics->screenUpdate();
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-08 11:27:34 +01:00
|
|
|
// done with the next frame.
|
|
|
|
return;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_music->updateMusic();
|
2015-12-07 01:06:04 +02:00
|
|
|
_header = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_size = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
switch (_header) {
|
2015-12-10 07:04:17 +01:00
|
|
|
case 8:
|
2015-12-13 04:12:29 +02:00
|
|
|
memcpy(_diffPalette, _diffFile, _size);
|
|
|
|
_diffFile += _size;
|
2015-12-02 00:34:51 +01:00
|
|
|
_isPal = true;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 10:
|
2015-12-07 01:06:04 +02:00
|
|
|
_rawDiffBM._planes[_curBit] = _diffFile;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-13 04:12:29 +02:00
|
|
|
if (onlyDiffData) {
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size;
|
2015-12-13 04:12:29 +02:00
|
|
|
} else {
|
|
|
|
memcpy(DrawBitMap->_planes[_curBit], _diffFile, _size);
|
|
|
|
_diffFile += _size;
|
|
|
|
}
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 11:
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += 4;
|
2015-12-07 17:46:37 +01:00
|
|
|
_vm->_utils->runLengthDecode(DrawBitMap->_planes[_curBit], _diffFile);
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size - 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 12:
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += 4;
|
2015-12-07 17:46:37 +01:00
|
|
|
_vm->_utils->VRunLengthDecode(DrawBitMap->_planes[_curBit], _diffFile, DrawBitMap->_bytesPerRow);
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size - 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 20:
|
2015-12-08 21:33:03 +01:00
|
|
|
_vm->_utils->unDiff(DrawBitMap->_planes[_curBit], _vm->_graphics->_dispBitMap->_planes[_curBit], _diffFile, DrawBitMap->_bytesPerRow, false);
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 21:
|
2015-12-08 21:33:03 +01:00
|
|
|
_vm->_utils->unDiff(DrawBitMap->_planes[_curBit], _vm->_graphics->_dispBitMap->_planes[_curBit], _diffFile, DrawBitMap->_bytesPerRow, true);
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 25:
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 26:
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit++;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
case 30:
|
|
|
|
case 31:
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_waitForEffect) {
|
2015-12-01 20:10:42 +01:00
|
|
|
while (_vm->_music->isSoundEffectActive()) {
|
|
|
|
_vm->_music->updateMusic();
|
|
|
|
_vm->waitTOF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 07:04:17 +01:00
|
|
|
_size -= 8;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += 4;
|
|
|
|
_sampleSpeed = READ_LE_UINT16(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-07 01:11:29 +02:00
|
|
|
_vm->_music->playSoundEffect(_sampleSpeed, _size, _diffFile);
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
2015-12-10 07:04:17 +01:00
|
|
|
|
|
|
|
case 65535:
|
2015-12-02 00:34:51 +01:00
|
|
|
if ((_frameNum == 1) || _playOnce || _stopPlayingEnd) {
|
2015-12-07 08:21:27 +01:00
|
|
|
bool didTOF = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_waitForEffect) {
|
2015-12-01 20:10:42 +01:00
|
|
|
while (_vm->_music->isSoundEffectActive()) {
|
|
|
|
_vm->_music->updateMusic();
|
|
|
|
_vm->waitTOF();
|
|
|
|
|
2015-12-10 10:53:15 +02:00
|
|
|
if (_vm->_graphics->_dispBitMap->_drawOnScreen)
|
2015-12-07 08:21:27 +01:00
|
|
|
didTOF = true;
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_isPlaying = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
_vm->_event->mouseShow();
|
|
|
|
|
|
|
|
if (!didTOF)
|
2015-12-04 13:32:08 +01:00
|
|
|
_vm->_graphics->screenUpdate();
|
2015-12-01 20:10:42 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-08 11:27:34 +01:00
|
|
|
// Random frame number so it never gets back to 2
|
|
|
|
_frameNum = 4;
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile = _buffer;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile += _size;
|
2015-12-01 20:10:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 09:46:54 +01:00
|
|
|
/**
|
2015-12-10 03:15:13 +02:00
|
|
|
* Stops an animation from running.
|
|
|
|
*/
|
|
|
|
void Anim::stopDiff() {
|
|
|
|
if (_isPlaying && _isAnim)
|
|
|
|
_vm->_graphics->blackScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops an animation from running.
|
|
|
|
*/
|
|
|
|
void Anim::stopDiffEnd() {
|
2015-12-10 07:04:17 +01:00
|
|
|
if (!_isPlaying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_stopPlayingEnd = true;
|
|
|
|
while (_isPlaying) {
|
|
|
|
_vm->_music->updateMusic();
|
|
|
|
diffNextFrame();
|
2015-12-10 03:15:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads in a DIFF file.
|
2015-12-08 09:46:54 +01:00
|
|
|
*/
|
2015-12-10 03:15:13 +02:00
|
|
|
void Anim::readDiff(byte *buffer, bool playOnce, bool onlyDiffData) {
|
|
|
|
_playOnce = playOnce;
|
2015-12-10 07:04:17 +01:00
|
|
|
_delayMicros = 0;
|
2015-12-08 09:19:00 +01:00
|
|
|
_header = 0;
|
2015-12-02 00:34:51 +01:00
|
|
|
_curBit = 0;
|
|
|
|
_frameNum = 0;
|
2015-12-08 09:19:00 +01:00
|
|
|
_numChunks = 1;
|
|
|
|
_donePal = false;
|
2015-12-02 00:34:51 +01:00
|
|
|
_stopPlayingEnd = false;
|
2015-12-08 09:19:00 +01:00
|
|
|
_isPlaying = true;
|
2015-12-02 00:34:51 +01:00
|
|
|
|
|
|
|
if (_doBlack) {
|
|
|
|
_doBlack = false;
|
2015-12-04 13:32:08 +01:00
|
|
|
_vm->_graphics->blackScreen();
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_diffFile = buffer;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
_continuous = false;
|
2015-12-07 01:06:04 +02:00
|
|
|
uint32 signature = READ_BE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_header = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if ((signature != MKTAG('D', 'I', 'F', 'F')) || (_header != 1219009121L)) {
|
|
|
|
_isPlaying = false;
|
2015-12-01 20:10:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_header = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-07 01:06:04 +02:00
|
|
|
_size = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_header == 0) {
|
2015-12-01 20:10:42 +01:00
|
|
|
// sizeof(headerdata) != 18, but the padding might be at the end
|
2015-12-07 01:06:04 +02:00
|
|
|
_headerdata._version = READ_LE_UINT16(_diffFile);
|
|
|
|
_diffFile += 2;
|
|
|
|
_headerdata._width = READ_LE_UINT16(_diffFile);
|
|
|
|
_diffFile += 2;
|
|
|
|
_headerdata._height = READ_LE_UINT16(_diffFile);
|
|
|
|
_diffFile += 2;
|
|
|
|
_headerdata._depth = _diffFile[0];
|
|
|
|
_diffFile++;
|
|
|
|
_headerdata._fps = _diffFile[0];
|
|
|
|
_diffFile++;
|
|
|
|
_headerdata._bufferSize = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
|
|
|
_headerdata._machine = READ_LE_UINT16(_diffFile);
|
|
|
|
_diffFile += 2;
|
|
|
|
_headerdata._flags = READ_LE_UINT32(_diffFile);
|
|
|
|
_diffFile += 4;
|
|
|
|
|
|
|
|
_diffFile += _size - 18;
|
2015-12-02 00:34:51 +01:00
|
|
|
|
|
|
|
_continuous = CONTINUOUS & _headerdata._flags;
|
|
|
|
_diffWidth = _headerdata._width;
|
|
|
|
_diffHeight = _headerdata._height;
|
2015-12-07 17:46:37 +01:00
|
|
|
_vm->_utils->setBytesPerRow(_diffWidth);
|
2015-12-02 00:34:51 +01:00
|
|
|
|
2015-12-10 03:15:13 +02:00
|
|
|
_numChunks = (((int32)_diffWidth) * _diffHeight) / 0x10000;
|
2015-12-02 00:34:51 +01:00
|
|
|
|
2015-12-10 03:15:13 +02:00
|
|
|
if ((uint32)(_numChunks * 0x10000) < (uint32)(((int32)_diffWidth) * _diffHeight))
|
2015-12-02 00:34:51 +01:00
|
|
|
_numChunks++;
|
2015-12-10 07:04:17 +01:00
|
|
|
} else
|
2015-12-01 20:10:42 +01:00
|
|
|
return;
|
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
for (_header = 0; _header < 8; _header++)
|
|
|
|
_rawDiffBM._planes[_header] = NULL;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_headerdata._fps)
|
|
|
|
_delayMicros = ONESECOND / _headerdata._fps;
|
2015-12-01 20:10:42 +01:00
|
|
|
|
2015-12-02 00:34:51 +01:00
|
|
|
if (_playOnce) {
|
|
|
|
while (_header != 65535)
|
2015-12-08 11:29:23 +02:00
|
|
|
diffNextFrame(onlyDiffData);
|
2015-12-10 07:04:17 +01:00
|
|
|
} else
|
2015-12-10 03:15:13 +02:00
|
|
|
diffNextFrame(onlyDiffData);
|
2015-12-01 20:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Lab
|