BVB Source Codes

CRYENGINE Show VehiclePartParticleEffect.cpp Source code

Return Download CRYENGINE: download VehiclePartParticleEffect.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Vehicle part class that spawns a particle effect and attaches it to the vehicle.
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 01:09:2010: Created by Paul Slinger
  12.  
  13. *************************************************************************/
  14.  
  15. #include "StdAfx.h"
  16.  
  17. #include <IViewSystem.h>
  18. #include <IItemSystem.h>
  19. #include <IVehicleSystem.h>
  20. #include <CryPhysics/IPhysics.h>
  21. #include <CryAnimation/ICryAnimation.h>
  22. #include <IActorSystem.h>
  23. #include <CryNetwork/ISerialize.h>
  24. #include <CryAISystem/IAgent.h>
  25.  
  26. #include "CryAction.h"
  27. #include "Vehicle.h"
  28. #include "VehiclePartParticleEffect.h"
  29. #include "VehicleUtils.h"
  30.  
  31. //------------------------------------------------------------------------
  32. CVehiclePartParticleEffect::CVehiclePartParticleEffect() : m_id(0), m_pParticleEffect(NULL), m_pHelper(NULL)
  33. {
  34. }
  35.  
  36. //------------------------------------------------------------------------
  37. CVehiclePartParticleEffect::~CVehiclePartParticleEffect()
  38. {
  39.         CRY_ASSERT(m_pVehicle);
  40.  
  41.         m_pVehicle->UnregisterVehicleEventListener(this);
  42.  
  43.         ActivateParticleEffect(false);
  44.  
  45.         if (m_pParticleEffect)
  46.         {
  47.                 m_pParticleEffect->Release();
  48.         }
  49. }
  50.  
  51. //------------------------------------------------------------------------
  52. bool CVehiclePartParticleEffect::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
  53. {
  54.         if (!CVehiclePartBase::Init(pVehicle, table, parent, initInfo, eVPT_Entity))
  55.         {
  56.                 return false;
  57.         }
  58.  
  59.         if (CVehicleParams params = table.findChild("ParticleEffect"))
  60.         {
  61.                 params.getAttr("id", m_id);
  62.  
  63.                 m_particleEffectName = params.getAttr("particleEffect");
  64.                 m_helperName = params.getAttr("helper");
  65.         }
  66.  
  67.         m_pVehicle->RegisterVehicleEventListener(this, "VehiclePartParticleEffect");
  68.  
  69.         return true;
  70. }
  71.  
  72. //------------------------------------------------------------------------
  73. void CVehiclePartParticleEffect::PostInit()
  74. {
  75.         if (!m_particleEffectName.empty())
  76.         {
  77.                 m_pParticleEffect = gEnv->pParticleManager->FindEffect(m_particleEffectName.c_str());
  78.  
  79.                 if (m_pParticleEffect)
  80.                 {
  81.                         m_pParticleEffect->AddRef();
  82.                 }
  83.         }
  84.  
  85.         if (!m_helperName.empty())
  86.         {
  87.                 m_pHelper = m_pVehicle->GetHelper(m_helperName.c_str());
  88.         }
  89. }
  90.  
  91. //------------------------------------------------------------------------
  92. void CVehiclePartParticleEffect::Reset()
  93. {
  94.         ActivateParticleEffect(false);
  95. }
  96.  
  97. //------------------------------------------------------------------------
  98. void CVehiclePartParticleEffect::Update(const float frameTime)
  99. {
  100.         CVehiclePartBase::Update(frameTime);
  101. }
  102.  
  103. //------------------------------------------------------------------------
  104. void CVehiclePartParticleEffect::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params)
  105. {
  106.         switch (event)
  107.         {
  108.         case eVE_Destroyed:
  109.                 {
  110.                         ActivateParticleEffect(false);
  111.  
  112.                         break;
  113.                 }
  114.  
  115.         case eVE_StartParticleEffect:
  116.         case eVE_StopParticleEffect:
  117.                 {
  118.                         if ((params.iParam == 0) || (params.iParam == m_id))
  119.                         {
  120.                                 ActivateParticleEffect(event == eVE_StartParticleEffect);
  121.                         }
  122.  
  123.                         break;
  124.                 }
  125.         }
  126. }
  127.  
  128. //------------------------------------------------------------------------
  129. void CVehiclePartParticleEffect::GetMemoryUsage(ICrySizer* pSizer) const
  130. {
  131.         CRY_ASSERT(pSizer);
  132.  
  133.         pSizer->Add(*this);
  134.  
  135.         CVehiclePartBase::GetMemoryUsageInternal(pSizer);
  136. }
  137.  
  138. //------------------------------------------------------------------------
  139. void CVehiclePartParticleEffect::ActivateParticleEffect(bool activate)
  140. {
  141.         IEntity* pEntity = m_pVehicle->GetEntity();
  142.  
  143.         if (activate)
  144.         {
  145.                 m_slot = pEntity->LoadParticleEmitter(-1, m_pParticleEffect, NULL, false, true);
  146.  
  147.                 if (m_slot > 0)
  148.                 {
  149.                         SpawnParams spawnParams;
  150.  
  151.                         spawnParams.fPulsePeriod = 1.0f;
  152.  
  153.                         pEntity->GetParticleEmitter(m_slot)->SetSpawnParams(spawnParams);
  154.  
  155.                         if (m_pHelper)
  156.                         {
  157.                                 Matrix34 tm;
  158.  
  159.                                 m_pHelper->GetVehicleTM(tm);
  160.  
  161.                                 pEntity->SetSlotLocalTM(m_slot, tm);
  162.                         }
  163.                 }
  164.         }
  165.         else if (m_slot > 0)
  166.         {
  167.                 pEntity->FreeSlot(m_slot);
  168.  
  169.                 m_slot = -1;
  170.         }
  171. }
  172.  
  173. //------------------------------------------------------------------------
  174. DEFINE_VEHICLEOBJECT(CVehiclePartParticleEffect)
  175.  
downloadVehiclePartParticleEffect.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