BVB Source Codes

CRYENGINE Show ProceduralClipFactory.cpp Source code

Return Download CRYENGINE: download ProceduralClipFactory.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 "ProceduralClipFactory.h"
  5. #include "ICryMannequin.h"
  6. #include "Mannequin/Serialization.h"
  7.  
  8. CProceduralClipFactory::CProceduralClipFactory()
  9. {
  10. }
  11.  
  12. CProceduralClipFactory::~CProceduralClipFactory()
  13. {
  14. }
  15.  
  16. const char* CProceduralClipFactory::FindTypeName(const THash& typeNameHash) const
  17. {
  18.         const THashToNameMap::const_iterator cit = m_typeHashToName.find(typeNameHash);
  19.         const bool typeNameFound = (cit != m_typeHashToName.end());
  20.         if (typeNameFound)
  21.         {
  22.                 const char* const typeName = cit->second.c_str();
  23.                 return typeName;
  24.         }
  25.         return NULL;
  26. }
  27.  
  28. size_t CProceduralClipFactory::GetRegisteredCount() const
  29. {
  30.         const size_t registeredCount = m_typeHashToName.size();
  31.         return registeredCount;
  32. }
  33.  
  34. IProceduralClipFactory::THash CProceduralClipFactory::GetTypeNameHashByIndex(const size_t index) const
  35. {
  36.         CRY_ASSERT(index < m_typeHashToName.size());
  37.  
  38.         THashToNameMap::const_iterator cit = m_typeHashToName.begin();
  39.         std::advance(cit, index);
  40.  
  41.         const THash typeNameHash = cit->first;
  42.         return typeNameHash;
  43. }
  44.  
  45. const char* CProceduralClipFactory::GetTypeNameByIndex(const size_t index) const
  46. {
  47.         CRY_ASSERT(index < m_typeHashToName.size());
  48.  
  49.         THashToNameMap::const_iterator cit = m_typeHashToName.begin();
  50.         std::advance(cit, index);
  51.  
  52.         const char* const typeName = cit->second.c_str();
  53.         return typeName;
  54. }
  55.  
  56. bool CProceduralClipFactory::Register(const char* const typeName, const SProceduralClipFactoryRegistrationInfo& registrationInfo)
  57. {
  58.         CRY_ASSERT(typeName);
  59.         CRY_ASSERT(registrationInfo.pProceduralClipCreator != NULL);
  60.         CRY_ASSERT(registrationInfo.pProceduralParamsCreator != NULL);
  61.  
  62.         const THash typeNameHash(typeName);
  63.  
  64.         const char* const registeredTypeNameForHash = FindTypeName(typeNameHash);
  65.         const bool alreadyRegistered = (registeredTypeNameForHash != NULL);
  66.         if (alreadyRegistered)
  67.         {
  68.                 const bool namesMatch = (strcmp(typeName, registeredTypeNameForHash) == 0);
  69.                 if (namesMatch)
  70.                 {
  71.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::Register: Register called more than once for type with name '%s'.", typeName);
  72.                 }
  73.                 else
  74.                 {
  75.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::Register: Trying to register type with name '%s' and hash '%u', but hash collides with already registered type with name '%s'. Choose a different name for the type.", typeName, typeNameHash.ToUInt32(), registeredTypeNameForHash);
  76.                         // TODO: FatalError?
  77.                 }
  78.  
  79.                 CRY_ASSERT(false);
  80.                 return false;
  81.         }
  82.  
  83. #if defined(_DEBUG)
  84.         CryLogAlways("CProceduralClipFactory: Registering procedural clip with name '%s'.", typeName);
  85. #endif
  86.         m_typeHashToName[typeNameHash] = string(typeName);
  87.         m_typeHashToRegistrationInfo[typeNameHash] = registrationInfo;
  88.  
  89.         return true;
  90. }
  91.  
  92. IProceduralParamsPtr CProceduralClipFactory::CreateProceduralClipParams(const char* const typeName) const
  93. {
  94.         CRY_ASSERT(typeName);
  95.  
  96.         const THash typeNameHash(typeName);
  97.         return CreateProceduralClipParams(typeNameHash);
  98. }
  99.  
  100. IProceduralParamsPtr CProceduralClipFactory::CreateProceduralClipParams(const THash& typeNameHash) const
  101. {
  102.         const SProceduralClipFactoryRegistrationInfo* const pRegistrationInfo = FindRegistrationInfo(typeNameHash);
  103.         if (!pRegistrationInfo)
  104.         {
  105.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::CreateProceduralClipParams: Failed to create procedural params for type with hash '%u'.", typeNameHash.ToUInt32());
  106.                 return IProceduralParamsPtr();
  107.         }
  108.         IProceduralParamsPtr pParams = (*pRegistrationInfo->pProceduralParamsCreator)();
  109.         return pParams;
  110. }
  111.  
  112. IProceduralClipPtr CProceduralClipFactory::CreateProceduralClip(const char* const typeName) const
  113. {
  114.         CRY_ASSERT(typeName);
  115.  
  116.         const THash typeNameHash(typeName);
  117.         return CreateProceduralClip(typeNameHash);
  118. }
  119.  
  120. IProceduralClipPtr CProceduralClipFactory::CreateProceduralClip(const THash& typeNameHash) const
  121. {
  122.         const SProceduralClipFactoryRegistrationInfo* const pRegistrationInfo = FindRegistrationInfo(typeNameHash);
  123.         if (!pRegistrationInfo)
  124.         {
  125.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::CreateProceduralClip: Failed to create procedural clip for type with hash '%u'.", typeNameHash.ToUInt32());
  126.                 return IProceduralClipPtr();
  127.         }
  128.         IProceduralClipPtr pClip = (*pRegistrationInfo->pProceduralClipCreator)();
  129.         return pClip;
  130. }
  131.  
  132. const SProceduralClipFactoryRegistrationInfo* CProceduralClipFactory::FindRegistrationInfo(const THash& typeNameHash) const
  133. {
  134.         const TTypeHashToRegistrationInfoMap::const_iterator cit = m_typeHashToRegistrationInfo.find(typeNameHash);
  135.         const bool registrationInfoFound = (cit != m_typeHashToRegistrationInfo.end());
  136.         if (registrationInfoFound)
  137.         {
  138.                 const SProceduralClipFactoryRegistrationInfo& registrationInfo = cit->second;
  139.                 return &registrationInfo;
  140.         }
  141.  
  142.         return NULL;
  143. }
  144.  
downloadProceduralClipFactory.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