Files
GDevelop/Extensions/VideoObject/VideoWrapper.cpp
T
Florian cf1c037c00 Added VideoWrapper to abstract video operations and copy behaviour.
VideoObject uses now LoadRuntimeResources function to load the video only if necessary.

git-svn-id: svn://localhost@244 8062f311-0dae-4547-b526-b8ab9ac864a5
2010-09-16 20:38:58 +00:00

79 lines
1.9 KiB
C++

#include "VideoWrapper.h"
#include <iostream>
VideoWrapper::VideoWrapper() :
clip(NULL),
started(false)
{
if ( TheoraVideoManager::getSingletonPtr() == NULL )
new TheoraVideoManager;
currentFrameImage.Create(100,100, sf::Color(100,100,100));
}
VideoWrapper::~VideoWrapper()
{
if ( clip ) TheoraVideoManager::getSingletonPtr()->destroyVideoClip(clip);
}
void VideoWrapper::Init(const VideoWrapper & other)
{
if ( TheoraVideoManager::getSingletonPtr() == NULL )
new TheoraVideoManager;
if ( clip ) TheoraVideoManager::getSingletonPtr()->destroyVideoClip(clip);
clip = NULL;
started = false;
}
bool VideoWrapper::Load(std::string filename)
{
//Destroy old clip if necessary
if ( clip ) TheoraVideoManager::getSingletonPtr()->destroyVideoClip(clip);
//Load new clip
clip = TheoraVideoManager::getSingletonPtr()->createVideoClip(filename, TH_RGBA);
if ( clip )
{
clip->setAutoRestart(1);
currentFrameImage.Create(clip->getWidth(), clip->getHeight(), sf::Color(0,0,0));
}
else //Something failed
{
currentFrameImage.Create(50, 50, sf::Color(255,0,0));
return false;
}
return true;
}
void VideoWrapper::UpdateTime(float time_increase)
{
if ( clip == NULL ) return;
if (started)
{
// let's wait until the system caches up a few frames on startup
if (clip->getNumReadyFrames() < clip->getNumPrecachedFrames()*0.5f)
return;
started=false;
}
TheoraVideoManager::getSingletonPtr()->update(time_increase);
}
const sf::Image & VideoWrapper::GetNextFrameImage()
{
if ( clip != NULL )
{
TheoraVideoFrame* f=clip->getNextFrame();
if (f)
{
currentFrameImage.LoadFromPixels(f->getWidth(), f->getHeight(), f->getBuffer());
clip->popFrame();
}
}
return currentFrameImage;
}