From b0804734e577d58c7b514b9df8893d2d187e6b7d Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 1 May 2015 03:03:44 +0200 Subject: [PATCH] Port VideoWidget --- apps/openmw/engine.cpp | 2 +- apps/openmw/mwgui/videowidget.cpp | 41 ++++++++++++++----- apps/openmw/mwgui/videowidget.hpp | 16 ++++++-- apps/openmw/mwgui/windowmanagerimp.cpp | 37 ++++++++--------- apps/openmw/mwgui/windowmanagerimp.hpp | 1 + extern/osg-ffmpeg-videoplayer/videoplayer.cpp | 8 ++-- 6 files changed, 65 insertions(+), 40 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 488c94501..0abb43cfd 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -468,7 +468,7 @@ void OMW::Engine::go() mViewer->realize(); osg::Timer frameTimer; - while (!mViewer->done()) + while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { double dt = frameTimer.time_s(); frameTimer.setStartTick(); diff --git a/apps/openmw/mwgui/videowidget.cpp b/apps/openmw/mwgui/videowidget.cpp index 28771f14f..13fabfeed 100644 --- a/apps/openmw/mwgui/videowidget.cpp +++ b/apps/openmw/mwgui/videowidget.cpp @@ -1,51 +1,70 @@ #include "videowidget.hpp" -//#include +#include #include -//#include "../mwsound/movieaudiofactory.hpp" +#include + +#include +#include + +#include "../mwsound/movieaudiofactory.hpp" namespace MWGui { VideoWidget::VideoWidget() + : mVFS(NULL) { - //mPlayer.reset(new Video::VideoPlayer()); + mPlayer.reset(new Video::VideoPlayer()); setNeedKeyFocus(true); } +void VideoWidget::setVFS(const VFS::Manager *vfs) +{ + mVFS = vfs; +} + void VideoWidget::playVideo(const std::string &video) { - //mPlayer->setAudioFactory(new MWSound::MovieAudioFactory()); - //mPlayer->playVideo(video); + mPlayer->setAudioFactory(new MWSound::MovieAudioFactory()); + + mPlayer->playVideo(mVFS->get(video)); + + osg::ref_ptr texture = mPlayer->getVideoTexture(); + if (!texture) + return; + + mTexture.reset(new osgMyGUI::OSGTexture(texture)); - //setImageTexture(mPlayer->getTextureName()); + setRenderItemTexture(mTexture.get()); + getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f)); } int VideoWidget::getVideoWidth() { - return 0;//mPlayer->getVideoWidth(); + return mPlayer->getVideoWidth(); } int VideoWidget::getVideoHeight() { - return 0;//mPlayer->getVideoHeight(); + return mPlayer->getVideoHeight(); } bool VideoWidget::update() { - return 0;//mPlayer->update(); + return mPlayer->update(); } void VideoWidget::stop() { - //mPlayer->close(); + mPlayer->close(); } bool VideoWidget::hasAudioStream() { - return 0;//mPlayer->hasAudioStream(); + return mPlayer->hasAudioStream(); } void VideoWidget::autoResize(bool stretch) diff --git a/apps/openmw/mwgui/videowidget.hpp b/apps/openmw/mwgui/videowidget.hpp index 75aa6e98a..6b265628e 100644 --- a/apps/openmw/mwgui/videowidget.hpp +++ b/apps/openmw/mwgui/videowidget.hpp @@ -1,26 +1,34 @@ #ifndef OPENMW_MWGUI_VIDEOWIDGET_H #define OPENMW_MWGUI_VIDEOWIDGET_H -#include +#include namespace Video { class VideoPlayer; } +namespace VFS +{ + class Manager; +} + namespace MWGui { /** * Widget that plays a video. */ - class VideoWidget : public MyGUI::ImageBox + class VideoWidget : public MyGUI::Widget { public: MYGUI_RTTI_DERIVED(VideoWidget) VideoWidget(); + /// Set the VFS (virtual file system) to find the videos on. + void setVFS(const VFS::Manager* vfs); + void playVideo (const std::string& video); int getVideoWidth(); @@ -42,7 +50,9 @@ namespace MWGui void autoResize (bool stretch); private: - //std::auto_ptr mPlayer; + const VFS::Manager* mVFS; + std::auto_ptr mTexture; + std::auto_ptr mPlayer; }; } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index cf7475d5c..7ce8d6200 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -3,9 +3,7 @@ #include #include -#include -#include -#include +#include #include #include @@ -38,6 +36,8 @@ #include "../mwbase/inputmanager.hpp" #include "../mwbase/statemanager.hpp" +#include "../mwrender/vismask.hpp" + #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" #include "../mwworld/cellstore.hpp" @@ -102,7 +102,8 @@ namespace MWGui osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem , const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map& fallbackMap) - : mConsoleOnlyScripts(consoleOnlyScripts) + : mViewer(viewer) + , mConsoleOnlyScripts(consoleOnlyScripts) , mHud(NULL) , mMap(NULL) , mMenu(NULL) @@ -236,6 +237,7 @@ namespace MWGui mVideoWidget = mVideoBackground->createWidgetReal("ImageBox", 0,0,1,1, MyGUI::Align::Default); mVideoWidget->setNeedMouseFocus(true); mVideoWidget->setNeedKeyFocus(true); + mVideoWidget->setVFS(resourceSystem->getVFS()); // Removes default MyGUI system clipboard implementation, which supports windows only MyGUI::ClipboardManager::getInstance().eventClipboardChanged.clear(); @@ -1127,8 +1129,8 @@ namespace MWGui mGuiModes.push_back(mode); - bool gameMode = !isGuiMode(); - MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode); + //bool gameMode = !isGuiMode(); + //MWBase::Environment::get().getInputManager()->changeInputMode(!gameMode); updateVisible(); } @@ -1683,7 +1685,6 @@ namespace MWGui void WindowManager::playVideo(const std::string &name, bool allowSkipping) { - return; mVideoWidget->playVideo("video\\" + name); mVideoWidget->eventKeyButtonPressed.clear(); @@ -1695,16 +1696,10 @@ namespace MWGui } // Turn off all rendering except for the GUI - /* - mRendering->getScene()->clearSpecialCaseRenderQueues(); - // SCRQM_INCLUDE with RENDER_QUEUE_OVERLAY does not work? - for(int i = 0;i < Ogre::RENDER_QUEUE_MAX;++i) - { - if(i > 0 && i < 96) - mRendering->getScene()->addSpecialCaseRenderQueue(i); - } - mRendering->getScene()->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); - */ + int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask(); + int oldCullMask = mViewer->getCamera()->getCullMask(); + mViewer->getUpdateVisitor()->setTraversalMask(MWRender::Mask_GUI); + mViewer->getCamera()->setCullMask(MWRender::Mask_GUI); MyGUI::IntSize screenSize = MyGUI::RenderManager::getInstance().getViewSize(); sizeVideo(screenSize.width, screenSize.height); @@ -1722,9 +1717,9 @@ namespace MWGui while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { - MWBase::Environment::get().getInputManager()->update(0, true, false); + //MWBase::Environment::get().getInputManager()->update(0, true, false); - //mRendering->getWindow()->update(); + mViewer->frame(); } mVideoWidget->stop(); @@ -1733,8 +1728,8 @@ namespace MWGui setCursorVisible(cursorWasVisible); // Restore normal rendering - //mRendering->getScene()->clearSpecialCaseRenderQueues(); - //mRendering->getScene()->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE); + mViewer->getUpdateVisitor()->setTraversalMask(oldUpdateMask); + mViewer->getCamera()->setCullMask(oldCullMask); mVideoBackground->setVisible(false); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index ec99364c7..3a6f3b024 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -360,6 +360,7 @@ namespace MWGui private: osgMyGUI::Platform* mGuiPlatform; + osgViewer::Viewer* mViewer; std::auto_ptr mFontLoader; diff --git a/extern/osg-ffmpeg-videoplayer/videoplayer.cpp b/extern/osg-ffmpeg-videoplayer/videoplayer.cpp index 8dedeaf64..1336e45a3 100644 --- a/extern/osg-ffmpeg-videoplayer/videoplayer.cpp +++ b/extern/osg-ffmpeg-videoplayer/videoplayer.cpp @@ -65,16 +65,16 @@ osg::ref_ptr VideoPlayer::getVideoTexture() int VideoPlayer::getVideoWidth() { int width=0; - if (mState && mState->mTexture.get()) - width = mState->mTexture->getTextureWidth(); + if (mState && mState->mTexture.get() && mState->mTexture->getImage()) + width = mState->mTexture->getImage()->s(); return width; } int VideoPlayer::getVideoHeight() { int height=0; - if (mState && mState->mTexture.get()) - height = mState->mTexture->getTextureHeight(); + if (mState && mState->mTexture.get() && mState->mTexture->getImage()) + height = mState->mTexture->getImage()->t(); return height; }