BVB Source Codes

CRYENGINE Show FeatureComponent.cpp Source code

Return Download CRYENGINE: download FeatureComponent.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "ParticleSystem/ParticleFeature.h"
  5. #include "ParticleSystem/ParticleEmitter.h"
  6.  
  7. CRY_PFX2_DBG
  8.  
  9. namespace pfx2
  10. {
  11.  
  12. class CEvaluator
  13. {
  14. public:
  15.         void SerializeInplace(Serialization::IArchive& ar)
  16.         {
  17.                 ar(m_attributeName, "Attribute", "Attribute");
  18.         }
  19.  
  20.         bool Evaluate(CParticleEmitter* pEmitter) const
  21.         {
  22.                 const CAttributeInstance& attributes = pEmitter->GetAttributeInstance();
  23.                 const auto attributeId = attributes.FindAttributeIdByName(m_attributeName.c_str());
  24.                 const bool attributeValue = attributes.GetAsBoolean(attributeId, true);
  25.                 return attributeValue;
  26.         }
  27.  
  28. private:
  29.         string m_attributeName;
  30. };
  31.  
  32. //////////////////////////////////////////////////////////////////////////
  33. // CFeatureComponentEnableIf
  34.  
  35. class CFeatureComponentEnableIf : public CParticleFeature
  36. {
  37. public:
  38.         CRY_PFX2_DECLARE_FEATURE
  39.  
  40. public:
  41.         virtual bool CanMakeRuntime(CParticleEmitter* pEmitter) const override
  42.         {
  43.                 CRY_PFX2_PROFILE_DETAILS;
  44.                 return m_evaluator.Evaluate(pEmitter);
  45.         }
  46.  
  47.         virtual void Serialize(Serialization::IArchive& ar) override
  48.         {
  49.                 CParticleFeature::Serialize(ar);
  50.                 m_evaluator.SerializeInplace(ar);
  51.         }
  52.  
  53. private:
  54.         CEvaluator m_evaluator;
  55. };
  56.  
  57. CRY_PFX2_IMPLEMENT_FEATURE(CParticleFeature, CFeatureComponentEnableIf, "Component", "EnableIf", colorComponent);
  58.  
  59. //////////////////////////////////////////////////////////////////////////
  60. // CFeatureComponentSpawnIf
  61.  
  62. class CFeatureComponentSpawnIf : public CParticleFeature
  63. {
  64. public:
  65.         CRY_PFX2_DECLARE_FEATURE
  66.  
  67. public:
  68.         virtual void AddToComponent(CParticleComponent* pComponent, SComponentParams* pParams) override
  69.         {
  70.                 pComponent->AddToUpdateList(EUL_MainPreUpdate, this);
  71.         }
  72.  
  73.         virtual void Serialize(Serialization::IArchive& ar) override
  74.         {
  75.                 CParticleFeature::Serialize(ar);
  76.                 m_evaluator.SerializeInplace(ar);
  77.         }
  78.  
  79.         virtual void MainPreUpdate(CParticleComponentRuntime* pComponentRuntime) override
  80.         {
  81.                 CRY_PFX2_PROFILE_DETAILS;
  82.                 if (!m_evaluator.Evaluate(pComponentRuntime->GetEmitter()))
  83.                         pComponentRuntime->RemoveAllSubInstances();
  84.         }
  85.  
  86. private:
  87.         CEvaluator m_evaluator;
  88. };
  89.  
  90. CRY_PFX2_IMPLEMENT_FEATURE(CParticleFeature, CFeatureComponentSpawnIf, "Component", "SpawnIf", colorComponent);
  91.  
  92. //////////////////////////////////////////////////////////////////////////
  93. // CFeatureComponentEnableByConfig
  94.  
  95. SERIALIZATION_DECLARE_ENUM(EEnableIfConfig,
  96.         Low      = CONFIG_LOW_SPEC,
  97.         Medium   = CONFIG_MEDIUM_SPEC,
  98.         High     = CONFIG_HIGH_SPEC,
  99.         VeryHigh = CONFIG_VERYHIGH_SPEC
  100.         )
  101.  
  102. class CFeatureComponentEnableByConfig : public CParticleFeature
  103. {
  104. public:
  105.         CRY_PFX2_DECLARE_FEATURE
  106.  
  107. public:
  108.         CFeatureComponentEnableByConfig()
  109.                 : m_minimumConfig(EEnableIfConfig::Low)
  110.                 , m_maximumConfig(EEnableIfConfig::VeryHigh)
  111.                 , m_PC(true), m_XBoxOne(true), m_PS4(true) {}
  112.  
  113.         virtual bool CanMakeRuntime(CParticleEmitter* pEmitter) const override
  114.         {
  115.                 CRY_PFX2_PROFILE_DETAILS;
  116.  
  117.                 CVars* pCVars = static_cast<C3DEngine*>(gEnv->p3DEngine)->GetCVars();
  118.                 const ESystemConfigSpec configSpec = gEnv->pSystem->GetConfigSpec();
  119.                 const uint particleSpec = pCVars->e_ParticlesQuality != 0 ? pCVars->e_ParticlesQuality : configSpec;
  120.                 const bool isPc = particleSpec <= CONFIG_VERYHIGH_SPEC;
  121.  
  122.                 if (isPc)
  123.                 {
  124.                         return
  125.                                 (particleSpec >= uint(m_minimumConfig)) &&
  126.                                 (particleSpec <= uint(m_maximumConfig));
  127.                 }
  128.                 else if (particleSpec == CONFIG_DURANGO && m_XBoxOne)
  129.                         return true;
  130.                 else if (particleSpec == CONFIG_ORBIS && m_PS4)
  131.                         return true;
  132.  
  133.                 return false;
  134.         }
  135.  
  136.         virtual void Serialize(Serialization::IArchive& ar) override
  137.         {
  138.                 CParticleFeature::Serialize(ar);
  139.                 ar(m_PC, "PC", "PC");
  140.                 if (m_PC)
  141.                 {
  142.                         ar(m_minimumConfig, "Minimum", "Minimum");
  143.                         ar(m_maximumConfig, "Maximum", "Maximum");
  144.                 }
  145.                 ar(m_XBoxOne, "XBoxOne", "XBox One");
  146.                 ar(m_PS4, "PS4", "Playstation 4");
  147.         }
  148.  
  149. private:
  150.         EEnableIfConfig m_minimumConfig;
  151.         EEnableIfConfig m_maximumConfig;
  152.         bool m_PC, m_XBoxOne, m_PS4;
  153. };
  154.  
  155. CRY_PFX2_IMPLEMENT_FEATURE(CParticleFeature, CFeatureComponentEnableByConfig, "Component", "EnableByConfig", colorComponent);
  156.  
  157. }
  158.  
downloadFeatureComponent.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