📄 movielogic.cpp
字号:
#include "OgrePrerequisites.h"
#include "CEGUI.h"
#include "renderers/OgreGUIRenderer/ogrerenderer.h"
#include "MovieLogic.h"
#include "OgreLogManager.h"
#include "OgreTexture.h"
#include "OgreTextureManager.h"
#include "OgreMaterialManager.h"
#include "OgreTechnique.h"
#include "OgreExternalTextureSourceManager.h"
namespace Ogre
{
/*************************************************************************
Sample sub-class for ListboxTextItem that auto-sets the selection brush
image.
*************************************************************************/
class MyListItem : public CEGUI::ListboxTextItem
{
public:
MyListItem(const CEGUI::String& text) : ListboxTextItem(text)
{
setSelectionBrushImage((CEGUI::utf8*)"TaharezImagery", (CEGUI::utf8*)"MultiListSelectionBrush");
}
};
//-------------------------------------------------------------------------//
MovieLogic::MovieLogic( CEGUI::OgreRenderer *renderer ) : mPaused(true)
{
mVideoControl = static_cast<TheoraVideoController*>(ExternalTextureSourceManager::getSingleton().getExternalTextureSource("ogg_video"));
if( !mVideoControl )
throw;
mGUIRenderer = renderer;
mText = 0;
}
//-------------------------------------------------------------------------//
MovieLogic::~MovieLogic()
{
//Stop the clip before we delete our sound system, or else
//it will result in thread errors.
TheoraMovieClip *pClip;
//Get movie clip
pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
//NOTE: If using audio, you must delete the movie before you delete the
//sound class, perhaps a unregisterAudio method will be added to resolve
//that problem
if( pClip )
{
pClip->changePlayMode( TextureEffectPause );
mVideoControl->DestroyAdvancedTexture( "Example/TheoraVideoPlayer/Play" );
}
mSoundSystem.destroyAudioClip();
}
//-------------------------------------------------------------------------//
unsigned int MovieLogic::getWidth()
{
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
return pClip->getVideoDriver()->getWidth();
}
//-------------------------------------------------------------------------//
unsigned int MovieLogic::getHeight()
{
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
return pClip->getVideoDriver()->getHeight();
}
//-------------------------------------------------------------------------//
void MovieLogic::createCETexture()
{
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
if( pClip )
{
//mCurrentMoviePlaying should have texture name (most likely path+filename)
//mText = mGUIRenderer->createTexture( mCurrentMoviePlaying );
mText = mGUIRenderer->createTexture( pClip->getVideoDriver()->getTexture() );
}
}
//-------------------------------------------------------------------------//
void MovieLogic::destroyCETexture()
{
//if( mText )
// mGUIRenderer->destroyTexture( mText );
mText = 0;
}
//-------------------------------------------------------------------------//
void MovieLogic::populateListBox( CEGUI::Listbox *listBox )
{
//Get a set (because duplicates are ignored) of FileNames of these two types
//We are not worried about path info because the PlugIn should sort that out
std::set< String > OGG_MovieList = ResourceManager::_getAllCommonNamesLike( "./", "ogg" );
std::set< String >::iterator i;
//Not worried about new - StringResource handles deletion
for( i = OGG_MovieList.begin(); i != OGG_MovieList.end(); ++i )
listBox->addItem(new MyListItem( (*i) ));
}
//-------------------------------------------------------------------------//
void MovieLogic::stopMovie()
{
mPaused = true;
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
if( pClip )
{
pClip->changePlayMode( TextureEffectPause );
mVideoControl->DestroyAdvancedTexture( "Example/TheoraVideoPlayer/Play" );
mSoundSystem.destroyAudioClip();
}
}
//-------------------------------------------------------------------------//
void MovieLogic::pauseMovie( bool bPause )
{
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
if( mPaused == bPause )
return;
if( pClip )
{
if( mPaused == false )
pClip->changePlayMode( TextureEffectPause );
else
pClip->changePlayMode( TextureEffectPlay_ASAP );
mPaused = !mPaused;
}
}
//-------------------------------------------------------------------------//
void MovieLogic::playMovie( const String& movieName )
{
TheoraMovieClip *pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
//Tear down current movie if any
mPaused = true;
if( pClip )
{
destroyCETexture();
pClip->changePlayMode( TextureEffectPause );
mVideoControl->DestroyAdvancedTexture( "Example/TheoraVideoPlayer/Play" );
mSoundSystem.destroyAudioClip();
}
//Sets an input file name - needed by plugin
mVideoControl->setInputName( movieName );
//Start paused so we can have audio
mVideoControl->setPlayMode( TextureEffectPause );
//! Used for attaching texture to Technique, State, and texture unit layer
mVideoControl->setTextureTecPassStateLevel( 0, 0, 0 );
// Grab Our material, then add a new texture unit
bool bSucceed = true;
Material *material = 0;
try
{
material = static_cast<Material*>(MaterialManager::getSingleton().getByName("Example/TheoraVideoPlayer/Play"));
if( !material )
bSucceed = false;
}
catch(...)
{
bSucceed = false;
}
if( !bSucceed )
{
//Looks like material wasn't found, so create a new one here
material = static_cast<Material*>(MaterialManager::getSingleton().create("Example/TheoraVideoPlayer/Play"));
if( !material )
return; //Some wierd error
material->createTechnique()->createPass();
}
material->getTechnique(0)->getPass(0)->createTextureUnitState();
mVideoControl->createDefinedTexture( "Example/TheoraVideoPlayer/Play" );
pClip = mVideoControl->getMaterialNameClip( "Example/TheoraVideoPlayer/Play" );
//Same process, register, add audio, start playback
pClip->registerMessageHandler( this );
pClip->setAudioDriver( mSoundSystem.getAudioClip() );
pClip->changePlayMode( TextureEffectPlay_ASAP );
//Movie name is the texture name
mCurrentMoviePlaying = pClip->getMovieName();
createCETexture();
mPaused = false;
}
//-------------------------------------------------------------------------//
int MovieLogic::messageEvent( PLUGIN_theora_message m )
{
switch( m )
{
case TH_TheoraStreamDone:
//Signal that movie video packets reached end
LogManager::getSingleton().logMessage("Video Packets empty");
break;
case TH_VorbisStreamDone:
//Signal that movie audio packets reached end
LogManager::getSingleton().logMessage("Audio Packets empty");
case TH_OggStreamDone:
//Signal that movie reached end
LogManager::getSingleton().logMessage("End of movie file reached");
break;
}
return 0;
}
//-------------------------------------------------------------------------//
void MovieLogic::displayedFrame( float vTime,
float aTime,
unsigned int frameNumber,
unsigned int framesDropped )
{
// mImg->setImage( (CEGUI::utf8*)"MyImages", mCurrentMoviePlaying );
// GuiElement* guiTemp;
// guiTemp = GuiManager::getSingleton().getGuiElement("Theora/PlayList/VStream");
// guiTemp->setCaption( StringConverter::toString(vTime) );
// guiTemp = GuiManager::getSingleton().getGuiElement("Theora/PlayList/AStream");
// guiTemp->setCaption( StringConverter::toString(aTime) );
// guiTemp = GuiManager::getSingleton().getGuiElement("Theora/PlayList/FrameNum");
// guiTemp->setCaption( StringConverter::toString(frameNumber) );
// guiTemp = GuiManager::getSingleton().getGuiElement("Theora/PlayList/FramesDropped");
// guiTemp->setCaption( StringConverter::toString(framesDropped) );
}
} //end Ogre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -