Skip to content

Commit

Permalink
ACCESS: Implemented playVideo
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 29, 2014
1 parent 819cad3 commit e57d7e8
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 28 deletions.
2 changes: 0 additions & 2 deletions engines/access/access.cpp
Expand Up @@ -71,7 +71,6 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_scaleI = 0;
_scaleFlag = false;
_eseg = nullptr;
_plotBuffer = nullptr;

_conversation = 0;
_currentMan = 0;
Expand Down Expand Up @@ -130,7 +129,6 @@ AccessEngine::~AccessEngine() {
delete _music;
delete _title;
delete _eseg;
delete _plotBuffer;
}

void AccessEngine::setVGA() {
Expand Down
1 change: 0 additions & 1 deletion engines/access/access.h
Expand Up @@ -129,7 +129,6 @@ class AccessEngine : public Engine {
ASurface *_current;
ASurface _buffer1;
ASurface _buffer2;
byte *_plotBuffer;
Common::Array<CharEntry *> _charTable;
SpriteResource *_objectsTable[100];
bool _establishTable[100];
Expand Down
22 changes: 16 additions & 6 deletions engines/access/scripts.cpp
Expand Up @@ -103,7 +103,7 @@ void Scripts::executeCommand(int commandIndex) {
&Scripts::cmdRetNeg, &Scripts::cmdRetPos, &Scripts::cmdCheckLoc,
&Scripts::cmdSetAnim, &Scripts::cmdDispInv, &Scripts::cmdSetTimer,
&Scripts::cmdSetTimer, &Scripts::cmdCheckTimer, &Scripts::cmdSetTravel,
&Scripts::cmdSetTravel, &Scripts::cmdSetVideo, &Scripts::CMDPLAYVID,
&Scripts::cmdSetTravel, &Scripts::cmdSetVideo, &Scripts::cmdPlayVideo,
&Scripts::cmdPlotImage, &Scripts::cmdSetDisplay, &Scripts::cmdSetBuffer,
&Scripts::cmdSetScroll, &Scripts::CMDSAVERECT, &Scripts::CMDSAVERECT,
&Scripts::CMDSETBUFVID, &Scripts::CMDPLAYBUFVID, &Scripts::cmdRemoveLast,
Expand All @@ -112,7 +112,7 @@ void Scripts::executeCommand(int commandIndex) {
&Scripts::cmdTexSpeak, &Scripts::cmdTexChoice, &Scripts::CMDWAIT,
&Scripts::cmdSetConPos, &Scripts::CMDCHECKVFRAME, &Scripts::cmdJumpChoice,
&Scripts::cmdReturnChoice, &Scripts::cmdClearBlock, &Scripts::cmdLoadSound,
&Scripts::CMDFREESOUND, &Scripts::cmdSetVideoSound, &Scripts::CMDPLAYVIDSND,
&Scripts::CMDFREESOUND, &Scripts::cmdSetVideoSound, &Scripts::cmdPlayVideoSound,
&Scripts::CMDPUSHLOCATION, &Scripts::CMDPUSHLOCATION, &Scripts::CMDPUSHLOCATION,
&Scripts::CMDPUSHLOCATION, &Scripts::CMDPUSHLOCATION, &Scripts::cmdPlayerOff,
&Scripts::cmdPlayerOn, &Scripts::CMDDEAD, &Scripts::cmdFadeOut,
Expand Down Expand Up @@ -426,7 +426,9 @@ void Scripts::cmdSetVideo() {
_vm->_video->setVideo(_vm->_screen, pt, _vm->_extraCells[cellIndex]._vid, rate);
}

void Scripts::CMDPLAYVID() { error("TODO CMDPLAYVID"); }
void Scripts::cmdPlayVideo() {
_vm->_video->playVideo();
}

void Scripts::cmdPlotImage() {
_vm->_destIn = _vm->_current;
Expand Down Expand Up @@ -667,11 +669,19 @@ void Scripts::cmdSetVideoSound() {
cmdSetVideo();

_data->skip(2);
_vm->_sound->_soundFrame = _data->readUint16LE();
_vm->_sound->_soundFlag = false;
_vm->_video->_soundFrame = _data->readUint16LE();
_vm->_video->_soundFlag = false;
}

void Scripts::cmdPlayVideoSound() {
_vm->_video->playVideo();
if (_vm->_video->_soundFrame == _vm->_video->_videoFrame &&
!_vm->_video->_soundFlag) {
_vm->_sound->playSound(0);
_vm->_video->_soundFlag = true;
}
}

void Scripts::CMDPLAYVIDSND() { error("TODO CMDPLAYVIDSND"); }
void Scripts::CMDPUSHLOCATION() { error("TODO CMDPUSHLOCATION"); }

void Scripts::cmdPlayerOff() {
Expand Down
4 changes: 2 additions & 2 deletions engines/access/scripts.h
Expand Up @@ -91,7 +91,7 @@ class Scripts: public Manager {
void cmdCheckTimer();
void cmdSetTravel();
void cmdSetVideo();
void CMDPLAYVID();
void cmdPlayVideo();
void cmdPlotImage();
void cmdSetDisplay();
void cmdSetBuffer();
Expand All @@ -114,7 +114,7 @@ class Scripts: public Manager {
void cmdClearBlock();
void cmdLoadSound();
void cmdSetVideoSound();
void CMDPLAYVIDSND();
void cmdPlayVideoSound();
void CMDPUSHLOCATION();
void cmdPlayerOff();
void cmdPlayerOn();
Expand Down
2 changes: 0 additions & 2 deletions engines/access/sound.cpp
Expand Up @@ -35,8 +35,6 @@ SoundManager::SoundManager(AccessEngine *vm, Audio::Mixer *mixer) :

_music = nullptr;
_musicRepeat = false;
_soundFrame = 0;
_soundFlag = false;
}

SoundManager::~SoundManager() {
Expand Down
2 changes: 0 additions & 2 deletions engines/access/sound.h
Expand Up @@ -45,8 +45,6 @@ class SoundManager {
int _soundPriority[MAX_SOUNDS];
Resource *_music;
bool _musicRepeat;
int _soundFrame;
bool _soundFlag;
public:
SoundManager(AccessEngine *vm, Audio::Mixer *mixer);
~SoundManager();
Expand Down
49 changes: 40 additions & 9 deletions engines/access/video.cpp
Expand Up @@ -27,10 +27,13 @@ namespace Access {

VideoPlayer::VideoPlayer(AccessEngine *vm) : Manager(vm) {
_vidSurface = nullptr;
_videoFrame = 0;
_soundFlag = false;
_soundFrame = 0;
}

VideoPlayer::~VideoPlayer() {
freeVideo();
closeVideo();
}


Expand All @@ -55,45 +58,73 @@ void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, FileId
_frameCount = _header._frameCount - 2;
_xCount = _header._width;
_scanCount = _header._height;
_vidFrame = 0;
_videoFrame = 0;

getFrame();

if (_header._flags == VIDEOFLAG_BG) {
// Draw the background
const byte *pSrc = _vm->_plotBuffer;
for (int y = 0; y < _scanCount; ++y) {
byte *pDest = (byte *)vidSurface->getBasePtr(pt.x, pt.y + y);
Common::copy(pSrc, pSrc + _xCount, pDest);
pSrc += _xCount;
_videoData->_stream->read(pDest, _xCount);
}

if (vidSurface == _vm->_screen)
_vm->_newRects.push_back(Common::Rect(pt.x, pt.y, pt.x + _xCount, pt.y + _scanCount));



getFrame();
}

_videoEnd = false;
}

void VideoPlayer::freeVideo() {
void VideoPlayer::closeVideo() {
delete _videoData;
_videoData = nullptr;
}

void VideoPlayer::getFrame() {
_frameSize = _videoData->_stream->readUint16LE();
_videoData->_stream->read(_vm->_plotBuffer, _frameSize);
}

void VideoPlayer::playVideo() {
if (_vm->_timers[31]._flag)
return;
++_vm->_timers[31]._flag;

byte *pDest = _startCoord;
byte *pLine = _startCoord;
uint32 frameEnd = _videoData->_stream->pos() + _frameSize;

while ((uint32)_videoData->_stream->pos() < frameEnd) {
int count = _videoData->_stream->readByte();

if (count & 0x80) {
count &= 0x7f;

// Skip count number of pixels
// Loop across lines if necessary
while ((pDest - pLine + count) >= _xCount) {
pLine += _vidSurface->pitch;
pDest = pLine;
count -= _xCount;
}

// Skip any remaining pixels in the new line
pDest += count;
} else {
// Readcount number of pixels
assert(count <= (pDest - pLine));
_videoData->_stream->read(pDest, count);
pDest += count;
}
}

getFrame();
if (++_videoFrame == _frameCount) {
closeVideo();
_videoEnd = true;
}
}


Expand Down
20 changes: 16 additions & 4 deletions engines/access/video.h
Expand Up @@ -47,20 +47,32 @@ class VideoPlayer: public Manager {
int _frameCount;
int _xCount;
int _scanCount;
int _vidFrame;
int _frameSize;
bool _videoEnd;

void getFrame();

void playVideo();
public:
int _videoFrame;
bool _soundFlag;
int _soundFrame;
public:
VideoPlayer(AccessEngine *vm);
~VideoPlayer();

/**
* Start up a video
*/
void setVideo(ASurface *vidSurface, const Common::Point &pt, FileIdent &videoFile, int rate);

void freeVideo();
/**
* Decodes a frame of the video
*/
void playVideo();

/**
* Frees the data for a previously loaded video
*/
void closeVideo();
};

} // End of namespace Access
Expand Down

0 comments on commit e57d7e8

Please sign in to comment.