1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "engines/nancy/graphics.h"
#include "engines/nancy/nancy.h"
#include "engines/nancy/sound.h"
#include "engines/nancy/util.h"
#include "engines/nancy/video.h"
#include "engines/nancy/action/secondarymovie.h"
#include "engines/nancy/state/scene.h"
#include "common/serializer.h"
#include "video/bink_decoder.h"
namespace Nancy {
namespace Action {
PlaySecondaryMovie::~PlaySecondaryMovie() {
delete _decoder;
if (NancySceneState.getActiveMovie() == this) {
NancySceneState.setActiveMovie(nullptr);
}
if (_playerCursorAllowed == kNoPlayerCursorAllowed) {
g_nancy->setMouseEnabled(true);
}
}
void PlaySecondaryMovie::readData(Common::SeekableReadStream &stream) {
Common::Serializer ser(&stream, nullptr);
ser.setVersion(g_nancy->getGameType());
readFilename(ser, _videoName);
readFilename(ser, _paletteName, kGameTypeVampire, kGameTypeVampire);
readFilename(ser, _bitmapOverlayName);
ser.syncAsUint16LE(_videoType, kGameTypeNancy7);
ser.skip(2); // videoPlaySource
ser.syncAsUint16LE(_videoFormat);
ser.skip(4, kGameTypeVampire, kGameTypeVampire); // paletteStart, paletteSize
ser.skip(2); // hasBitmapOverlaySurface
ser.skip(2); // VIDEO_STOP_RENDERING, VIDEO_CONTINUE_RENDERING
ser.syncAsUint16LE(_videoSceneChange);
ser.syncAsUint16LE(_playerCursorAllowed);
ser.syncAsUint16LE(_playDirection);
ser.syncAsUint16LE(_firstFrame);
ser.syncAsUint16LE(_lastFrame);
if (ser.getVersion() >= kGameTypeNancy1) {
_frameFlags.resize(15);
for (uint i = 0; i < 15; ++i) {
ser.syncAsSint16LE(_frameFlags[i].frameID);
ser.syncAsSint16LE(_frameFlags[i].flagDesc.label);
ser.syncAsUint16LE(_frameFlags[i].flagDesc.flag);
}
}
_triggerFlags.readData(stream);
_sound.readNormal(stream);
_sceneChange.readData(stream, ser.getVersion() == kGameTypeVampire);
uint16 numVideoDescs = 0;
ser.syncAsUint16LE(numVideoDescs);
_videoDescs.resize(numVideoDescs);
for (uint i = 0; i < numVideoDescs; ++i) {
_videoDescs[i].readData(stream);
}
if (ser.getVersion() >= kGameTypeNancy6) {
// Movie sound was deliberately disabled in nancy6
_sound.name = "NO SOUND";
}
}
void PlaySecondaryMovie::init() {
if (!_decoder) {
if (_videoType == kVideoPlaytypeAVF) {
_decoder = new AVFDecoder();
} else {
_decoder = new Video::BinkDecoder();
}
}
if (!_decoder->isVideoLoaded()) {
if (!_decoder->loadFile(_videoName.append(_videoType == kVideoPlaytypeAVF ? ".avf" : ".bik"))) {
error("Couldn't load video file %s", _videoName.toString().c_str());
}
if (!_paletteName.empty()) {
GraphicsManager::loadSurfacePalette(_fullFrame, _paletteName);
GraphicsManager::loadSurfacePalette(_drawSurface, _paletteName);
}
if (g_nancy->getGameType() == kGameTypeVampire) {
setTransparent(true);
_fullFrame.setTransparentColor(_drawSurface.getTransparentColor());
// TVD uses empty video files during the endgame ceremony
// This makes sure the screen doesn't go black while the sound is playing
_drawSurface.clear(_drawSurface.getTransparentColor());
}
}
_screenPosition = _drawSurface.getBounds();
RenderObject::init();
}
void PlaySecondaryMovie::onPause(bool pause) {
_decoder->pauseVideo(pause);
RenderActionRecord::onPause(pause);
}
void PlaySecondaryMovie::execute() {
switch (_state) {
case kBegin:
init();
registerGraphics();
g_nancy->_sound->loadSound(_sound);
g_nancy->_sound->playSound(_sound);
if (_sound.name != "NO SOUND" && g_nancy->getGameType() <= kGameTypeNancy5) {
// Sync audio and video. This is mostly relevant for some nancy2 scenes, as the
// devs stopped using the built-in movie sound around nancy4. The 12 ms
// difference is roughly how long it takes for a single execution of the main game loop
((AVFDecoder *)_decoder)->addFrameTime(12);
}
if (_playerCursorAllowed == kNoPlayerCursorAllowed) {
g_nancy->setMouseEnabled(false);
}
NancySceneState.setActiveMovie(this);
_state = kRun;
if (Common::Rect(_decoder->getWidth(), _decoder->getHeight()) == NancySceneState.getViewport().getBounds()) {
g_nancy->_graphics->suppressNextDraw();
break;
}
// fall through
case kRun: {
int newFrame = NancySceneState.getSceneInfo().frameID;
if (newFrame != _curViewportFrame) {
_curViewportFrame = newFrame;
int activeFrame = -1;
for (uint i = 0; i < _videoDescs.size(); ++i) {
if (newFrame == _videoDescs[i].frameID) {
activeFrame = i;
break;
}
}
if (activeFrame != -1) {
_screenPosition = _videoDescs[activeFrame].destRect;
setVisible(true);
} else {
setVisible(false);
}
}
// We update the decoder here instead of in updateGraphics() to avoid an
// edge case in nancy4 (scene 3180) where the very last frame has a frameFlag that should trigger
// another action record, but doesn't do so, because updateGraphics() gets called after all
// action record execution. Instead, the movie's own scene change (which is inexplicably enabled)
// gets triggered, and teleports the player to the wrong place instead of making them lose the game
if (!_decoder->isPlaying() && _isVisible && !_isFinished) {
_decoder->start();
if (_playDirection == kPlayMovieReverse) {
_decoder->setRate(-_decoder->getRate());
_decoder->seekToFrame(_lastFrame);
} else {
_decoder->seekToFrame(_firstFrame);
}
}
if (_decoder->needsUpdate()) {
uint descID = 0;
for (uint i = 0; i < _videoDescs.size(); ++i) {
if (_videoDescs[i].frameID == _curViewportFrame) {
descID = i;
}
}
GraphicsManager::copyToManaged(*_decoder->decodeNextFrame(), _fullFrame, g_nancy->getGameType() == kGameTypeVampire, _videoFormat == kSmallVideoFormat);
_drawSurface.create(_fullFrame, _videoDescs[descID].srcRect);
moveTo(_videoDescs[descID].destRect);
_needsRedraw = true;
for (auto &f : _frameFlags) {
if (_decoder->getCurFrame() == f.frameID) {
NancySceneState.setEventFlag(f.flagDesc);
}
}
}
if ((_decoder->getCurFrame() == _lastFrame && _playDirection == kPlayMovieForward) ||
(_decoder->getCurFrame() == _firstFrame && _playDirection == kPlayMovieReverse) ||
_decoder->endOfVideo()) {
// Stop the video and block it from starting again, but also wait for
// sound to end before changing state
_decoder->pauseVideo(true);
_isFinished = true;
if (!g_nancy->_sound->isSoundPlaying(_sound)) {
g_nancy->_sound->stopSound(_sound);
_state = kActionTrigger;
}
}
break;
}
case kActionTrigger:
_triggerFlags.execute();
if (_videoSceneChange == kMovieSceneChange) {
NancySceneState.changeScene(_sceneChange);
} else {
// Not changing the scene so enable the mouse now
if (_playerCursorAllowed == kNoPlayerCursorAllowed) {
g_nancy->setMouseEnabled(true);
}
}
NancySceneState.setActiveMovie(nullptr);
finishExecution();
// Allow looping
if (!_isDone) {
_isFinished = false;
_decoder->seek(0);
_decoder->pauseVideo(false);
}
break;
}
}
} // End of namespace Action
} // End of namespace Nancy
|