aboutsummaryrefslogtreecommitdiff
path: root/engines/zvision/scripting
diff options
context:
space:
mode:
authorMatthew Hoops2014-12-28 04:43:22 -0500
committerMatthew Hoops2014-12-28 04:43:22 -0500
commitd0ac19062526e5617d08b587e64aee00fd395876 (patch)
tree0af6e1fdc811ceeb146f2f283418c9ef8b2f1779 /engines/zvision/scripting
parent329c9386c6db79b3c52fbd6712f3ae1718d04c1f (diff)
downloadscummvm-rg350-d0ac19062526e5617d08b587e64aee00fd395876.tar.gz
scummvm-rg350-d0ac19062526e5617d08b587e64aee00fd395876.tar.bz2
scummvm-rg350-d0ac19062526e5617d08b587e64aee00fd395876.zip
ZVISION: Use VideoDecoder facilities better in AnimationNode
setEndFrame() will ensure the audio stops when it is supposed to. Also removes the hack of retrieving the frame rate through the getDuration()'s timestamp return value. Thanks to md5 for testing
Diffstat (limited to 'engines/zvision/scripting')
-rw-r--r--engines/zvision/scripting/sidefx/animation_node.cpp99
-rw-r--r--engines/zvision/scripting/sidefx/animation_node.h2
2 files changed, 54 insertions, 47 deletions
diff --git a/engines/zvision/scripting/sidefx/animation_node.cpp b/engines/zvision/scripting/sidefx/animation_node.cpp
index 3dd80f3699..1657a6e0ec 100644
--- a/engines/zvision/scripting/sidefx/animation_node.cpp
+++ b/engines/zvision/scripting/sidefx/animation_node.cpp
@@ -40,19 +40,18 @@ AnimationNode::AnimationNode(ZVision *engine, uint32 controlKey, const Common::S
_animation(NULL) {
_animation = engine->loadAnimation(fileName);
+ _animation->start();
- if (fileName.hasSuffix(".rlf"))
- _frmDelay = _animation->getTimeToNextFrame();
- else
- _frmDelay = Common::Rational(1000, _animation->getDuration().framerate()).toInt();
+ if (frate > 0) {
+ _frmDelayOverride = (int32)(1000.0 / frate);
- if (frate > 0)
- _frmDelay = 1000.0 / frate;
-
- // WORKAROUND: We do not allow the engine to delay more than 66 msec
- // per frame (15fps max)
- if (_frmDelay > 66)
- _frmDelay = 66;
+ // WORKAROUND: We do not allow the engine to delay more than 66 msec
+ // per frame (15fps max)
+ if (_frmDelayOverride > 66)
+ _frmDelayOverride = 66;
+ } else {
+ _frmDelayOverride = 0;
+ }
}
AnimationNode::~AnimationNode() {
@@ -90,44 +89,52 @@ bool AnimationNode::process(uint32 deltaTimeInMillis) {
if (it != _playList.end()) {
playnode *nod = &(*it);
- nod->_delay -= deltaTimeInMillis;
- if (nod->_delay <= 0) {
- nod->_delay += _frmDelay;
-
- const Graphics::Surface *frame = NULL;
-
- if (nod->_curFrame == -1) { // Start of new playlist node
- nod->_curFrame = nod->start;
-
- _animation->seekToFrame(nod->_curFrame);
- frame = _animation->decodeNextFrame();
-
- nod->_delay = _frmDelay;
- if (nod->slot)
- scriptManager->setStateValue(nod->slot, 1);
- } else {
- nod->_curFrame++;
-
- if (nod->_curFrame > nod->stop) {
- nod->loop--;
-
- if (nod->loop == 0) {
- if (nod->slot >= 0)
- scriptManager->setStateValue(nod->slot, 2);
- if (nod->_scaled) {
- nod->_scaled->free();
- delete nod->_scaled;
- }
- _playList.erase(it);
- return _DisposeAfterUse;
- }
-
- nod->_curFrame = nod->start;
- _animation->seekToFrame(nod->_curFrame);
+ if (nod->_curFrame == -1) {
+ // The node is just beginning playback
+ nod->_curFrame = nod->start;
+
+ _animation->seekToFrame(nod->start);
+ _animation->setEndFrame(nod->stop);
+
+ nod->_delay = deltaTimeInMillis; // Force the frame to draw
+ if (nod->slot)
+ scriptManager->setStateValue(nod->slot, 1);
+ } else if (_animation->endOfVideo()) {
+ // The node has reached the end; check if we need to loop
+ nod->loop--;
+
+ if (nod->loop == 0) {
+ if (nod->slot >= 0)
+ scriptManager->setStateValue(nod->slot, 2);
+ if (nod->_scaled) {
+ nod->_scaled->free();
+ delete nod->_scaled;
}
+ _playList.erase(it);
+ return _DisposeAfterUse;
+ }
- frame = _animation->decodeNextFrame();
+ nod->_curFrame = nod->start;
+ _animation->seekToFrame(nod->start);
+ }
+
+ // Check if we need to draw a frame
+ bool needsUpdate = false;
+ if (_frmDelayOverride == 0) {
+ // If not overridden, use the VideoDecoder's check
+ needsUpdate = _animation->needsUpdate();
+ } else {
+ // Otherwise, implement our own timing
+ nod->_delay -= deltaTimeInMillis;
+
+ if (nod->_delay <= 0) {
+ nod->_delay += _frmDelayOverride;
+ needsUpdate = true;
}
+ }
+
+ if (needsUpdate) {
+ const Graphics::Surface *frame = _animation->decodeNextFrame();
if (frame) {
uint32 dstw;
diff --git a/engines/zvision/scripting/sidefx/animation_node.h b/engines/zvision/scripting/sidefx/animation_node.h
index 368f0291fd..64270ebc79 100644
--- a/engines/zvision/scripting/sidefx/animation_node.h
+++ b/engines/zvision/scripting/sidefx/animation_node.h
@@ -64,7 +64,7 @@ private:
bool _DisposeAfterUse;
Video::VideoDecoder *_animation;
- int32 _frmDelay;
+ int32 _frmDelayOverride;
public:
bool process(uint32 deltaTimeInMillis);