BVB Source Codes

CRYENGINE Show BlockyXml.cpp Source code

Return Download CRYENGINE: download BlockyXml.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 "BlockyXml.h"
  5.  
  6. bool BlockyXmlBlocks::AddBlock(const char* scopeName, const char* name, const XmlNodeRef& node, const char* fileName)
  7. {
  8.         assert(scopeName && name);
  9.  
  10.         std::pair<BlockScopes::iterator, bool> siresult = m_scopes.insert(
  11.           BlockScopes::value_type(scopeName, Blocks()));
  12.         Blocks& blocks = siresult.first->second;
  13.  
  14.         std::pair<Blocks::iterator, bool> iresult = blocks.insert(
  15.           Blocks::value_type(name, Block(fileName, node)));
  16.  
  17.         if (iresult.second)
  18.                 return true;
  19.  
  20.         AIWarning("Duplicate block definition '%s' in file '%s' at line %d. First defined in '%s'.",
  21.                   name, fileName, node->getLine(), iresult.first->second.fileName.c_str());
  22.  
  23.         return false;
  24. }
  25.  
  26. BlockyXmlBlocks::Block BlockyXmlBlocks::GetBlock(const char* scopeName, const char* blockName)
  27. {
  28.         assert(scopeName && blockName);
  29.  
  30.         BlockScopes::iterator scopeIt = m_scopes.find(CONST_TEMP_STRING(scopeName));
  31.  
  32.         bool globalScope = false;
  33.         if ((scopeIt == m_scopes.end()) && (stricmp(scopeName, "Global")))
  34.         {
  35.                 globalScope = true;
  36.                 scopeIt = m_scopes.find(CONST_TEMP_STRING("Global"));
  37.         }
  38.  
  39.         while (scopeIt != m_scopes.end())
  40.         {
  41.                 Blocks& blocks = scopeIt->second;
  42.                 Blocks::iterator it = blocks.find(blockName);
  43.  
  44.                 if (it != blocks.end())
  45.                         return it->second;
  46.                 else if (!globalScope)
  47.                 {
  48.                         globalScope = true;
  49.                         scopeIt = m_scopes.find(CONST_TEMP_STRING("Global"));
  50.                 }
  51.                 else
  52.                         break;
  53.         }
  54.  
  55.         return Block();
  56. }
  57.  
  58. BlockyXmlNodeRef::BlockyXmlNodeRef()
  59.         : m_currIdx(0)
  60. {
  61. }
  62.  
  63. BlockyXmlNodeRef::BlockyXmlNodeRef(const BlockyXmlBlocks::Ptr& blocks, const char* scopeName, const XmlNodeRef& rootNode,
  64.                                    const char* fileName)
  65.         : m_rootNode(rootNode)
  66.         , m_scopeName(scopeName)
  67.         , m_fileName(fileName)
  68.         , m_blocks(blocks)
  69.         , m_currIdx(0)
  70. {
  71. }
  72.  
  73. BlockyXmlNodeRef::BlockyXmlNodeRef(const BlockyXmlBlocks::Ptr& blocks, const char* scopeName, const BlockyXmlBlocks::Block& block)
  74.         : m_rootNode(block.blockNode)
  75.         , m_scopeName(scopeName)
  76.         , m_fileName(block.fileName)
  77.         , m_blocks(blocks)
  78.         , m_currIdx(0)
  79. {
  80. }
  81.  
  82. BlockyXmlNodeRef::BlockyXmlNodeRef(const BlockyXmlNodeRef& other)
  83.         : m_rootNode(other.m_rootNode)
  84.         , m_scopeName(other.m_scopeName)
  85.         , m_fileName(other.m_fileName)
  86.         , m_blocks(other.m_blocks)
  87.         , m_currIdx(other.m_currIdx)
  88. {
  89.         if (other.m_currRef.get())
  90.                 m_currRef.reset(new BlockyXmlNodeRef(*other.m_currRef.get()));
  91. }
  92.  
  93. void BlockyXmlNodeRef::first()
  94. {
  95.         m_currIdx = 0;
  96.         m_currRef.reset();
  97. }
  98.  
  99. XmlNodeRef BlockyXmlNodeRef::next()
  100. {
  101.         if (m_currIdx >= m_rootNode->getChildCount())
  102.                 return XmlNodeRef();
  103.  
  104.         XmlNodeRef currNode = m_rootNode->getChild(m_currIdx);
  105.         if (stricmp(currNode->getTag(), "Ref"))
  106.         {
  107.                 ++m_currIdx;
  108.                 return currNode;
  109.         }
  110.  
  111.         if (m_currRef.get())
  112.         {
  113.                 if (currNode = m_currRef->next())
  114.                         return currNode;
  115.                 else
  116.                 {
  117.                         m_currRef.reset();
  118.                         ++m_currIdx;
  119.                         return next();
  120.                 }
  121.         }
  122.  
  123.         const char* blockName = 0;
  124.         if (currNode->haveAttr("name"))
  125.                 currNode->getAttr("name", &blockName);
  126.  
  127.         if (m_blocks != NULL)
  128.         {
  129.                 const BlockyXmlBlocks::Block& block = m_blocks->GetBlock(m_scopeName.c_str(), blockName);
  130.                 if (block.blockNode)
  131.                 {
  132.                         m_currRef.reset(new BlockyXmlNodeRef(m_blocks, m_scopeName.c_str(), block));
  133.  
  134.                         return next();
  135.                 }
  136.         }
  137.  
  138.         AIWarning("Unresolved block reference '%s' in file '%s' at line %d.", blockName, m_fileName.c_str(), currNode->getLine());
  139.  
  140.         return XmlNodeRef();
  141. }
  142.  
downloadBlockyXml.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