BVB Source Codes

CRYENGINE Show ProceduralBreakingRecordingListener.cpp Source code

Return Download CRYENGINE: download ProceduralBreakingRecordingListener.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:  network breakability: recording of procedural breaks
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 22/01/2007   10:34 : Created by Craig Tiller
  11. *************************************************************************/
  12.  
  13. #include "StdAfx.h"
  14.  
  15. #if !NET_USE_SIMPLE_BREAKAGE
  16.  
  17.         #include "ProceduralBreakingRecordingListener.h"
  18.         #include "GameContext.h"
  19.         #include "BreakReplicator.h"
  20.         #include "NetworkCVars.h"
  21.  
  22. CProceduralBreakingRecordingListener::CProceduralBreakingRecordingListener(IProceduralBreakTypePtr pBreakType)
  23.         : CProceduralBreakingBaseListener(pBreakType)
  24.         #if BREAK_HIERARCHICAL_TRACKING
  25.         , m_frame(0)
  26.         #else
  27.         , m_gotRemove(false)
  28.         #endif
  29. {
  30.         m_orderId = CBreakReplicator::Get()->PullOrderId();
  31. }
  32.  
  33. CProceduralBreakingRecordingListener::~CProceduralBreakingRecordingListener()
  34. {
  35.         if (m_orderId >= 0 && CBreakReplicator::Get())
  36.                 CBreakReplicator::Get()->PushAbandonment(m_orderId);
  37. }
  38.  
  39. int CProceduralBreakingRecordingListener::GetEntRef(EntityId id)
  40. {
  41.         if (!id)
  42.         {
  43.                 CRY_ASSERT(false);
  44.                 return -1; // hrm...
  45.         }
  46.         for (int i = 0; i < m_ents.size(); i++)
  47.                 if (m_ents[i] == id)
  48.                         return i;
  49.         m_ents.push_back(id);
  50.         return m_ents.size() - 1;
  51. }
  52.  
  53. bool CProceduralBreakingRecordingListener::AllowComplete()
  54. {
  55.         SProceduralBreakRecordingState state;
  56.         #if BREAK_HIERARCHICAL_TRACKING
  57.         state.gotRemove = m_openIds.empty();
  58.         #else
  59.         state.gotRemove = m_gotRemove;
  60.         #endif
  61.         state.numEmptySteps = GetNumEmptySteps();
  62.         return GetBreakType()->AllowComplete(state);
  63. }
  64.  
  65. bool CProceduralBreakingRecordingListener::AttemptAbsorb(const IProceduralBreakTypePtr& pBT)
  66. {
  67.         if (GetBreakType()->AttemptAbsorb(pBT))
  68.         {
  69.                 GotBreakOp(eNBO_AbsorbStep, -1, -1, 0);
  70.                 return true;
  71.         }
  72.         return false;
  73. }
  74.  
  75. void CProceduralBreakingRecordingListener::GotJointBreak(int idxRef, int id, int epicenter)
  76. {
  77.         // this is an auto created constraint joint to make trees look cooler when they're breaking
  78.         if (id == 1000000)
  79.                 return;
  80.  
  81.         SJointBreakRec brk;
  82.         brk.idxRef = idxRef;
  83.         brk.id = id;
  84.         #if BREAK_HIERARCHICAL_TRACKING
  85.         brk.frame = m_frame;
  86.         #endif
  87.         brk.epicenter = epicenter;
  88.         m_jointBreaks.push_back(brk);
  89. }
  90.  
  91. void CProceduralBreakingRecordingListener::GotJointBreakParticle(const EventPhysCreateEntityPart* pEvent)
  92. {
  93.         SJointBreakParticleRec rec;
  94.         pe_status_dynamics statusDyn;
  95.         pEvent->pEntNew->GetStatus(&statusDyn);
  96.         rec.vel = statusDyn.v;
  97.         m_gibs.push_back(rec);
  98. }
  99.  
  100. int CProceduralBreakingRecordingListener::GotBreakOp(ENetBreakOperation op, int idxRef, int partid, EntityId to)
  101. {
  102.         CRY_ASSERT(op >= eNBO_Create && op < eNBO_NUM_OPERATIONS);
  103.         LOGBREAK("GotBreakOp(op:%d, idxRef:%d, partid:%d, entid:%x)", op, idxRef, partid, to);
  104.  
  105.         #if BREAK_HIERARCHICAL_TRACKING
  106.         STATIC_CHECK(0 == (OPS_ADD_OPEN & OPS_REMOVE_OPEN), AddAndRemoveOpSetsIntersect);
  107.         if (BIT(op) & OPS_ADD_OPEN)
  108.                 m_openIds.insert(idxRef);
  109.         else if (BIT(op) & OPS_REMOVE_OPEN)
  110.                 m_openIds.erase(idxRef);
  111.         #else
  112.         m_gotRemove |= (op == eNBO_Remove_NoSpawn || op == eNBO_Remove);
  113.         if (m_gotRemove)
  114.                 DisallowAdditions();
  115.         #endif
  116.  
  117.         #if BREAK_HIERARCHICAL_TRACKING
  118.         if (op == eNBO_PostStep && !m_spawnRecs.empty() && m_spawnRecs.back().op == eNBO_PostStep)
  119.                 return -1;
  120.  
  121.         if (BIT(op) & OPS_JOINT_FRAME_COUNTERS)
  122.         {
  123.                 m_frame++;
  124.                 LOGBREAK("GotBreakOp: m_frame++ -> %d)", m_frame);
  125.                 CRY_ASSERT(m_frame > 0);
  126.         }
  127.         #endif
  128.  
  129.         SProceduralSpawnRec rec;
  130.         rec.op = op;
  131.         rec.partid = partid;
  132.         if (BIT(op) & OPS_CAUSING_ENTS)
  133.         {
  134.                 rec.idx = GetEntRef(to);
  135.                 if (rec.idx < 0)
  136.                         return -1;
  137.         }
  138.         if (BIT(op) & OPS_REFERENCING_ENTS)
  139.                 rec.idxRef = idxRef;
  140.         m_spawnRecs.push_back(rec);
  141.  
  142.         LOGBREAK("GotBreakOp: push spawnRec: %d)", m_frame);
  143.  
  144.         return rec.idx;
  145. }
  146.  
  147. void CProceduralBreakingRecordingListener::FinishBreakOp(ENetBreakOperation op, int idxRef, EntityId to, int virtId)
  148. {
  149. }
  150.  
  151. void CProceduralBreakingRecordingListener::Complete()
  152. {
  153.         _smart_ptr<SProceduralBreak> brk = GetBreakType()->CompleteSend();
  154.         if (!brk)
  155.                 return;
  156.  
  157.         LOGBREAK("Created an SProceduralBreak from a CompleteSend()");
  158.  
  159.         #if BREAK_HIERARCHICAL_TRACKING
  160.         while (!m_spawnRecs.empty() && m_spawnRecs.back().op == eNBO_PostStep)
  161.                 m_spawnRecs.pop_back();
  162.         #endif
  163.  
  164.         GetBreakType()->PatchRecording(m_spawnRecs, m_jointBreaks);
  165.  
  166.         char message[256];
  167.         cry_sprintf(message, "recording %p order=%d", this, m_orderId);
  168.         DumpSpawnRecs(m_spawnRecs, m_jointBreaks, message);
  169.         brk->spawnRecs = m_spawnRecs;
  170.         brk->gibs = m_gibs;
  171.  
  172.         //      std::sort(m_jointBreaks.begin(), m_jointBreaks.end());
  173.         //      m_jointBreaks.resize( std::unique(m_jointBreaks.begin(), m_jointBreaks.end()) - m_jointBreaks.begin() );
  174.         brk->jointBreaks = m_jointBreaks;
  175.  
  176.         if (CNetworkCVars::Get().BreakageLog)
  177.                 brk->magicId = m_orderId;
  178.  
  179.         SNetBreakDescription desc;
  180.         if (GetBreakType()->SendOnlyOnClientJoin())
  181.         {
  182.                 desc.flags = (ENetBreakDescFlags)(desc.flags | eNBF_SendOnlyOnClientJoin);
  183.         }
  184.         desc.nEntities = m_ents.size();
  185.         EntityId blah = 0;
  186.         desc.pEntities = m_ents.empty() ? &blah : &m_ents[0];
  187.         desc.pMessagePayload = &*brk;
  188.         CBreakReplicator::Get()->PushBreak(m_orderId, desc);
  189.         m_orderId = -1;
  190.         //      CCryAction::GetCryAction()->GetGameContext()->GetNetContext()->LogBreak(desc);
  191. }
  192.  
  193. #endif // !NET_USE_SIMPLE_BREAKAGE
  194.  
downloadProceduralBreakingRecordingListener.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