bool AVISurface::play(int startFrame, int endFrame, int initialFrame, uint flags, CGameObject *obj) { CMovieRangeInfo *info = new CMovieRangeInfo(); info->_startFrame = startFrame; info->_endFrame = endFrame; info->_isReversed = endFrame < startFrame; info->_initialFrame = 0; info->_isRepeat = flags & MOVIE_REPEAT; if (obj) { CMovieEvent *me = new CMovieEvent(); me->_type = MET_MOVIE_END; me->_startFrame = startFrame; me->_endFrame = endFrame; me->_initialFrame = 0; me->_gameObject = obj; info->addEvent(me); } _movieRangeInfo.push_back(info); if (_movieRangeInfo.size() == 1) { // First play call, so start the movie playing setReversed(info->_isReversed); return startAtFrame(initialFrame); } else { return true; } }
bool AVISurface::handleEvents(CMovieEventList &events) { if (!isPlaying()) return true; CMovieRangeInfo *info = _movieRangeInfo.front(); _priorFrame = _currentFrame; _currentFrame += _isReversed ? -1 : 1; int newFrame = _currentFrame; if ((info->_isReversed && newFrame < info->_endFrame) || (!info->_isReversed && newFrame > info->_endFrame)) { if (info->_isRepeat) { newFrame = info->_startFrame; } else { info->getMovieEnd(events); _movieRangeInfo.remove(info); delete info; if (_movieRangeInfo.empty()) { // No more ranges, so stop playback stop(); } else { // Not empty, so move onto new first one info = _movieRangeInfo.front(); newFrame = info->_startFrame; setReversed(info->_isReversed); } } } if (isPlaying()) { if (newFrame != getFrame()) { // The frame has been changed, so move to new position seekToFrame(newFrame); renderFrame(); } // Get any events for the given position info->getMovieFrame(events, newFrame); return renderFrame(); } else { return false; } }
bool AVISurface::addEvent(int frameNumber, CGameObject *obj) { if (!_movieRangeInfo.empty()) { CMovieRangeInfo *tail = _movieRangeInfo.back(); if (frameNumber == -1) frameNumber = tail->_startFrame; CMovieEvent *me = new CMovieEvent(); me->_type = MET_FRAME; me->_startFrame = 0; me->_endFrame = 0; me->_initialFrame = frameNumber; me->_gameObject = obj; tail->addEvent(me); return _movieRangeInfo.size() == 1 && frameNumber == getFrame(); } return false; }