2004-01-18 05:52:04 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "sword1/animation.h"
|
2004-03-22 01:28:45 +00:00
|
|
|
#include "sound/audiostream.h"
|
2004-01-18 05:52:04 +00:00
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
|
2004-01-18 05:52:04 +00:00
|
|
|
namespace Sword1 {
|
|
|
|
|
|
|
|
AnimationState::AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys)
|
2004-03-22 01:28:45 +00:00
|
|
|
: BaseAnimationState(snd, sys, 640, 400), _scr(scr) {
|
2004-01-18 05:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationState::~AnimationState() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef BACKEND_8BIT
|
|
|
|
|
2004-03-21 18:49:04 +00:00
|
|
|
void AnimationState::setPalette(byte *pal) {
|
|
|
|
_sys->setPalette(pal, 0, 256);
|
|
|
|
}
|
|
|
|
|
2004-01-18 05:52:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bool AnimationState::decodeFrame() {
|
|
|
|
#ifdef USE_MPEG2
|
|
|
|
mpeg2_state_t state;
|
|
|
|
const mpeg2_sequence_t *sequence_i;
|
|
|
|
size_t size = (size_t) -1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
state = mpeg2_parse(decoder);
|
|
|
|
sequence_i = info->sequence;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case STATE_BUFFER:
|
|
|
|
size = mpgfile->read(buffer, BUFFER_SIZE);
|
|
|
|
mpeg2_buffer(decoder, buffer, buffer + size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATE_SLICE:
|
|
|
|
case STATE_END:
|
|
|
|
if (info->display_fbuf) {
|
|
|
|
/* simple audio video sync code:
|
2004-02-12 17:16:38 +00:00
|
|
|
* we calculate the actual frame by taking the elapsed audio time and try
|
|
|
|
* to stay inside +- 1 frame of this calculated frame number by dropping
|
|
|
|
* frames if we run behind and delaying if we are too fast
|
2004-01-28 04:11:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-22 18:13:54 +00:00
|
|
|
/* Avoid deadlock is sound was too far ahead */
|
|
|
|
if (bgSoundStream && !bgSound.isActive())
|
|
|
|
return false;
|
|
|
|
|
2004-01-21 08:50:15 +00:00
|
|
|
if (checkPaletteSwitch() || (bgSoundStream == NULL) ||
|
2004-03-22 01:40:24 +00:00
|
|
|
((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) ||
|
|
|
|
frameskipped > 10) {
|
2004-03-04 18:54:35 +00:00
|
|
|
if (frameskipped > 10) {
|
|
|
|
warning("force frame %i redraw", framenum);
|
|
|
|
frameskipped = 0;
|
|
|
|
}
|
2004-03-22 01:40:24 +00:00
|
|
|
#ifdef BACKEND_8BIT
|
2004-01-18 05:52:04 +00:00
|
|
|
_scr->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf);
|
|
|
|
#else
|
2004-01-30 20:57:23 +00:00
|
|
|
plotYUV(lookup, sequence_i->width, sequence_i->height, info->display_fbuf->buf);
|
2004-03-22 01:28:45 +00:00
|
|
|
_sys->copy_rect_overlay(overlay, MOVIE_WIDTH, 0, 40, MOVIE_WIDTH, MOVIE_HEIGHT);
|
2004-03-22 01:40:24 +00:00
|
|
|
#endif
|
2004-03-22 01:28:45 +00:00
|
|
|
|
2004-01-18 05:52:04 +00:00
|
|
|
if (bgSoundStream) {
|
2004-02-12 17:16:38 +00:00
|
|
|
while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum)
|
2004-01-18 05:52:04 +00:00
|
|
|
_sys->delay_msecs(10);
|
|
|
|
} else {
|
|
|
|
ticks += 83;
|
|
|
|
while (_sys->get_msecs() < ticks)
|
|
|
|
_sys->delay_msecs(10);
|
|
|
|
}
|
|
|
|
|
2004-03-04 18:54:35 +00:00
|
|
|
} else {
|
2004-01-20 13:28:49 +00:00
|
|
|
warning("dropped frame %i", framenum);
|
2004-03-04 18:54:35 +00:00
|
|
|
frameskipped++;
|
|
|
|
}
|
2004-01-18 05:52:04 +00:00
|
|
|
|
2004-03-22 01:40:24 +00:00
|
|
|
#ifdef BACKEND_8BIT
|
|
|
|
buildLookup(palnum + 1, lutcalcnum);
|
2004-01-18 05:52:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
framenum++;
|
|
|
|
return true;
|
|
|
|
|
2004-01-30 20:47:21 +00:00
|
|
|
}
|
2004-01-18 05:52:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (size);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-03-21 18:49:04 +00:00
|
|
|
MoviePlayer::MoviePlayer(Screen *scr, SoundMixer *snd, OSystem *sys)
|
|
|
|
: _scr(scr), _snd(snd), _sys(sys) {
|
|
|
|
}
|
|
|
|
|
2004-01-18 05:52:04 +00:00
|
|
|
/**
|
|
|
|
* Plays an animated cutscene.
|
|
|
|
* @param filename the file name of the cutscene file
|
|
|
|
*/
|
|
|
|
void MoviePlayer::play(const char *filename) {
|
|
|
|
#ifdef USE_MPEG2
|
|
|
|
AnimationState *anim = new AnimationState(_scr, _snd, _sys);
|
|
|
|
|
|
|
|
if (anim->init(filename)) {
|
|
|
|
while (anim->decodeFrame()) {
|
|
|
|
#ifndef BACKEND_8BIT
|
2004-02-28 12:58:13 +00:00
|
|
|
_sys->updateScreen();
|
2004-01-18 05:52:04 +00:00
|
|
|
#endif
|
|
|
|
// FIXME: check for ESC and abbort animation be just returning from the function
|
2004-02-08 14:11:11 +00:00
|
|
|
OSystem::Event event;
|
|
|
|
while (_sys->poll_event(&event)) {
|
|
|
|
if ((event.event_code == OSystem::EVENT_KEYDOWN) &&
|
|
|
|
(event.kbd.keycode == 27)) {
|
|
|
|
delete anim;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.event_code == OSystem::EVENT_QUIT)
|
|
|
|
_sys->quit();
|
|
|
|
}
|
2004-01-18 05:52:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete anim;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Sword2
|