BVB Source Codes

CRYENGINE Show AttachmentMerged.cpp Source code

Return Download CRYENGINE: download AttachmentMerged.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. #include "AttachmentMerged.h"
  5.  
  6. #include "AttachmentMerger.h"
  7. #include "AttachmentManager.h"
  8.  
  9. CAttachmentMerged::CAttachmentMerged(string strName, CAttachmentManager* pAttachmentManager)
  10.         : m_bRequiresIndexUpdate(false)
  11. {
  12.         m_pMergedSkinAttachment = new CAttachmentSKIN();
  13.         m_pMergedSkinAttachment->m_pAttachmentManager = pAttachmentManager;
  14.         m_pMergedSkinAttachment->m_strSocketName = strName;
  15.         m_pMergedSkinAttachment->m_nSocketCRC32 = CCrc32::ComputeLowercase(strName.c_str());
  16. }
  17.  
  18. CAttachmentMerged::~CAttachmentMerged()
  19. {
  20.         CAttachmentMerger::Instance().OnDeleteMergedAttachment(this);
  21. }
  22.  
  23. DynArray<CAttachmentMerged::MergeInfo>::iterator CAttachmentMerged::FindAttachment(IAttachment* pAttachment)
  24. {
  25.         return std::find_if(m_MergedAttachments.begin(), m_MergedAttachments.end(),
  26.                             [&](const MergeInfo& attachmentInfo) { return attachmentInfo.pAttachment == pAttachment; });
  27. }
  28.  
  29. DynArray<CAttachmentMerged::MergeInfo>::const_iterator CAttachmentMerged::FindAttachment(const IAttachment* pAttachment) const
  30. {
  31.         return std::find_if(m_MergedAttachments.begin(), m_MergedAttachments.end(),
  32.                             [&](const MergeInfo& attachmentInfo) { return attachmentInfo.pAttachment == pAttachment; });
  33. }
  34.  
  35. bool CAttachmentMerged::HasAttachment(const IAttachment* pAttachment) const
  36. {
  37.         auto it = FindAttachment(pAttachment);
  38.         return it != m_MergedAttachments.end();
  39. }
  40.  
  41. void CAttachmentMerged::HideMergedAttachment(const IAttachment* pAttachment, bool bHide)
  42. {
  43.         CRY_ASSERT(pAttachment->IsMerged());
  44.         CRY_ASSERT(HasAttachment(pAttachment));
  45.  
  46.         m_bRequiresIndexUpdate = true;
  47. }
  48.  
  49. void CAttachmentMerged::AddAttachments(const DynArray<MergeInfo>& attachmentInfos)
  50. {
  51.         for (auto const& attachmentInfo : attachmentInfos)
  52.         {
  53.                 CRY_ASSERT(CAttachmentMerger::Instance().CanMerge(m_pMergedSkinAttachment, attachmentInfo.pAttachment));
  54.                 CRY_ASSERT(!attachmentInfo.pAttachment->IsMerged());
  55.  
  56.                 for (int lod = 0; lod < MAX_STATOBJ_LODS_NUM; ++lod)
  57.                 {
  58.                         CRY_ASSERT(attachmentInfo.IndexInfo[lod].nFirstIndex == 0 || attachmentInfo.IndexInfo[lod].nFirstIndex + attachmentInfo.IndexInfo[lod].nIndexCount - 1 < m_MergedAttachmentIndices[lod].size());
  59.                 }
  60.  
  61.                 uint nFlags = attachmentInfo.pAttachment->GetFlags();
  62.                 attachmentInfo.pAttachment->SetFlags(nFlags | FLAGS_ATTACH_MERGED_FOR_SHADOWS);
  63.         }
  64.  
  65.         m_MergedAttachments.insert(m_MergedAttachments.end(), attachmentInfos.begin(), attachmentInfos.end());
  66. }
  67.  
  68. bool CAttachmentMerged::AreAttachmentBindingsValid()
  69. {
  70.         for (auto& attachmentInfo : m_MergedAttachments)
  71.         {
  72.                 CRY_ASSERT(attachmentInfo.pAttachment);
  73.                 if (attachmentInfo.pAttachment->GetIAttachmentObject() != attachmentInfo.pAttachmentObject)
  74.                         return false;
  75.         }
  76.  
  77.         return m_MergedAttachments.size() > 0;
  78. }
  79.  
  80. void CAttachmentMerged::Invalidate()
  81. {
  82.         for (auto& attachmentInfo : m_MergedAttachments)
  83.         {
  84.                 CRY_ASSERT(attachmentInfo.pAttachment->IsMerged());
  85.  
  86.                 uint nFlags = attachmentInfo.pAttachment->GetFlags();
  87.                 attachmentInfo.pAttachment->SetFlags(nFlags & ~FLAGS_ATTACH_MERGED_FOR_SHADOWS);
  88.  
  89.                 m_pMergedSkinAttachment->m_pAttachmentManager->RemoveExtraBone(attachmentInfo.pAttachment);
  90.         }
  91.  
  92.         m_MergedAttachments.clear();
  93.         m_bRequiresIndexUpdate = false;
  94.  
  95.         CAttachmentMerger::Instance().OnDeleteMergedAttachment(this);
  96.         m_pMergedSkinAttachment->Immediate_ClearBinding();
  97. }
  98.  
  99. void CAttachmentMerged::DrawAttachment(SRendParams& rParams, const SRenderingPassInfo& passInfo, const Matrix34& rWorldMat34, f32 fZoomFactor)
  100. {
  101.         if (m_bRequiresIndexUpdate)
  102.         {
  103.                 for (int lod = 0; lod < m_pMergedSkinAttachment->m_pModelSkin->GetNumLODs(); ++lod)
  104.                 {
  105.                         DynArray<std::pair<uint32, uint32>> indexRanges;
  106.                         indexRanges.reserve(m_MergedAttachments.size());
  107.  
  108.                         auto curRange = std::make_pair(0u, 0u);
  109.                         for (auto& mergeInfo : m_MergedAttachments)
  110.                         {
  111.                                 if (mergeInfo.pAttachment->IsAttachmentHiddenInShadow())
  112.                                         continue;
  113.  
  114.                                 if (curRange.second == 0)
  115.                                         curRange.first = mergeInfo.IndexInfo[lod].nFirstIndex;
  116.  
  117.                                 // cannot merge: start new range
  118.                                 if (mergeInfo.IndexInfo[lod].nFirstIndex > curRange.first + curRange.second)
  119.                                 {
  120.                                         indexRanges.push_back(curRange);
  121.  
  122.                                         curRange.first = mergeInfo.IndexInfo[lod].nFirstIndex;
  123.                                         curRange.second = mergeInfo.IndexInfo[lod].nIndexCount;
  124.                                 }
  125.                                 else
  126.                                 {
  127.                                         curRange.second += mergeInfo.IndexInfo[lod].nIndexCount;
  128.                                 }
  129.                         }
  130.                         indexRanges.push_back(curRange);
  131.  
  132.                         CAttachmentMerger::Instance().UpdateIndices(this, lod, indexRanges);
  133.                 }
  134.  
  135.                 m_bRequiresIndexUpdate = false;
  136.         }
  137.  
  138.         m_pMergedSkinAttachment->DrawAttachment(rParams, passInfo, rWorldMat34, fZoomFactor);
  139. }
  140.  
downloadAttachmentMerged.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