1 /* ResidualVM - A 3D game interpreter
2 *
3 * ResidualVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "engines/grim/movie/codecs/smush_decoder.h"
24 #include "engines/grim/movie/smush.h"
25
26 #include "engines/grim/resource.h"
27 #include "engines/grim/grim.h"
28
29 namespace Grim {
30
CreateSmushPlayer(bool demo)31 MoviePlayer *CreateSmushPlayer(bool demo) {
32 return new SmushPlayer(demo);
33 }
34
SmushPlayer(bool demo)35 SmushPlayer::SmushPlayer(bool demo) : MoviePlayer(), _demo(demo) {
36 _smushDecoder = new SmushDecoder();
37 _videoDecoder = _smushDecoder;
38 //_smushDecoder->setDemo(_demo);
39 }
40
loadFile(const Common::String & filename)41 bool SmushPlayer::loadFile(const Common::String &filename) {
42 if (!_demo)
43 return _videoDecoder->loadStream(g_resourceloader->openNewStreamFile(filename.c_str()));
44 else
45 return _videoDecoder->loadFile(filename);
46 }
47
init()48 void SmushPlayer::init() {
49 if (_demo) {
50 _x = _smushDecoder->getX();
51 _y = _smushDecoder->getY();
52 } else {
53 _smushDecoder->setLooping(_videoLooping);
54 }
55 MoviePlayer::init();
56 }
57
handleFrame()58 void SmushPlayer::handleFrame() {
59 // Force the last frame to stay in place for it's duration:
60 if (_videoDecoder->endOfVideo() && _videoDecoder->getTime() >= (uint32)_videoDecoder->getDuration().msecs()) {
61 // If we're not supposed to loop (or looping fails) then end the video
62 if (!_videoLooping) {
63 _videoFinished = true;
64 g_grim->setMode(GrimEngine::NormalMode);
65 deinit();
66 return;
67 } else {
68 _smushDecoder->rewind(); // This doesnt handle if looping fails.
69 _smushDecoder->start();
70 }
71 }
72 }
73
postHandleFrame()74 void SmushPlayer::postHandleFrame() {
75 if (_demo) {
76 _x = _smushDecoder->getX();
77 _y = _smushDecoder->getY();
78 }
79 }
80
restore(SaveGame * state)81 void SmushPlayer::restore(SaveGame *state) {
82 if (isPlaying()) {
83 _smushDecoder->seek((uint32)_movieTime);
84 _smushDecoder->start();
85 timerCallback(this);
86 }
87 }
88
89 } // end of namespace Grim
90