BVB Source Codes

CRYENGINE Show XmlLoadGame.cpp Source code

Return Download CRYENGINE: download XmlLoadGame.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 "XmlLoadGame.h"
  5. #include "XmlSerializeHelper.h"
  6.  
  7. #include <CryCore/Platform/IPlatformOS.h>
  8.  
  9. struct CXmlLoadGame::Impl
  10. {
  11.         XmlNodeRef root;
  12.         XmlNodeRef metadata;
  13.         string     inputFile;
  14.  
  15.         std::vector<_smart_ptr<CXmlSerializeHelper>> sections;
  16. };
  17.  
  18. CXmlLoadGame::CXmlLoadGame() : m_pImpl(new Impl)
  19. {
  20. }
  21.  
  22. CXmlLoadGame::~CXmlLoadGame()
  23. {
  24. }
  25.  
  26. bool CXmlLoadGame::Init(const char* name)
  27. {
  28.         if (GetISystem()->GetPlatformOS()->UsePlatformSavingAPI())
  29.         {
  30.                 IPlatformOS::ISaveReaderPtr pSaveReader = GetISystem()->GetPlatformOS()->SaveGetReader(name);
  31.                 if (!pSaveReader)
  32.                 {
  33.                         return false;
  34.                 }
  35.  
  36.                 size_t nFileSize;
  37.  
  38.                 if ((pSaveReader->GetNumBytes(nFileSize) == IPlatformOS::eFOC_Failure) || (nFileSize <= 0))
  39.                 {
  40.                         return false;
  41.                 }
  42.  
  43.                 std::vector<char> xmlData;
  44.                 xmlData.resize(nFileSize);
  45.  
  46.                 if (pSaveReader->ReadBytes(&xmlData[0], nFileSize) == IPlatformOS::eFOC_Failure)
  47.                 {
  48.                         return false;
  49.                 }
  50.  
  51.                 m_pImpl->root = GetISystem()->LoadXmlFromBuffer(&xmlData[0], nFileSize);
  52.         }
  53.         else
  54.         {
  55.                 m_pImpl->root = GetISystem()->LoadXmlFromFile(name);
  56.         }
  57.  
  58.         if (!m_pImpl->root)
  59.                 return false;
  60.  
  61.         m_pImpl->inputFile = name;
  62.  
  63.         m_pImpl->metadata = m_pImpl->root->findChild("Metadata");
  64.         if (!m_pImpl->metadata)
  65.                 return false;
  66.  
  67.         return true;
  68. }
  69.  
  70. bool CXmlLoadGame::Init(const XmlNodeRef& root, const char* fileName)
  71. {
  72.         m_pImpl->root = root;
  73.         if (!m_pImpl->root)
  74.                 return false;
  75.  
  76.         m_pImpl->inputFile = fileName;
  77.  
  78.         m_pImpl->metadata = m_pImpl->root->findChild("Metadata");
  79.         if (!m_pImpl->metadata)
  80.                 return false;
  81.  
  82.         return true;
  83. }
  84.  
  85. const char* CXmlLoadGame::GetMetadata(const char* tag)
  86. {
  87.         return m_pImpl->metadata->getAttr(tag);
  88. }
  89.  
  90. bool CXmlLoadGame::GetMetadata(const char* tag, int& value)
  91. {
  92.         return m_pImpl->metadata->getAttr(tag, value);
  93. }
  94.  
  95. bool CXmlLoadGame::HaveMetadata(const char* tag)
  96. {
  97.         return m_pImpl->metadata->haveAttr(tag);
  98. }
  99.  
  100. std::unique_ptr<TSerialize> CXmlLoadGame::GetSection(const char* section)
  101. {
  102.         XmlNodeRef node = m_pImpl->root->findChild(section);
  103.         if (!node)
  104.                 return std::unique_ptr<TSerialize>();
  105.  
  106.         _smart_ptr<CXmlSerializeHelper> pSerializer = new CXmlSerializeHelper;
  107.         m_pImpl->sections.push_back(pSerializer);
  108.         return std::unique_ptr<TSerialize>(new TSerialize(pSerializer->GetReader(node)));
  109. }
  110.  
  111. bool CXmlLoadGame::HaveSection(const char* section)
  112. {
  113.         return m_pImpl->root->findChild(section) != 0;
  114. }
  115.  
  116. void CXmlLoadGame::Complete()
  117. {
  118.         delete this;
  119. }
  120.  
  121. const char* CXmlLoadGame::GetFileName() const
  122. {
  123.         if (m_pImpl.get())
  124.                 return m_pImpl.get()->inputFile;
  125.         return NULL;
  126. }
  127.  
downloadXmlLoadGame.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