Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cry Video MOD: NEW VIDEO MANAGER CLASS
- #include "StdAfx.h"
- #include <IGameFramework.h>
- #include <IRenderer.h>
- #include <UIDraw/UIDraw.h>
- #include <Actor.h>
- #include <IFlashUI.h>
- #include "HUD/UIMenuEvents.h"
- #include "HUD/UIManager.h"
- #include <GameCVars.h>
- #include "VideoManager.h"
- #include "VideoTimer.h"
- #include "CryVideo.h"
- //#include <d3d9.h>
- //#include <D3dx9core.h>
- //#pragma once
- //#pragma comment(lib, "d3d9.lib")
- //#pragma comment(lib, "d3dx9.lib")
- //////////////////////////////////////////////////////////////////////////
- CVideoManager::CVideoManager()
- : m_pGameFramework( NULL )
- , m_pUiDraw( NULL )
- {
- assert( g_pCryVideo != NULL );
- isPlaying = false;
- isPaused = false;
- listFilePlaying = false;
- listFileFinished = false;
- stopVideo = false;
- firstStart = true;
- firstStartFinished = false;
- firstStartCounter = 1;
- lastVideoFinishedReason = "None";
- isLoopedVideo = false;
- freezeOnLastFrame = false;
- scheduleUnpause = false;
- currentVideoListId = 0;
- master_texture_id = 0;
- //Initalisierung der benötigten Komponente
- //pD3DDevice = static_cast<IDirect3DDevice9 *>(gEnv->pRenderer->EF_Query(EFQ_D3DDevice));
- frameCounter = -1;
- m_pGameFramework = g_pCryVideo->m_pFramework;
- assert( m_pGameFramework != NULL );
- if ( m_pGameFramework == NULL )
- {
- return;
- }
- m_pUiDraw = m_pGameFramework->GetIUIDraw();
- assert( m_pUiDraw != NULL );
- if ( m_pUiDraw == NULL )
- {
- return;
- }
- //Create new OpenCV instance
- m_pCryVideoOpenCV = g_pCryVideo->CreateOpenCVInstance();
- m_pGameFramework->RegisterListener( this, "VideoManager", eFLPriority_HUD );
- if (gEnv->pInput)
- gEnv->pInput->AddEventListener(this);
- if (g_pCryVideo && g_pCryVideo->GetTimerManager())
- g_pCryVideo->GetTimerManager()->RegisterListener(this);
- ILevelSystem* pLevelSystem = m_pGameFramework->GetILevelSystem();
- if ( pLevelSystem != NULL )
- {
- pLevelSystem->AddListener(this);
- }
- IUIActionManager* pUIActionManager = gEnv->pFlashUI->GetUIActionManager();
- if ( pUIActionManager != NULL )
- {
- pUIActionManager->AddListener(this, "VideoManager");
- }
- //Test
- /*
- HANDLE hNote;
- bool exit = false;
- hNote = g_pCryVideo->ExecuteProcess( "Bin32\\CryVideo\\ffmpeg.exe", "ffmpeg -i Elephants_Dream.WebM -vn TempAudio\\output.mp2", "Game\\Videos\\Library");
- if ( hNote )
- {
- while (!exit)
- {
- DWORD noteExitCode;
- if ( GetExitCodeProcess(hNote , ¬eExitCode) )
- {
- if ( noteExitCode == STILL_ACTIVE )
- {
- // immer noch an
- }
- else
- {
- // Programm beendet
- CloseHandle( hNote );
- exit = true;
- }
- }
- }
- }
- */
- }
- //////////////////////////////////////////////////////////////////////////
- CVideoManager::~CVideoManager()
- {
- if ( m_pGameFramework != NULL )
- {
- m_pGameFramework->GetILevelSystem()->RemoveListener( this );
- m_pGameFramework->UnregisterListener( this );
- }
- //Kill last Timer
- if (m_TimerID)
- g_pCryVideo->GetTimerManager()->KillTimer(m_TimerID);
- if (g_pCryVideo && g_pCryVideo->GetTimerManager())
- g_pCryVideo->GetTimerManager()->UnregisterListener(this);
- if (gEnv->pInput)
- gEnv->pInput->RemoveEventListener(this);
- if (gEnv->pFlashUI->GetUIActionManager())
- gEnv->pFlashUI->GetUIActionManager()->RemoveListener(this);
- if(!m_currentVideoList.empty())
- m_currentVideoList.clear();
- //Free OpenCV instance
- SAFE_DELETE(m_pCryVideoOpenCV);
- }
- //////////////////////////////////////////////////////////////////////////
- bool CVideoManager::PlayVideoList(string videoListName)
- {
- if (!IsEnabled() )
- {
- listFileFinished = true;
- listFilePlaying = false;
- isPlaying = false;
- isPaused = false;
- return false;
- }
- if (listFilePlaying)
- {
- return false;
- }
- listFilePlaying = false;
- if(!m_currentVideoList.empty())
- m_currentVideoList.clear();
- string szVideoListFile = "Videos\\" + videoListName;
- if (szVideoListFile.substr(szVideoListFile.size()-4,4) != ".xml")
- {
- szVideoListFile += ".xml";
- }
- XmlNodeRef videoListInfo = GetISystem()->LoadXmlFromFile(szVideoListFile.c_str());
- if(videoListInfo == 0)
- {
- GameWarning("Cry Video: Could not load video list xml file: %s", szVideoListFile);
- }
- else
- {
- if(videoListInfo)
- {
- for(int n = 0; n < videoListInfo->getChildCount(); ++n)
- {
- XmlNodeRef videoNode = videoListInfo->getChild(n);
- const char* name = videoNode->getTag();
- if(!stricmp(name, "Video"))
- {
- SVideoListInfo info;
- int attribs = videoNode->getNumAttributes();
- const char* key;
- const char* value;
- for(int i = 0; i < attribs; ++i)
- {
- videoNode->getAttributeByIndex(i, &key, &value);
- if(!stricmp(key,"Name"))
- {
- info.videoName = value;
- }
- }
- m_currentVideoList.push_back(info);
- }
- }
- }
- }
- if (!m_currentVideoList.empty())
- {
- //Try to play first video in list
- bool success = PlaySingleVideo(m_currentVideoList[0].videoName, false);
- if (success)
- {
- listFilePlaying = true;
- listFileFinished = false;
- currentVideoListId = 0;
- return true;
- }
- }
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::PlayNextVideoInList(int listIndex)
- {
- if (!IsEnabled() )
- {
- listFileFinished = true;
- listFilePlaying = false;
- isPlaying = false;
- isPaused = false;
- return;
- }
- //Try to play next video in list
- if (!m_currentVideoList.empty())
- PlaySingleVideo(m_currentVideoList[listIndex].videoName, false);
- }
- //////////////////////////////////////////////////////////////////////////
- bool CVideoManager::PlaySingleVideo(string videoName, bool ingame, string ingameAudio, float ingameAudioVolume, IEntity* ingameVideoEntity, int slot, int subMtlId, int texSlot, bool loop, bool keepLastFrame)
- {
- CryLogAlways("VideoManager: Play Single Video!");
- if (!IsEnabled() )
- {
- isPlaying = false;
- isPaused = false;
- return false;
- }
- assert( m_pGameFramework != NULL );
- if ( m_pGameFramework == NULL )
- {
- return false;
- }
- assert( m_pUiDraw != NULL );
- if ( m_pUiDraw == NULL )
- {
- return false;
- }
- IRenderer* pRenderer = gEnv->pRenderer;
- assert( pRenderer != NULL );
- if ( pRenderer == NULL )
- {
- return false;
- }
- //Find video info
- bool bFound = false;
- int iFoundIndex = 0;
- if (!g_pCryVideo->m_globalVideoList.empty())
- {
- for(int i=0; i<g_pCryVideo->m_globalVideoList.size(); i++)
- {
- SVideoInfo info = g_pCryVideo->m_globalVideoList[i];
- if (info.videoName.MakeLower() == videoName.MakeLower())
- {
- //0.9.6: Detect right game folder
- const char* gameFolder;
- ICVar *pVar = gEnv->pConsole->GetCVar("sys_game_folder");
- if (pVar)
- gameFolder = pVar->GetString();
- else
- gameFolder = "Game";
- //Init Video File
- char fileName[255];
- sprintf(fileName, "%s/Videos/Library/%s", gameFolder, videoName.MakeLower());
- string fileNameString;
- fileNameString = fileName;
- bool success = false;
- if (fileNameString.substr(fileNameString.size()-5,5) == ".webm")
- {
- videoFormat = 2;
- success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
- if (!success)
- {
- GameWarning("CryVideo: WebM file '%s' couldn't be opened. Retrying!", videoName);
- success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
- }
- }
- else
- {
- videoFormat = 1;
- success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
- if (!success)
- {
- GameWarning("CryVideo: Video file '%s' couldn't be opened. Retrying!", videoName);
- success = m_pCryVideoOpenCV->LoadVideoFile(fileName, videoFormat);
- }
- }
- if (!success)
- {
- GameWarning("CryVideo: Video file '%s' couldn't be opened. Check file?", videoName);
- }
- else
- {
- bFound = true;
- iFoundIndex = i;
- }
- break;
- }
- }
- }
- if (bFound)
- {
- //Set values
- pIngameVideoTargetEntity = ingameVideoEntity;
- ingameVideoMaterialSlotId = slot;
- ingameVideoSubMtlId = subMtlId;
- ingameVideoTexSlot = texSlot;
- ingameAudioFile = ingameAudio;
- ingameAudioVol = ingameAudioVolume;
- isIngameVideo = ingame;
- isLoopedVideo = loop;
- freezeOnLastFrame = keepLastFrame;
- //Alternate Playback mode (WIP!!)
- /*
- bUseSingleFile = false;
- if (gEnv->pCryPak->IsFileExist("Videos/Library/" + videoName + "/" + videoName + ".CVF"))
- {
- videoCryFileCVF = gEnv->pCryPak->FOpen("Videos\\Library\\" + videoName + "\\" + videoName + ".CVF", "rb" );
- if (videoCryFileCVF)
- {
- BUFSZ = 4096;
- outputBuf = new char[BUFSZ];
- skipFrames = 1;
- startPosition = 0;
- bUseSingleFile = true;
- }
- }
- */
- StartVideo(iFoundIndex);
- if (isPlaying)
- return true;
- }
- else
- {
- GameWarning("CryVideo: Video '%s' couldn't be played! Skipping...", videoName);
- }
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::StartVideo(int videoIndex)
- {
- IRenderer* pRenderer = gEnv->pRenderer;
- assert( pRenderer != NULL );
- if ( pRenderer == NULL )
- {
- return;
- }
- //Set values
- SVideoInfo info = g_pCryVideo->m_globalVideoList[videoIndex];
- pIngameVideoTargetTex = NULL;
- //frameCounter = -1;
- frameCounter = 0;
- videoName = info.videoName;
- blackFramesCounter = int_round(gEnv->pTimer->GetFrameRate());
- videoWidth = info.videoWidth;
- videoHeight = info.videoHeight;
- xPos = info.posX;
- yPos = info.posY;
- pSoundId = NULL;
- frameEndIndex = m_pCryVideoOpenCV->GetFrameCount();
- frameRate = m_pCryVideoOpenCV->GetVideoFrameRate();
- frameWidth = m_pCryVideoOpenCV->GetVideoWidth();
- frameHeight = m_pCryVideoOpenCV->GetVideoHeight();
- desiredFrameUpdateTime = 1.0f / frameRate;
- CryLogAlways("VideoManager: Desired Frame Update Time: %f", desiredFrameUpdateTime);
- //Check Sound Type
- string szSoundFilePath;
- if (info.soundFile == "Default")
- szSoundFilePath = "videos/library/TempAudio/CryVideo_" + info.videoName + ".mp2";
- else
- szSoundFilePath = "videos/library/" + info.soundFile;
- if (info.allowSkip == 1)
- {
- isSkippable = true;
- }
- else
- {
- isSkippable = false;
- }
- if (firstStart && !g_pCryVideo->m_bMenuRendered)
- {
- isSkippable = false;
- firstStartCounter = int_round(frameRate);
- }
- //Intialize master texture
- CryLogAlways("VideoManager: CreateMasterTexture!");
- //Create master texture
- char* imageData = m_pCryVideoOpenCV->StartPlayback();
- if (imageData != NULL)
- {
- bool success = false;
- if (g_pCryVideo->IsRGB8Usable())
- {
- master_texture_id = gEnv->pRenderer->DownLoadToVideoMemory(reinterpret_cast<unsigned char*> (imageData), frameWidth, frameHeight, eTF_R8G8B8, eTF_R8G8B8, 0x1, false);
- }
- else
- {
- master_texture_id = gEnv->pRenderer->DownLoadToVideoMemory(reinterpret_cast<unsigned char*> (imageData), frameWidth, frameHeight, eTF_A8R8G8B8, eTF_A8R8G8B8, 0x1, false);
- }
- ITexture *pTexture = gEnv->pRenderer->EF_GetTextureByID(master_texture_id);
- if (pTexture)
- if (pTexture->IsTextureLoaded())
- success = true;
- if (!success)
- {
- GameWarning("CryVideo: Critical Error. Texture format not recognized. Check video file '%s' !", videoName);
- StopVideo();
- return;
- }
- }
- else
- {
- GameWarning("CryVideo: Critical Error. Frame couldn't be retrieved. Check video file '%s' !", videoName);
- StopVideo();
- return;
- }
- //Start Audio
- if(!isIngameVideo)
- {
- if (szSoundFilePath != "" && szSoundFilePath != "videos/library/")
- {
- ISound *pSound;
- pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(), FLAG_SOUND_2D|FLAG_SOUND_MOVIE|FLAG_SOUND_PRECACHE_LOAD_SOUND);
- if (pSound)
- {
- pSoundId = pSound->GetId();
- if (!isLoopedVideo)
- pSound->GetInterfaceDeprecated()->SetLoopMode(false);
- if (firstStart && !g_pCryVideo->m_bMenuRendered)
- {
- pSound->Play(0.0f);
- }
- else
- {
- pSound->Play();
- }
- }
- }
- }
- else
- {
- if (pIngameVideoTargetEntity && szSoundFilePath != "" && szSoundFilePath != "videos/library/")
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (!pSoundProxy)
- pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->CreateProxy(ENTITY_PROXY_SOUND);
- pSoundProxy->StopAllSounds();
- ISound *pSound;
- if (pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- {
- pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(),FLAG_SOUND_DEFAULT_3D | FLAG_SOUND_VOICE);
- pSound->SetSemantic(eSoundSemantic_Dialog);
- }
- else
- {
- pSound = gEnv->pSoundSystem->CreateSound(szSoundFilePath.c_str(),FLAG_SOUND_DEFAULT_3D);
- pSound->SetSemantic(eSoundSemantic_Living_Entity);
- }
- if (pSound)
- {
- pSoundId = pSound->GetId();
- if (!isLoopedVideo)
- pSound->GetInterfaceDeprecated()->SetLoopMode(false);
- pSoundProxy->PlaySound(pSound, Vec3(ZERO), FORWARD_DIRECTION, ingameAudioVol, false);
- }
- }
- if (pIngameVideoTargetEntity)
- {
- if (pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- {
- IEntityRenderProxy* pRenderProxy((IEntityRenderProxy*)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_RENDER));
- if (pRenderProxy)
- {
- IMaterial* pMtl(pRenderProxy->GetRenderMaterial(ingameVideoMaterialSlotId));
- if (pMtl)
- {
- pMtl = pMtl->GetSafeSubMtl(ingameVideoSubMtlId);
- if (pMtl)
- {
- //CryLogAlways(pMtl->GetName());
- const SShaderItem& shaderItem(pMtl->GetShaderItem());
- if (shaderItem.m_pShaderResources)
- {
- SEfResTexture* pTex = shaderItem.m_pShaderResources->GetTexture(ingameVideoTexSlot);
- if (pTex)
- {
- pIngameVideoTargetTex = pTex;
- pDefaultTexture = NULL;
- pDefaultTexture = pTex->m_Sampler.m_pITex;
- if (pIngameVideoTargetTex)
- {
- //ITexture *pNewTexture = pRenderer->EF_GetTextureByID(nextFrame);
- ITexture *pNewTexture = pRenderer->EF_GetTextureByID(master_texture_id);
- if (pNewTexture)
- {
- //ITexture *pOldTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
- pIngameVideoTargetTex->m_Sampler.m_pITex = pNewTexture;
- /*
- if (pOldTexture && pOldTexture != pDefaultTexture)
- {
- //Try to delete Dummy File from disk
- if (bUseSingleFile)
- gEnv->pCryPak->RemoveFile(pOldTexture->GetName());
- if (pOldTexture)
- m_pUiDraw->DeleteTexture(pOldTexture->GetTextureID());
- }
- */
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- lastVideoFinishedReason = "None";
- isPlaying = true;
- isPaused = false;
- scheduleUnpause = false;
- //Schedule Timer
- if (m_TimerID)
- g_pCryVideo->GetTimerManager()->KillTimer(m_TimerID);
- m_TimerID = g_pCryVideo->GetTimerManager()->CreateTimer(this, desiredFrameUpdateTime, true, true);
- //OnVideoTimer(m_TimerID);
- }
- /////////////////////////////////////////////////////////////////////////
- void CVideoManager::StopVideo()
- {
- if (gEnv->IsDedicated())
- return;
- if (!IsEnabled() || !isPlaying)
- return;
- stopVideo = true;
- isLoopedVideo = false;
- OnVideoTimer(m_TimerID); //Stop video immediately
- }
- /////////////////////////////////////////////////////////////////////////
- void CVideoManager::PauseVideo()
- {
- if (gEnv->IsDedicated())
- return;
- if (!IsEnabled() || !isPlaying || isPaused || !isIngameVideo)
- return;
- isPaused = true;
- if (pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId)
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- ISound *pSound = pSoundProxy->GetSound(pSoundId);
- if (pSound)
- {
- pSound->SetPaused(true);
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////
- void CVideoManager::ResumeVideo()
- {
- if (gEnv->IsDedicated())
- return;
- if (!IsEnabled() || !isPlaying || !isPaused || !isIngameVideo)
- return;
- isPaused = false;
- if (pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId)
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- ISound *pSound = pSoundProxy->GetSound(pSoundId);
- if (pSound)
- {
- pSound->SetPaused(false);
- }
- }
- }
- OnVideoTimer(m_TimerID);
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::UpdateVideo()
- {
- if (!IsEnabled() )
- {
- isPlaying = false;
- isPaused = false;
- return;
- }
- if (!isPlaying)
- {
- return;
- }
- //No update needed here, just draw the same
- if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- {
- IRenderer* pRenderer = gEnv->pRenderer;
- if (!pRenderer)
- return;
- //m_pUiDraw->PreRender();
- //char fileName[255];
- //char frameCounterString[255];
- /*
- sprintf(frameCounterString,"%i",(int)frameCounter);
- int digitsOffset = frameDigitsNumber - strlen(frameCounterString);
- string sequencePrefix = "";
- while (digitsOffset > 0)
- {
- sequencePrefix = sequencePrefix + "0";
- --digitsOffset;
- }
- */
- /*
- if (!bUseSingleFile)
- {
- sprintf(fileName,"Videos\\Library\\" + videoName + "\\" + videoName + sequencePrefix + "%i.tif",(int)frameCounter);
- }
- */
- if (firstStart && !g_pCryVideo->m_bMenuRendered)
- {
- //first video and engine is not fully stable, render some black frames first
- int nextFrame = m_pUiDraw->CreateTexture("Textures\\defaults\\black.tif", false);
- pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- m_pUiDraw->DeleteTexture(nextFrame);
- }
- else
- {
- if (frameCounter == 0)
- return;
- /*
- if (bUseSingleFile)
- {
- char fileNameOut[255];
- sprintf(fileNameOut, "%s_Dummy_%i.dds", videoName, frameCounter);
- nextFrame = m_pUiDraw->CreateTexture(fileNameOut, false);
- }
- else
- {
- nextFrame = m_pUiDraw->CreateTexture(fileName, false);
- }
- */
- pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, master_texture_id, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- //pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- //m_pUiDraw->DeleteTexture(nextFrame);
- }
- //m_pUiDraw->PostRender();
- }
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::OnVideoTimer(CryVideoTimerID id)
- {
- if(id != m_TimerID)
- return;
- if (!IsEnabled() )
- {
- isPlaying = false;
- isPaused = false;
- return;
- }
- //Enough black frames rendered, start first video
- if (firstStart && !firstStartFinished && !g_pCryVideo->m_bMenuRendered && firstStartCounter <= 0)
- {
- CryLogAlways("VideoManager: Engine Stable1!");
- stopVideo = true;
- }
- IRenderer* pRenderer = gEnv->pRenderer;
- if (!pRenderer)
- return;
- if (stopVideo)
- {
- stopVideo = false;
- if (firstStart && !g_pCryVideo->m_bMenuRendered)
- {
- firstStartFinished = true;
- }
- else
- {
- if (listFilePlaying && !listFileFinished && !m_currentVideoList.empty() && currentVideoListId + 1 == m_currentVideoList.size())
- {
- listFileFinished = true;
- listFilePlaying = false;
- if(!m_currentVideoList.empty())
- m_currentVideoList.clear();
- }
- }
- lastVideoFinishedReason = "Skipped";
- isPlaying = false;
- isPaused = false;
- if (isIngameVideo)
- {
- if (pIngameVideoTargetEntity)
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- pSoundProxy->StopAllSounds();
- }
- }
- }
- else
- {
- ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
- if (pSound)
- pSound->Stop(ESoundStopMode_AtOnce);
- }
- if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- {
- if (pIngameVideoTargetTex)
- {
- ITexture *pLastTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
- pIngameVideoTargetTex->m_Sampler.m_pITex = pDefaultTexture;
- if (pLastTexture)
- m_pUiDraw->DeleteTexture(pLastTexture->GetTextureID());
- }
- }
- m_pUiDraw->DeleteTexture(master_texture_id);
- //Close Video file
- m_pCryVideoOpenCV->CloseVideoFile();
- //Close Video File and delete final Dummy Files
- /*
- if (bUseSingleFile)
- {
- char* fileNameDummy;
- fileNameDummy = new char[255];
- int frameNumber = frameCounter - 1;
- sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
- gEnv->pCryPak->RemoveFile(fileNameDummy);
- fileNameDummy = new char[255];
- frameNumber = frameCounter;
- sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
- gEnv->pCryPak->RemoveFile(fileNameDummy);
- //Close CVF File
- gEnv->pCryPak->FClose(videoCryFileCVF);
- //Clean Memory
- videoCryFileCVF = NULL;
- BUFSZ = NULL;
- outputBuf = NULL;
- outputLen = NULL;
- nRead = NULL;
- startPosition = NULL;
- }
- */
- //Can cause a crash...
- //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- //pRenderer->ResetToDefault();
- }
- if (!isPlaying || isPaused)
- {
- return;
- }
- //Advance to next frame
- //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- //m_pUiDraw->PreRender();
- if (videoFormat == 1 && frameCounter < frameEndIndex || videoFormat == 2)
- {
- if (firstStart && !g_pCryVideo->m_bMenuRendered)
- {
- //first video and engine is not fully stable, render some black frames first
- int nextFrame = m_pUiDraw->CreateTexture("Textures\\defaults\\black.tif", false);
- --firstStartCounter;
- pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- m_pUiDraw->DeleteTexture(nextFrame);
- }
- else
- {
- //char fileName[255];
- //char frameCounterString[255];
- ++frameCounter;
- if(frameCounter == 1)
- return;
- /*
- sprintf(frameCounterString,"%i",(int)frameCounter);
- int digitsOffset = frameDigitsNumber - strlen(frameCounterString);
- string sequencePrefix = "";
- while (digitsOffset > 0)
- {
- sequencePrefix = sequencePrefix + "0";
- --digitsOffset;
- }
- */
- //CryLogAlways("Query Frame!");
- char* imageData = m_pCryVideoOpenCV->GetNextFrame();
- if (imageData == NULL)
- goto end;
- if (g_pCryVideo->IsRGB8Usable())
- {
- gEnv->pRenderer->UpdateTextureInVideoMemory(master_texture_id, reinterpret_cast<unsigned char*> (imageData), 0, 0, frameWidth, frameHeight, eTF_R8G8B8);
- }
- else
- {
- gEnv->pRenderer->UpdateTextureInVideoMemory(master_texture_id, reinterpret_cast<unsigned char*> (imageData), 0, 0, frameWidth, frameHeight, eTF_A8R8G8B8);
- }
- //CryLogAlways("Frame received!");
- /*
- float videoPlayTime = (float) frameCounter;
- float audioPlayTime = 0.0f;
- videoPlayTime = videoPlayTime / (float)int_round((1.0f / desiredFrameUpdateTime));
- if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && pSoundId && !IsPaused())
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- ISound *pSound = pSoundProxy->GetSound(pSoundId);
- if (pSound)
- {
- audioPlayTime = pSound->GetInterfaceExtended()->GetCurrentSamplePos(true) / 1000.0f;
- }
- }
- }
- else if (!isIngameVideo && !IsPaused())
- {
- ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
- if (pSound)
- {
- audioPlayTime = pSound->GetInterfaceExtended()->GetCurrentSamplePos(true) / 1000.0f;
- }
- }
- CryLogAlways("VideoZeit: %f\nAudioZeit: %f\n---------------------------", videoPlayTime, audioPlayTime);
- */
- /*
- if (!bUseSingleFile)
- {
- sprintf(fileName,"Videos\\Library\\" + videoName + "\\" + videoName + sequencePrefix + "%i.tif",(int)frameCounter);
- nextFrame = m_pUiDraw->CreateTexture(fileName, false);
- }
- else if (videoCryFileCVF)
- {
- int skipFramesNow = skipFrames;
- bool isBreak = false;
- //Seek to right start position
- gEnv->pCryPak->FSeek(videoCryFileCVF, startPosition, SEEK_SET);
- //Save Dummy DDS File
- char fileNameOut[255];
- sprintf(fileNameOut, "%s_Dummy_%i.dds", videoName, frameCounter);
- FILE *fileHandle = gEnv->pCryPak->FOpen(fileNameOut, "wb");
- if (fileHandle)
- {
- // scan for new frame
- do
- {
- nRead = gEnv->pCryPak->FRead(outputBuf, BUFSZ, videoCryFileCVF);
- startPosition = startPosition + nRead;
- for(size_t c = 0; c < nRead; ++c)
- {
- if(outputBuf[c] == 'D' && outputBuf[c+1] == 'D' && outputBuf[c+2] == 'S')
- {
- if (skipFramesNow <= 0)
- {
- outputLen = c;
- startPosition = startPosition - (nRead - c);
- isBreak = true;
- break;
- }
- else
- {
- --skipFramesNow;
- }
- }
- }
- if (isBreak)
- break;
- gEnv->pCryPak->FWrite(outputBuf, nRead, 1, fileHandle);
- }
- while (nRead == BUFSZ);
- gEnv->pCryPak->FWrite(outputBuf, outputLen, 1, fileHandle);
- gEnv->pCryPak->FClose(fileHandle);
- }
- nextFrame = m_pUiDraw->CreateTexture(fileNameOut, false);
- }
- */
- if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- {
- pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, master_texture_id, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- //pRenderer->Draw2dImage(xPos, yPos, videoWidth, videoHeight, nextFrame, 0.0f,1.0f,1.0f,0.0f, 0.0f);
- //m_pUiDraw->DeleteTexture(nextFrame);
- }
- //Delete last Dummy File
- /*
- if (bUseSingleFile)
- {
- char fileNameDummy[255];
- int frameNumber = frameCounter - 1;
- sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
- gEnv->pCryPak->RemoveFile(fileNameDummy);
- }
- */
- }
- }
- else
- {
- end:
- lastVideoFinishedReason = "Finished";
- if (isIngameVideo)
- {
- if (pIngameVideoTargetEntity)
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- pSoundProxy->StopAllSounds();
- }
- }
- }
- else
- {
- ISound *pSound = gEnv->pSoundSystem->GetSound(pSoundId);
- if (pSound)
- pSound->Stop(ESoundStopMode_AtOnce);
- }
- if (listFilePlaying && !listFileFinished && !m_currentVideoList.empty() && currentVideoListId + 1 == m_currentVideoList.size())
- {
- listFileFinished = true;
- listFilePlaying = false;
- if(!m_currentVideoList.empty())
- m_currentVideoList.clear();
- }
- if (isIngameVideo && pIngameVideoTargetEntity && pIngameVideoTargetEntity != g_pCryVideo->m_pFramework->GetClientActor()->GetEntity() && !freezeOnLastFrame)
- {
- if (pIngameVideoTargetTex)
- {
- ITexture *pLastTexture = pIngameVideoTargetTex->m_Sampler.m_pITex;
- pIngameVideoTargetTex->m_Sampler.m_pITex = pDefaultTexture;
- if (pLastTexture)
- m_pUiDraw->DeleteTexture(pLastTexture->GetTextureID());
- }
- }
- //Close Video file
- m_pCryVideoOpenCV->CloseVideoFile();
- /*
- //Close Video File and delete final Dummy Files
- if (bUseSingleFile)
- {
- char* fileNameDummy;
- fileNameDummy = new char[255];
- int frameNumber = frameCounter - 1;
- sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
- gEnv->pCryPak->RemoveFile(fileNameDummy);
- fileNameDummy = new char[255];
- frameNumber = frameCounter;
- sprintf(fileNameDummy, "%s_Dummy_%i.dds", videoName, frameNumber);
- gEnv->pCryPak->RemoveFile(fileNameDummy);
- //Close CVF File
- gEnv->pCryPak->FClose(videoCryFileCVF);
- //Clean Memory
- videoCryFileCVF = NULL;
- BUFSZ = NULL;
- outputBuf = NULL;
- outputLen = NULL;
- nRead = NULL;
- startPosition = NULL;
- }
- */
- isPlaying = false;
- isPaused = false;
- m_pUiDraw->DeleteTexture(master_texture_id);
- //Can cause a crash...
- //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- //pRenderer->ResetToDefault();
- }
- //if (!isIngameVideo || pIngameVideoTargetEntity && pIngameVideoTargetEntity == g_pCryVideo->m_pFramework->GetClientActor()->GetEntity())
- //m_pUiDraw->PostRender();
- }
- void CVideoManager::OnPostUpdate( float fDeltaTime )
- {
- if (firstStart && !g_pCryVideo->m_bMenuRendered && firstStartCounter <= 0 && firstStartFinished)
- {
- //Engine is now stable: restart first video
- CryLogAlways("VideoManager: Engine Stable2!");
- firstStart = false;
- PlayNextVideoInList(currentVideoListId);
- }
- else if (listFilePlaying && !listFileFinished && !isPlaying && !m_currentVideoList.empty() && currentVideoListId + 1 != m_currentVideoList.size())
- {
- --blackFramesCounter;
- if (blackFramesCounter <= 0)
- {
- ++currentVideoListId;
- PlayNextVideoInList(currentVideoListId);
- }
- }
- if (isLoopedVideo && !isPlaying)
- {
- PlaySingleVideo(videoName, false, "", 1.0f, 0, 0, 0, 0, true, false);
- }
- //Check for stop/pause conditions
- if (gEnv->IsEditor() && !gEnv->IsEditorGameMode() && isPlaying)
- {
- StopVideo();
- }
- if (!gEnv->IsEditor() && !gEnv->IsDedicated() && m_pGameFramework->IsGameStarted() && g_pCryVideo->m_bMenuRendered && m_pGameFramework->IsGamePaused() && isPlaying && !isPaused && !scheduleUnpause)
- {
- scheduleUnpause = true;
- PauseVideo();
- }
- if (!gEnv->IsEditor() && !gEnv->IsDedicated() && m_pGameFramework->IsGameStarted() && g_pCryVideo->m_bMenuRendered && !m_pGameFramework->IsGamePaused() && isPlaying && isPaused && scheduleUnpause)
- {
- scheduleUnpause = false;
- ResumeVideo();
- }
- UpdateVideo();
- }
- //////////////////////////////////////////////////////////////////////////
- bool CVideoManager::OnInputEvent( const SInputEvent &event )
- {
- if (event.deviceId!=eDI_Keyboard)
- return false;
- if (gEnv->IsDedicated() || event.keyId == eKI_SYS_Commit)
- return false;
- if (!IsEnabled())
- return false;
- if (!isPlaying)
- return false;
- if (eIS_Pressed != event.state)
- return false;
- bool stopVideoNow = false;
- //skip movie
- if(!gEnv->pConsole->GetStatus() && !isPaused && isSkippable && !isLoopedVideo)
- {
- if(event.keyId == eKI_Space || event.keyId == eKI_Escape && !g_pCryVideo->m_bMenuRendered)
- {
- stopVideoNow = true;
- }
- }
- if (stopVideoNow)
- {
- StopVideo();
- return true;
- }
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::OnLoadingStart( ILevelInfo* pLevel )
- {
- if (gEnv->IsEditor() || gEnv->IsDedicated())
- return;
- isLoopedVideo = false;
- if (isPlaying)
- {
- StopVideo();
- }
- }
- //////////////////////////////////////////////////////////////////////////
- void CVideoManager::OnEnd( IUIAction* pAction, const SUIArguments& args )
- {
- if (gEnv->IsEditor() || gEnv->IsDedicated())
- return;
- static IUIAction* pActionMenu = gEnv->pFlashUI->GetUIAction("MM_DisplayMenu");
- if (pAction && pActionMenu)
- {
- if (pAction == pActionMenu)
- {
- //Level BG MOD: Check if video bg menu is prefered
- bool bUseVideoBgMenu = false;
- string videoNameLoop = "";
- ICVar *pVarVideo = gEnv->pConsole->GetCVar("cv_useVideoAsMenuBg");
- if (pVarVideo)
- {
- if (pVarVideo->GetIVal() == 1)
- {
- //Level BG MOD: Load video
- ICVar *pVarVideoName = gEnv->pConsole->GetCVar("cv_videoMenuBgVideoName");
- if (pVarVideoName)
- {
- videoNameLoop = pVarVideoName->GetString();
- }
- if (videoNameLoop != "")
- {
- bUseVideoBgMenu = true;
- }
- }
- }
- if (bUseVideoBgMenu)
- {
- //Schedule video playback on next frame
- isLoopedVideo = true;
- videoName = videoNameLoop;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment