Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FlowCryVideoPlayer.cpp
- #include "StdAfx.h"
- #include "Nodes/G2FlowBaseNode.h"
- #include "HUD/CryVideo/VideoManager.h"
- #include "Game.h"
- #include "CryVideo.h"
- #include "IRenderer.h"
- #include "UIDraw/UIDraw.h"
- class CFlowCryVideoPlayer : public CFlowBaseNode<eNCT_Instanced>, public IGameFrameworkListener
- {
- private:
- SActivationInfo m_ActInfo;
- IRenderer* m_pRenderer;
- CVideoManager* m_pVideoManager;
- bool m_bEnabled;
- bool m_bPaused;
- bool m_bLooped;
- public:
- CFlowCryVideoPlayer( SActivationInfo * pActInfo )
- {
- m_pRenderer = gEnv->pRenderer;
- m_pVideoManager = NULL;
- m_bEnabled = false;
- m_bPaused = false;
- m_bLooped = false;
- }
- ~CFlowCryVideoPlayer()
- {
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->UnregisterListener(this);
- SAFE_DELETE(m_pVideoManager);
- }
- void Serialize(SActivationInfo* pActInfo, TSerialize ser)
- {
- ser.Value("m_bEnabled", m_bEnabled);
- ser.Value("m_bPaused", m_bPaused);
- ser.Value("m_bLooped", m_bLooped);
- if (ser.IsReading())
- {
- m_ActInfo = *pActInfo;
- //Listener
- if (g_pCryVideo && g_pCryVideo->m_pFramework && m_bEnabled && !m_bPaused && m_pVideoManager->IsPlaying() && !m_pVideoManager->IsPaused())
- g_pCryVideo->m_pFramework->RegisterListener(this, "FlowNode_CryVideoPlayer", eFLPriority_Default);
- }
- }
- enum EInputPorts
- {
- EIP_Play = 0,
- EIP_Stop,
- EIP_Pause,
- EIP_Resume,
- EIP_Slot,
- EIP_SubMtlId,
- EIP_TexSlot,
- EIP_VideoName,
- EIP_AudioVolume,
- EIP_Looped,
- EIP_KeepLastFrame,
- };
- enum EOutputPorts
- {
- EOP_OnPlay = 0,
- EOP_OnStop,
- EOP_OnPause,
- EOP_OnResume,
- EOP_OnVideoNotFound,
- };
- virtual void GetConfiguration(SFlowNodeConfig& config)
- {
- static const SInputPortConfig inputs[] = {
- InputPortConfig_Void ("Play", _HELP("Start playback")),
- InputPortConfig_Void ("Stop", _HELP("Stop playback")),
- InputPortConfig_Void ("Pause", _HELP("Pause playback")),
- InputPortConfig_Void ("Resume", _HELP("Resume playback")),
- InputPortConfig<int> ("Slot", 0, _HELP("Material Slot (e.g. to use CryVideoPlayer on dynamic textures)")),
- InputPortConfig<int> ("SubMtlId", 0, _HELP("Sub Material Id (e.g. to use CryVideoPlayer on dynamic textures)")),
- InputPortConfig<int> ("TexSlot", 0, _HELP("Texture Slot (e.g. to use CryVideoPlayer on dynamic textures)")),
- InputPortConfig<string> ("VideoName", _HELP("Name of video to play"), 0, _UICONFIG("enum_global:video")), //Patch 0.9.8: Changed
- InputPortConfig<float> ("Volume", 1.0f, _HELP("Volume (dynamic)")),
- InputPortConfig<bool> ("Loop", false, _HELP("Video is looped")),
- InputPortConfig<bool> ("KeepLastFrame", false, _HELP("The video stops at the last frame. Can be used together with loop to create a seemless looping video")),
- {0}
- };
- static const SOutputPortConfig outputs[] =
- {
- OutputPortConfig_Void ("OnPlay", _HELP("Triggered once the video started")),
- OutputPortConfig<bool> ("OnStop", _HELP("Triggered once the video stopped. True if the video was finished, false if skipped")),
- OutputPortConfig_Void ("OnPause", _HELP("Triggered once the video is paused")),
- OutputPortConfig_Void ("OnResume", _HELP("Triggered once the video resumes")),
- OutputPortConfig_Void ("OnVideoNotFound", _HELP("Triggered on Video was not found")),
- {0}
- };
- config.pInputPorts = inputs;
- config.pOutputPorts = outputs;
- config.sDescription = _HELP( "CryVideo player node" );
- config.nFlags |= EFLN_TARGET_ENTITY;
- config.SetCategory(EFLN_APPROVED);
- }
- virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
- {
- switch (event)
- {
- case eFE_Initialize:
- {
- m_ActInfo = *pActInfo;
- m_pRenderer = gEnv->pRenderer;
- if (m_pVideoManager == NULL)
- m_pVideoManager = new CVideoManager();
- }
- break;
- case eFE_Activate:
- {
- if (IsPortActive(pActInfo, EIP_Play) && false == m_bEnabled && false == m_bPaused)
- {
- IUIDraw *pDraw = NULL;
- if (g_pCryVideo)
- if (IGameFramework *pFW = g_pCryVideo->m_pFramework)
- pDraw = pFW->GetIUIDraw();
- if (NULL == pDraw) return;
- string videoName = GetPortString(pActInfo, EIP_VideoName);
- float volume = GetPortFloat(pActInfo, EIP_AudioVolume);
- //0.9.6: Loop and KeepLastFrame option added
- m_bLooped = GetPortBool(pActInfo, EIP_Looped);
- bool keepLastFrame = GetPortBool(pActInfo, EIP_KeepLastFrame);
- int slot = GetPortInt(pActInfo, EIP_Slot);
- int subMtlId = GetPortInt(pActInfo, EIP_SubMtlId);
- int texSlot = GetPortInt(pActInfo, EIP_TexSlot);
- if (!videoName || videoName == "")
- {
- ActivateOutput(pActInfo, EOP_OnVideoNotFound, true);
- return;
- }
- IEntity* pEntity = pActInfo->pEntity;
- if(pEntity)
- {
- bool success = m_pVideoManager->PlaySingleVideo(videoName, true, "", 1.0f, pEntity, slot, subMtlId, texSlot, false, keepLastFrame);
- if (success)
- {
- m_bEnabled = true;
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->RegisterListener(this, "FlowNode_CryVideoPlayer", eFLPriority_Default);
- ActivateOutput(pActInfo, EOP_OnPlay, true);
- pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
- }
- else
- {
- ActivateOutput(pActInfo, EOP_OnVideoNotFound, true);
- }
- }
- }
- if (IsPortActive(pActInfo, EIP_Stop) && true == m_bEnabled)
- {
- m_bEnabled = false;
- m_bPaused = false;
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->UnregisterListener(this);
- pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
- if (!m_pVideoManager->IsPlaying())
- {
- ActivateOutput(pActInfo, EOP_OnStop, false);
- }
- else
- {
- m_pVideoManager->StopVideo();
- ActivateOutput(pActInfo, EOP_OnStop, false);
- }
- }
- if (IsPortActive(pActInfo, EIP_Pause) && true == m_bEnabled && false == m_bPaused)
- {
- m_bPaused = true;
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->UnregisterListener(this);
- pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
- if (m_pVideoManager->IsPlaying() && !m_pVideoManager->IsPaused())
- {
- m_pVideoManager->PauseVideo();
- ActivateOutput(pActInfo, EOP_OnPause, true);
- }
- }
- if (IsPortActive(pActInfo, EIP_Resume) && true == m_bEnabled && true == m_bPaused)
- {
- m_bPaused = false;
- if (m_pVideoManager->IsPlaying() && m_pVideoManager->IsPaused())
- {
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->RegisterListener(this, "FlowNode_CryVideoPlayer", eFLPriority_Default);
- pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
- m_pVideoManager->ResumeVideo();
- ActivateOutput(pActInfo, EOP_OnResume, true);
- }
- }
- }
- break;
- case eFE_Update:
- {
- if (m_bEnabled && !m_bPaused)
- {
- if (m_pVideoManager->IsPlaying() && !m_pVideoManager->IsPaused())
- {
- if (m_pVideoManager->pIngameVideoTargetEntity && m_pVideoManager->pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND) && m_pVideoManager->pSoundId)
- {
- IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)m_pVideoManager->pIngameVideoTargetEntity->GetProxy(ENTITY_PROXY_SOUND);
- if (pSoundProxy)
- {
- ISound *pSound = pSoundProxy->GetSound(m_pVideoManager->pSoundId);
- if (pSound)
- {
- float newVolume = GetPortFloat(pActInfo, EIP_AudioVolume);
- pSound->GetInterfaceExtended()->SetVolume(newVolume);
- }
- }
- }
- }
- }
- }
- break;
- }
- }
- IFlowNodePtr Clone( SActivationInfo * pActInfo )
- {
- return new CFlowCryVideoPlayer(pActInfo);
- }
- virtual void GetMemoryUsage(ICrySizer * s) const
- {
- s->Add(*this);
- }
- ////////////////////////////////////////////////////
- // ~IGameFrameworkListener
- virtual void OnSaveGame(ISaveGame* pSaveGame) {}
- virtual void OnLoadGame(ILoadGame* pLoadGame) {}
- virtual void OnLevelEnd(const char* nextLevel) {}
- virtual void OnActionEvent(const SActionEvent& event) {}
- virtual void OnPostUpdate(float fDeltaTime)
- {
- if (false == m_bEnabled || true == m_bPaused) return;
- IUIDraw *pDraw;
- if (g_pCryVideo)
- if (IGameFramework *pFW = g_pCryVideo->m_pFramework)
- pDraw = pFW->GetIUIDraw();
- if (!pDraw) return;
- if (!m_pVideoManager) return;
- if (!m_pVideoManager->IsPlaying() && !m_pVideoManager->IsPaused())
- {
- if (m_pVideoManager->lastVideoFinishedReason == "Finished")
- {
- ActivateOutput(&m_ActInfo, EOP_OnStop, true);
- }
- else if (m_pVideoManager->lastVideoFinishedReason == "Skipped")
- {
- ActivateOutput(&m_ActInfo, EOP_OnStop, false);
- }
- m_bEnabled = false;
- m_bPaused = false;
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->UnregisterListener(this);
- m_ActInfo.pGraph->SetRegularlyUpdated(m_ActInfo.myID, false);
- //0.9.6: Loop and KeepLastFrame option added
- if (m_pVideoManager->lastVideoFinishedReason == "Finished" && m_bLooped)
- {
- string videoName = GetPortString(&m_ActInfo, EIP_VideoName);
- float volume = GetPortFloat(&m_ActInfo, EIP_AudioVolume);
- m_bLooped = GetPortBool(&m_ActInfo, EIP_Looped);
- bool keepLastFrame = GetPortBool(&m_ActInfo, EIP_KeepLastFrame);
- int slot = GetPortInt(&m_ActInfo, EIP_Slot);
- int subMtlId = GetPortInt(&m_ActInfo, EIP_SubMtlId);
- int texSlot = GetPortInt(&m_ActInfo, EIP_TexSlot);
- if (!videoName || videoName == "")
- {
- ActivateOutput(&m_ActInfo, EOP_OnVideoNotFound, true);
- return;
- }
- IEntity* pEntity = m_ActInfo.pEntity;
- if(pEntity)
- {
- bool success = m_pVideoManager->PlaySingleVideo(videoName, true, "", 1.0f, pEntity, slot, subMtlId, texSlot, false, keepLastFrame);
- if (success)
- {
- m_bEnabled = true;
- if (g_pCryVideo && g_pCryVideo->m_pFramework)
- g_pCryVideo->m_pFramework->RegisterListener(this, "FlowNode_CryVideoPlayer", eFLPriority_Default);
- ActivateOutput(&m_ActInfo, EOP_OnPlay, true);
- m_ActInfo.pGraph->SetRegularlyUpdated(m_ActInfo.myID, true);
- }
- else
- {
- ActivateOutput(&m_ActInfo, EOP_OnVideoNotFound, true);
- }
- }
- }
- }
- }
- };
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- REGISTER_FLOW_NODE("Video:CryVideoPlayer", CFlowCryVideoPlayer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement