BVB Source Codes

CRYENGINE Show FlowVehicleMovement.cpp Source code

Return Download CRYENGINE: download FlowVehicleMovement.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: Implements a flow node to handle a vehicle movement features
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 11:07:2006: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "IVehicleSystem.h"
  17. #include "FlowVehicleMovement.h"
  18. #include <CryFlowGraph/IFlowBaseNode.h>
  19.  
  20. //------------------------------------------------------------------------
  21. IFlowNodePtr CFlowVehicleMovement::Clone(SActivationInfo* pActivationInfo)
  22. {
  23.         IFlowNode* pNode = new CFlowVehicleMovement(pActivationInfo);
  24.         return pNode;
  25. }
  26.  
  27. //------------------------------------------------------------------------
  28. void CFlowVehicleMovement::GetConfiguration(SFlowNodeConfig& nodeConfig)
  29. {
  30.         CFlowVehicleBase::GetConfiguration(nodeConfig);
  31.  
  32.         static const SInputPortConfig pInConfig[] =
  33.         {
  34.                 InputPortConfig<bool>("warmupEngineTrigger",    _HELP("Warmup the vehicle engine")),
  35.                 InputPortConfig<SFlowSystemVoid>("zeroMass",    _HELP("Zero vehicle mass to make it static (this is usually a crude hack, don't use it unless you absolutely have to).")),
  36.                 InputPortConfig<SFlowSystemVoid>("restoreMass", _HELP("Restore the vehicles mass.")),
  37.                 { 0 }
  38.         };
  39.  
  40.         static const SOutputPortConfig pOutConfig[] =
  41.         {
  42.                 { 0 }
  43.         };
  44.  
  45.         nodeConfig.sDescription = _HELP("Handle vehicle movement");
  46.         nodeConfig.nFlags |= EFLN_TARGET_ENTITY;
  47.         nodeConfig.pInputPorts = pInConfig;
  48.         nodeConfig.pOutputPorts = pOutConfig;
  49.         nodeConfig.SetCategory(EFLN_APPROVED);
  50. }
  51.  
  52. //------------------------------------------------------------------------
  53. void CFlowVehicleMovement::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo)
  54. {
  55.         CFlowVehicleBase::ProcessEvent(flowEvent, pActivationInfo);
  56.  
  57.         if (flowEvent == eFE_Activate)
  58.         {
  59.                 if (IVehicle* pVehicle = GetVehicle())
  60.                 {
  61.                         if (IsPortActive(pActivationInfo, In_WarmupEngine))
  62.                         {
  63.                                 if (IVehicleMovement* pMovement = pVehicle->GetMovement())
  64.                                 {
  65.                                         SVehicleMovementEventParams eventParams;
  66.                                         pMovement->OnEvent(IVehicleMovement::eVME_WarmUpEngine, eventParams);
  67.                                 }
  68.                         }
  69.  
  70.                         if (IsPortActive(pActivationInfo, In_ZeroMass) || IsPortActive(pActivationInfo, In_RestoreMass))
  71.                         {
  72.                                 ZeroMass(!IsPortActive(pActivationInfo, In_RestoreMass));
  73.                         }
  74.                 }
  75.         }
  76.         else if (flowEvent == eFE_Initialize)
  77.         {
  78.                 ZeroMass(false);
  79.         }
  80.         else if (flowEvent == eFE_Update)
  81.         {
  82.                 if (m_shouldZeroMass)
  83.                 {
  84.                         ZeroMass(false); // reset vehicle to initial state
  85.                         ZeroMass(true);  // reapply the zero mass
  86.                         m_shouldZeroMass = false;
  87.                 }
  88.  
  89.                 pActivationInfo->pGraph->SetRegularlyUpdated(pActivationInfo->myID, false);
  90.         }
  91. }
  92.  
  93. //------------------------------------------------------------------------
  94. void CFlowVehicleMovement::ZeroMass(bool enable)
  95. {
  96.         IVehicle* pVehicle = GetVehicle();
  97.         if (!pVehicle || !pVehicle->GetEntity())
  98.                 return;
  99.  
  100.         IPhysicalEntity* pPhysics = pVehicle->GetEntity()->GetPhysics();
  101.         if (!pPhysics)
  102.                 return;
  103.  
  104.         if (enable)
  105.         {
  106.                 // store list of partIds + mass
  107.                 pe_status_nparts nparts;
  108.                 int count = pPhysics->GetStatus(&nparts);
  109.  
  110.                 for (int i = 0; i < count; ++i)
  111.                 {
  112.                         pe_params_part paramsGet;
  113.                         paramsGet.ipart = i;
  114.                         if (pPhysics->GetParams(&paramsGet) && paramsGet.mass > 0.0f)
  115.                         {
  116.                                 SPartMass mass(paramsGet.partid, paramsGet.mass);
  117.                                 m_partMass.push_back(mass);
  118.  
  119.                                 pe_params_part paramsSet;
  120.                                 paramsSet.ipart = i;
  121.                                 paramsSet.mass = 0.0f;
  122.                                 pPhysics->SetParams(&paramsSet);
  123.                         }
  124.                 }
  125.         }
  126.         else
  127.         {
  128.                 for (int i = 0, n = m_partMass.size(); i < n; ++i)
  129.                 {
  130.                         pe_params_part params;
  131.                         params.partid = m_partMass[i].partid;
  132.                         params.mass = m_partMass[i].mass;
  133.                         pPhysics->SetParams(&params);
  134.                 }
  135.  
  136.                 m_partMass.clear();
  137.         }
  138. }
  139.  
  140. //------------------------------------------------------------------------
  141. void CFlowVehicleMovement::Serialize(SActivationInfo* pActivationInfo, TSerialize ser)
  142. {
  143.         CFlowVehicleBase::Serialize(pActivationInfo, ser);
  144.  
  145.         ser.BeginGroup("FlowVehicleMovement");
  146.  
  147.         if (ser.IsReading())
  148.                 m_partMass.resize(0);
  149.  
  150.         int count = m_partMass.size();
  151.         int oldCount = count;
  152.         ser.Value("count", count);
  153.  
  154.         if (count > oldCount)
  155.                 m_partMass.resize(count);
  156.  
  157.         char buf[16];
  158.         for (int i = 0; i < count; ++i)
  159.         {
  160.                 cry_sprintf(buf, "partid_%i", i);
  161.                 ser.Value(buf, m_partMass[i].partid);
  162.  
  163.                 cry_sprintf(buf, "mass_%i", i);
  164.                 ser.Value(buf, m_partMass[i].mass);
  165.         }
  166.  
  167.         if (ser.IsReading())
  168.         {
  169.                 m_shouldZeroMass = (count > 0);
  170.                 if (m_shouldZeroMass)
  171.                         pActivationInfo->pGraph->SetRegularlyUpdated(pActivationInfo->myID, true);
  172.         }
  173.  
  174.         ser.EndGroup();
  175. }
  176.  
  177. //////////////////////////////////////////////////////////////////////////
  178.  
  179. //------------------------------------------------------------------------
  180. IFlowNodePtr CFlowVehicleMovementParams::Clone(SActivationInfo* pActivationInfo)
  181. {
  182.         IFlowNode* pNode = new CFlowVehicleMovementParams(pActivationInfo);
  183.         return pNode;
  184. }
  185.  
  186. //------------------------------------------------------------------------
  187. void CFlowVehicleMovementParams::GetConfiguration(SFlowNodeConfig& nodeConfig)
  188. {
  189.         CFlowVehicleBase::GetConfiguration(nodeConfig);
  190.  
  191.         static const SInputPortConfig pInConfig[] =
  192.         {
  193.                 InputPortConfig<SFlowSystemVoid>("Trigger",  _HELP("Applies the changes")),
  194.                 InputPortConfig<float>("MaxSpeedFactor",     1.0f,                         _HELP("Multiplier to the vehicle's max speed.")),
  195.                 InputPortConfig<float>("AccelerationFactor", 1.0f,                         _HELP("Multiplier to the vehicle's acceleration.")),
  196.                 { 0 }
  197.         };
  198.  
  199.         static const SOutputPortConfig pOutConfig[] =
  200.         {
  201.                 { 0 }
  202.         };
  203.  
  204.         nodeConfig.sDescription = _HELP("Modifies vehicle movement params");
  205.         nodeConfig.nFlags |= EFLN_TARGET_ENTITY;
  206.         nodeConfig.pInputPorts = pInConfig;
  207.         nodeConfig.pOutputPorts = pOutConfig;
  208.         nodeConfig.SetCategory(EFLN_APPROVED);
  209. }
  210.  
  211. //------------------------------------------------------------------------
  212. void CFlowVehicleMovementParams::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo)
  213. {
  214.         CFlowVehicleBase::ProcessEvent(flowEvent, pActivationInfo);
  215.  
  216.         if (flowEvent == eFE_Activate)
  217.         {
  218.                 if (IVehicle* pVehicle = GetVehicle())
  219.                 {
  220.                         if (IsPortActive(pActivationInfo, In_Trigger))
  221.                         {
  222.                                 if (IVehicleMovement* pMovement = pVehicle->GetMovement())
  223.                                 {
  224.                                         SVehicleMovementEventParams eventParams;
  225.                                         eventParams.fValue = GetPortFloat(pActivationInfo, In_MaxSpeedFactor);
  226.                                         pMovement->OnEvent(IVehicleMovement::eVME_SetFactorMaxSpeed, eventParams);
  227.  
  228.                                         eventParams.fValue = GetPortFloat(pActivationInfo, In_MaxAcceleration);
  229.                                         pMovement->OnEvent(IVehicleMovement::eVME_SetFactorAccel, eventParams);
  230.                                 }
  231.                         }
  232.                 }
  233.         }
  234. }
  235.  
  236. REGISTER_FLOW_NODE("Vehicle:Movement", CFlowVehicleMovement);
  237. REGISTER_FLOW_NODE("Vehicle:MovementParams", CFlowVehicleMovementParams);
  238.  
downloadFlowVehicleMovement.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