dragonbane

[CryVideo] VideoManager.cpp

Feb 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 32.45 KB | None | 0 0
  1. //Cry Video MOD: NEW VIDEO MANAGER CLASS
  2.  
  3. #include "StdAfx.h"
  4.  
  5. #include <IGameFramework.h>
  6. #include <IRenderer.h>
  7. #include <UIDraw/UIDraw.h>
  8. #include <Actor.h>
  9. #include <IFlashUI.h>
  10. #include "HUD/UIMenuEvents.h"
  11. #include "HUD/UIManager.h"
  12.  
  13. #include <GameCVars.h>
  14. #include "VideoManager.h"
  15. #include "VideoTimer.h"
  16. #include "CryVideo.h"
  17.  
  18. //#include <d3d9.h>
  19. //#include <D3dx9core.h>
  20.  
  21. //#pragma once
  22. //#pragma comment(lib, "d3d9.lib")
  23. //#pragma comment(lib, "d3dx9.lib")
  24.  
  25.  
  26. //////////////////////////////////////////////////////////////////////////
  27. CVideoManager::CVideoManager()
  28. : m_pGameFramework( NULL )
  29. , m_pUiDraw( NULL )
  30. {
  31.     assert( g_pCryVideo != NULL );
  32.  
  33.     isPlaying = false;
  34.     isPaused = false;
  35.     listFilePlaying = false;
  36.     listFileFinished = false;
  37.     stopVideo = false;
  38.     firstStart = true;
  39.     firstStartFinished = false;
  40.     firstStartCounter = 1;
  41.     lastVideoFinishedReason = "None";
  42.     isLoopedVideo = false;
  43.     freezeOnLastFrame = false;
  44.     scheduleUnpause = false;
  45.  
  46.     currentVideoListId = 0;
  47.     master_texture_id = 0;
  48.  
  49.     //Initalisierung der benötigten Komponente  
  50.     //pD3DDevice = static_cast<IDirect3DDevice9 *>(gEnv->pRenderer->EF_Query(EFQ_D3DDevice));
  51.    
  52.     frameCounter = -1;
  53.  
  54.     m_pGameFramework = g_pCryVideo->m_pFramework;
  55.  
  56.     assert( m_pGameFramework != NULL );
  57.     if ( m_pGameFramework == NULL )
  58.     {
  59.         return;
  60.     }
  61.  
  62.     m_pUiDraw = m_pGameFramework->GetIUIDraw();
  63.  
  64.     assert( m_pUiDraw != NULL );
  65.     if ( m_pUiDraw == NULL )
  66.     {
  67.         return;
  68.     }
  69.  
  70.     //Create new OpenCV instance
  71.     m_pCryVideoOpenCV = g_pCryVideo->CreateOpenCVInstance();
  72.  
  73.     m_pGameFramework->RegisterListener( this, "VideoManager", eFLPriority_HUD );
  74.  
  75.     if (gEnv->pInput)
  76.         gEnv->pInput->AddEventListener(this);
  77.  
  78.     if (g_pCryVideo && g_pCryVideo->GetTimerManager())
  79.         g_pCryVideo->GetTimerManager()->RegisterListener(this);
  80.  
  81.     ILevelSystem* pLevelSystem = m_pGameFramework->GetILevelSystem();
  82.     if ( pLevelSystem != NULL )
  83.     {
  84.         pLevelSystem->AddListener(this);
  85.     }
  86.  
  87.     IUIActionManager* pUIActionManager = gEnv->pFlashUI->GetUIActionManager();
  88.     if ( pUIActionManager != NULL )
  89.     {
  90.         pUIActionManager->AddListener(this, "VideoManager");
  91.     }
  92.  
  93.  
  94.     //Test
  95.     /*
  96.     HANDLE hNote;
  97.     bool exit = false;
  98.  
  99.     hNote = g_pCryVideo->ExecuteProcess( "Bin32\\CryVideo\\ffmpeg.exe", "ffmpeg -i Elephants_Dream.WebM -vn TempAudio\\output.mp2", "Game\\Videos\\Library");
  100.     if ( hNote )
  101.     {
  102.         while (!exit)
  103.         {
  104.             DWORD noteExitCode;
  105.             if ( GetExitCodeProcess(hNote , &noteExitCode) )
  106.             {
  107.                 if ( noteExitCode == STILL_ACTIVE )
  108.                 {
  109.                     // immer noch an
  110.                 }
  111.                 else
  112.                 {
  113.                     // Programm beendet
  114.                     CloseHandle( hNote );
  115.                     exit = true;
  116.                 }
  117.             }
  118.         }
  119.     }
  120.     */
  121.  
  122.  
  123. }
  124.  
  125. //////////////////////////////////////////////////////////////////////////
  126. CVideoManager::~CVideoManager()
  127. {
  128.     if ( m_pGameFramework != NULL )
  129.     {
  130.         m_pGameFramework->GetILevelSystem()->RemoveListener( this );
  131.         m_pGameFramework->UnregisterListener( this );
  132.     }
  133.  
  134.     //Kill last Timer
  135.     if (m_TimerID)
  136.         g_pCryVideo->GetTimerManager()->KillTimer(m_TimerID);
  137.  
  138.     if (g_pCryVideo && g_pCryVideo->GetTimerManager())
  139.         g_pCryVideo->GetTimerManager()->UnregisterListener(this);
  140.  
  141.     if (gEnv->pInput)
  142.         gEnv->pInput->RemoveEventListener(this);
  143.  
  144.     if (gEnv->pFlashUI->GetUIActionManager())
  145.         gEnv->pFlashUI->GetUIActionManager()->RemoveListener(this);
  146.  
  147.     if(!m_currentVideoList.empty())
  148.         m_currentVideoList.clear();
  149.    
  150.     //Free OpenCV instance
  151.     SAFE_DELETE(m_pCryVideoOpenCV);
  152. }
  153.  
  154.  
  155. //////////////////////////////////////////////////////////////////////////
  156. bool CVideoManager::PlayVideoList(string videoListName)
  157. {
  158.     if (!IsEnabled() )
  159.     {
  160.         listFileFinished = true;
  161.         listFilePlaying = false;
  162.         isPlaying = false;
  163.         isPaused = false;
  164.  
  165.         return false;
  166.     }
  167.    
  168.     if (listFilePlaying)
  169.     {
  170.         return false;
  171.     }
  172.  
  173.     listFilePlaying = false;
  174.  
  175.     if(!m_currentVideoList.empty())
  176.         m_currentVideoList.clear();
  177.  
  178.     string szVideoListFile = "Videos\\" + videoListName;
  179.     if (szVideoListFile.substr(szVideoListFile.size()-4,4) != ".xml")
  180.     {
  181.         szVideoListFile += ".xml";
  182.     }
  183.  
  184.     XmlNodeRef videoListInfo = GetISystem()->LoadXmlFromFile(szVideoListFile.c_str());
  185.  
  186.     if(videoListInfo == 0)
  187.     {
  188.         GameWarning("Cry Video: Could not load video list xml file: %s", szVideoListFile);
  189.     }
  190.     else
  191.     {
  192.         if(videoListInfo)
  193.         {
  194.             for(int n = 0; n < videoListInfo->getChildCount(); ++n)
  195.             {
  196.                 XmlNodeRef videoNode = videoListInfo->getChild(n);
  197.                 const char* name = videoNode->getTag();
  198.                 if(!stricmp(name, "Video"))
  199.                 {
  200.                     SVideoListInfo info;
  201.                     int attribs = videoNode->getNumAttributes();
  202.                     const char* key;
  203.                     const char* value;
  204.                     for(int i = 0; i < attribs; ++i)
  205.                     {
  206.                         videoNode->getAttributeByIndex(i, &key, &value);
  207.                         if(!stricmp(key,"Name"))
  208.                         {
  209.                             info.videoName = value;
  210.                         }  
  211.                     }
  212.                     m_currentVideoList.push_back(info);
  213.                 }
  214.             }
  215.         }
  216.     }
  217.  
  218.     if (!m_currentVideoList.empty())
  219.     {
  220.         //Try to play first video in list
  221.         bool success = PlaySingleVideo(m_currentVideoList[0].videoName, false);
  222.  
  223.         if (success)
  224.         {
  225.             listFilePlaying = true;
  226.             listFileFinished = false;
  227.             currentVideoListId = 0;
  228.  
  229.             return true;
  230.         }
  231.     }
  232.  
  233.     return false;
  234. }
  235. //////////////////////////////////////////////////////////////////////////
  236. void CVideoManager::PlayNextVideoInList(int listIndex)
  237. {
  238.     if (!IsEnabled() )
  239.     {
  240.         listFileFinished = true;
  241.         listFilePlaying = false;
  242.         isPlaying = false;
  243.         isPaused = false;
  244.         return;
  245.     }
  246.  
  247.     //Try to play next video in list
  248.     if (!m_currentVideoList.empty())
  249.         PlaySingleVideo(m_currentVideoList[listIndex].videoName, false);
  250. }
  251. //////////////////////////////////////////////////////////////////////////
  252. bool CVideoManager::PlaySingleVideo(string videoName, bool ingame, string ingameAudio, float ingameAudioVolume, IEntity* ingameVideoEntity, int slot, int subMtlId, int texSlot, bool loop, bool keepLastFrame)
  253. {
  254.     CryLogAlways("VideoManager: Play Single Video!");
  255.     if (!IsEnabled() )
  256.     {
  257.         isPlaying = false;
  258.         isPaused = false;
  259.         return false;
  260.     }
  261.  
  262.     assert( m_pGameFramework != NULL );
  263.     if ( m_pGameFramework == NULL )
  264.     {
  265.         return false;
  266.     }
  267.  
  268.     assert( m_pUiDraw != NULL );
  269.     if ( m_pUiDraw == NULL )
  270.     {
  271.         return false;
  272.     }
  273.  
  274.     IRenderer* pRenderer = gEnv->pRenderer;
  275.     assert( pRenderer != NULL );
  276.     if ( pRenderer == NULL )
  277.     {
  278.         return false;
  279.     }
  280.  
  281.     //Find video info
  282.     bool bFound = false;
  283.     int iFoundIndex = 0;
  284.  
  285.     if (!g_pCryVideo->m_globalVideoList.empty())
  286.     {
  287.         for(int i=0; i<g_pCryVideo->m_globalVideoList.size(); i++)
  288.         {
  289.             SVideoInfo info = g_pCryVideo->m_globalVideoList[i];
  290.             if (info.videoName.MakeLower() == videoName.MakeLower())
  291.             {
  292.                 //0.9.6: Detect right game folder
  293.                 const char* gameFolder;
  294.                 ICVar *pVar = gEnv->pConsole->GetCVar("sys_game_folder");
  295.                 if (pVar)
  296.                     gameFolder = pVar->GetString();
  297.                 else
  298.                     gameFolder = "Game";
  299.    
  300.                 //Init Video File
  301.                 char fileName[255];
  302.                 sprintf(fileName, "%s/Videos/Library/%s", gameFolder, videoName.MakeLower());
  303.                
  304.                 string fileNameString;
  305.                 fileNameString = fileName;
  306.  
  307.                 bool success = false;
  308.  
  309.                 if (fileNameString.substr(fileNameString.size()-5,5) == ".webm")
  310.                 {
  311.                     videoFormat = 2;
  312.                     success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  313.                     if (!success)
  314.                     {
  315.                         GameWarning("CryVideo: WebM file '%s' couldn't be opened. Retrying!", videoName);
  316.                         success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  317.                     }
  318.                 }
  319.                 else
  320.                 {          
  321.                     videoFormat = 1;
  322.                     success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  323.                     if (!success)
  324.                     {
  325.                         GameWarning("CryVideo: Video file '%s' couldn't be opened. Retrying!", videoName);
  326.                         success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  327.                     }
  328.                 }
  329.                
  330.                 if (!success)
  331.                 {
  332.                     GameWarning("CryVideo: Video file '%s' couldn't be opened. Check file?", videoName);
  333.                 }
  334.                 else
  335.                 {
  336.                     bFound = true;
  337.                     iFoundIndex = i;
  338.                 }
  339.  
  340.                 break;
  341.             }
  342.         }
  343.     }
  344.  
  345.     if (bFound)
  346.     {
  347.         //Set values
  348.         pIngameVideoTargetEntity = ingameVideoEntity;
  349.  
  350.         ingameVideoMaterialSlotId = slot;
  351.         ingameVideoSubMtlId = subMtlId;
  352.         ingameVideoTexSlot = texSlot;
  353.  
  354.         ingameAudioFile = ingameAudio;
  355.         ingameAudioVol = ingameAudioVolume;
  356.         isIngameVideo = ingame;
  357.         isLoopedVideo = loop;
  358.         freezeOnLastFrame = keepLastFrame;
  359.  
  360.         //Alternate Playback mode (WIP!!)
  361.         /*
  362.         bUseSingleFile = false;
  363.         if (gEnv->pCryPak->IsFileExist("Videos/Library/" + videoName + "/" + videoName + ".CVF"))
  364.         {
  365.             videoCryFileCVF = gEnv->pCryPak->FOpen("Videos\\Library\\" + videoName + "\\" + videoName + ".CVF", "rb" );
  366.             if (videoCryFileCVF)
  367.             {
  368.                 BUFSZ = 4096;
  369.                 outputBuf = new char[BUFSZ];
  370.        
  371.                 skipFrames = 1;
  372.                 startPosition = 0;
  373.  
  374.                 bUseSingleFile = true;
  375.             }
  376.         }
  377.         */
  378.  
  379.         StartVideo(iFoundIndex);
  380.  
  381.         if (isPlaying)
  382.             return true;
  383.     }
  384.     else
  385.     {
  386.         GameWarning("CryVideo: Video '%s' couldn't be played! Skipping...", videoName);
  387.     }
  388.    
  389.     return false;
  390. }
  391. //////////////////////////////////////////////////////////////////////////
  392. void CVideoManager::StartVideo(int videoIndex)
  393. {
  394.     IRenderer* pRenderer = gEnv->pRenderer;
  395.     assert( pRenderer != NULL );
  396.     if ( pRenderer == NULL )
  397.     {
  398.         return;
  399.     }
  400.  
  401.     //Set values
  402.     SVideoInfo info = g_pCryVideo->m_globalVideoList[videoIndex];
  403.  
  404.     pIngameVideoTargetTex = NULL;
  405.  
  406.     //frameCounter = -1;
  407.     frameCounter = 0;
  408.     videoName = info.videoName;
  409.  
  410.     blackFramesCounter = int_round(gEnv->pTimer->GetFrameRate());
  411.  
  412.     videoWidth = info.videoWidth;
  413.     videoHeight = info.videoHeight;
  414.     xPos = info.posX;
  415.     yPos = info.posY;
  416.     pSoundId = NULL;
  417.  
  418.     frameEndIndex = m_pCryVideoOpenCV->GetFrameCount();
  419.     frameRate = m_pCryVideoOpenCV->GetVideoFrameRate();
  420.     frameWidth = m_pCryVideoOpenCV->GetVideoWidth();
  421.     frameHeight = m_pCryVideoOpenCV->GetVideoHeight();
  422.  
  423.     desiredFrameUpdateTime = 1.0f / frameRate;
  424.     CryLogAlways("VideoManager: Desired Frame Update Time: %f", desiredFrameUpdateTime);
  425.  
  426.  
  427.     //Check Sound Type
  428.     string szSoundFilePath;
  429.  
  430.     if (info.soundFile == "Default")
  431.         szSoundFilePath = "videos/library/TempAudio/CryVideo_" + info.videoName + ".mp2";
  432.     else
  433.         szSoundFilePath = "videos/library/" + info.soundFile;
  434.  
  435.  
  436.     if (info.allowSkip == 1)
  437.     {
  438.         isSkippable = true;
  439.     }
  440.     else
  441.     {
  442.         isSkippable = false;
  443.     }
  444.     if (firstStart && !g_pCryVideo->m_bMenuRendered)
  445.     {
  446.         isSkippable = false;
  447.         firstStartCounter = int_round(frameRate);
  448.     }
  449.    
  450.     //Intialize master texture
  451.     CryLogAlways("VideoManager: CreateMasterTexture!");
  452.  
  453.     //Create master texture
  454.     char* imageData = m_pCryVideoOpenCV->StartPlayback();
  455.  
  456.     if (imageData != NULL)
  457.     {
  458.         bool success = false;
  459.         if (g_pCryVideo->IsRGB8Usable())
  460.         {
  461.             master_texture_id = gEnv->pRenderer->DownLoadToVideoMemory(reinterpret_cast<unsigned char*> (imageData), frameWidth, frameHeight,  eTF_R8G8B8,  eTF_R8G8B8, 0x1, false);
  462.         }
  463.         else
  464.         {
  465.             master_texture_id = gEnv->pRenderer->DownLoadToVideoMemory(reinterpret_cast<unsigned char*> (imageData), frameWidth, frameHeight,  eTF_A8R8G8B8,  eTF_A8R8G8B8, 0x1, false);
  466.         }
  467.  
  468.         ITexture *pTexture = gEnv->pRenderer->EF_GetTextureByID(master_texture_id);
  469.         if (pTexture)
  470.             if (pTexture->IsTextureLoaded())
  471.                 success = true;
  472.  
  473.         if (!success)
  474.         {
  475.             GameWarning("CryVideo: Critical Error. Texture format not recognized. Check video file '%s' !", videoName);
  476.             StopVideo();
  477.             return;
  478.         }
  479.     }
  480.     else
  481.     {
  482.         GameWarning("CryVideo: Critical Error. Frame couldn't be retrieved. Check video file '%s' !", videoName);
  483.         StopVideo();
  484.         return;
  485.     }
  486.  
  487.     //Start Audio
  488.     if(!isIngameVideo)
  489.     {
  490.         if (szSoundFilePath != "" && szSoundFilePath != "videos/library/")
  491.         {
  492.             ISound *pSound;
  493.             pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(), FLAG_SOUND_2D|FLAG_SOUND_MOVIE|FLAG_SOUND_PRECACHE_LOAD_SOUND);
  494.  
  495.             if (pSound)
  496.             {
  497.                 pSoundId = pSound->GetId();
  498.  
  499.                 if (!isLoopedVideo)
  500.                     pSound->GetInterfaceDeprecated()->SetLoopMode(false);
  501.  
  502.                 if (firstStart && !g_pCryVideo->m_bMenuRendered)
  503.                 {
  504.                     pSound->Play(0.0f);
  505.                 }
  506.                 else
  507.                 {
  508.                     pSound->Play();
  509.                 }
  510.             }
  511.         }
  512.     }
  513.     else
  514.     {
  515.         if (pIngameVideoTargetEntity && szSoundFilePath != "" && szSoundFilePath != "videos/library/")
  516.         {
  517.             IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  518.             if (!pSoundProxy)
  519.                 pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->CreateProxy(ENTITY_PROXY_SOUND);
  520.  
  521.             pSoundProxy->StopAllSounds();
  522.  
  523.             ISound *pSound;
  524.  
  525.             if (pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  526.             {
  527.                 pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(),FLAG_SOUND_DEFAULT_3D | FLAG_SOUND_VOICE);
  528.                 pSound->SetSemantic(eSoundSemantic_Dialog);
  529.             }
  530.             else
  531.             {
  532.                 pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(),FLAG_SOUND_DEFAULT_3D);
  533.                 pSound->SetSemantic(eSoundSemantic_Living_Entity);
  534.             }
  535.  
  536.             if (pSound)
  537.             {
  538.                 pSoundId = pSound->GetId();
  539.  
  540.                 if (!isLoopedVideo)
  541.                     pSound->GetInterfaceDeprecated()->SetLoopMode(false);
  542.  
  543.                 pSoundProxy->PlaySound(pSound, Vec3(ZERO), FORWARD_DIRECTION, ingameAudioVol, false);
  544.             }
  545.  
  546.         }
  547.    
  548.         if (pIngameVideoTargetEntity)
  549.         {
  550.             if (pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  551.             {
  552.                 IEntityRenderProxy* pRenderProxy((IEntityRenderProxy*)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_RENDER));
  553.                    
  554.                 if (pRenderProxy)
  555.                 {
  556.                     IMaterial* pMtl(pRenderProxy->GetRenderMaterial(ingameVideoMaterialSlotId));
  557.                     if (pMtl)
  558.                     {
  559.                         pMtl = pMtl->GetSafeSubMtl(ingameVideoSubMtlId);
  560.                         if (pMtl)
  561.                         {
  562.                             //CryLogAlways(pMtl->GetName());
  563.                             const SShaderItem& shaderItem(pMtl->GetShaderItem());
  564.                             if (shaderItem.m_pShaderResources)
  565.                             {
  566.                                 SEfResTexture* pTex = shaderItem.m_pShaderResources->GetTexture(ingameVideoTexSlot);
  567.                                 if (pTex)
  568.                                 {
  569.                                     pIngameVideoTargetTex = pTex;
  570.                                     pDefaultTexture = NULL;
  571.                                     pDefaultTexture = pTex->m_Sampler.m_pITex;
  572.                
  573.                                     if (pIngameVideoTargetTex)
  574.                                     {
  575.                                         //ITexture *pNewTexture = pRenderer->EF_GetTextureByID(nextFrame);
  576.                                         ITexture *pNewTexture = pRenderer->EF_GetTextureByID(master_texture_id);
  577.                                         if (pNewTexture)
  578.                                         {
  579.                                             //ITexture *pOldTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
  580.                                             pIngameVideoTargetTex->m_Sampler.m_pITex = pNewTexture;
  581.  
  582.                                             /*
  583.                                             if (pOldTexture && pOldTexture != pDefaultTexture)
  584.                                             {
  585.                                                 //Try to delete Dummy File from disk
  586.                                                 if (bUseSingleFile)
  587.                                                     gEnv->pCryPak->RemoveFile(pOldTexture->GetName());
  588.  
  589.                                                 if (pOldTexture)
  590.                                                     m_pUiDraw->DeleteTexture(pOldTexture->GetTextureID());
  591.                                             }
  592.                                             */
  593.                                         }
  594.                                     }
  595.                                 }
  596.                             }
  597.                         }
  598.                     }
  599.                 }
  600.             }
  601.         }
  602.     }
  603.  
  604.     lastVideoFinishedReason = "None";
  605.     isPlaying = true;
  606.     isPaused = false;
  607.     scheduleUnpause = false;
  608.  
  609.     //Schedule Timer
  610.     if (m_TimerID)
  611.         g_pCryVideo->GetTimerManager()->KillTimer(m_TimerID);
  612.  
  613.     m_TimerID = g_pCryVideo->GetTimerManager()->CreateTimer(this, desiredFrameUpdateTime, true, true);
  614.  
  615.     //OnVideoTimer(m_TimerID);
  616. }
  617. /////////////////////////////////////////////////////////////////////////
  618. void CVideoManager::StopVideo()
  619. {
  620.     if (gEnv->IsDedicated())
  621.         return;
  622.  
  623.     if (!IsEnabled() || !isPlaying)
  624.         return;
  625.  
  626.  
  627.     stopVideo = true;
  628.     isLoopedVideo = false;
  629.  
  630.     OnVideoTimer(m_TimerID); //Stop video immediately
  631. }
  632. /////////////////////////////////////////////////////////////////////////
  633. void CVideoManager::PauseVideo()
  634. {
  635.     if (gEnv->IsDedicated())
  636.         return;
  637.  
  638.     if (!IsEnabled() || !isPlaying || isPaused || !isIngameVideo)
  639.         return;
  640.  
  641.     isPaused = true;
  642.  
  643.     if (pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId)
  644.     {
  645.         IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  646.         if (pSoundProxy)
  647.         {
  648.             ISound *pSound = pSoundProxy->GetSound(pSoundId);
  649.             if (pSound)
  650.             {
  651.                 pSound->SetPaused(true);
  652.             }
  653.         }
  654.     }
  655. }
  656. /////////////////////////////////////////////////////////////////////////
  657. void CVideoManager::ResumeVideo()
  658. {
  659.     if (gEnv->IsDedicated())
  660.         return;
  661.  
  662.     if (!IsEnabled() || !isPlaying || !isPaused || !isIngameVideo)
  663.         return;
  664.  
  665.     isPaused = false;
  666.  
  667.     if (pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId)
  668.     {
  669.         IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  670.         if (pSoundProxy)
  671.         {
  672.             ISound *pSound = pSoundProxy->GetSound(pSoundId);
  673.             if (pSound)
  674.             {
  675.                 pSound->SetPaused(false);
  676.             }
  677.         }
  678.     }
  679.  
  680.     OnVideoTimer(m_TimerID);
  681. }
  682. //////////////////////////////////////////////////////////////////////////
  683. void CVideoManager::UpdateVideo()
  684. {
  685.     if (!IsEnabled() )
  686.     {
  687.         isPlaying = false;
  688.         isPaused = false;
  689.         return;
  690.     }
  691.  
  692.     if (!isPlaying)
  693.     {
  694.         return;
  695.     }
  696.  
  697.     //No update needed here, just draw the same
  698.     if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  699.     {
  700.         IRenderer* pRenderer = gEnv->pRenderer;
  701.         if (!pRenderer)
  702.             return;
  703.  
  704.         //m_pUiDraw->PreRender();
  705.  
  706.         //char fileName[255];
  707.         //char frameCounterString[255];
  708.  
  709.         /*
  710.         sprintf(frameCounterString,"%i",(int)frameCounter);
  711.         int digitsOffset = frameDigitsNumber - strlen(frameCounterString);
  712.  
  713.         string sequencePrefix = "";
  714.         while (digitsOffset > 0)
  715.         {
  716.             sequencePrefix = sequencePrefix + "0";
  717.             --digitsOffset;
  718.         }
  719.         */
  720.  
  721.         /*
  722.         if (!bUseSingleFile)
  723.         {
  724.             sprintf(fileName,"Videos\\Library\\" + videoName + "\\" + videoName + sequencePrefix + "%i.tif",(int)frameCounter);
  725.         }
  726.         */
  727.         if (firstStart && !g_pCryVideo->m_bMenuRendered)
  728.         {
  729.             //first video and engine is not fully stable, render some black frames first
  730.             int nextFrame = m_pUiDraw->CreateTexture("Textures\\defaults\\black.tif", false);
  731.            
  732.             pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  733.  
  734.             m_pUiDraw->DeleteTexture(nextFrame);
  735.         }
  736.         else
  737.         {
  738.             if (frameCounter == 0)
  739.                 return;
  740.  
  741.             /*
  742.             if (bUseSingleFile)
  743.             {
  744.                 char fileNameOut[255];
  745.                 sprintf(fileNameOut, "%s_Dummy_%i.dds", videoName, frameCounter);
  746.  
  747.                 nextFrame = m_pUiDraw->CreateTexture(fileNameOut, false);
  748.             }
  749.             else
  750.             {
  751.                 nextFrame = m_pUiDraw->CreateTexture(fileName, false);
  752.             }
  753.             */
  754.  
  755.             pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, master_texture_id, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  756.  
  757.             //pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  758.    
  759.             //m_pUiDraw->DeleteTexture(nextFrame);
  760.         }
  761.  
  762.         //m_pUiDraw->PostRender();
  763.     }
  764. }
  765.  
  766.  
  767. //////////////////////////////////////////////////////////////////////////
  768. void CVideoManager::OnVideoTimer(CryVideoTimerID id)
  769. {
  770.     if(id != m_TimerID)
  771.         return;
  772.  
  773.     if (!IsEnabled() )
  774.     {
  775.         isPlaying = false;
  776.         isPaused = false;
  777.         return;
  778.     }
  779.  
  780.     //Enough black frames rendered, start first video
  781.     if (firstStart && !firstStartFinished && !g_pCryVideo->m_bMenuRendered && firstStartCounter <= 0)
  782.     {
  783.         CryLogAlways("VideoManager: Engine Stable1!");
  784.         stopVideo = true;
  785.     }
  786.            
  787.     IRenderer* pRenderer = gEnv->pRenderer;
  788.     if (!pRenderer)
  789.         return;
  790.  
  791.  
  792.     if (stopVideo)
  793.     {
  794.         stopVideo = false;
  795.  
  796.         if (firstStart && !g_pCryVideo->m_bMenuRendered)
  797.         {
  798.             firstStartFinished = true;
  799.         }
  800.         else
  801.         {
  802.             if (listFilePlaying && !listFileFinished && !m_currentVideoList.empty() && currentVideoListId + 1 == m_currentVideoList.size())
  803.             {
  804.                 listFileFinished = true;
  805.                 listFilePlaying = false;
  806.  
  807.                 if(!m_currentVideoList.empty())
  808.                     m_currentVideoList.clear();
  809.             }
  810.         }
  811.         lastVideoFinishedReason = "Skipped";
  812.         isPlaying = false;
  813.         isPaused = false;
  814.        
  815.         if (isIngameVideo)
  816.         {
  817.             if (pIngameVideoTargetEntity)
  818.             {
  819.                 IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  820.                 if (pSoundProxy)
  821.                 {
  822.                     pSoundProxy->StopAllSounds();
  823.                 }
  824.             }
  825.         }
  826.         else
  827.         {
  828.             ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
  829.             if (pSound)
  830.                 pSound->Stop(ESoundStopMode_AtOnce);
  831.         }
  832.  
  833.         if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  834.         {
  835.             if (pIngameVideoTargetTex)
  836.             {
  837.                 ITexture *pLastTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
  838.                 pIngameVideoTargetTex->m_Sampler.m_pITex = pDefaultTexture;
  839.  
  840.                 if (pLastTexture)
  841.                     m_pUiDraw->DeleteTexture(pLastTexture->GetTextureID());
  842.             }
  843.         }
  844.  
  845.         m_pUiDraw->DeleteTexture(master_texture_id);
  846.    
  847.  
  848.         //Close Video file
  849.         m_pCryVideoOpenCV->CloseVideoFile();
  850.  
  851.         //Close Video File and delete final Dummy Files
  852.         /*
  853.         if (bUseSingleFile)
  854.         {
  855.             char* fileNameDummy;
  856.             fileNameDummy = new char[255];
  857.             int frameNumber = frameCounter - 1;
  858.  
  859.             sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
  860.             gEnv->pCryPak->RemoveFile(fileNameDummy);
  861.  
  862.             fileNameDummy = new char[255];
  863.             frameNumber = frameCounter;
  864.  
  865.             sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
  866.             gEnv->pCryPak->RemoveFile(fileNameDummy);
  867.  
  868.             //Close CVF File
  869.             gEnv->pCryPak->FClose(videoCryFileCVF);
  870.                
  871.             //Clean Memory
  872.             videoCryFileCVF = NULL;
  873.             BUFSZ = NULL;
  874.             outputBuf = NULL;
  875.             outputLen = NULL;
  876.             nRead = NULL;
  877.             startPosition = NULL;
  878.         }
  879.         */
  880.  
  881.         //Can cause a crash...
  882.         //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  883.             //pRenderer->ResetToDefault();
  884.     }
  885.  
  886.  
  887.     if (!isPlaying || isPaused)
  888.     {
  889.         return;
  890.     }
  891.  
  892.     //Advance to next frame
  893.     //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  894.         //m_pUiDraw->PreRender();
  895.        
  896.         if (videoFormat == 1 && frameCounter < frameEndIndex || videoFormat == 2)
  897.         {
  898.             if (firstStart && !g_pCryVideo->m_bMenuRendered)
  899.             {
  900.                 //first video and engine is not fully stable, render some black frames first
  901.                 int nextFrame = m_pUiDraw->CreateTexture("Textures\\defaults\\black.tif", false);
  902.                 --firstStartCounter;
  903.  
  904.                 pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  905.  
  906.                 m_pUiDraw->DeleteTexture(nextFrame);
  907.             }
  908.             else
  909.             {
  910.                 //char fileName[255];
  911.                 //char frameCounterString[255];
  912.  
  913.  
  914.                 ++frameCounter;
  915.  
  916.                 if(frameCounter == 1)
  917.                     return;
  918.  
  919.                 /*
  920.                 sprintf(frameCounterString,"%i",(int)frameCounter);
  921.                 int digitsOffset = frameDigitsNumber - strlen(frameCounterString);
  922.  
  923.                 string sequencePrefix = "";
  924.                 while (digitsOffset > 0)
  925.                 {
  926.                     sequencePrefix = sequencePrefix + "0";
  927.                     --digitsOffset;
  928.                 }
  929.                 */
  930.  
  931.                 //CryLogAlways("Query Frame!");
  932.  
  933.                 char* imageData = m_pCryVideoOpenCV->GetNextFrame();
  934.                
  935.                 if (imageData == NULL)
  936.                     goto end;
  937.  
  938.  
  939.                 if (g_pCryVideo->IsRGB8Usable())
  940.                 {
  941.                     gEnv->pRenderer->UpdateTextureInVideoMemory(master_texture_id, reinterpret_cast<unsigned char*> (imageData), 0, 0, frameWidth, frameHeight, eTF_R8G8B8);
  942.                 }
  943.                 else
  944.                 {
  945.                     gEnv->pRenderer->UpdateTextureInVideoMemory(master_texture_id, reinterpret_cast<unsigned char*> (imageData), 0, 0, frameWidth, frameHeight, eTF_A8R8G8B8);
  946.                 }
  947.  
  948.                 //CryLogAlways("Frame received!");
  949.  
  950.                 /*
  951.                 float videoPlayTime = (float) frameCounter;
  952.                 float audioPlayTime = 0.0f;
  953.  
  954.                 videoPlayTime = videoPlayTime / (float)int_round((1.0f / desiredFrameUpdateTime));
  955.  
  956.                 if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId && !IsPaused())
  957.                 {
  958.                     IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  959.                     if (pSoundProxy)
  960.                     {
  961.                         ISound *pSound = pSoundProxy->GetSound(pSoundId);
  962.                         if (pSound)
  963.                         {
  964.                             audioPlayTime = pSound->GetInterfaceExtended()->GetCurrentSamplePos(true) / 1000.0f;
  965.                         }
  966.                     }
  967.                 }
  968.                 else if (!isIngameVideo && !IsPaused())
  969.                 {
  970.                     ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
  971.                     if (pSound)
  972.                     {
  973.                         audioPlayTime = pSound->GetInterfaceExtended()->GetCurrentSamplePos(true) / 1000.0f;
  974.                     }
  975.                 }
  976.                 CryLogAlways("VideoZeit: %f\nAudioZeit: %f\n---------------------------", videoPlayTime, audioPlayTime);
  977.                 */
  978.  
  979.  
  980.                 /*
  981.                 if (!bUseSingleFile)
  982.                 {
  983.                     sprintf(fileName,"Videos\\Library\\" + videoName + "\\" + videoName + sequencePrefix + "%i.tif",(int)frameCounter);
  984.  
  985.                     nextFrame = m_pUiDraw->CreateTexture(fileName, false);
  986.                 }
  987.                 else if (videoCryFileCVF)
  988.                 {
  989.                     int skipFramesNow = skipFrames;
  990.                     bool isBreak = false;
  991.  
  992.                     //Seek to right start position
  993.                     gEnv->pCryPak->FSeek(videoCryFileCVF, startPosition, SEEK_SET);
  994.  
  995.                     //Save Dummy DDS File
  996.                     char fileNameOut[255];
  997.                     sprintf(fileNameOut, "%s_Dummy_%i.dds", videoName, frameCounter);
  998.            
  999.                     FILE *fileHandle = gEnv->pCryPak->FOpen(fileNameOut, "wb");
  1000.                     if (fileHandle)
  1001.                     {
  1002.                         // scan for new frame
  1003.                         do
  1004.                         {
  1005.                             nRead = gEnv->pCryPak->FRead(outputBuf, BUFSZ, videoCryFileCVF);
  1006.  
  1007.                             startPosition = startPosition + nRead;
  1008.  
  1009.                             for(size_t c = 0; c < nRead; ++c)
  1010.                             {
  1011.                                 if(outputBuf[c] == 'D' && outputBuf[c+1] == 'D' && outputBuf[c+2] == 'S')
  1012.                                 {
  1013.                                     if (skipFramesNow <= 0)
  1014.                                     {
  1015.                                         outputLen = c;
  1016.  
  1017.                                         startPosition = startPosition - (nRead - c);
  1018.  
  1019.                                         isBreak = true;
  1020.  
  1021.                                         break;
  1022.                                     }
  1023.                                     else
  1024.                                     {
  1025.                                         --skipFramesNow;
  1026.                                     }
  1027.                                 }
  1028.                             }
  1029.                             if (isBreak)
  1030.                                 break;
  1031.  
  1032.                             gEnv->pCryPak->FWrite(outputBuf, nRead, 1, fileHandle);
  1033.                         }
  1034.                         while (nRead == BUFSZ);
  1035.  
  1036.                         gEnv->pCryPak->FWrite(outputBuf, outputLen, 1, fileHandle);
  1037.                         gEnv->pCryPak->FClose(fileHandle);
  1038.                     }
  1039.  
  1040.                     nextFrame = m_pUiDraw->CreateTexture(fileNameOut, false);
  1041.                 }
  1042.                 */
  1043.  
  1044.                 if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  1045.                 {
  1046.                     pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, master_texture_id, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  1047.                    
  1048.                     //pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  1049.                     //m_pUiDraw->DeleteTexture(nextFrame);
  1050.                 }
  1051.                 //Delete last Dummy File
  1052.                 /*
  1053.                 if (bUseSingleFile)
  1054.                 {
  1055.                     char fileNameDummy[255];
  1056.                     int frameNumber = frameCounter - 1;
  1057.  
  1058.                     sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
  1059.                     gEnv->pCryPak->RemoveFile(fileNameDummy);
  1060.                 }
  1061.                 */
  1062.             }
  1063.         }
  1064.         else
  1065.         {
  1066. end:       
  1067.             lastVideoFinishedReason = "Finished";
  1068.             if (isIngameVideo)
  1069.             {
  1070.                 if (pIngameVideoTargetEntity)
  1071.                 {
  1072.                     IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
  1073.                     if (pSoundProxy)
  1074.                     {
  1075.                         pSoundProxy->StopAllSounds();
  1076.                     }
  1077.                 }
  1078.             }
  1079.             else
  1080.             {
  1081.                 ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
  1082.                 if (pSound)
  1083.                     pSound->Stop(ESoundStopMode_AtOnce);
  1084.             }
  1085.  
  1086.             if (listFilePlaying && !listFileFinished && !m_currentVideoList.empty() && currentVideoListId + 1 == m_currentVideoList.size())
  1087.             {
  1088.                 listFileFinished = true;
  1089.                 listFilePlaying = false;
  1090.  
  1091.                 if(!m_currentVideoList.empty())
  1092.                     m_currentVideoList.clear();
  1093.             }
  1094.  
  1095.             if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity() && !freezeOnLastFrame)
  1096.             {
  1097.                 if (pIngameVideoTargetTex)
  1098.                 {
  1099.                     ITexture *pLastTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
  1100.                     pIngameVideoTargetTex->m_Sampler.m_pITex = pDefaultTexture;
  1101.  
  1102.                     if (pLastTexture)
  1103.                         m_pUiDraw->DeleteTexture(pLastTexture->GetTextureID());
  1104.                 }
  1105.             }
  1106.  
  1107.             //Close Video file
  1108.             m_pCryVideoOpenCV->CloseVideoFile();
  1109.  
  1110.             /*
  1111.             //Close Video File and delete final Dummy Files
  1112.             if (bUseSingleFile)
  1113.             {
  1114.                 char* fileNameDummy;
  1115.                 fileNameDummy = new char[255];
  1116.                 int frameNumber = frameCounter - 1;
  1117.  
  1118.                 sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
  1119.                 gEnv->pCryPak->RemoveFile(fileNameDummy);
  1120.  
  1121.                 fileNameDummy = new char[255];
  1122.                 frameNumber = frameCounter;
  1123.  
  1124.                 sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
  1125.                 gEnv->pCryPak->RemoveFile(fileNameDummy);
  1126.  
  1127.                 //Close CVF File
  1128.                 gEnv->pCryPak->FClose(videoCryFileCVF);
  1129.                
  1130.                 //Clean Memory
  1131.                 videoCryFileCVF = NULL;
  1132.                 BUFSZ = NULL;
  1133.                 outputBuf = NULL;
  1134.                 outputLen = NULL;
  1135.                 nRead = NULL;
  1136.                 startPosition = NULL;
  1137.             }
  1138.             */
  1139.  
  1140.             isPlaying = false;
  1141.             isPaused = false;
  1142.  
  1143.             m_pUiDraw->DeleteTexture(master_texture_id);
  1144.  
  1145.             //Can cause a crash...
  1146.             //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  1147.                 //pRenderer->ResetToDefault();
  1148.         }
  1149.    
  1150.     //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
  1151.         //m_pUiDraw->PostRender();
  1152. }
  1153.  
  1154. void CVideoManager::OnPostUpdate( float fDeltaTime )
  1155. {
  1156.     if (firstStart && !g_pCryVideo->m_bMenuRendered && firstStartCounter <= 0 && firstStartFinished)
  1157.     {
  1158.         //Engine is now stable: restart first video
  1159.         CryLogAlways("VideoManager: Engine Stable2!");
  1160.         firstStart = false;
  1161.         PlayNextVideoInList(currentVideoListId);
  1162.  
  1163.     }
  1164.     else if (listFilePlaying && !listFileFinished && !isPlaying && !m_currentVideoList.empty() && currentVideoListId + 1 != m_currentVideoList.size())
  1165.     {
  1166.         --blackFramesCounter;
  1167.         if (blackFramesCounter <= 0)
  1168.         {
  1169.             ++currentVideoListId;
  1170.  
  1171.             PlayNextVideoInList(currentVideoListId);
  1172.         }
  1173.     }
  1174.  
  1175.     if (isLoopedVideo && !isPlaying)
  1176.     {
  1177.         PlaySingleVideo(videoName, false, "", 1.0f, 0, 0, 0, 0, true, false);
  1178.     }
  1179.  
  1180.  
  1181.     //Check for stop/pause conditions
  1182.     if (gEnv->IsEditor() && !gEnv->IsEditorGameMode() && isPlaying)
  1183.     {
  1184.         StopVideo();
  1185.     }
  1186.     if (!gEnv->IsEditor() && !gEnv->IsDedicated() && m_pGameFramework->IsGameStarted() && g_pCryVideo->m_bMenuRendered && m_pGameFramework->IsGamePaused() && isPlaying && !isPaused && !scheduleUnpause)
  1187.     {
  1188.         scheduleUnpause = true;
  1189.         PauseVideo();
  1190.     }
  1191.     if (!gEnv->IsEditor() && !gEnv->IsDedicated() && m_pGameFramework->IsGameStarted() && g_pCryVideo->m_bMenuRendered && !m_pGameFramework->IsGamePaused() && isPlaying && isPaused && scheduleUnpause)
  1192.     {
  1193.         scheduleUnpause = false;
  1194.         ResumeVideo();
  1195.     }
  1196.  
  1197.     UpdateVideo();
  1198. }
  1199. //////////////////////////////////////////////////////////////////////////
  1200. bool CVideoManager::OnInputEvent( const SInputEvent &event )
  1201. {
  1202.     if (event.deviceId!=eDI_Keyboard)
  1203.         return false;
  1204.  
  1205.     if (gEnv->IsDedicated() || event.keyId == eKI_SYS_Commit)
  1206.         return false;
  1207.  
  1208.     if (!IsEnabled())
  1209.         return false;
  1210.    
  1211.     if (!isPlaying)
  1212.         return false;
  1213.  
  1214.     if (eIS_Pressed != event.state)
  1215.         return false;
  1216.  
  1217.     bool stopVideoNow = false;
  1218.  
  1219.     //skip movie
  1220.     if(!gEnv->pConsole->GetStatus() && !isPaused && isSkippable && !isLoopedVideo)
  1221.     {
  1222.         if(event.keyId == eKI_Space || event.keyId == eKI_Escape && !g_pCryVideo->m_bMenuRendered)         
  1223.         {
  1224.             stopVideoNow = true;
  1225.         }
  1226.     }
  1227.     if (stopVideoNow)
  1228.     {
  1229.         StopVideo();
  1230.         return true;
  1231.     }
  1232.  
  1233.     return false;
  1234. }
  1235. //////////////////////////////////////////////////////////////////////////
  1236. void CVideoManager::OnLoadingStart( ILevelInfo* pLevel )
  1237. {
  1238.     if (gEnv->IsEditor() || gEnv->IsDedicated())
  1239.         return;
  1240.  
  1241.     isLoopedVideo = false;
  1242.  
  1243.     if (isPlaying)
  1244.     {
  1245.         StopVideo();
  1246.     }
  1247. }
  1248. //////////////////////////////////////////////////////////////////////////
  1249. void CVideoManager::OnEnd( IUIAction* pAction, const SUIArguments& args )
  1250. {
  1251.     if (gEnv->IsEditor() || gEnv->IsDedicated())
  1252.         return;
  1253.  
  1254.     static IUIAction* pActionMenu = gEnv->pFlashUI->GetUIAction("MM_DisplayMenu");
  1255.     if (pAction && pActionMenu)
  1256.     {
  1257.         if (pAction == pActionMenu)
  1258.         {
  1259.             //Level BG MOD: Check if video bg menu is prefered
  1260.             bool bUseVideoBgMenu = false;
  1261.             string videoNameLoop = "";
  1262.  
  1263.             ICVar *pVarVideo = gEnv->pConsole->GetCVar("cv_useVideoAsMenuBg");
  1264.             if (pVarVideo)
  1265.             {
  1266.                 if (pVarVideo->GetIVal() == 1)
  1267.                 {
  1268.                     //Level BG MOD: Load video
  1269.                     ICVar *pVarVideoName = gEnv->pConsole->GetCVar("cv_videoMenuBgVideoName");
  1270.                     if (pVarVideoName)
  1271.                     {
  1272.                         videoNameLoop = pVarVideoName->GetString();
  1273.                     }
  1274.  
  1275.                     if (videoNameLoop != "")
  1276.                     {
  1277.                         bUseVideoBgMenu = true;
  1278.                     }  
  1279.                 }
  1280.             }
  1281.            
  1282.             if (bUseVideoBgMenu)
  1283.             {
  1284.                 //Schedule video playback on next frame
  1285.                 isLoopedVideo = true;
  1286.                 videoName = videoNameLoop;
  1287.             }
  1288.         }
  1289.     }
  1290. }
Add Comment
Please, Sign In to add comment