Initial commit
This commit is contained in:
229
engines/sword25/fmv/movieplayer.cpp
Normal file
229
engines/sword25/fmv/movieplayer.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
*
|
||||
* Licensed under GNU GPL v2
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/system.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#include "sword25/sword25.h" // for kDebugScript
|
||||
#include "sword25/fmv/movieplayer.h"
|
||||
#include "sword25/gfx/graphicengine.h"
|
||||
#include "sword25/gfx/panel.h"
|
||||
#include "sword25/kernel/kernel.h"
|
||||
#include "sword25/package/packagemanager.h"
|
||||
|
||||
namespace Sword25 {
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
|
||||
#endif
|
||||
|
||||
#ifdef USE_THEORADEC
|
||||
MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder() {
|
||||
if (!registerScriptBindings())
|
||||
error("Script bindings could not be registered.");
|
||||
else
|
||||
debugC(kDebugScript, "Script bindings registered.");
|
||||
}
|
||||
|
||||
MoviePlayer::~MoviePlayer() {
|
||||
_decoder.close();
|
||||
}
|
||||
|
||||
bool MoviePlayer::loadMovie(const Common::String &filename, uint z) {
|
||||
if (isMovieLoaded())
|
||||
unloadMovie();
|
||||
// Get the file and load it into the decoder
|
||||
Common::SeekableReadStream *in = Kernel::getInstance()->getPackage()->getStream(filename);
|
||||
_decoder.loadStream(in);
|
||||
_decoder.start();
|
||||
|
||||
GraphicEngine *pGfx = Kernel::getInstance()->getGfx();
|
||||
|
||||
#ifdef THEORA_INDIRECT_RENDERING
|
||||
_outputBitmap = pGfx->getMainPanel()->addDynamicBitmap(_decoder.getWidth(), _decoder.getHeight());
|
||||
if (!_outputBitmap.isValid()) {
|
||||
error("Output bitmap for movie playback could not be created.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute the scaling of the output bitmap, so that it takes up the most space
|
||||
float screenToVideoWidth = (float)pGfx->getDisplayWidth() / (float)_outputBitmap->getWidth();
|
||||
float screenToVideoHeight = (float)pGfx->getDisplayHeight() / (float)_outputBitmap->getHeight();
|
||||
float scaleFactor = MIN(screenToVideoWidth, screenToVideoHeight);
|
||||
|
||||
if (abs((int)(scaleFactor - 1.0f)) < FLT_EPSILON)
|
||||
scaleFactor = 1.0f;
|
||||
|
||||
_outputBitmap->setScaleFactor(scaleFactor);
|
||||
_outputBitmap->setZ(z);
|
||||
|
||||
// Center bitmap on screen
|
||||
_outputBitmap->setX((pGfx->getDisplayWidth() - _outputBitmap->getWidth()) / 2);
|
||||
_outputBitmap->setY((pGfx->getDisplayHeight() - _outputBitmap->getHeight()) / 2);
|
||||
#else
|
||||
_backSurface = pGfx->getSurface();
|
||||
|
||||
_outX = (pGfx->getDisplayWidth() - _decoder.getWidth()) / 2;
|
||||
_outY = (pGfx->getDisplayHeight() - _decoder.getHeight()) / 2;
|
||||
|
||||
if (_outX < 0)
|
||||
_outX = 0;
|
||||
if (_outY < 0)
|
||||
_outY = 0;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::unloadMovie() {
|
||||
_decoder.close();
|
||||
_outputBitmap.erase();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::play() {
|
||||
_decoder.pauseVideo(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::pause() {
|
||||
_decoder.pauseVideo(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MoviePlayer::update() {
|
||||
if (_decoder.isVideoLoaded()) {
|
||||
if (_decoder.endOfVideo()) {
|
||||
// Movie complete, so unload the movie
|
||||
unloadMovie();
|
||||
} else if (_decoder.needsUpdate()) {
|
||||
const Graphics::Surface *s = _decoder.decodeNextFrame();
|
||||
if (s) {
|
||||
// Transfer the next frame
|
||||
assert(s->format.bytesPerPixel == 4);
|
||||
|
||||
#ifdef THEORA_INDIRECT_RENDERING
|
||||
const byte *frameData = (const byte *)s->getPixels();
|
||||
_outputBitmap->setContent(frameData, s->pitch * s->h, 0, s->pitch);
|
||||
#else
|
||||
g_system->copyRectToScreen(s->getPixels(), s->pitch, _outX, _outY, MIN(s->w, _backSurface->w), MIN(s->h, _backSurface->h));
|
||||
g_system->updateScreen();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MoviePlayer::isMovieLoaded() {
|
||||
return _decoder.isVideoLoaded();
|
||||
}
|
||||
|
||||
bool MoviePlayer::isPaused() {
|
||||
return _decoder.isPaused() || _decoder.endOfVideo();
|
||||
}
|
||||
|
||||
float MoviePlayer::getScaleFactor() {
|
||||
if (_decoder.isVideoLoaded())
|
||||
return _outputBitmap->getScaleFactorX();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MoviePlayer::setScaleFactor(float scaleFactor) {
|
||||
if (_decoder.isVideoLoaded()) {
|
||||
_outputBitmap->setScaleFactor(scaleFactor);
|
||||
|
||||
// Ausgabebitmap auf dem Bildschirm zentrieren
|
||||
GraphicEngine *gfxPtr = Kernel::getInstance()->getGfx();
|
||||
_outputBitmap->setX((gfxPtr->getDisplayWidth() - _outputBitmap->getWidth()) / 2);
|
||||
_outputBitmap->setY((gfxPtr->getDisplayHeight() - _outputBitmap->getHeight()) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
double MoviePlayer::getTime() {
|
||||
return _decoder.getTime() / 1000.0;
|
||||
}
|
||||
|
||||
#else // USE_THEORADEC
|
||||
|
||||
MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) {
|
||||
if (!registerScriptBindings())
|
||||
error("Script bindings could not be registered.");
|
||||
else
|
||||
debugC(kDebugScript, "Script bindings registered.");
|
||||
}
|
||||
|
||||
MoviePlayer::~MoviePlayer() {
|
||||
}
|
||||
|
||||
bool MoviePlayer::loadMovie(const Common::String &Filename, unsigned int Z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::unloadMovie() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::play() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoviePlayer::pause() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MoviePlayer::update() {
|
||||
}
|
||||
|
||||
bool MoviePlayer::isMovieLoaded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MoviePlayer::isPaused() {
|
||||
return true;
|
||||
}
|
||||
|
||||
float MoviePlayer::getScaleFactor() {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
void MoviePlayer::setScaleFactor(float ScaleFactor) {
|
||||
}
|
||||
|
||||
double MoviePlayer::getTime() {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
#endif // USE_THEORADEC
|
||||
|
||||
} // End of namespace Sword25
|
||||
154
engines/sword25/fmv/movieplayer.h
Normal file
154
engines/sword25/fmv/movieplayer.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
*
|
||||
* Licensed under GNU GPL v2
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_MOVIEPLAYER_H
|
||||
#define SWORD25_MOVIEPLAYER_H
|
||||
|
||||
#include "common/scummsys.h" // for USE_THEORADEC
|
||||
|
||||
#include "sword25/kernel/common.h"
|
||||
#include "sword25/kernel/service.h"
|
||||
#include "sword25/gfx/bitmap.h"
|
||||
|
||||
#ifdef USE_THEORADEC
|
||||
#include "video/theora_decoder.h"
|
||||
#endif
|
||||
|
||||
#define THEORA_INDIRECT_RENDERING
|
||||
|
||||
namespace Sword25 {
|
||||
|
||||
class MoviePlayer : public Service {
|
||||
public:
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constructor / Destructor
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
MoviePlayer(Kernel *pKernel);
|
||||
~MoviePlayer() override;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Player interface must be implemented by a Movie Player
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Loads a movie file
|
||||
*
|
||||
* This method loads a movie file and prepares it for playback.
|
||||
* There can be oly one movie file loaded at a time. If you already have loaded a
|
||||
* movie file, it will be unloaded and, if necessary, stopped playing.
|
||||
* @param Filename The filename of the movie file to be loaded
|
||||
* @param Z Z indicates the position of the film on the main graphics layer
|
||||
* @return Returns false if an error occurred while loading, otherwise true.
|
||||
*/
|
||||
bool loadMovie(const Common::String &filename, uint z);
|
||||
|
||||
/**
|
||||
* Unloads the currently loaded movie file.
|
||||
* @return Returns false if an error occurred while unloading, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool unloadMovie();
|
||||
|
||||
/**
|
||||
* Plays the loaded movie.
|
||||
*
|
||||
* The film will be keeping the aspect ratio of the screen.
|
||||
* If the film was previously paused with Pause(), then the film will resume playing.
|
||||
* @return Returns false if an error occurred while starting, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool play();
|
||||
|
||||
/**
|
||||
* Pauses movie playback.
|
||||
*
|
||||
* A paused movie can later be resumed by calling the Play() method again.
|
||||
* @return Returns false if an error occurred while pausing, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool pause();
|
||||
|
||||
/**
|
||||
* This function must be called once per frame.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns whether a film is loaded for playback.
|
||||
*/
|
||||
bool isMovieLoaded();
|
||||
|
||||
/**
|
||||
* Returns whether the movie playback is paused.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool isPaused();
|
||||
|
||||
/**
|
||||
* Returns the scaling factor for the loaded film.
|
||||
*
|
||||
* When a movie is loaded, the scaling factor is automatically selected so that the film
|
||||
* takes the maximum screen space, without the film being distorted.
|
||||
* @return Returns the scaling factor of the film.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
float getScaleFactor();
|
||||
|
||||
/**
|
||||
* Sets the factor by which the loaded film is to be scaled.
|
||||
* @param ScaleFactor The desired scale factor.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
void setScaleFactor(float scaleFactor);
|
||||
|
||||
/**
|
||||
* Returns the current playing position in seconds.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
double getTime();
|
||||
|
||||
private:
|
||||
bool registerScriptBindings();
|
||||
|
||||
|
||||
#ifdef USE_THEORADEC
|
||||
Video::TheoraDecoder _decoder;
|
||||
|
||||
Graphics::Surface *_backSurface;
|
||||
int _outX, _outY;
|
||||
|
||||
RenderObjectPtr<Bitmap> _outputBitmap;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
||||
#endif
|
||||
159
engines/sword25/fmv/movieplayer_script.cpp
Normal file
159
engines/sword25/fmv/movieplayer_script.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
*
|
||||
* Licensed under GNU GPL v2
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/scummsys.h" // for USE_THEORADEC
|
||||
|
||||
#include "sword25/kernel/common.h"
|
||||
#include "sword25/kernel/kernel.h"
|
||||
#include "sword25/script/script.h"
|
||||
#include "sword25/script/luabindhelper.h"
|
||||
|
||||
#include "sword25/fmv/movieplayer.h"
|
||||
|
||||
namespace Sword25 {
|
||||
|
||||
int loadMovie(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->loadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast<uint>(luaL_checknumber(L, 2)) : 10));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int unloadMovie(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->unloadMovie());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int play(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->play());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pause(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->pause());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int update(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
FMVPtr->update();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isMovieLoaded(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->isMovieLoaded());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int isPaused(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushbooleancpp(L, FMVPtr->isPaused());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int getScaleFactor(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushnumber(L, FMVPtr->getScaleFactor());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setScaleFactor(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
FMVPtr->setScaleFactor(static_cast<float>(luaL_checknumber(L, 1)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getTime(lua_State *L) {
|
||||
MoviePlayer *FMVPtr = Kernel::getInstance()->getFMV();
|
||||
assert(FMVPtr);
|
||||
|
||||
lua_pushnumber(L, FMVPtr->getTime());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *LIBRARY_NAME = "Movieplayer";
|
||||
|
||||
const luaL_reg LIBRARY_FUNCTIONS[] = {
|
||||
{ "LoadMovie", loadMovie },
|
||||
{ "UnloadMovie", unloadMovie },
|
||||
{ "Play", play },
|
||||
{ "Pause", pause },
|
||||
{ "Update", update },
|
||||
{ "IsMovieLoaded", isMovieLoaded },
|
||||
{ "IsPaused", isPaused },
|
||||
{ "GetScaleFactor", getScaleFactor },
|
||||
{ "SetScaleFactor", setScaleFactor },
|
||||
{ "GetTime", getTime },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
bool MoviePlayer::registerScriptBindings() {
|
||||
ScriptEngine *pScript = Kernel::getInstance()->getScript();
|
||||
assert(pScript);
|
||||
lua_State *L = static_cast<lua_State *>(pScript->getScriptObject());
|
||||
assert(L);
|
||||
|
||||
if (!LuaBindhelper::addFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // End of namespace Sword25
|
||||
Reference in New Issue
Block a user