BVB Source Codes

CRYENGINE Show MFXFlowGraphEffect.cpp Source code

Return Download CRYENGINE: download MFXFlowGraphEffect.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   MFXFlowGraphEffect.cpp
  5. //  Version:     v1.00
  6. //  Created:     29/11/2006 by AlexL-Benito GR
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: IMFXEffect implementation
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14. #include "MFXFlowGraphEffect.h"
  15. #include "MaterialEffects.h"
  16. #include "MaterialFGManager.h"
  17. #include "MaterialEffectsCVars.h"
  18. #include "CryAction.h"
  19.  
  20. namespace
  21. {
  22. CMaterialFGManager* GetFGManager()
  23. {
  24.         CMaterialEffects* pMFX = static_cast<CMaterialEffects*>(CCryAction::GetCryAction()->GetIMaterialEffects());
  25.         if (pMFX == 0)
  26.                 return 0;
  27.         CMaterialFGManager* pMFXFGMgr = pMFX->GetFGManager();
  28.         assert(pMFXFGMgr != 0);
  29.         return pMFXFGMgr;
  30. }
  31. };
  32.  
  33. CMFXFlowGraphEffect::CMFXFlowGraphEffect()
  34.         : CMFXEffectBase(eMFXPF_Flowgraph)
  35. {
  36. }
  37.  
  38. CMFXFlowGraphEffect::~CMFXFlowGraphEffect()
  39. {
  40.         CMaterialFGManager* pMFXFGMgr = GetFGManager();
  41.         if (pMFXFGMgr && m_flowGraphParams.fgName.empty() == false)
  42.                 pMFXFGMgr->EndFGEffect(m_flowGraphParams.fgName);
  43. }
  44.  
  45. void CMFXFlowGraphEffect::LoadParamsFromXml(const XmlNodeRef& paramsNode)
  46. {
  47.         // Xml data format
  48.         /*
  49.            <FlowGraph name="..." maxdist="..." param1="..." param2="..." />
  50.          */
  51.  
  52.         m_flowGraphParams.fgName = paramsNode->getAttr("name");
  53.         if (paramsNode->haveAttr("maxdist"))
  54.         {
  55.                 paramsNode->getAttr("maxdist", m_flowGraphParams.maxdistSq);
  56.                 m_flowGraphParams.maxdistSq *= m_flowGraphParams.maxdistSq;
  57.         }
  58.         paramsNode->getAttr("param1", m_flowGraphParams.params[0]); //MFX custom param 1
  59.         paramsNode->getAttr("param2", m_flowGraphParams.params[1]); //MFX custom param 2
  60.         m_flowGraphParams.params[2] = 1.0f;                         //Intensity (set dynamically from game code)
  61.         m_flowGraphParams.params[3] = 0.0f;                         //Blend out time
  62. }
  63.  
  64. void CMFXFlowGraphEffect::Execute(const SMFXRunTimeEffectParams& params)
  65. {
  66.         FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);
  67.  
  68.         if (CMaterialEffectsCVars::Get().mfx_EnableFGEffects == 0)
  69.                 return;
  70.  
  71.         const float distToCameraSq = (gEnv->pSystem->GetViewCamera().GetPosition() - params.pos).GetLengthSquared();
  72.  
  73.         //Check max distance
  74.         if (m_flowGraphParams.maxdistSq == 0.f || distToCameraSq <= m_flowGraphParams.maxdistSq)
  75.         {
  76.                 CMaterialFGManager* pMFXFGMgr = GetFGManager();
  77.                 pMFXFGMgr->StartFGEffect(m_flowGraphParams, sqrt_tpl(distToCameraSq));
  78.                 //if(pMFXFGMgr->StartFGEffect(m_flowGraphParams.fgName))
  79.                 //      CryLogAlways("Starting FG HUD effect %s (player distance %f)", m_flowGraphParams.fgName.c_str(),distToPlayer);
  80.         }
  81. }
  82.  
  83. void CMFXFlowGraphEffect::SetCustomParameter(const char* customParameter, const SMFXCustomParamValue& customParameterValue)
  84. {
  85.         FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);
  86.  
  87.         if (CMaterialEffectsCVars::Get().mfx_EnableFGEffects == 0)
  88.                 return;
  89.  
  90.         CMaterialFGManager* pMFXFGMgr = GetFGManager();
  91.         pMFXFGMgr->SetFGCustomParameter(m_flowGraphParams, customParameter, customParameterValue);
  92. }
  93.  
  94. void CMFXFlowGraphEffect::GetResources(SMFXResourceList& resourceList) const
  95. {
  96.         SMFXFlowGraphListNode* listNode = SMFXFlowGraphListNode::Create();
  97.         listNode->m_flowGraphParams.name = m_flowGraphParams.fgName;
  98.  
  99.         SMFXFlowGraphListNode* next = resourceList.m_flowGraphList;
  100.  
  101.         if (!next)
  102.                 resourceList.m_flowGraphList = listNode;
  103.         else
  104.         {
  105.                 while (next->pNext)
  106.                         next = next->pNext;
  107.  
  108.                 next->pNext = listNode;
  109.         }
  110. }
  111.  
  112. void CMFXFlowGraphEffect::GetMemoryUsage(ICrySizer* pSizer) const
  113. {
  114.         pSizer->AddObject(this, sizeof(*this));
  115.         pSizer->AddObject(m_flowGraphParams.fgName);
  116. }
  117.  
downloadMFXFlowGraphEffect.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top