GRIM: Reduce dependencies on engines/grim in engines/grim/movie

This commit is contained in:
Einar Johan T. Sømåen 2011-10-02 00:21:21 +02:00
parent ceb42b40e0
commit abea6d10fb
9 changed files with 78 additions and 58 deletions

View File

@ -456,12 +456,12 @@ Common::Error GrimEngine::run() {
g_resourceloader = new ResourceLoader();
g_localizer = new Localizer();
if (getGameType() == GType_GRIM)
g_movie = CreateSmushPlayer();
g_movie = CreateSmushPlayer(getGameFlags() & ADGF_DEMO);
else if (getGameType() == GType_MONKEY4) {
if (_gamePlatform == Common::kPlatformPS2)
g_movie = CreateMpegPlayer();
else
g_movie = CreateBinkPlayer();
g_movie = CreateBinkPlayer(getGameFlags() & ADGF_DEMO);
}
g_imuse = new Imuse(20);

View File

@ -25,28 +25,25 @@
#include "engines/grim/movie/bink.h"
#include "engines/grim/grim.h"
#ifdef USE_BINK
namespace Grim {
MoviePlayer *CreateBinkPlayer() {
return new BinkPlayer();
MoviePlayer *CreateBinkPlayer(bool demo) {
return new BinkPlayer(demo);
}
BinkPlayer::BinkPlayer() : MoviePlayer() {
g_movie = this;
BinkPlayer::BinkPlayer(bool demo) : MoviePlayer(), _demo(demo) {
_videoDecoder = new Video::BinkDecoder();
_speed = 1000;
}
bool BinkPlayer::play(const char *filename, bool looping, int x, int y) {
_fname = filename;
bool BinkPlayer::loadFile(Common::String filename) {
// The demo uses a weird .lab suffix instead of the normal .bik
_fname += (g_grim->getGameFlags() & ADGF_DEMO) ? ".lab" : ".bik";
_fname = filename;
_fname += (_demo) ? ".lab" : ".bik";
return MoviePlayer::play(_fname.c_str(), looping, x, y);
return MoviePlayer::loadFile(_fname);
}
} // end of namespace Grim

View File

@ -31,8 +31,10 @@ namespace Grim {
class BinkPlayer : public MoviePlayer {
public:
BinkPlayer();
bool play(const char *filename, bool looping, int x, int y);
BinkPlayer(bool demo);
private:
bool loadFile(Common::String filename);
bool _demo;
};
} // end of namespace Grim

View File

@ -33,15 +33,19 @@
#include "audio/decoders/raw.h"
#include "engines/grim/debug.h"
#include "engines/grim/grim.h"
#include "engines/grim/resource.h"
#include "engines/grim/movie/codecs/blocky8.h"
#include "engines/grim/movie/codecs/blocky16.h"
#include "engines/grim/movie/codecs/smush_decoder.h"
#ifdef USE_SMUSH
namespace Grim {
// Prototypes to avoid depending on grim.h
void vimaInit(uint16 *destTable);
void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable);
#define ANNO_HEADER "MakeAnim animation type 'Bl16' parameters: "
#define BUFFER_SIZE 16385
#define SMUSH_SPEED 66667
@ -62,16 +66,23 @@ SmushDecoder::SmushDecoder() {
_startPos = 0;
_x = 0;
_y = 0;
_blocky8 = new Blocky8();
_blocky16 = new Blocky16();
init();
}
SmushDecoder::~SmushDecoder() {
delete _blocky8;
delete _blocky16;
}
void SmushDecoder::init() {
_IACTpos = 0;
_stream = NULL;
_curFrame = 0;
_videoPause = false;
if (!(g_grim->getGameFlags() & ADGF_DEMO)) {
if (!_demo) {
_surface.create(_width, _height, _format);
vimaInit(smushDestTable);
}
@ -175,7 +186,7 @@ void SmushDecoder::handleFrame() {
do {
if (READ_BE_UINT32(frame + pos) == MKTAG('B','l','1','6')) {
_blocky16.decode((byte *)_surface.pixels, frame + pos + 8);
_blocky16->decode((byte *)_surface.pixels, frame + pos + 8);
pos += READ_BE_UINT32(frame + pos + 4) + 8;
} else if (READ_BE_UINT32(frame + pos) == MKTAG('W','a','v','e')) {
int decompressed_size = READ_BE_UINT32(frame + pos + 8);
@ -316,9 +327,9 @@ void SmushDecoder::handleFrameDemo() {
_width = width;
_height = height;
_surface.create(_width, _height, _format);
_blocky8.init(_width, _height);
_blocky8->init(_width, _height);
}
_blocky8.decode((byte *)_surface.pixels, frame + pos + 8 + 14);
_blocky8->decode((byte *)_surface.pixels, frame + pos + 8 + 14);
pos += READ_BE_UINT32(frame + pos + 4) + 8;
} else if (READ_BE_UINT32(frame + pos) == MKTAG('I','A','C','T')) {
handleIACT(frame + pos + 8, READ_BE_UINT32(frame + pos + 4));
@ -431,7 +442,7 @@ bool SmushDecoder::setupAnim() {
int width = READ_LE_UINT16(s_header + 8);
int height = READ_LE_UINT16(s_header + 10);
if (_width != width || _height != height) {
_blocky16.init(width, height);
_blocky16->init(width, height);
}
_width = width;
@ -459,7 +470,7 @@ bool SmushDecoder::loadStream(Common::SeekableReadStream *stream) {
close();
// Load the video
if (g_grim->getGameFlags() & ADGF_DEMO) {
if (_demo) {
_file = stream;
if (!setupAnimDemo())
return false;
@ -474,24 +485,13 @@ bool SmushDecoder::loadStream(Common::SeekableReadStream *stream) {
_startPos = _file->pos();
init();
if (!g_grim->getGameFlags() & ADGF_DEMO)
if (!_demo)
_surface.create(_width, _height, _format);
return true;
}
bool SmushDecoder::loadFile(const Common::String &filename) {
if (gDebugLevel == DEBUG_MOVIE)
warning("Playing video '%s'.\n", filename.c_str());
if (g_grim->getGameFlags() & ADGF_DEMO) {
return VideoDecoder::loadFile(filename);
} else {
return loadStream(g_resourceloader->openNewSubStreamFile(filename.c_str()));
}
}
const Graphics::Surface *SmushDecoder::decodeNextFrame() {
if (g_grim->getGameFlags() & ADGF_DEMO)
if (_demo)
handleFrameDemo();
else
handleFrame();

View File

@ -25,9 +25,6 @@
#include "common/rational.h"
#include "engines/grim/movie/codecs/blocky8.h"
#include "engines/grim/movie/codecs/blocky16.h"
#include "audio/mixer.h"
#include "video/video_decoder.h"
@ -42,15 +39,16 @@ namespace Audio {
namespace Grim {
class SaveGame;
class Blocky8;
class Blocky16;
class SmushDecoder : public virtual Video::SeekableVideoDecoder, public virtual Video::FixedRateVideoDecoder {
private:
int32 _nbframes;
int _width, _height;
int _x, _y;
Blocky8 _blocky8;
Blocky16 _blocky16;
Blocky8 *_blocky8;
Blocky16 *_blocky16;
Common::SeekableReadStream *_file;
Common::Rational _frameRate;
Graphics::Surface _surface;
@ -69,12 +67,15 @@ private:
int _freq;
bool _videoPause;
bool _videoLooping;
bool _demo;
public:
SmushDecoder();
~SmushDecoder();
int getX() { return _x; }
int getY() { return _y; }
void setLooping(bool l);
void setDemo(bool demo) { _demo = demo; }
uint16 getWidth() const { return _width; }
uint16 getHeight() const { return _height; }
@ -82,7 +83,6 @@ public:
Graphics::PixelFormat getPixelFormat() const { return _surface.format; }
bool isVideoLoaded() const { return _file != 0; }
bool loadFile(const Common::String &filename);
bool loadStream(Common::SeekableReadStream *stream);
const Graphics::Surface *decodeNextFrame();

View File

@ -129,24 +129,28 @@ void MoviePlayer::deinit() {
_videoFinished = true;
}
bool MoviePlayer::play(const char *filename, bool looping, int x, int y) {
bool MoviePlayer::play(Common::String filename, bool looping, int x, int y) {
deinit();
_x = x;
_y = y;
_fname = filename;
_videoLooping = looping;
if (!_videoDecoder->loadFile(_fname))
if (!loadFile(_fname))
return false;
if (gDebugLevel == DEBUG_MOVIE)
warning("Playing video '%s'.\n", filename);
warning("Playing video '%s'.\n", filename.c_str());
init();
return true;
}
bool MoviePlayer::loadFile(Common::String filename) {
return _videoDecoder->loadFile(filename);
}
void MoviePlayer::saveState(SaveGame *state) {
state->beginSection('SMUS');

View File

@ -48,7 +48,6 @@ protected:
bool _videoPause;
bool _videoLooping;
int _x, _y;
//int _width, _height;
public:
MoviePlayer();
@ -66,7 +65,7 @@ public:
* @see init
* @see stop
*/
virtual bool play(const char *filename, bool looping, int x, int y);
virtual bool play(Common::String filename, bool looping, int x, int y);
virtual void stop();
virtual void pause(bool p);
virtual bool isPlaying() { return !_videoFinished; }
@ -129,14 +128,24 @@ protected:
* @see init
*/
virtual void deinit();
/**
* Loads a file for playback, any additional setup is not done here, but in
* the play-function. This function is supposed to handle any specifics w.r.t.
* files vs containers (i.e. load from LAB vs load from file).
*
* @see play
* @param filename The filename to be handled.
*/
virtual bool loadFile(Common::String filename);
};
// Factory-like functions:
MoviePlayer *CreateMpegPlayer();
MoviePlayer *CreateSmushPlayer();
MoviePlayer *CreateBinkPlayer();
MoviePlayer *CreateSmushPlayer(bool demo);
MoviePlayer *CreateBinkPlayer(bool demo);
extern MoviePlayer *g_movie;
} // end of namespace Grim

View File

@ -23,22 +23,28 @@
#include "engines/grim/movie/codecs/smush_decoder.h"
#include "engines/grim/movie/smush.h"
#include "engines/grim/savegame.h"
#include "engines/grim/resource.h"
#include "engines/grim/grim.h"
#ifdef USE_SMUSH
namespace Grim {
MoviePlayer *CreateSmushPlayer() {
return new SmushPlayer();
MoviePlayer *CreateSmushPlayer(bool demo) {
return new SmushPlayer(demo);
}
SmushPlayer::SmushPlayer() : MoviePlayer() {
g_movie = this;
SmushPlayer::SmushPlayer(bool demo) : MoviePlayer(), _demo(demo) {
_speed = 5000;
_videoDecoder = new Grim::SmushDecoder();
getDecoder()->setDemo(_demo);
}
bool SmushPlayer::loadFile(Common::String filename) {
if (!_demo)
return _videoDecoder->loadStream(g_resourceloader->openNewSubStreamFile(filename.c_str()));
else
return _videoDecoder->loadFile(filename);
}
SmushDecoder* SmushPlayer::getDecoder() {
@ -46,7 +52,7 @@ SmushDecoder* SmushPlayer::getDecoder() {
}
void SmushPlayer::init() {
if (g_grim->getGameFlags() & ADGF_DEMO) {
if (_demo) {
_x = getDecoder()->getX();
_y = getDecoder()->getY();
} else {
@ -56,7 +62,7 @@ void SmushPlayer::init() {
}
void SmushPlayer::handleFrame() {
if (g_grim->getGameFlags() & ADGF_DEMO) {
if (_demo) {
_x = getDecoder()->getX();
_y = getDecoder()->getY();
}

View File

@ -33,13 +33,15 @@ class SmushDecoder;
class SmushPlayer : public MoviePlayer {
public:
SmushPlayer();
SmushPlayer(bool demo);
void restoreState(SaveGame *state);
private:
bool loadFile(Common::String filename);
void handleFrame();
SmushDecoder* getDecoder();
void init();
bool _demo;
};
} // end of namespace Grim