BVB Source Codes

CRYENGINE Show ProceduralClipConversion.cpp Source code

Return Download CRYENGINE: download ProceduralClipConversion.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 "ProceduralClipConversion.h"
  5.  
  6. static const char* const ProceduralClipConversionFilename = "Scripts/Mannequin/ProcClipConversion.xml";
  7.  
  8. //////////////////////////////////////////////////////////////////////////
  9. namespace
  10. {
  11. void InitParamList(SProcClipConversionEntry::ParamConversionStringList& paramList, const string& s)
  12. {
  13.         paramList.clear();
  14.  
  15.         int start = 0;
  16.         string token = s.Tokenize(".", start);
  17.         while (!token.empty())
  18.         {
  19.                 paramList.push_back(token);
  20.                 token = s.Tokenize(".", start);
  21.         }
  22. }
  23. }
  24.  
  25. //////////////////////////////////////////////////////////////////////////
  26. XmlNodeRef SProcClipConversionEntry::Convert(const XmlNodeRef& pOldNode) const
  27. {
  28.         CRY_ASSERT(pOldNode);
  29.  
  30.         const string typeName = pOldNode->getAttr("type");
  31.  
  32.         XmlNodeRef pNewNode = gEnv->pSystem->CreateXmlNode("ProceduralParams");
  33.         if (!pNewNode)
  34.         {
  35.                 CryFatalError("SProcClipConversionEntry::Convert: Unable to create a ProceduralParams XmlNode while trying to convert old node of type '%s'.", typeName.c_str());
  36.         }
  37.  
  38.         pNewNode->setAttr("type", typeName.c_str());
  39.  
  40.         ConvertAttribute(pOldNode, pNewNode, "anim", animRef);
  41.         ConvertAttribute(pOldNode, pNewNode, "string", dataString);
  42.         ConvertAttribute(pOldNode, pNewNode, "crcString", crcString);
  43.  
  44.         XmlNodeRef pOldParamsNode = pOldNode->findChild("Params");
  45.         if (pOldParamsNode)
  46.         {
  47.                 const int oldParamsCount = pOldParamsNode->getChildCount();
  48.                 const int expectedParamsCount = static_cast<int>(parameters.size());
  49.                 if (expectedParamsCount < oldParamsCount)
  50.                 {
  51.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "SProcClipConversionEntry::Convert: Mismatch in xml Proc clip node of type '%s' at line %d between expected parameters (%d, defined in '%s') and number of parameters in the xml node (%d).", typeName.c_str(), pOldNode->getLine(), expectedParamsCount, ProceduralClipConversionFilename, oldParamsCount);
  52.                 }
  53.  
  54.                 const int safeParamsCount = min(oldParamsCount, expectedParamsCount);
  55.                 for (int i = 0; i < safeParamsCount; ++i)
  56.                 {
  57.                         XmlNodeRef pOldParamsChildNode = pOldParamsNode->getChild(i);
  58.                         const ParamConversionStringList& paramList = parameters[i];
  59.                         ConvertAttribute(pOldParamsChildNode, pNewNode, "value", paramList);
  60.                 }
  61.  
  62.                 // Convert remaining parameters as if they had a value of 0 because the old procedural clip format would not save trailing parameters when their value was 0.
  63.                 for (int i = safeParamsCount; i < expectedParamsCount; ++i)
  64.                 {
  65.                         const ParamConversionStringList& paramList = parameters[i];
  66.                         CreateAttribute(pNewNode, paramList, "0");
  67.                 }
  68.         }
  69.  
  70.         return pNewNode;
  71. }
  72.  
  73. //////////////////////////////////////////////////////////////////////////
  74. XmlNodeRef SProcClipConversionEntry::CreateNodeStructure(XmlNodeRef pNewNode, const ParamConversionStringList& paramList) const
  75. {
  76.         CRY_ASSERT(pNewNode);
  77.         if (paramList.empty())
  78.         {
  79.                 return XmlNodeRef();
  80.         }
  81.  
  82.         const size_t paramListSize = paramList.size();
  83.         XmlNodeRef pCurrentNode = pNewNode;
  84.         for (size_t i = 0; i < paramListSize; ++i)
  85.         {
  86.                 const string& paramName = paramList[i];
  87.                 XmlNodeRef pChildNode = pCurrentNode->findChild(paramName.c_str());
  88.                 if (!pChildNode)
  89.                 {
  90.                         pChildNode = pCurrentNode->createNode(paramName.c_str());
  91.                         pCurrentNode->addChild(pChildNode);
  92.                 }
  93.                 pCurrentNode = pChildNode;
  94.         }
  95.         return pCurrentNode;
  96. }
  97.  
  98. //////////////////////////////////////////////////////////////////////////
  99. void SProcClipConversionEntry::ConvertAttribute(const XmlNodeRef& pOldNode, XmlNodeRef pNewNode, const char* const oldAttributeName, const ParamConversionStringList& newAttributeName) const
  100. {
  101.         CRY_ASSERT(pOldNode);
  102.         CRY_ASSERT(pNewNode);
  103.  
  104.         if (pOldNode->haveAttr(oldAttributeName))
  105.         {
  106.                 if (newAttributeName.empty())
  107.                 {
  108.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Procedural clip conversion for attribute '%s' failed: Mapping to a new attribute name is missing.", oldAttributeName);
  109.                         return;
  110.                 }
  111.  
  112.                 XmlNodeRef pAttributeNode = CreateNodeStructure(pNewNode, newAttributeName);
  113.                 if (!pAttributeNode)
  114.                 {
  115.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Procedural clip conversion for attribute '%s' failed: Unable to create structure for new node.", oldAttributeName);
  116.                         return;
  117.                 }
  118.  
  119.                 pAttributeNode->setAttr("value", pOldNode->getAttr(oldAttributeName));
  120.         }
  121. }
  122.  
  123. //////////////////////////////////////////////////////////////////////////
  124. void SProcClipConversionEntry::CreateAttribute(XmlNodeRef pNewNode, const ParamConversionStringList& newAttributeName, const char* const newAttributeValue) const
  125. {
  126.         CRY_ASSERT(pNewNode);
  127.  
  128.         if (newAttributeName.empty())
  129.         {
  130.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Procedural clip conversion failed: Failed to create new attribute since no name is defined.");
  131.                 return;
  132.         }
  133.  
  134.         XmlNodeRef pAttributeNode = CreateNodeStructure(pNewNode, newAttributeName);
  135.         if (!pAttributeNode)
  136.         {
  137.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Procedural clip conversion failed: Unable to create node structure for new attribute.");
  138.                 return;
  139.         }
  140.  
  141.         pAttributeNode->setAttr("value", newAttributeValue);
  142. }
  143.  
  144. //////////////////////////////////////////////////////////////////////////
  145. //////////////////////////////////////////////////////////////////////////
  146. CProcClipConversionHelper::CProcClipConversionHelper()
  147. {
  148.         XmlNodeRef pXmlNode = gEnv->pSystem->LoadXmlFromFile(ProceduralClipConversionFilename);
  149.         if (!pXmlNode)
  150.         {
  151.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Unable to load '%s'. Old procedural clips will not be converted.", ProceduralClipConversionFilename);
  152.                 return;
  153.         }
  154.  
  155.         const int childCount = pXmlNode->getChildCount();
  156.         for (int i = 0; i < childCount; ++i)
  157.         {
  158.                 XmlNodeRef pXmlEntryNode = pXmlNode->getChild(i);
  159.                 LoadEntry(pXmlEntryNode);
  160.         }
  161. }
  162.  
  163. //////////////////////////////////////////////////////////////////////////
  164. void CProcClipConversionHelper::LoadEntry(const XmlNodeRef& pXmlEntryNode)
  165. {
  166.         CRY_ASSERT(pXmlEntryNode);
  167.  
  168.         const string name = pXmlEntryNode->getTag();
  169.  
  170.         SProcClipConversionEntry entry;
  171.  
  172.         InitParamList(entry.animRef, pXmlEntryNode->getAttr("anim"));
  173.         InitParamList(entry.crcString, pXmlEntryNode->getAttr("crcString"));
  174.         InitParamList(entry.dataString, pXmlEntryNode->getAttr("string"));
  175.  
  176.         const int childCount = pXmlEntryNode->getChildCount();
  177.         for (int i = 0; i < childCount; ++i)
  178.         {
  179.                 XmlNodeRef pXmlParamsNode = pXmlEntryNode->getChild(i);
  180.                 SProcClipConversionEntry::ParamConversionStringList paramEntry;
  181.                 InitParamList(paramEntry, pXmlParamsNode->getAttr("value"));
  182.                 entry.parameters.push_back(paramEntry);
  183.         }
  184.  
  185.         conversionMap[name] = entry;
  186. }
  187.  
  188. //////////////////////////////////////////////////////////////////////////
  189. XmlNodeRef CProcClipConversionHelper::Convert(const XmlNodeRef& pOldXmlNode)
  190. {
  191.         const string typeName = pOldXmlNode->getAttr("type");
  192.  
  193.         ConversionEntryMap::const_iterator cit = conversionMap.find(typeName);
  194.         if (cit == conversionMap.end())
  195.         {
  196.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Found no conversion information for old procedural clip of type '%s'. Please add it to '%s'.", typeName.c_str(), ProceduralClipConversionFilename);
  197.                 return XmlNodeRef();
  198.         }
  199.  
  200.         const SProcClipConversionEntry& entry = cit->second;
  201.         return entry.Convert(pOldXmlNode);
  202. }
  203.  
downloadProceduralClipConversion.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