BVB Source Codes

CRYENGINE Show NetActionSync.h Source code

Return Download CRYENGINE: download NetActionSync.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Helper template to provide correct action synchronization
  8.                for actors and vehicles
  9.  
  10.    -------------------------------------------------------------------------
  11.    History:
  12.    - 17:9:2004 : Created by Craig Tiller
  13.  
  14. *************************************************************************/
  15.  
  16. #ifndef __NETACTIONSYNC_H__
  17. #define __NETACTIONSYNC_H__
  18.  
  19. #pragma once
  20.  
  21. #ifdef __GNUC__
  22. // GCC requires a full decl of TSerialize, not just a fwd decl.
  23.         #include <CryNetwork/ISerialize.h>
  24. #endif
  25.  
  26. template<class ActionRep>
  27. class CNetActionSync
  28. {
  29. public:
  30.         CNetActionSync() : m_havePublished(false), m_lastReceived(0), m_lastCancelation(1) {}
  31.  
  32.         static const NetworkAspectType CONTROLLED_ASPECT = ActionRep::CONTROLLED_ASPECT;
  33.  
  34.         // publish current state of actions - returns true if net-sync required
  35.         bool PublishActions(ActionRep rep)
  36.         {
  37.                 bool changed = false;
  38.                 if (m_lastReceived > m_lastCancelation)
  39.                 {
  40.                         rep = m_received;
  41.                 }
  42.                 if (!m_havePublished || m_published != rep)
  43.                 {
  44.                         m_published = rep;
  45.                         changed = true;
  46.                 }
  47.                 m_havePublished = true;
  48.                 return changed;
  49.         }
  50.         void Serialize(TSerialize ser, EEntityAspects aspects)
  51.         {
  52.                 // ensure CONTROLLED_ASPECT only has one bit set
  53.                 CRY_ASSERT((CONTROLLED_ASPECT & (CONTROLLED_ASPECT - 1)) == 0);
  54.                 if ((aspects & CONTROLLED_ASPECT) == 0)
  55.                         return;
  56.                 if (ser.IsReading())
  57.                 {
  58.                         m_received.Serialize(ser, aspects);
  59.                         m_lastReceived = gEnv->nMainFrameID;
  60.                 }
  61.                 else // writing
  62.                 {
  63.                         CRY_ASSERT(m_havePublished);
  64.                         m_published.Serialize(ser, aspects);
  65.                 }
  66.         }
  67.         void CancelReceived()
  68.         {
  69.                 m_lastCancelation = gEnv->nMainFrameID;
  70.         }
  71.         void UpdateObject(typename ActionRep::UpdateObjectSink obj)
  72.         {
  73.                 if (m_lastReceived > m_lastCancelation)
  74.                         m_received.UpdateObject(obj);
  75.         }
  76.  
  77. private:
  78.         ActionRep m_published;
  79.         ActionRep m_received;
  80.         bool      m_havePublished;
  81.         uint32    m_lastCancelation;
  82.         uint32    m_lastReceived;
  83. };
  84.  
  85. #endif
  86.  
downloadNetActionSync.h 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