VOYEUR: Cleanup of doGossip, and better generic video playback code

This commit is contained in:
Paul Gilbert 2014-01-17 21:57:33 -05:00
parent c1657dc278
commit 6b059631ce
3 changed files with 70 additions and 72 deletions

View File

@ -23,6 +23,7 @@
#include "voyeur/animation.h"
#include "voyeur/staticres.h"
#include "voyeur/voyeur.h"
#include "common/endian.h"
#include "common/memstream.h"
#include "common/system.h"
#include "audio/decoders/raw.h"
@ -98,27 +99,6 @@ RL2Decoder::RL2VideoTrack *RL2Decoder::getVideoTrack() {
return (RL2VideoTrack *)track;
}
void RL2Decoder::play(::Voyeur::VoyeurEngine *vm) {
vm->_eventsManager.getMouseInfo();
while (!vm->shouldQuit() && !endOfVideo() && !vm->_eventsManager._mouseClicked) {
if (hasDirtyPalette()) {
const byte *palette = getPalette();
vm->_graphicsManager.setPalette(palette, 0, 256);
}
if (needsUpdate()) {
const Graphics::Surface *frame = decodeNextFrame();
Common::copy((const byte *)frame->getPixels(), (const byte *)frame->getPixels() + 320 * 200,
(byte *)vm->_graphicsManager._screenSurface.getPixels());
}
vm->_eventsManager.getMouseInfo();
g_system->delayMillis(10);
}
}
/*------------------------------------------------------------------------*/
RL2Decoder::RL2FileHeader::RL2FileHeader() {
@ -446,3 +426,45 @@ Audio::QueuingAudioStream *RL2Decoder::RL2AudioTrack::createAudioStream() {
}
} // End of namespace Video
/*------------------------------------------------------------------------*/
namespace Voyeur {
void VoyeurRL2Decoder::play(VoyeurEngine *vm, int resourceOffset, byte *frames, byte *imgPos) {
vm->flipPageAndWait();
PictureResource videoFrame(getVideoTrack()->getBackSurface());
int picCtr = 0;
while (!vm->shouldQuit() && !endOfVideo() && !vm->_eventsManager._mouseClicked) {
if (hasDirtyPalette()) {
const byte *palette = getPalette();
vm->_graphicsManager.setPalette(palette, 128, 128);
}
if (needsUpdate()) {
if (frames) {
// If reached a point where a new background is needed, load it
// and copy over to the video decoder
if (getCurFrame() >= READ_LE_UINT16(frames + picCtr * 4)) {
PictureResource *newPic = vm->_bVoy->boltEntry(0x302 + picCtr)._picResource;
Common::Point pt(READ_LE_UINT16(imgPos + 4 * picCtr) - 32,
READ_LE_UINT16(imgPos + 4 * picCtr + 2) - 20);
vm->_graphicsManager.sDrawPic(newPic, &videoFrame, pt);
++picCtr;
}
// Decode the next frame and display
const Graphics::Surface *frame = decodeNextFrame();
Common::copy((const byte *)frame->getPixels(), (const byte *)frame->getPixels() + 320 * 200,
(byte *)vm->_graphicsManager._screenSurface.getPixels());
}
}
vm->_eventsManager.getMouseInfo();
g_system->delayMillis(10);
}
}
} // End of namespace Video

View File

@ -29,6 +29,7 @@
#include "common/list.h"
#include "common/rect.h"
#include "common/stream.h"
#include "voyeur/files.h"
namespace Voyeur {
@ -156,10 +157,25 @@ public:
void clearDirtyRects();
void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
RL2VideoTrack *getVideoTrack();
void play(::Voyeur::VoyeurEngine *vm);
int getPaletteCount() const { return _header._colorCount; }
};
} // End of namespace Video
namespace Voyeur {
class VoyeurRL2Decoder: public Video::RL2Decoder {
public:
/**
* Play back a given Voyeur RL2 video
* @param vm Engine reference
* @param resourceOffset Starting resource to use for frame pictures
* @param frames Optional frame numbers resource for when to apply image data
* @param imgPos Position to draw image data
*/
void play(VoyeurEngine *vm, int resourceOffset = 0, byte *frames = NULL, byte *imgPos = NULL);
};
}
#endif /* VOYEUR_ANIMATION_H */

