BVB Source Codes

CRYENGINE Show VehicleSeatSerializer.cpp Source code

Return Download CRYENGINE: download VehicleSeatSerializer.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 an entity class which can serialize vehicle parts
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 16:09:2005: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "VehicleSeatSerializer.h"
  16. #include "Vehicle.h"
  17. #include "VehicleSeat.h"
  18. #include "CryAction.h"
  19. #include "Network/GameContext.h"
  20.  
  21. //------------------------------------------------------------------------
  22. CVehicleSeatSerializer::CVehicleSeatSerializer()
  23.         : m_pVehicle(0),
  24.         m_pSeat(0)
  25. {
  26. }
  27.  
  28. //------------------------------------------------------------------------
  29. CVehicleSeatSerializer::~CVehicleSeatSerializer()
  30. {
  31. }
  32.  
  33. //------------------------------------------------------------------------
  34. bool CVehicleSeatSerializer::Init(IGameObject* pGameObject)
  35. {
  36.         SetGameObject(pGameObject);
  37.  
  38.         if (m_pSeat) // needs to be done here since anywhere earlier, EntityId is not known
  39.                 m_pSeat->SetSerializer(this);
  40.         else if (!gEnv->bServer)
  41.                 return false;
  42.  
  43.         CVehicleSeat* pSeat = NULL;
  44.         EntityId parentId = 0;
  45.         if (gEnv->bServer)
  46.         {
  47.                 pSeat = static_cast<CVehicleSystem*>(CCryAction::GetCryAction()->GetIVehicleSystem())->GetInitializingSeat();
  48.                 CRY_ASSERT(pSeat);
  49.                 SetVehicle(static_cast<CVehicle*>(pSeat->GetVehicle()));
  50.                 parentId = m_pVehicle->GetEntityId();
  51.         }
  52.  
  53.         if (0 == (GetEntity()->GetFlags() & (ENTITY_FLAG_CLIENT_ONLY | ENTITY_FLAG_SERVER_ONLY)))
  54.                 if (!GetGameObject()->BindToNetworkWithParent(eBTNM_Normal, parentId))
  55.                         return false;
  56.  
  57.         GetEntity()->Activate(0);
  58.         GetEntity()->Hide(true);
  59.  
  60.         if (!IsDemoPlayback())
  61.         {
  62.                 if (gEnv->bServer)
  63.                 {
  64.                         pSeat->SetSerializer(this);
  65.                         SetSeat(pSeat);
  66.                 }
  67.                 else
  68.                 {
  69.                         if (m_pVehicle)
  70.                         {
  71.                                 GetGameObject()->SetNetworkParent(m_pVehicle->GetEntityId());
  72.                         }
  73.                 }
  74.         }
  75.  
  76.         return true;
  77. }
  78.  
  79. //------------------------------------------------------------------------
  80. void CVehicleSeatSerializer::InitClient(int channelId)
  81. {
  82. }
  83.  
  84. //------------------------------------------------------------------------
  85. bool CVehicleSeatSerializer::ReloadExtension(IGameObject* pGameObject, const SEntitySpawnParams& params)
  86. {
  87.         ResetGameObject();
  88.  
  89.         CRY_ASSERT_MESSAGE(false, "CVehicleSeatSerializer::ReloadExtension not implemented");
  90.  
  91.         return false;
  92. }
  93.  
  94. //------------------------------------------------------------------------
  95. void CVehicleSeatSerializer::FullSerialize(TSerialize ser)
  96. {
  97. }
  98.  
  99. //------------------------------------------------------------------------
  100. bool CVehicleSeatSerializer::NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags)
  101. {
  102.         if (m_pSeat)
  103.                 m_pSeat->SerializeActions(ser, aspect);
  104.         return true;
  105. }
  106.  
  107. //------------------------------------------------------------------------
  108. void CVehicleSeatSerializer::Update(SEntityUpdateContext& ctx, int)
  109. {
  110. }
  111.  
  112. //------------------------------------------------------------------------
  113. void CVehicleSeatSerializer::HandleEvent(const SGameObjectEvent& event)
  114. {
  115. }
  116.  
  117. //------------------------------------------------------------------------
  118. void CVehicleSeatSerializer::SerializeSpawnInfo(TSerialize ser)
  119. {
  120.         EntityId vehicle;
  121.         TVehicleSeatId seatId;
  122.  
  123.         ser.Value("vehicle", vehicle, 'eid');
  124.         ser.Value("seat", seatId, 'seat');
  125.  
  126.         CRY_ASSERT(ser.IsReading());
  127.  
  128.         // warning GameObject not set at this point
  129.         // GetGameObject calls will fail miserably
  130.  
  131.         m_pVehicle = static_cast<CVehicle*>(CCryAction::GetCryAction()->GetIVehicleSystem()->GetVehicle(vehicle));
  132.         if (!m_pVehicle)
  133.         {
  134.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed to find vehicle with id '%u' for the seat id '%d', this will most likely result in context corruption", vehicle, seatId);
  135.                 return;
  136.         }
  137.  
  138.         CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(m_pVehicle->GetSeatById(seatId));
  139.         m_pSeat = pSeat;
  140.  
  141.         // the serializer is set on the seat in ::Init
  142. }
  143.  
  144. namespace CVehicleSeatSerializerGetSpawnInfo
  145. {
  146. struct SInfo : public ISerializableInfo
  147. {
  148.         EntityId       vehicle;
  149.         TVehicleSeatId seatId;
  150.         void SerializeWith(TSerialize ser)
  151.         {
  152.                 ser.Value("vehicle", vehicle, 'eid');
  153.                 ser.Value("seat", seatId, 'seat');
  154.         }
  155. };
  156. }
  157.  
  158. //------------------------------------------------------------------------
  159. ISerializableInfoPtr CVehicleSeatSerializer::GetSpawnInfo()
  160. {
  161.  
  162.         CVehicleSeatSerializerGetSpawnInfo::SInfo* p = new CVehicleSeatSerializerGetSpawnInfo::SInfo;
  163.         p->vehicle = m_pVehicle->GetEntityId();
  164.         p->seatId = m_pSeat->GetSeatId();
  165.         return p;
  166. }
  167.  
  168. //------------------------------------------------------------------------
  169. void CVehicleSeatSerializer::SetVehicle(CVehicle* pVehicle)
  170. {
  171.         m_pVehicle = pVehicle;
  172. }
  173.  
  174. //------------------------------------------------------------------------
  175. void CVehicleSeatSerializer::SetSeat(CVehicleSeat* pSeat)
  176. {
  177.         m_pSeat = pSeat;
  178. }
  179.  
downloadVehicleSeatSerializer.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