BVB Source Codes

CRYENGINE Show XmlSaveGame.cpp Source code

Return Download CRYENGINE: download XmlSaveGame.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 "XmlSaveGame.h"
  5. #include "XmlSerializeHelper.h"
  6.  
  7. #include <CryCore/Platform/IPlatformOS.h>
  8.  
  9. static const int XML_SAVEGAME_MAX_CHUNK_SIZE = 32767 / 2;
  10.  
  11. struct CXmlSaveGame::Impl
  12. {
  13.         void GetMemoryUsage(ICrySizer* pSizer) const
  14.         {
  15.                 pSizer->Add(*this);
  16.                 pSizer->AddObject(sections);
  17.                 pSizer->AddObject(root);
  18.                 pSizer->AddObject(metadata);
  19.                 pSizer->AddObject(outputFile);
  20.         }
  21.  
  22.         XmlNodeRef root;
  23.         XmlNodeRef metadata;
  24.         string     outputFile;
  25.  
  26.         typedef std::vector<_smart_ptr<CXmlSerializeHelper>> TContexts;
  27.         TContexts sections;
  28. };
  29.  
  30. CXmlSaveGame::CXmlSaveGame() : m_pImpl(new Impl), m_eReason(eSGR_QuickSave)
  31. {
  32. }
  33.  
  34. CXmlSaveGame::~CXmlSaveGame()
  35. {
  36. }
  37.  
  38. bool CXmlSaveGame::Init(const char* name)
  39. {
  40.         m_pImpl->outputFile = name;
  41.         m_pImpl->root = GetISystem()->CreateXmlNode("SaveGame", true);
  42.         m_pImpl->metadata = m_pImpl->root->createNode("Metadata");
  43.         m_pImpl->root->addChild(m_pImpl->metadata);
  44.         return true;
  45. }
  46.  
  47. XmlNodeRef CXmlSaveGame::GetMetadataXmlNode() const
  48. {
  49.         return m_pImpl->metadata;
  50. }
  51.  
  52. void CXmlSaveGame::AddMetadata(const char* tag, const char* value)
  53. {
  54.         m_pImpl->metadata->setAttr(tag, value);
  55. }
  56.  
  57. void CXmlSaveGame::AddMetadata(const char* tag, int value)
  58. {
  59.         m_pImpl->metadata->setAttr(tag, value);
  60. }
  61.  
  62. TSerialize CXmlSaveGame::AddSection(const char* section)
  63. {
  64.         XmlNodeRef node = m_pImpl->root->createNode(section);
  65.         m_pImpl->root->addChild(node);
  66.  
  67.         _smart_ptr<CXmlSerializeHelper> pSerializer = new CXmlSerializeHelper;
  68.         m_pImpl->sections.push_back(pSerializer);
  69.  
  70.         return TSerialize(pSerializer->GetWriter(node));
  71. }
  72.  
  73. uint8* CXmlSaveGame::SetThumbnail(const uint8* imageData, int width, int height, int depth)
  74. {
  75.         return 0;
  76. }
  77.  
  78. bool CXmlSaveGame::SetThumbnailFromBMP(const char* filename)
  79. {
  80.         return false;
  81. }
  82.  
  83. bool CXmlSaveGame::Complete(bool successfulSoFar)
  84. {
  85.         if (successfulSoFar)
  86.         {
  87.                 successfulSoFar &= Write(m_pImpl->outputFile.c_str(), m_pImpl->root);
  88.         }
  89.         delete this;
  90.         return successfulSoFar;
  91. }
  92.  
  93. const char* CXmlSaveGame::GetFileName() const
  94. {
  95.         if (m_pImpl.get())
  96.                 return m_pImpl.get()->outputFile;
  97.         return NULL;
  98. }
  99.  
  100. void CXmlSaveGame::GetMemoryUsage(ICrySizer* pSizer) const
  101. {
  102.         pSizer->AddObject(m_pImpl);
  103. }
  104.  
  105. bool CXmlSaveGame::Write(const char* filename, XmlNodeRef data)
  106. {
  107. #if CRY_PLATFORM_WINDOWS
  108.         CrySetFileAttributes(filename, 0x00000080);    // FILE_ATTRIBUTE_NORMAL
  109. #endif
  110.  
  111.         // Try opening file for creation first, will also create directory.
  112.         FILE* pFile = NULL;
  113.  
  114.         if (!GetISystem()->GetPlatformOS()->UsePlatformSavingAPI())
  115.         {
  116.                 pFile = gEnv->pCryPak->FOpen(filename, "wb");
  117.                 if (!pFile)
  118.                 {
  119.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Failed to create file %s", filename);
  120.                         return false;
  121.                 }
  122.         }
  123.  
  124.         const bool bSavedToFile = data->saveToFile(filename, XML_SAVEGAME_MAX_CHUNK_SIZE, pFile);
  125.         if (pFile)
  126.         {
  127.                 gEnv->pCryPak->FClose(pFile);
  128.         }
  129.         return bSavedToFile;
  130. }
  131.  
downloadXmlSaveGame.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