View File

@ -230,7 +230,7 @@ void VoyeurEngine::doTailTitle() {
_graphicsManager.screenReset();
if (_bVoy->getBoltGroup(0x600)) {
::Video::RL2Decoder decoder;
VoyeurRL2Decoder decoder;
decoder.loadFile("a1100200.rl2");
decoder.start();
decoder.play(this);
@ -679,10 +679,11 @@ void VoyeurEngine::doGossip() {
return;
// Load the gossip animation
::Video::RL2Decoder decoder;
VoyeurRL2Decoder decoder;
decoder.loadFile("a2050100.rl2");
decoder.start();
// Get the resource data for the first gossip video
PictureResource *bgPic = _bVoy->boltEntry(0x300)._picResource;
CMapResource *pal = _bVoy->boltEntry(0x301)._cMapResource;
pal->startFade();
@ -692,61 +693,20 @@ void VoyeurEngine::doGossip() {
bgPic->_bounds.moveTo(0, 0);
_graphicsManager.sDrawPic(bgPic, &videoFrame, Common::Point(0, 0));
flipPageAndWait();
byte *frameNumsP = _bVoy->memberAddr(0x309);
byte *posP = _bVoy->boltEntry(0x30A)._data;
// Main playback loop
int picCtr = 0;
while (!shouldQuit() && !decoder.endOfVideo() && !_eventsManager._mouseClicked) {
if (decoder.hasDirtyPalette()) {
const byte *palette = decoder.getPalette();
_graphicsManager.setPalette(palette, 128, 128);
}
if (decoder.needsUpdate()) {
// If reached a point where a new background is needed, load it
// and copy over to the video decoder
if (decoder.getCurFrame() >= READ_LE_UINT16(frameNumsP + picCtr * 4)) {
PictureResource *newBgPic = _bVoy->boltEntry(0x302 + picCtr)._picResource;
Common::Point pt(READ_LE_UINT16(posP + 4 * picCtr + 2),
READ_LE_UINT16(posP + 4 * picCtr));
// Play the initial gossip video
decoder.play(this, 0x302, frameNumsP, posP);
_graphicsManager.sDrawPic(newBgPic, &videoFrame, pt);
++picCtr;
}
if (!_eventsManager._mouseClicked) {
// Play further interview
decoder.loadFile("a2110100.rl2");
decoder.start();
// Decode the next frame and display
const Graphics::Surface *frame = decoder.decodeNextFrame();
Common::copy((const byte *)frame->getPixels(), (const byte *)frame->getPixels() + 320 * 200,
(byte *)_graphicsManager._screenSurface.getPixels());
}
_eventsManager.getMouseInfo();
g_system->delayMillis(10);
decoder.play(this);
}
/*
decoder.loadFile("a2110100.rl2");
decoder.start();
while (!shouldQuit() && !decoder.endOfVideo() && !_eventsManager._mouseClicked) {
if (decoder.hasDirtyPalette()) {
const byte *palette = decoder.getPalette();
_graphicsManager.setPalette(palette, 0, 256);
}
if (decoder.needsUpdate()) {
const Graphics::Surface *frame = decoder.decodeNextFrame();
Common::copy((const byte *)frame->getPixels(), (const byte *)frame->getPixels() + 320 * 200,
(byte *)_graphicsManager._screenSurface.getPixels());
}
_eventsManager.pollEvents();
g_system->delayMillis(10);
}
*/
_bVoy->freeBoltGroup(0x300);
_graphicsManager.screenReset();
}