Skip to content

Commit

Permalink
TITANIC: Support cutscene frame counting beyond end of video
Browse files Browse the repository at this point in the history
The intro credits cutscene at least, uses an end frame beyond the
video as a way of adding an extra delay after the video finishes
  • Loading branch information
dreammaster committed Oct 30, 2016
1 parent 31fd315 commit 5348f4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 18 additions & 4 deletions engines/titanic/support/avi_surface.cpp
Expand Up @@ -41,6 +41,7 @@ AVISurface::AVISurface(const CResourceKey &key) {
_streamCount = 0;
_movieFrameSurface[0] = _movieFrameSurface[1] = nullptr;
_framePixels = nullptr;
_priorFrameTime = 0;

// Reset current frame. We need to keep track of frames separately from the decoder,
// since it needs to be able to go beyond the frame count or to negative to allow
Expand Down Expand Up @@ -287,8 +288,20 @@ void AVISurface::setFrame(int frameNumber) {
renderFrame();
}

bool AVISurface::isNextFrame() const {
return _decoder->getTimeToNextFrame() == 0;
bool AVISurface::isNextFrame() {
if (!_decoder->endOfVideo())
return _decoder->getTimeToNextFrame() == 0;

// We're at the end of the video, so we need to manually
// keep track of frame delays. Hardcoded at the moment for 15FPS
const uint FRAME_TIME = 1000 / 15;
uint32 currTime = g_system->getMillis();
if (currTime >= (_priorFrameTime + FRAME_TIME)) {
_priorFrameTime = currTime;
return true;
}

return false;
}

bool AVISurface::renderFrame() {
Expand Down Expand Up @@ -376,11 +389,12 @@ void AVISurface::playCutscene(const Rect &r, uint startFrame, uint endFrame) {
_movieFrameSurface[0]->h != r.height();

startAtFrame(startFrame);
_currentFrame = startFrame;

while (_currentFrame < (int)endFrame && !g_vm->shouldQuit()) {
if (isNextFrame()) {
renderFrame();
_currentFrame = _decoder->endOfVideo() ? _decoder->getFrameCount() :
_decoder->getCurFrame();
++_currentFrame;

if (isDifferent) {
// Clear the destination area, and use the transBlitFrom method,
Expand Down
3 changes: 2 additions & 1 deletion engines/titanic/support/avi_surface.h
Expand Up @@ -66,6 +66,7 @@ class AVISurface {
Graphics::ManagedSurface *_framePixels;
bool _isReversed;
int _currentFrame;
uint32 _priorFrameTime;
private:
/**
* Render a frame to the video surface
Expand Down Expand Up @@ -196,7 +197,7 @@ class AVISurface {
/**
* Returns true if it's time for the next
*/
bool isNextFrame() const;
bool isNextFrame();

/**
* Plays an interruptable cutscene
Expand Down

0 comments on commit 5348f4f

Please sign in to comment.