Advertisement
dragonbane

[CryVideo] CryVideo.cpp

Feb 24th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.20 KB | None | 0 0
  1. /*************************************************************************
  2.   Cry Video Source File.
  3.   Copyright (C), Marwin Misselhorn 2012
  4.  -------------------------------------------------------------------------
  5. *************************************************************************/
  6.  
  7. #include "StdAfx.h"
  8. #include "CryVideo.h"
  9. #include "Nodes/G2FlowBaseNode.h"
  10. #include <ICryVideo.h>
  11. #include <IVideoManager.h>
  12.  
  13. #include <CryLibrary.h>
  14. #include <IGameFramework.h>
  15. #include <IRenderer.h>
  16. #include <UIDraw/UIDraw.h>
  17. #include <IEditorGame.h> //0.9.8: Native Audio Support
  18.  
  19.  
  20. CCryVideo *g_pCryVideo = 0;
  21.  
  22. // Needed for the Game02 specific flow node
  23. CG2AutoRegFlowNodeBase *CG2AutoRegFlowNodeBase::m_pFirst=0;
  24. CG2AutoRegFlowNodeBase *CG2AutoRegFlowNodeBase::m_pLast=0;
  25.  
  26. //New CVars
  27. static int      cv_useLevelAsMenuBg;
  28. static ICVar*   cv_levelMenuBgMapName;
  29. static int      cv_useVideoAsMenuBg;
  30. static ICVar*   cv_videoMenuBgVideoName;
  31. static ICVar*   cv_startingLevel;
  32.  
  33. static int      cv_renderToSecondWindow;
  34. static int      cv_forceManualConversion;
  35. static int      cv_swapBGRA;
  36.  
  37. //static int        cv_useOpenGL;
  38.  
  39.  
  40. static HMODULE m_hCryVideoOpenCVHandle = 0;
  41. typedef ICryVideoOpenCV *(*PFNCREATECRYVIDEOOPENCV)();
  42.  
  43. static HMODULE m_hCryVideoWebMHandle = 0;
  44. typedef ICryVideoWebM *(*PFNCREATECRYVIDEOWEBM)();
  45.  
  46.  
  47.  
  48. //0.9.8: Message Box
  49. void Error( const char* sErrorText )
  50. {
  51.     MessageBox( 0,sErrorText, "...", MB_OK | MB_DEFAULT_DESKTOP_ONLY);
  52. }
  53.  
  54. //0.9.8: Native Audio Support
  55. HANDLE CCryVideo::ExecuteProcess(string applicationName, string commandLine, string workingDir)
  56. {
  57.     STARTUPINFO sStartInfo;
  58.     ZeroMemory( &sStartInfo, sizeof(STARTUPINFO) );
  59.     sStartInfo.cb = sizeof(STARTUPINFO);
  60.     sStartInfo.dwFlags = STARTF_USESHOWWINDOW;
  61.     //sStartInfo.wShowWindow = SW_SHOWDEFAULT;
  62.     sStartInfo.wShowWindow = SW_HIDE;
  63.  
  64.     PROCESS_INFORMATION sProcessInfo;
  65.     ZeroMemory( &sProcessInfo, sizeof(PROCESS_INFORMATION) );
  66.     BOOL ok = CreateProcess( applicationName.c_str(), (LPSTR)commandLine.c_str(),
  67.                            NULL, NULL, true,
  68.                            NORMAL_PRIORITY_CLASS, NULL, workingDir.c_str(), &sStartInfo, &sProcessInfo );
  69.  
  70.     if ( ok == 0 )
  71.     {
  72.         sProcessInfo.hProcess = 0;
  73.  
  74.         DWORD error = GetLastError();
  75.         CryLogAlways("CryVideo: Create Process Error Code: %i", error);
  76.     }
  77.  
  78.     return sProcessInfo.hProcess;
  79. }
  80.  
  81.  
  82.  
  83. CCryVideo::CCryVideo()
  84. :  m_pTimerManager(0) //Cry Video MOD: Timer Manager
  85. {
  86.     g_pCryVideo = this;
  87.     started = false;
  88.     soundUpdate = false;
  89.     isRGB8Usable = false;
  90.     m_bMenuRendered = false;
  91.  
  92.     //0.9.8: Native Audio Support
  93.     //check if CryEngine runs in 32 or 64 Bit Mode
  94.     #if defined(WIN64)      //WIN 64
  95.         m_bIs64Bit = true;
  96.     #else                   //WIN 32
  97.         m_bIs64Bit = false;
  98.     #endif
  99. }
  100.  
  101. CCryVideo::~CCryVideo()
  102. {
  103.     g_pCryVideo = 0;
  104.     started = false;
  105.     soundUpdate = false;
  106.     m_bMenuRendered = false;
  107.  
  108.     //Clean lists
  109.     if(!m_globalVideoList.empty())
  110.         m_globalVideoList.clear();
  111.  
  112.     if(!m_priorityAudioJobList.empty())
  113.         m_priorityAudioJobList.clear();
  114.  
  115.     if(!m_globalAudioJobList.empty())
  116.         m_globalAudioJobList.clear();
  117.  
  118.  
  119.     //0.9.8: Native Audio Support
  120.     if (gEnv->pRenderer)
  121.         gEnv->pRenderer->UnRegisterCaptureFrame(this);
  122.  
  123.  
  124.     //Clean TempAudio folder
  125.     string audio = "Videos\\Library\\TempAudio\\";
  126.     _finddata_t fileDataAudio;
  127.     char szAudioPath[260];
  128.     strncpy_s(szAudioPath, 260, audio.c_str(), 260);
  129.     strncat_s(szAudioPath, 260, "*.mp2", 260);
  130.  
  131.     intptr_t hFileAudio = gEnv->pCryPak->FindFirst(szAudioPath, &fileDataAudio);
  132.     if (hFileAudio > -1)
  133.     {
  134.         do
  135.         {
  136.             string audioPath = (audio+fileDataAudio.name);
  137.             gEnv->pCryPak->RemoveFile(audioPath);
  138.  
  139.         } while (gEnv->pCryPak->FindNext(hFileAudio, &fileDataAudio) > -1);
  140.         gEnv->pCryPak->FindClose(hFileAudio);
  141.     }
  142.  
  143.     //Cry Video MOD: Timer Manager
  144.     SAFE_DELETE(m_pTimerManager);
  145.  
  146.     //Free WebM DLL
  147.     if (m_hCryVideoWebMHandle)
  148.         CryFreeLibrary(m_hCryVideoWebMHandle);
  149.  
  150.     m_hCryVideoWebMHandle = 0;
  151.  
  152.     //Free OpenCV DLL
  153.     if (m_hCryVideoOpenCVHandle)
  154.         CryFreeLibrary(m_hCryVideoOpenCVHandle);
  155.  
  156.     m_hCryVideoOpenCVHandle = 0;
  157.  
  158.     //Unregister CVars
  159.     gEnv->pConsole->UnregisterVariable("cv_useLevelAsMenuBg", true);
  160.     gEnv->pConsole->UnregisterVariable("cv_levelMenuBgMapName", true);
  161.     gEnv->pConsole->UnregisterVariable("cv_useVideoAsMenuBg", true);
  162.     gEnv->pConsole->UnregisterVariable("cv_videoMenuBgVideoName", true);
  163.  
  164.     gEnv->pConsole->UnregisterVariable("cv_startingLevel", true);
  165.  
  166.     gEnv->pConsole->UnregisterVariable("cv_renderToSecondWindow", true);
  167.     gEnv->pConsole->UnregisterVariable("cv_forceManualConversion", true);
  168.     gEnv->pConsole->UnregisterVariable("cv_swapBGRA", true);
  169.  
  170.     //gEnv->pConsole->UnregisterVariable("cv_useOpenGL", true);
  171. }
  172.  
  173. bool CCryVideo::Init(ISystem *pSystem, IGameFramework *pGameFramework, IGameToEditorInterface *pGameToEditorInterface) //0.9.8: Native Audio Support
  174. {
  175.     //0.9.8: Dlls moved to CryVideo directory
  176.     if (m_bIs64Bit)
  177.         SetDllDirectory("Bin64\\CryVideo");
  178.     else
  179.         SetDllDirectory("Bin32\\CryVideo");
  180.  
  181.  
  182.     started = false;
  183.     m_bMenuRendered = false;
  184.     gEnv = pSystem->GetGlobalEnvironment();
  185.     m_pFramework = pGameFramework;
  186.  
  187.     //0.9.8: Native Audio Support
  188.     gEnv->pRenderer->RegisterCaptureFrame(this);
  189.     pGameToEditorIface = pGameToEditorInterface;
  190.  
  191.     //Cry Video MOD: Timer Manager
  192.     if(!m_pTimerManager)
  193.         m_pTimerManager = new CTimerManager();
  194.  
  195.     // Initialize Game02 flow nodes
  196.     if (IFlowSystem *pFlow = m_pFramework->GetIFlowSystem())
  197.     {
  198.         CG2AutoRegFlowNodeBase *pFactory = CG2AutoRegFlowNodeBase::m_pFirst;
  199.  
  200.         while (pFactory)
  201.         {
  202.             pFlow->RegisterType( pFactory->m_sClassName,pFactory );
  203.             pFactory = pFactory->m_pNext;
  204.         }
  205.     }
  206.  
  207.     //Init OpenCV plugin
  208.     if (m_hCryVideoOpenCVHandle)
  209.         CryFreeLibrary(m_hCryVideoOpenCVHandle);
  210.  
  211.     m_hCryVideoOpenCVHandle = 0;
  212.     m_hCryVideoOpenCVHandle = CryLoadLibrary( "CryVideo\\CryVideoOpenCV.dll" );
  213.  
  214.     if (!m_hCryVideoOpenCVHandle)
  215.     {
  216.         GameWarning( "CryVideoOpenCV.DLL Loading Failed" );
  217.     }
  218.  
  219.     //Init WebM plugin
  220.     if (m_hCryVideoWebMHandle)
  221.         CryFreeLibrary(m_hCryVideoWebMHandle);
  222.  
  223.     m_hCryVideoWebMHandle = 0;
  224.     m_hCryVideoWebMHandle = CryLoadLibrary( "CryVideo\\CryVideoWebM.dll" );
  225.  
  226.     if (!m_hCryVideoWebMHandle)
  227.     {
  228.         GameWarning( "CryVideoWebM.dll Loading Failed" );
  229.     }
  230.  
  231.     //Test if RGB8 is available
  232.     int testTextureId = m_pFramework->GetIUIDraw()->CreateTexture("Textures\\defaults\\black.tif", false);
  233.     ITexture *pTestTexture = gEnv->pRenderer->EF_GetTextureByID(testTextureId);
  234.  
  235.     unsigned char* textureData = pTestTexture->GetData32(0,0,(uint8*)0, eTF_A8R8G8B8);
  236.  
  237.     int finalTestTextureId = gEnv->pRenderer->DownLoadToVideoMemory(textureData, pTestTexture->GetWidth(), pTestTexture->GetHeight(), eTF_A8R8G8B8, eTF_R8G8B8, 0x1, false);
  238.     ITexture *pFinalTestTexture = gEnv->pRenderer->EF_GetTextureByID(finalTestTextureId);
  239.  
  240.     if (pFinalTestTexture->IsTextureLoaded())
  241.         isRGB8Usable = true;
  242.     else
  243.         isRGB8Usable = false;
  244.  
  245.  
  246.     m_pFramework->GetIUIDraw()->DeleteTexture(testTextureId);
  247.     m_pFramework->GetIUIDraw()->DeleteTexture(finalTestTextureId);
  248.  
  249.     if (isRGB8Usable)
  250.         CryLogAlways("CryVideo: RGB8 is available!");
  251.     else
  252.         CryLogAlways("CryVideo: RGB8 is NOT available!");
  253.  
  254.  
  255.     //Check for right color order
  256.     int features = gEnv->pRenderer->GetFeatures();
  257.  
  258.     if (features & RFT_RGBA)
  259.         CryLogAlways("CryVideo: Special --> RGBA color channel order!!!");
  260.     else
  261.         CryLogAlways("CryVideo: Default --> BGRA color channel order!");
  262.  
  263.  
  264.     //Overide Window Name
  265.     //ICVar *gameName = gEnv->pConsole->GetCVar("cvGameName");
  266.     //if (gameName)
  267.         //gameName->ForceSet("CryENGINE 3 CryVideo System © Marwin Misselhorn");
  268.     //ICVar *verboseWindow = gEnv->pConsole->GetCVar("cvDoVerboseWindowTitle");
  269.     //if (verboseWindow)
  270.         //verboseWindow->ForceSet("1");
  271.  
  272.    
  273.     //Register CVars
  274.     gEnv->pConsole->Register("cv_useLevelAsMenuBg", &cv_useLevelAsMenuBg, 0, VF_NULL, "use level as menu background");
  275.     cv_levelMenuBgMapName = gEnv->pConsole->RegisterString("cv_levelMenuBgMapName", "", VF_NULL, "level menu map name");
  276.    
  277.     gEnv->pConsole->Register("cv_useVideoAsMenuBg", &cv_useVideoAsMenuBg, 0, VF_NULL, "use video as menu background");
  278.     cv_videoMenuBgVideoName = gEnv->pConsole->RegisterString("cv_videoMenuBgVideoName", "", VF_NULL, "video menu video name");
  279.  
  280.     cv_startingLevel = gEnv->pConsole->RegisterString("cv_startingLevel", "", VF_CHEAT|VF_DUMPTODISK|VF_READONLY, "default starting level when running the launcher");
  281.  
  282.     gEnv->pConsole->Register("cv_renderToSecondWindow", &cv_renderToSecondWindow, 0, VF_NULL, "render all videos to a separate window for debugging");
  283.     gEnv->pConsole->Register("cv_forceManualConversion", &cv_forceManualConversion, 0, VF_NULL, "force manual color conversion for debugging");
  284.     gEnv->pConsole->Register("cv_swapBGRA", &cv_swapBGRA, -1, VF_CHEAT|VF_DUMPTODISK|VF_READONLY, "-1=Autodetect(Default); 0=BGRA; 1=RGBA");
  285.    
  286.     //gEnv->pConsole->Register("cv_useOpenGL", &cv_useOpenGL, 0, VF_NULL, "use OpenGL for color conversion");
  287.    
  288.     //Cry Video MOD: Load Config
  289.     gEnv->pConsole->ExecuteString( "exec CryVideo.cfg" );
  290.  
  291.  
  292.     //Swap BRGA Auto-Detect
  293.     ICVar* swapChannels = gEnv->pConsole->GetCVar("cv_swapBGRA");
  294.     if (swapChannels)
  295.     {
  296.         if (swapChannels->GetIVal() == -1)
  297.         {
  298.             if (gEnv->pRenderer->GetRenderType()== eRT_DX11)
  299.                 swapChannels->ForceSet("1");
  300.             else
  301.                 swapChannels->ForceSet("0");
  302.         }
  303.     }
  304.  
  305.  
  306.     /*
  307.     //Test
  308.     HANDLE hNote;
  309.     bool exit = false;
  310.  
  311.     hNote = ExecuteProcess( "Bin32\\CryVideo\\ffmpeg.exe", "ffmpeg -i Elephants_Dream.WebM -vn TempAudio\\output.mp2", "Game\\Videos\\Library");
  312.     if ( hNote )
  313.     {
  314.         while (!exit)
  315.         {
  316.             DWORD noteExitCode;
  317.             if ( GetExitCodeProcess(hNote , &noteExitCode) )
  318.             {
  319.                 if ( noteExitCode == STILL_ACTIVE )
  320.                 {
  321.                     // immer noch an
  322.                 }
  323.                 else
  324.                 {
  325.                     // Programm beendet
  326.                     CloseHandle( hNote );
  327.                     exit = true;
  328.                 }
  329.             }
  330.         }
  331.     }
  332.     */
  333.  
  334.     //0.9.8: Detect number of Cores for Audio Job
  335.     SYSTEM_INFO sysinfo;
  336.     GetSystemInfo( &sysinfo );
  337.  
  338.     maxSoundJobs = sysinfo.dwNumberOfProcessors;
  339.  
  340.     CryLogAlways("CryVideo: Use %i thread(s) for audio conversion!", maxSoundJobs);
  341.  
  342.     //0.9.8: Create Global Video List on startup
  343.     CreateGlobalVideoList();
  344.  
  345.     CryLogAlways("Hello20");
  346.     //Start Timer
  347.     m_LastSoundUpdate = gEnv->pTimer->GetAsyncCurTime();
  348.  
  349.     started = true;
  350.  
  351.     return true;
  352. }
  353.  
  354. IVideoManager* CCryVideo::CreateVideoPlayerInstance()
  355. {
  356.     CVideoManager* m_pVideoManager;
  357.     m_pVideoManager = new CVideoManager();
  358.        
  359.     return m_pVideoManager;
  360. }
  361.  
  362. ICryVideoOpenCV* CCryVideo::CreateOpenCVInstance()
  363. {
  364.     ICryVideoOpenCV* m_pCryVideoOpenCV;
  365.        
  366.     PFNCREATECRYVIDEOOPENCV pfnCreateCryVideoOpenCV = (PFNCREATECRYVIDEOOPENCV)::GetProcAddress( m_hCryVideoOpenCVHandle, "CreateCryVideoOpenCV" );
  367.  
  368.     m_pCryVideoOpenCV = pfnCreateCryVideoOpenCV();
  369.  
  370.     if (!m_pCryVideoOpenCV)
  371.     {
  372.         GameWarning("CreateOpenCVInterface Failed" );
  373.     }
  374.  
  375.     bool success = m_pCryVideoOpenCV->Init(gEnv->pSystem, m_pFramework, this);
  376.  
  377.     if (!success)
  378.         GameWarning("Init OpenCV Failed" );
  379.  
  380.     return m_pCryVideoOpenCV;
  381. }
  382.  
  383. ICryVideoWebM* CCryVideo::CreateWebMInstance()
  384. {
  385.     ICryVideoWebM* m_pCryVideoWebM;
  386.        
  387.     PFNCREATECRYVIDEOWEBM pfnCreateCryVideoWebM = (PFNCREATECRYVIDEOWEBM)::GetProcAddress( m_hCryVideoWebMHandle, "CreateCryVideoWebM" );
  388.  
  389.     m_pCryVideoWebM = pfnCreateCryVideoWebM();
  390.  
  391.     if (!m_pCryVideoWebM)
  392.     {
  393.         GameWarning("CreateWebMInterface Failed" );
  394.     }
  395.  
  396.     bool success = m_pCryVideoWebM->Init(gEnv->pSystem, m_pFramework);
  397.        
  398.     if (!success)
  399.         GameWarning("Init WebM Failed" );
  400.  
  401.     return m_pCryVideoWebM;
  402. }
  403.  
  404. //////////////////////////////////////////////////////////////////////////
  405. void CCryVideo::CreateGlobalVideoList()
  406. {
  407.     if (soundUpdate || m_pFramework->GetISystem()->IsQuitting())
  408.         return;
  409.  
  410.     if (!started) //First Start Only
  411.     {
  412.         //Clean list
  413.         m_globalVideoList.clear();
  414.  
  415.         //Create TempAudio folder
  416.         gEnv->pCryPak->MakeDir("Videos\\Library\\TempAudio", true);
  417.  
  418.         //Clean TempAudio folder
  419.         string audio = "Videos\\Library\\TempAudio\\";
  420.         _finddata_t fileDataAudio;
  421.         char szAudioPath[260];
  422.         strncpy_s(szAudioPath, 260, audio.c_str(), 260);
  423.         strncat_s(szAudioPath, 260, "*.mp2", 260);
  424.  
  425.         intptr_t hFileAudio = gEnv->pCryPak->FindFirst(szAudioPath, &fileDataAudio);
  426.         if (hFileAudio > -1)
  427.         {
  428.             do
  429.             {
  430.                 string audioPath = (audio+fileDataAudio.name);
  431.                 gEnv->pCryPak->RemoveFile(audioPath);
  432.  
  433.             } while (gEnv->pCryPak->FindNext(hFileAudio, &fileDataAudio) > -1);
  434.             gEnv->pCryPak->FindClose(hFileAudio);
  435.         }
  436.     }
  437.  
  438.     CryLogAlways("Hello1");
  439.  
  440.     //Create temp OpenCV instance
  441.     ICryVideoOpenCV* m_pCryVideoOpenCV = CreateOpenCVInstance();
  442.  
  443.     //Clean lists
  444.     m_priorityAudioJobList.clear();
  445.     m_globalAudioJobList.clear();
  446.  
  447.     //Detect right game folder
  448.     const char* gameFolder;
  449.     ICVar *pVar = gEnv->pConsole->GetCVar("sys_game_folder");
  450.     if (pVar)
  451.         gameFolder = pVar->GetString();
  452.     else
  453.         gameFolder = "Game";
  454.  
  455.  
  456.     //Search for all Videos in Library and apply default settings
  457.     string videos = "Videos\\Library\\";
  458.     _finddata_t fileData;
  459.     char szVideoPath[260];
  460.     strncpy_s(szVideoPath, 260, videos.c_str(), 260);
  461.     strncat_s(szVideoPath, 260, "*", 260);
  462.  
  463.     intptr_t hFile = gEnv->pCryPak->FindFirst(szVideoPath, &fileData);
  464.     if (hFile > -1)
  465.     {
  466.         do
  467.         {
  468.             if (fileData.size <= 0)
  469.                 continue;
  470.  
  471.             string videoPath = (videos+fileData.name);
  472.             string videoName = fileData.name;
  473.  
  474.             CryLogAlways("Hello2.4");
  475.  
  476.             //ToDo: Check if videoName is already in list. If yes, did checksum changed? If yes or when video is not in list update VideoList
  477.             std::vector<SVideoInfo>::const_iterator iter (m_globalVideoList.begin());
  478.             while (iter != m_globalVideoList.end())
  479.             {
  480.                 if (iter->videoName == fileData.name)
  481.                 {
  482.                     //Compare MD5 Checksum
  483.                     char* file1 = new char[255];
  484.                     char* file2 = new char[255];
  485.                     unsigned char* checkSumFile1 = new unsigned char[16];
  486.                     unsigned char* checkSumFile2 = new unsigned char[16];
  487.  
  488.                     sprintf(file1, "%s%s", videos, iter->videoName);
  489.                     sprintf(file2, "%s%s", videos, fileData.name);
  490.  
  491.                     gEnv->pCryPak->ComputeMD5(file1,checkSumFile1);
  492.                     gEnv->pCryPak->ComputeMD5(file2,checkSumFile2);
  493.  
  494.                     if (checkSumFile1 == checkSumFile2) //Skip identical files
  495.                         continue;
  496.                 }
  497.                 ++iter;
  498.             }
  499.  
  500.             //Init Video File
  501.             char fileName[255];
  502.             sprintf(fileName, "%s/Videos/Library/%s", gameFolder, videoName.MakeLower());
  503.                
  504.             string fileNameString;
  505.             fileNameString = fileName;
  506.  
  507.             int videoFormat; //AVI=1 ; WebM=2
  508.             bool success = false;
  509.  
  510.             CryLogAlways("Hello2.5");
  511.  
  512.             if (fileNameString.substr(fileNameString.size()-5,5) == ".webm")
  513.             {
  514.                 videoFormat = 2;
  515.                 CryLogAlways("Hello2.6");
  516.                 success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  517.                 if (!success)
  518.                 {
  519.                     GameWarning("CryVideo: WebM file '%s' couldn't be opened. Retrying!", fileData.name);
  520.                     success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  521.                 }
  522.             }
  523.             else
  524.             {  
  525.                 videoFormat = 1;
  526.                 CryLogAlways("Hello2.7");
  527.                 success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  528.                 CryLogAlways("Hello2.8");
  529.                 if (!success)
  530.                 {
  531.                     //One retry
  532.                     success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
  533.                     CryLogAlways("Hello2.9");
  534.                 }
  535.             }
  536.                    
  537.             if (success)
  538.             {
  539.                 CryLogAlways("Hello2.10");
  540.                 SVideoInfo videoInfo;
  541.                        
  542.                 //Set Default Settings
  543.                 videoInfo.videoName = fileData.name;
  544.                            
  545.                 videoInfo.videoWidth = 800.0f;
  546.                 videoInfo.videoHeight = 600.0f;
  547.                            
  548.                 videoInfo.posX = 0.0f;
  549.                 videoInfo.posY = 0.0f;
  550.                                
  551.                 videoInfo.soundFile = "Default";
  552.                            
  553.                 videoInfo.allowSkip = 1;
  554.  
  555.  
  556.                 m_globalVideoList.push_back(videoInfo);
  557.  
  558.                 CryLogAlways("Hello2.11");
  559.             }
  560.                    
  561.         } while (gEnv->pCryPak->FindNext(hFile, &fileData) > -1);
  562.         gEnv->pCryPak->FindClose(hFile);
  563.     }
  564.  
  565.  
  566.     //Search for xml files and overwrite default settings with it
  567.     string xml = "Videos\\Library\\";
  568.     _finddata_t fileDataXml;
  569.     char szXmlPath[260];
  570.     strncpy_s(szXmlPath, 260, xml.c_str(), 260);
  571.     strncat_s(szXmlPath, 260, "*.xml", 260);
  572.  
  573.     intptr_t hFileXml = gEnv->pCryPak->FindFirst(szXmlPath, &fileDataXml);
  574.     if (hFileXml > -1)
  575.     {
  576.         do
  577.         {
  578.             string xmlPath = (xml+fileDataXml.name);
  579.  
  580.             XmlNodeRef videoInfo = gEnv->pSystem->LoadXmlFromFile(xmlPath);
  581.  
  582.             if(videoInfo == 0)
  583.             {
  584.                 GameWarning("Cry Video: Could not load video xml: %s", xmlPath);
  585.             }
  586.             else
  587.             {
  588.                 if(videoInfo)
  589.                 {
  590.                     const char* name = videoInfo->getTag();
  591.  
  592.                     if(!stricmp(name, "VideoSettings"))
  593.                     {
  594.                         SVideoInfo info;
  595.                         int attribs = videoInfo->getNumAttributes();
  596.                         const char* key;
  597.                         const char* value;
  598.                         for(int i = 0; i < attribs; ++i)
  599.                         {
  600.                             videoInfo->getAttributeByIndex(i, &key, &value);
  601.                             if(!stricmp(key,"Name"))
  602.                             {
  603.                                 info.videoName = value;
  604.                             }
  605.                             else if(!stricmp(key,"Width") && value)
  606.                             {
  607.                                 info.videoWidth = (float)atof(value);
  608.                             }
  609.                             else if(!stricmp(key,"Height") && value)
  610.                             {
  611.                                 info.videoHeight = (float)atof(value);
  612.                             }
  613.                             else if(!stricmp(key,"PosX") && value)
  614.                             {
  615.                                 info.posX = (float)atof(value);
  616.                             }
  617.                             else if(!stricmp(key,"PosY") && value)
  618.                             {
  619.                                 info.posY = (float)atof(value);
  620.                             }
  621.                             else if(!stricmp(key,"SoundFile"))
  622.                             {
  623.                                 info.soundFile = value;
  624.                             }
  625.                             else if(!stricmp(key,"AllowSkip") && value)
  626.                             {
  627.                                 info.allowSkip = atoi(value);
  628.                             }
  629.                         }
  630.                         //Search for video file and replace settings
  631.                         if (!m_globalVideoList.empty())
  632.                         {
  633.                             for(int i=0; i<m_globalVideoList.size(); i++)
  634.                             {
  635.                                 SVideoInfo currInfo = m_globalVideoList[i];
  636.                                 if (currInfo.videoName.MakeLower() == info.videoName.MakeLower())
  637.                                 {
  638.                                     m_globalVideoList[i] = info;
  639.                                     break;
  640.                                 }
  641.                             }
  642.                         }
  643.                     }
  644.                 }
  645.             }
  646.         } while (gEnv->pCryPak->FindNext(hFileXml, &fileDataXml) > -1);
  647.         gEnv->pCryPak->FindClose(hFileXml);
  648.     }
  649.  
  650.     CryLogAlways("Hello3");
  651.  
  652.     //Send Video List to UIEnum, so they show up in Editor
  653.     if (pGameToEditorIface) //Only in Editor
  654.     {
  655.         CryLogAlways("Hello4");
  656.         int numAllVideos = 0;
  657.         const char** allVideos = new const char*[m_globalVideoList.size()];
  658.         CryLogAlways("Hello5");
  659.         std::vector<SVideoInfo>::const_iterator iter (m_globalVideoList.begin());
  660.         CryLogAlways("Hello6");
  661.         while (iter != m_globalVideoList.end())
  662.         {
  663.             allVideos[numAllVideos++] = iter->videoName;
  664.             ++iter;
  665.         }
  666.  
  667.         CryLogAlways("Hello7");
  668.  
  669.         pGameToEditorIface->SetUIEnums("video", allVideos, numAllVideos);
  670.  
  671.         CryLogAlways("Hello8");
  672.  
  673.         delete[] allVideos;
  674.     }
  675.  
  676.     CryLogAlways("Hello9");
  677.    
  678.  
  679.     //ToDo: Create Sound Job Lists and Priority Lists (introvideolist.xml & cv_videoMenuBgVideoName - Only in Launcher!!)
  680.     //ToDo: If Firststart=true ---> When Editor or PriorityList = Empty then durchstarten. When Launcher and PriorityList not empty, then warten bis List empty wird, dann durchstarten
  681.  
  682.     if (!m_priorityAudioJobList.empty() || !m_globalAudioJobList.empty())
  683.         soundUpdate = true;
  684.  
  685.     CryLogAlways("Hello10");
  686.  
  687.     //Free temp OpenCV instance
  688.     SAFE_DELETE(m_pCryVideoOpenCV);
  689.  
  690.     CryLogAlways("Hello11");
  691.  
  692.     //Start first sound job
  693.     DoSoundJob();
  694. }
  695.  
  696. void CCryVideo::DoSoundJob() //0.9.8: Check for Sound Job
  697. {
  698.     if (!soundUpdate)
  699.         return;
  700.    
  701.     //ToDo: Jeweils getrennt für Priority und Normal Jobs anlegen
  702.     //int currentSoundJobs;
  703.     //int finishedSoundJobs;
  704.  
  705.  
  706.     //1 ---> Priority Jobs:
  707.  
  708.     //1. List empty? If no...continue, if yes...go to Normal Jobs
  709.     //2. Check priority job status. If started = true && finished = false then check exit code. if exit code = exited then finished true && started = false && CloseHandle
  710.     //3. Check finished priority jobs. If jobFinishedCount = PriorityListSize then clear list (Signal zum Durchstarten)
  711.     //4. Count running priority jobs. maxSoundJobs - RunningJobCount = Number of free threads that can be used
  712.     //5. if freeThreads > 0 then find entrys where started = false and launch them (in einer for Schleife: i=1 ; i <= freeThreads; i++)
  713.  
  714.  
  715.     //2 ---> Normal Jobs:
  716.  
  717.     //1. List empty? If no...continue, if yes...then soundUpdate = false
  718.     //2. Check job status. If started = true && finished = false then check exit code. if exit code = exited then finished true && started = false && CloseHandle
  719.     //3. Check finished jobs. If jobFinishedCount = ListSize then soundUpdate = false
  720.     //4. Count running jobs. maxSoundJobs - RunningJobCount = Number of free threads that can be used
  721.     //5. if freeThreads > 0 then find entrys where started = false and launch them (in einer for Schleife: i=1 ; i <= freeThreads; i++)
  722.  
  723. }
  724.  
  725. void CCryVideo::Update()
  726. {
  727.     if (m_pFramework->IsGamePaused() == false)
  728.     {
  729.         //Cry Video MOD: Update Video Timer System
  730.         if(m_pTimerManager)
  731.         {
  732.             m_pTimerManager->Update();
  733.         }
  734.     }
  735. }
  736.  
  737. //0.9.8: Native Audio Support
  738. int CCryVideo::OnCaptureFrameBegin(void)
  739. {
  740.     CryLogAlways("UPDATE: New Frame!");
  741.  
  742.     //Check for updates
  743.     if (started)
  744.     {
  745.         if(m_LastSoundUpdate + 1.0f <= gEnv->pTimer->GetAsyncCurTime())
  746.         {
  747.             if (soundUpdate) //Check for sound update
  748.                 DoSoundJob();
  749.  
  750.             if (gEnv->IsEditor() && !soundUpdate) //Check for video list update (only in Editor)
  751.                 CreateGlobalVideoList();
  752.  
  753.             m_LastSoundUpdate = gEnv->pTimer->GetAsyncCurTime();
  754.         }
  755.     }
  756.  
  757.     return 0;
  758. }
  759.  
  760. void CCryVideo::Shutdown()
  761. {
  762.     this->~CCryVideo();
  763. }
  764.  
  765. void CCryVideo::GetMemoryStatistics(ICrySizer * s) const
  766. {
  767.     s->Add(*this);
  768. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement