BVB Source Codes

CRYENGINE Show JointBreak.cpp Source code

Return Download CRYENGINE: download JointBreak.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4.  
  5. #if !NET_USE_SIMPLE_BREAKAGE
  6.  
  7.         #include "JointBreak.h"
  8.         #include "BreakReplicator.h"
  9.         #include "NetworkCVars.h"
  10.  
  11. void SJointBreak::AddSendables(INetSendableSink* pSink, int32 brkId)
  12. {
  13.         CBreakReplicator::SendJointBreakWith(SJointBreakParams(brkId), pSink);
  14.         for (size_t i = 0; i < states.size(); i++)
  15.         {
  16.                 if (states[i].isEnt)
  17.                         pSink->NextRequiresEntityEnabled(states[i].entId);
  18.                 CBreakReplicator::SendDeclareExplosiveObjectStateWith(SDeclareExplosiveObjectState(brkId, states[i]), pSink);
  19.         }
  20.         SProceduralBreak::AddProceduralSendables(brkId, pSink);
  21. }
  22.  
  23.         #if BREAK_HIERARCHICAL_TRACKING
  24. static const uint32 JointBreakPBTFlags = ePBTF_ChainBreaking;
  25.         #else
  26. static const uint32 JointBreakPBTFlags = 0;
  27.         #endif
  28.  
  29. CJointBreak::CJointBreak() : IProceduralBreakType(JointBreakPBTFlags, 'j')
  30. {
  31. }
  32.  
  33. CJointBreak::CJointBreak(IPhysicalEntity* pEnt) : IProceduralBreakType(JointBreakPBTFlags, 'j')
  34. {
  35.         SExplosiveObjectState state;
  36.         ExplosiveObjectStateFromPhysicalEntity(state, pEnt);
  37.         m_states.push_back(state);
  38.  
  39.         pe_status_pos sts;
  40.         pEnt->GetStatus(&sts);
  41.         // TODO: use BBox
  42.         m_rgn = AABB(sts.pos - Vec3(10, 10, 10), sts.pos + Vec3(10, 10, 10));
  43. }
  44.  
  45. int CJointBreak::GetVirtualId(IPhysicalEntity* pEnt)
  46. {
  47.         int iForeignData = pEnt->GetiForeignData();
  48.         void* pForeignData = pEnt->GetForeignData(iForeignData);
  49.         if (iForeignData == PHYS_FOREIGN_ID_ENTITY && pForeignData)
  50.         {
  51.                 EntityId entId = ((IEntity*)pForeignData)->GetId();
  52.                 for (size_t i = 0; i < m_states.size(); i++)
  53.                 {
  54.                         if (m_states[i].isEnt && m_states[i].entId == entId)
  55.                                 return i + 1;
  56.                 }
  57.         }
  58.         else if (iForeignData == PHYS_FOREIGN_ID_STATIC && pForeignData)
  59.         {
  60.                 IRenderNode* rn = (IRenderNode*) pForeignData;
  61.                 const uint32 hash = CObjectSelector::CalculateHash(rn);
  62.                 for (size_t i = 0; i < m_states.size(); i++)
  63.                         if (!m_states[i].isEnt && m_states[i].hash == hash)
  64.                                 return i + 1;
  65.         }
  66.         return 0;
  67. }
  68.  
  69. CObjectSelector CJointBreak::GetObjectSelector(int idx)
  70. {
  71.         if (idx >= 1 && idx <= m_states.size())
  72.         {
  73.                 idx--;
  74.                 if (m_states[idx].isEnt)
  75.                         return CObjectSelector(m_states[idx].entId);
  76.                 else
  77.                         return CObjectSelector(m_states[idx].eventPos, m_states[idx].hash);
  78.         }
  79.         return CObjectSelector();
  80. }
  81.  
  82. bool CJointBreak::GotExplosiveObjectState(const SExplosiveObjectState* pState)
  83. {
  84.         m_states.push_back(*pState);
  85.         return true;
  86. }
  87.  
  88. void CJointBreak::PreparePlayback()
  89. {
  90.         for (size_t i = 0; i < m_states.size(); i++)
  91.         {
  92.                 if (m_states[i].isEnt)
  93.                 {
  94.                         if (IEntity* pEnt = gEnv->pEntitySystem->GetEntity(m_states[i].entId))
  95.                         {
  96.                                 pEnt->SetPosRotScale(m_states[i].entPos, m_states[i].entRot, m_states[i].entScale);
  97.                         }
  98.                         else
  99.                         {
  100.                                 GameWarning("[brk] CJointBreak::PreparePlayback unable to find entity %.8x to prepare for playback", m_states[i].entId);
  101.                         }
  102.                 }
  103.         }
  104. }
  105.  
  106. bool CJointBreak::AttemptAbsorb(const IProceduralBreakTypePtr& pBT)
  107. {
  108.         if (pBT->type == type)
  109.         {
  110.                 // can always absorb another joint break
  111.                 CJointBreak* pJB = (CJointBreak*)(IProceduralBreakType*)pBT;
  112.                 switch (pJB->m_states.size())
  113.                 {
  114.                 case 1:
  115.                         m_states.push_back(pJB->m_states[0]);
  116.                         return true;
  117.                 case 0:
  118.                         GameWarning("CJointBreak::AttemptAbsorb: nothing to absorb from new break");
  119.                         return false;
  120.                 default:
  121.                         GameWarning("CJointBreak::AttemptAbsorb: too many things to absorb");
  122.                         return false;
  123.                 }
  124.         }
  125.         return false;
  126. }
  127.  
  128. void CJointBreak::BeginPlayback(bool hasJointBreaks)
  129. {
  130.         /*
  131.            if (!hasJointBreaks)
  132.            {
  133.             // need to add some threshold to force a joint break of an object that has no joints
  134.             CObjectSelector sel;
  135.             if (m_state.isEnt)
  136.               sel = CObjectSelector(m_state.entId);
  137.             else
  138.               sel = CObjectSelector(m_state.objPos, m_state.objCenter, m_state.objVolume);
  139.             if (CNetworkCVars::Get().BreakageLog)
  140.               CryLogAlways("[brk] CJointBreak::BeginPlayback: apply impulse to simulate joint break on object %s", sel.GetDescription().c_str());
  141.             if (IPhysicalEntity * pEnt = sel.Find())
  142.             {
  143.               pe_params_structural_joint ppsj;
  144.               ppsj.idx = -1;
  145.               ppsj.partidEpicenter = 0;
  146.               pEnt->SetParams(&ppsj);
  147.             }
  148.             else
  149.             {
  150.               GameWarning("[brk] CJointBreak::BeginPlayback: couldn't apply fake-impulse since we could not find the object %s", sel.GetDescription().c_str());
  151.             }
  152.            }
  153.          */
  154. }
  155.  
  156. _smart_ptr<SProceduralBreak> CJointBreak::CompleteSend()
  157. {
  158.         SJointBreak* pjb = new SJointBreak;
  159.         pjb->region = m_rgn;
  160.         pjb->states = m_states;
  161.         return pjb;
  162. }
  163.  
  164. bool CJointBreak::AllowComplete(const SProceduralBreakRecordingState& state)
  165. {
  166.         return state.gotRemove && state.numEmptySteps > 0;
  167. }
  168.  
  169. void CJointBreak::PatchRecording(DynArray<SProceduralSpawnRec>& spawnRecs, DynArray<SJointBreakRec>& jointBreaks)
  170. {
  171.         LOGBREAK("PatchRecording");
  172.         std::map<int, int> rootEntitiesAndBreaks;
  173.         for (int i = 0; i < spawnRecs.size(); i++)
  174.                 if (BIT(spawnRecs[i].op) & OPS_REFERENCING_ENTS)
  175.                         if (spawnRecs[i].idxRef < 0)
  176.                         {
  177.                                 LOGBREAK("  -rootEntitiesAndBreaks[%d]=0", spawnRecs[i].idxRef);
  178.                                 rootEntitiesAndBreaks[spawnRecs[i].idxRef] = 0;
  179.                         }
  180.         for (int i = 0; i < jointBreaks.size(); i++)
  181.                 if (jointBreaks[i].idxRef < 0)
  182.                 {
  183.                         LOGBREAK("  -rootEntitiesAndBreaks[%d]++", jointBreaks[i].idxRef);
  184.                         rootEntitiesAndBreaks[jointBreaks[i].idxRef]++;
  185.                 }
  186.         for (std::map<int, int>::iterator it = rootEntitiesAndBreaks.begin(); it != rootEntitiesAndBreaks.end(); ++it)
  187.         {
  188.                 if (!it->second)
  189.                 {
  190.                         SJointBreakRec jb;
  191.                         jb.idxRef = it->first;
  192.                         jb.id = -1;
  193.         #if BREAK_HIERARCHICAL_TRACKING
  194.                         jb.frame = 0;
  195.         #endif
  196.                         jb.epicenter = 0;
  197.                         LOGBREAK("  - pushed SJointBreakRec");
  198.                         jointBreaks.push_back(jb);
  199.                 }
  200.         }
  201. }
  202.  
  203. #endif // ! NET_USE_SIMPLE_BREAKAGE
  204.  
downloadJointBreak.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