Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. #include "StdAfx.h"
  2. #include "ParticleEmitter.h"
  3.  
  4. #include "Game/GameFactory.h"
  5.  
  6. #include "FlowNodes/Helpers/FlowGameEntityNode.h"
  7.  
  8. #include <Cry3DEngine/I3DEngine.h>
  9. #include <CryParticleSystem/IParticlesPfx2.h>
  10.  
  11. class CParticleEmitterRegistrator
  12.     : public IEntityRegistrator
  13. {
  14.     virtual void Register() override
  15.     {
  16.         CParticleEmitter::Register();
  17.     }
  18. };
  19.  
  20. CParticleEmitterRegistrator g_particleEmitterRegistrator;
  21.  
  22. CParticleEmitter::CParticleEmitter()
  23.     : m_particleSlot(-1)
  24. {
  25. }
  26.  
  27. void CParticleEmitter::Register()
  28. {
  29.     auto properties = new SNativeEntityPropertyInfo[eNumProperties];
  30.     memset(properties, 0, sizeof(SNativeEntityPropertyInfo) * eNumProperties);
  31.  
  32.     RegisterEntityProperty<bool>(properties, eProperty_Active, "Active", "1", "", 0, 1);
  33.     RegisterEntityPropertyObject(properties, eProperty_EffectName, "ParticleEffect", "", "");
  34.  
  35.     // Finally, register the entity class so that instances can be created later on either via Launcher or Editor
  36.     CGameFactory::RegisterNativeEntity<CParticleEmitter>("ParticleEmitter", "UserStuff", "Particles.bmp", 0u, properties, eNumProperties);
  37.  
  38.  
  39.     // Create flownode
  40.     CGameEntityNodeFactory &nodeFactory = CGameFactory::RegisterEntityFlowNode("ParticleEmitter");
  41.  
  42.     // Define input ports, and the callback function for when they are triggered
  43.     std::vector<SInputPortConfig> inputs;
  44.     inputs.push_back(InputPortConfig_Void("TurnOn", "Turns on"));
  45.     inputs.push_back(InputPortConfig_Void("TurnOff", "Turns off"));
  46.     nodeFactory.AddInputs(inputs, OnFlowgraphActivation);
  47.  
  48.     // Mark the factory as complete, indicating that there will be no additional ports
  49.     nodeFactory.Close();
  50. }
  51.  
  52. void CParticleEmitter::PostInit(IGameObject *pGameObject)
  53. {
  54.     Reset();
  55. }
  56.  
  57. void CParticleEmitter::Reset()
  58. {
  59.     IEntity& entity = *GetEntity();
  60.  
  61.     // Check if we have to unload first
  62.     if (m_particleSlot != -1)
  63.     {
  64.         entity.FreeSlot(m_particleSlot);
  65.         m_particleSlot = -1;
  66.     }
  67.  
  68.     // Check if the light is active
  69.     if (!GetPropertyBool(eProperty_Active))
  70.         return;
  71.  
  72.     const char *effect = GetPropertyValue(eProperty_EffectName);
  73.     if (strlen(effect) > 0)
  74.     {
  75.         if (IParticleEffect* pEffect = gEnv->pParticleManager->FindEffect(effect, "ParticleEmitter"))
  76.         {
  77.             m_particleSlot = entity.LoadParticleEmitter(0, pEffect);
  78.         }
  79.     }
  80.  
  81.  
  82. }
  83.  
  84. void CParticleEmitter::ProcessEvent(SEntityEvent& event)
  85. {
  86.     if (gEnv->IsDedicated())
  87.         return;
  88.  
  89.     switch (event.event)
  90.     {
  91.         // Physicalize on level start for Launcher
  92.     case ENTITY_EVENT_START_LEVEL:
  93.         // Editor specific, physicalize on reset, property change or transform change
  94.     case ENTITY_EVENT_RESET:
  95.     case ENTITY_EVENT_EDITOR_PROPERTY_CHANGED:
  96.     case ENTITY_EVENT_XFORM_FINISHED_EDITOR:
  97.         Reset();
  98.         break;
  99.     }
  100. }
  101.  
  102. void CParticleEmitter::OnFlowgraphActivation(EntityId entityId, IFlowNode::SActivationInfo *pActInfo, const class CFlowGameEntityNode *pNode)
  103. {
  104.     if (auto *pExtension = static_cast<CParticleEmitter *>(QueryExtension(entityId)))
  105.     {
  106.         if (IsPortActive(pActInfo, eInputPort_TurnOn))
  107.         {
  108.             pExtension->SetPropertyBool(eProperty_Active, true);
  109.         }
  110.         else if (IsPortActive(pActInfo, eInputPort_TurnOff))
  111.         {
  112.             pExtension->SetPropertyBool(eProperty_Active, false);
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement