BVB Source Codes

CRYENGINE Show VehicleSeatActionAnimation.cpp Source code

Return Download CRYENGINE: download VehicleSeatActionAnimation.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 seat action for triggering animations
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 20:07:2007: Created by MichaelR
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15.  
  16. #include "IVehicleSystem.h"
  17. #include "VehicleSeatActionAnimation.h"
  18. #include "VehicleCVars.h"
  19.  
  20. //------------------------------------------------------------------------
  21. CVehicleSeatActionAnimation::CVehicleSeatActionAnimation()
  22.         : m_pVehicleAnim(NULL)
  23.         , m_pVehicle(NULL)
  24.         , m_userId(0)
  25.         , m_action(0.f)
  26.         , m_prevAction(0.f)
  27.         , m_speed(1.f)
  28.         , m_manualUpdate(true)
  29.         , m_pIEntityAudioComponent(NULL)
  30. {
  31.         m_control[0] = eVAI_Attack1;
  32.         m_control[1] = eVAI_Attack2;
  33. }
  34.  
  35. //------------------------------------------------------------------------
  36. bool CVehicleSeatActionAnimation::Init(IVehicle* pVehicle, IVehicleSeat* pSeat, const CVehicleParams& table)
  37. {
  38.         m_pVehicle = pVehicle;
  39.  
  40.         CVehicleParams animTable = table.findChild("Animation");
  41.         if (!animTable)
  42.                 return false;
  43.  
  44.         if (animTable.haveAttr("vehicleAnimation"))
  45.                 m_pVehicleAnim = m_pVehicle->GetAnimation(animTable.getAttr("vehicleAnimation"));
  46.  
  47.         string control = animTable.getAttr("control");
  48.         if (!control.empty())
  49.         {
  50.                 if (control == "roll")
  51.                 {
  52.                         m_control[0] = eVAI_RollLeft;
  53.                         m_control[1] = eVAI_RollRight;
  54.                 }
  55.         }
  56.  
  57.         animTable.getAttr("manualUpdate", m_manualUpdate);
  58.         animTable.getAttr("speed", m_speed);
  59.  
  60.         REINST("start/stop event?");
  61.         /*m_pIEntityAudioComponent = m_pVehicle->GetEntity()->GetComponent<IEntityAudioComponent>();
  62.  
  63.            if (m_pIEntityAudioComponent)
  64.            {
  65.            if (animTable.haveAttr("sound"))
  66.             m_pSound = gEnv->pAudioSystem->CreateSound(animTable.getAttr("sound"), FLAG_SOUND_DEFAULT_3D);
  67.  
  68.            if (animTable.haveAttr("stopSound"))
  69.             m_pStopSound = gEnv->pAudioSystem->CreateSound(animTable.getAttr("stopSound"), FLAG_SOUND_DEFAULT_3D);
  70.            }*/
  71.  
  72.         return true;
  73. }
  74.  
  75. //------------------------------------------------------------------------
  76. void CVehicleSeatActionAnimation::Reset()
  77. {
  78.         if (m_userId)
  79.                 StopUsing();
  80. }
  81.  
  82. //------------------------------------------------------------------------
  83. void CVehicleSeatActionAnimation::StartUsing(EntityId passengerId)
  84. {
  85.         m_userId = passengerId;
  86.         m_action = m_prevAction = 0.f;
  87.  
  88.         if (m_pVehicleAnim)
  89.         {
  90.                 if (m_manualUpdate)
  91.                 {
  92.                         m_pVehicleAnim->StartAnimation();
  93.                         m_pVehicleAnim->ToggleManualUpdate(true);
  94.  
  95.                         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_PassengerUpdate);
  96.                 }
  97.         }
  98. }
  99.  
  100. //------------------------------------------------------------------------
  101. void CVehicleSeatActionAnimation::StopUsing()
  102. {
  103.         if (m_pVehicleAnim)
  104.         {
  105.                 m_pVehicleAnim->StopAnimation();
  106.  
  107.                 if (m_manualUpdate)
  108.                         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  109.  
  110.                 REINST("event needed?");
  111.                 /*if (m_pSound.get())
  112.                    m_pIEntityAudioComponent->StopSound(m_pSound->GetId());*/
  113.         }
  114.  
  115.         m_userId = 0;
  116.         m_action = m_prevAction = 0.f;
  117. }
  118.  
  119. //------------------------------------------------------------------------
  120. void CVehicleSeatActionAnimation::OnAction(const TVehicleActionId actionId, int activationMode, float value)
  121. {
  122.         if (!m_pVehicleAnim)
  123.                 return;
  124.  
  125.         if (actionId == m_control[0])
  126.         {
  127.                 if (!m_manualUpdate)
  128.                 {
  129.                         m_pVehicleAnim->StartAnimation();
  130.                 }
  131.                 else
  132.                 {
  133.                         if (activationMode == eAAM_OnPress || activationMode == eAAM_OnRelease)
  134.                                 m_action += value * 2.f - 1.f;
  135.                 }
  136.         }
  137.         else if (actionId == m_control[1])
  138.         {
  139.                 if (!m_manualUpdate)
  140.                 {
  141.                         m_pVehicleAnim->StopAnimation();
  142.                 }
  143.                 else
  144.                 {
  145.                         if (activationMode == eAAM_OnPress || activationMode == eAAM_OnRelease)
  146.                                 m_action -= value * 2.f - 1.f;
  147.                 }
  148.         }
  149. }
  150.  
  151. //------------------------------------------------------------------------
  152. void CVehicleSeatActionAnimation::Update(float frameTime)
  153. {
  154.         if (!m_userId || !m_pVehicleAnim)
  155.                 return;
  156.  
  157.         if (m_action != 0.f)
  158.         {
  159.                 float currTime = m_pVehicleAnim->GetAnimTime(true);
  160.                 float newTime = currTime + m_action * m_speed * frameTime;
  161.                 Limit(newTime, 0.f, 1.f);
  162.  
  163.                 if (newTime != currTime)
  164.                 {
  165.                         m_pVehicleAnim->SetTime(newTime);
  166.  
  167.                         // starting
  168.                         if (m_prevAction == 0.f /*&& m_pSound.get()*/)
  169.                         {
  170.                                 REINST("starting something");
  171.                                 /*m_pIEntityAudioComponent->PlaySound(m_pSound);
  172.                                    m_pIEntityAudioComponent->SetStaticSound(m_pSound->GetId(), true);*/
  173.                         }
  174.                 }
  175.  
  176.                 //float color[] = {1,1,1,1};
  177.                 //IRenderAuxText::Draw2dLabel(200,250,1.5,color,false,"action: %.2f, time: %.2f, new: %.2f", m_action, currTime, newTime);
  178.         }
  179.         else
  180.         {
  181.                 // stopping
  182.                 if (m_prevAction != 0.f)
  183.                 {
  184.                         REINST("stopping something");
  185.                         /*if (m_pSound.get())
  186.                            m_pIEntityAudioComponent->StopSound(m_pSound->GetId());
  187.  
  188.                            if (m_pStopSound.get())
  189.                            {
  190.                            m_pIEntityAudioComponent->PlaySound(m_pStopSound);
  191.                            m_pIEntityAudioComponent->SetStaticSound(m_pStopSound->GetId(), true);
  192.                            }*/
  193.                 }
  194.         }
  195.  
  196.         m_prevAction = m_action;
  197. }
  198.  
  199. //------------------------------------------------------------------------
  200. void CVehicleSeatActionAnimation::Serialize(TSerialize ser, EEntityAspects aspects)
  201. {
  202.         if (ser.GetSerializationTarget() != eST_Network)
  203.         {
  204.         }
  205. }
  206.  
  207. DEFINE_VEHICLEOBJECT(CVehicleSeatActionAnimation);
  208.  
downloadVehicleSeatActionAnimation.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