2012-01-10 19:41:51 +00:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2011-09-18 08:55:23 +00:00
|
|
|
*
|
2012-01-10 19:41:51 +00:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2011-09-18 08:55:23 +00:00
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2012-01-05 09:07:48 +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.
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2012-01-05 09:07:48 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2011-09-18 08:55:23 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-01-05 09:07:48 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2012-01-05 09:07:48 +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.
|
2011-09-18 08:55:23 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/myst3/movie.h"
|
2011-09-24 10:53:49 +00:00
|
|
|
#include "engines/myst3/myst3.h"
|
|
|
|
#include "engines/myst3/variables.h"
|
2011-09-18 08:55:23 +00:00
|
|
|
|
|
|
|
namespace Myst3 {
|
|
|
|
|
2012-01-05 12:38:31 +00:00
|
|
|
Movie::Movie(Myst3Engine *vm, uint16 id) :
|
2011-10-15 19:21:46 +00:00
|
|
|
_vm(vm),
|
2012-01-12 08:44:50 +00:00
|
|
|
_posU(0),
|
|
|
|
_posV(0),
|
2011-10-15 19:21:46 +00:00
|
|
|
_startFrame(0),
|
2012-01-10 17:59:22 +00:00
|
|
|
_endFrame(0),
|
|
|
|
_texture(0) {
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2012-01-07 21:17:21 +00:00
|
|
|
const DirectorySubEntry *binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kMovie);
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2012-01-03 12:24:52 +00:00
|
|
|
if (!binkDesc)
|
2012-01-07 21:17:21 +00:00
|
|
|
binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kStillMovie);
|
2012-01-03 12:24:52 +00:00
|
|
|
|
2012-01-09 17:38:29 +00:00
|
|
|
if (!binkDesc)
|
2012-01-07 21:17:21 +00:00
|
|
|
binkDesc = _vm->getFileDescription(0, id, 0, DirectorySubEntry::kImagerMovie);
|
2012-01-03 12:24:52 +00:00
|
|
|
|
2011-09-18 08:55:23 +00:00
|
|
|
if (!binkDesc)
|
2011-09-24 10:53:49 +00:00
|
|
|
error("Movie %d does not exist", id);
|
|
|
|
|
|
|
|
loadPosition(binkDesc->getVideoData());
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2012-01-05 12:17:48 +00:00
|
|
|
Common::MemoryReadStream *binkStream = binkDesc->getData();
|
2011-09-24 10:53:49 +00:00
|
|
|
_bink.loadStream(binkStream, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::loadPosition(const VideoData &videoData) {
|
|
|
|
static const float scale = 50.0f;
|
2011-09-18 08:55:23 +00:00
|
|
|
|
|
|
|
Math::Vector3d planeDirection = videoData.v1;
|
|
|
|
planeDirection.normalize();
|
|
|
|
|
|
|
|
Math::Vector3d u;
|
|
|
|
u.set(planeDirection.z(), 0.0f, -planeDirection.x());
|
|
|
|
u.normalize();
|
|
|
|
|
2011-10-15 10:56:47 +00:00
|
|
|
Math::Vector3d v = Math::Vector3d::crossProduct(planeDirection, u);
|
2011-09-18 08:55:23 +00:00
|
|
|
v.normalize();
|
|
|
|
|
|
|
|
Math::Vector3d planeOrigin = planeDirection * scale;
|
|
|
|
|
|
|
|
float left = (videoData.u - 320) * 0.003125f;
|
|
|
|
float right = (videoData.u + videoData.width - 320) * 0.003125f;
|
|
|
|
float top = (320 - videoData.v) * 0.003125f;
|
|
|
|
float bottom = (320 - videoData.v - videoData.height) * 0.003125f;
|
|
|
|
|
|
|
|
Math::Vector3d vLeft = scale * left * u;
|
|
|
|
Math::Vector3d vRight = scale * right * u;
|
|
|
|
Math::Vector3d vTop = scale * top * v;
|
|
|
|
Math::Vector3d vBottom = scale * bottom * v;
|
|
|
|
|
|
|
|
_pTopLeft = planeOrigin + vTop + vLeft;
|
|
|
|
_pBottomLeft = planeOrigin + vBottom + vLeft;
|
|
|
|
_pBottomRight = planeOrigin + vBottom + vRight;
|
|
|
|
_pTopRight = planeOrigin + vTop + vRight;
|
2012-01-12 08:44:50 +00:00
|
|
|
|
|
|
|
_posU = videoData.u;
|
|
|
|
_posV = videoData.v;
|
2011-09-24 10:53:49 +00:00
|
|
|
}
|
2011-09-18 08:55:23 +00:00
|
|
|
|
2011-10-15 19:28:14 +00:00
|
|
|
void Movie::draw() {
|
2012-01-12 08:44:50 +00:00
|
|
|
if (_vm->_viewType == kCube) {
|
|
|
|
_vm->_gfx->drawTexturedRect3D(_pTopLeft, _pBottomLeft, _pTopRight, _pBottomRight, _texture);
|
|
|
|
} else {
|
|
|
|
Common::Rect screenRect = Common::Rect(_bink.getWidth(), _bink.getHeight());
|
|
|
|
screenRect.translate(_posU, _posV);
|
|
|
|
|
|
|
|
if (_vm->_viewType == kFrame)
|
|
|
|
screenRect.translate(0, Scene::kTopBorderHeight);
|
|
|
|
|
|
|
|
Common::Rect textureRect = Common::Rect(_bink.getWidth(), _bink.getHeight());
|
|
|
|
_vm->_gfx->drawTexturedRect2D(screenRect, textureRect, _texture, 0.99f);
|
|
|
|
}
|
2011-10-15 19:28:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Movie::drawNextFrameToTexture() {
|
|
|
|
const Graphics::Surface *frame = _bink.decodeNextFrame();
|
|
|
|
|
2012-01-10 17:59:22 +00:00
|
|
|
if (_texture)
|
|
|
|
_texture->update(frame);
|
|
|
|
else
|
|
|
|
_texture = _vm->_gfx->createTexture(frame);
|
2011-10-15 19:28:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Movie::~Movie() {
|
2012-01-10 17:59:22 +00:00
|
|
|
if (_texture)
|
|
|
|
_vm->_gfx->freeTexture(_texture);
|
2011-10-15 19:28:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 12:38:31 +00:00
|
|
|
ScriptedMovie::ScriptedMovie(Myst3Engine *vm, uint16 id) :
|
|
|
|
Movie(vm, id),
|
2011-10-15 19:28:14 +00:00
|
|
|
_condition(0),
|
|
|
|
_conditionBit(0),
|
|
|
|
_startFrameVar(0),
|
|
|
|
_endFrameVar(0),
|
|
|
|
_posUVar(0),
|
|
|
|
_posVVar(0),
|
|
|
|
_nextFrameReadVar(0),
|
|
|
|
_nextFrameWriteVar(0),
|
|
|
|
_playingVar(0),
|
|
|
|
_enabled(false),
|
|
|
|
_disableWhenComplete(false),
|
|
|
|
_scriptDriven(false),
|
|
|
|
_isLastFrame(false) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptedMovie::draw() {
|
|
|
|
if (!_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Movie::draw();
|
|
|
|
}
|
|
|
|
|
2011-10-15 15:49:18 +00:00
|
|
|
void ScriptedMovie::update() {
|
2011-09-24 10:53:49 +00:00
|
|
|
if (_startFrameVar) {
|
|
|
|
_startFrame = _vm->_vars->get(_startFrameVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_endFrameVar) {
|
|
|
|
_endFrame = _vm->_vars->get(_endFrameVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_endFrame) {
|
2011-10-15 08:02:30 +00:00
|
|
|
_endFrame = _bink.getFrameCount();
|
2011-09-24 10:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_posUVar) {
|
|
|
|
_posU = _vm->_vars->get(_posUVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_posVVar) {
|
|
|
|
_posV = _vm->_vars->get(_posVVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool newEnabled;
|
|
|
|
if (_conditionBit) {
|
|
|
|
newEnabled = (_vm->_vars->get(_condition) & (1 << (_conditionBit - 1))) != 0;
|
|
|
|
} else {
|
|
|
|
newEnabled = _vm->_vars->evaluate(_condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newEnabled != _enabled) {
|
|
|
|
_enabled = newEnabled;
|
|
|
|
|
|
|
|
if (newEnabled) {
|
|
|
|
if (_disableWhenComplete
|
|
|
|
|| _bink.getCurFrame() < _startFrame
|
|
|
|
|| _bink.endOfVideo()) {
|
|
|
|
_bink.seekToFrame(_startFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_scriptDriven)
|
|
|
|
_bink.pauseVideo(false);
|
|
|
|
|
|
|
|
drawNextFrameToTexture();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
_bink.pauseVideo(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_enabled) {
|
|
|
|
if (_nextFrameReadVar) {
|
|
|
|
int32 nextFrame = _vm->_vars->get(_nextFrameReadVar);
|
|
|
|
if (nextFrame > 0) {
|
2011-09-24 16:47:23 +00:00
|
|
|
if (_bink.getCurFrame() != nextFrame) {
|
|
|
|
_bink.seekToFrame(nextFrame - 1);
|
|
|
|
drawNextFrameToTexture();
|
|
|
|
}
|
2011-09-24 10:53:49 +00:00
|
|
|
_vm->_vars->set(_nextFrameReadVar, 0);
|
|
|
|
_isLastFrame = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_scriptDriven && (_bink.needsUpdate() || _isLastFrame)) {
|
|
|
|
|
|
|
|
bool complete = false;
|
|
|
|
|
|
|
|
if (_isLastFrame) {
|
|
|
|
_isLastFrame = 0;
|
|
|
|
|
|
|
|
if (_loop) {
|
|
|
|
_bink.seekToFrame(_startFrame);
|
|
|
|
drawNextFrameToTexture();
|
|
|
|
} else {
|
|
|
|
complete = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawNextFrameToTexture();
|
2011-10-15 08:02:30 +00:00
|
|
|
_isLastFrame = _bink.getCurFrame() == (_endFrame - 1);
|
2011-09-24 10:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_nextFrameWriteVar) {
|
|
|
|
_vm->_vars->set(_nextFrameWriteVar, _bink.getCurFrame() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_disableWhenComplete && complete) {
|
|
|
|
_bink.pauseVideo(true);
|
|
|
|
|
|
|
|
if (_playingVar) {
|
|
|
|
_vm->_vars->set(_playingVar, 0);
|
|
|
|
} else {
|
|
|
|
_enabled = 0;
|
|
|
|
_vm->_vars->set(_condition & 0x7FF, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 15:49:18 +00:00
|
|
|
ScriptedMovie::~ScriptedMovie() {
|
|
|
|
}
|
|
|
|
|
2012-01-05 12:38:31 +00:00
|
|
|
SimpleMovie::SimpleMovie(Myst3Engine *vm, uint16 id) :
|
|
|
|
Movie(vm, id),
|
2011-10-15 19:21:46 +00:00
|
|
|
_synchronized(false) {
|
|
|
|
_startFrame = 1;
|
|
|
|
_endFrame = _bink.getFrameCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleMovie::update() {
|
|
|
|
if (_bink.getCurFrame() < (_startFrame - 1)) {
|
|
|
|
_bink.seekToFrame(_startFrame - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint startEngineFrame = _vm->getFrameCount();
|
|
|
|
|
|
|
|
if (!_synchronized) {
|
|
|
|
// Play the movie according to the bink file framerate
|
|
|
|
if (_bink.needsUpdate()) {
|
|
|
|
drawNextFrameToTexture();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Draw a movie frame each two engine frames
|
|
|
|
int targetFrame = (_vm->getFrameCount() - startEngineFrame) >> 2;
|
|
|
|
if (_bink.getCurFrame() < targetFrame) {
|
|
|
|
drawNextFrameToTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !_bink.endOfVideo() && _bink.getCurFrame() < _endFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleMovie::~SimpleMovie() {
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:55:23 +00:00
|
|
|
} /* namespace Myst3 */
|