BVB Source Codes

CRYENGINE Show XMLCPB_AttrSetTableWriter.cpp Source code

Return Download CRYENGINE: download XMLCPB_AttrSetTableWriter.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4. *************************************************************************/
  5.  
  6. #include "StdAfx.h"
  7. #include "XMLCPB_AttrSetTableWriter.h"
  8. #include "XMLCPB_Writer.h"
  9.  
  10. using namespace XMLCPB;
  11.  
  12. const AttrSetID CAttrSetTableWriter::SEARCHING_ID = 0Xfffffffe;
  13.  
  14. //////////////////////////////////////////////////////////////////////////
  15.  
  16. CAttrSetTableWriter::CAttrSetTableWriter(uint32 maxNumSets, uint32 bufferSize)
  17.         : m_maxNumSets(maxNumSets)
  18.         , m_buffer(bufferSize)
  19.         , m_pWriter(NULL)
  20.         , m_pCheckSet(NULL)
  21.         , m_checkHash(0)
  22.         , m_sortedIndexes(256, SetHasher(GetThis()), SetHasher(GetThis()))
  23. {
  24. }
  25.  
  26. void CAttrSetTableWriter::Init(CWriter* pWriter)
  27. {
  28.         m_pWriter = pWriter;
  29.         m_buffer.Init(pWriter, false);
  30. }
  31.  
  32. //////////////////////////////////////////////////////////////////////////
  33. // AddSet could be used directly instead, with some changes. But then it would be very inefficient because it would need to copy every to-compare set first into the buffer.
  34. AttrSetID CAttrSetTableWriter::GetSetID(const CAttrSet& set)
  35. {
  36.         m_pCheckSet = &set;  // the internal std::set comparison code will use this set when trying to find SEARCHING_ID
  37.         m_checkHash = SetHasher::HashSet(set);
  38.         HashTableType::const_iterator iter = m_sortedIndexes.find(SEARCHING_ID);
  39.         m_pCheckSet = NULL;
  40.  
  41.         // found the set
  42.         if (iter != m_sortedIndexes.end())
  43.                 return *iter;
  44.  
  45.         // didnt find
  46.         AttrSetID ID = AddSet(set);
  47.         return ID;
  48. }
  49.  
  50. //////////////////////////////////////////////////////////////////////////
  51.  
  52. AttrSetID CAttrSetTableWriter::AddSet(const CAttrSet& set)
  53. {
  54.         assert(m_setAddrs.size() < m_maxNumSets);
  55.         assert(set.m_numAttrs <= MAX_NUM_ATTRS);
  56.  
  57.         AttrSetID addedSetId = m_setAddrs.size();
  58.         m_setAddrs.push_back(CBufferWriter::SAddr());
  59.         CBufferWriter::SAddr& setAddr = m_setAddrs.back();
  60.         m_buffer.AddDataNoSplit(setAddr, set.m_pHeaders, sizeof(set.m_pHeaders[0]) * set.m_numAttrs);  // no split = can not be internally splited in diferent internal buffers. Because we want to be able to read it in one go with the translated pointer
  61.         m_numAttrsArray.push_back(set.m_numAttrs);
  62.  
  63.         m_sortedIndexes.insert(addedSetId);
  64.  
  65.         return addedSetId;
  66. }
  67.  
  68. //////////////////////////////////////////////////////////////////////////
  69.  
  70. void CAttrSetTableWriter::WriteToFile()
  71. {
  72.         uint32 numSets = GetNumSets();
  73.         if (numSets == 0)
  74.                 return;
  75.  
  76.         FlatAddrVec flatAddrs;
  77.         CalculateFlatAddrs(flatAddrs);
  78.  
  79.         uint8* pNumTypes = &(m_numAttrsArray[0]);
  80.         m_pWriter->WriteDataIntoFile(pNumTypes, sizeof(*pNumTypes) * numSets);
  81.  
  82.         FlatAddr16* pFlatAddrs = &(flatAddrs[0]);
  83.         m_pWriter->WriteDataIntoFile(pFlatAddrs, sizeof(*pFlatAddrs) * numSets);
  84.  
  85.         m_buffer.WriteToFile();
  86. }
  87.  
  88. //////////////////////////////////////////////////////////////////////////
  89.  
  90. void CAttrSetTableWriter::WriteToMemory(uint8*& rpData, uint32& outWriteLoc)
  91. {
  92.         uint32 numSets = GetNumSets();
  93.         if (numSets == 0)
  94.                 return;
  95.  
  96.         FlatAddrVec flatAddrs;
  97.         CalculateFlatAddrs(flatAddrs);
  98.  
  99.         uint8* pNumTypes = &(m_numAttrsArray[0]);
  100.         m_pWriter->WriteDataIntoMemory(rpData, pNumTypes, sizeof(*pNumTypes) * numSets, outWriteLoc);
  101.  
  102.         FlatAddr16* pFlatAddrs = &(flatAddrs[0]);
  103.         m_pWriter->WriteDataIntoMemory(rpData, pFlatAddrs, sizeof(*pFlatAddrs) * numSets, outWriteLoc);
  104.  
  105.         m_buffer.WriteToMemory(rpData, outWriteLoc);
  106. }
  107.  
  108. //////////////////////////////////////////////////////////////////////////
  109. // total size
  110.  
  111. uint32 CAttrSetTableWriter::GetDataSize() const
  112. {
  113.         uint32 size = GetNumSets() * sizeof(uint8) + GetNumSets() * sizeof(FlatAddr16);
  114.         size += GetSetsDataSize();
  115.  
  116.         return size;
  117. }
  118.  
  119. //////////////////////////////////////////////////////////////////////////
  120. // only the size of all the headers
  121.  
  122. uint32 CAttrSetTableWriter::GetSetsDataSize() const
  123. {
  124.         uint32 size = m_buffer.GetDataSize();
  125.         return size;
  126. }
  127.  
  128. //////////////////////////////////////////////////////////////////////////
  129.  
  130. void CAttrSetTableWriter::CalculateFlatAddrs(FlatAddrVec& outFlatAddrs)
  131. {
  132.         uint32 numSets = GetNumSets();
  133.         outFlatAddrs.resize(numSets);
  134.  
  135.         for (int i = 0; i < numSets; ++i)
  136.         {
  137.                 FlatAddr16& flatAddr = outFlatAddrs[i];
  138.                 flatAddr = m_buffer.ConvertSegmentedAddrToFlatAddr(m_setAddrs[i]);
  139.         }
  140. }
  141.  
downloadXMLCPB_AttrSetTableWriter.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