BVB Source Codes

CRYENGINE Show VehicleDamagesTemplateRegistry.cpp Source code

Return Download CRYENGINE: download VehicleDamagesTemplateRegistry.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Implements a registry for vehicle damages templates
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 18:07:2006: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "Serialization/XMLScriptLoader.h"
  17. #include "IVehicleSystem.h"
  18. #include "Vehicle.h"
  19. #include "VehicleDamagesGroup.h"
  20. #include "VehicleDamagesTemplateRegistry.h"
  21.  
  22. //------------------------------------------------------------------------
  23. bool CVehicleDamagesTemplateRegistry::Init(const string& damagesTemplatesPath)
  24. {
  25.         if (damagesTemplatesPath.empty())
  26.                 return false;
  27.  
  28.         m_templates.clear();
  29.  
  30.         ICryPak* pCryPak = gEnv->pCryPak;
  31.  
  32.         _finddata_t fd;
  33.         int ret;
  34.         intptr_t handle;
  35.  
  36.         if ((handle = pCryPak->FindFirst(damagesTemplatesPath + string("*") + ".xml", &fd)) != -1)
  37.         {
  38.                 do
  39.                 {
  40.                         string name(fd.name);
  41.  
  42.                         if (name.substr(0, 4) != "def_")
  43.                         {
  44.                                 string filename = damagesTemplatesPath + name;
  45.  
  46.                                 if (!RegisterTemplates(filename))
  47.                                         CryLog("VehicleDamagesTemplateRegistry: error parsing template file <%s>.", filename.c_str());
  48.                         }
  49.  
  50.                         ret = pCryPak->FindNext(handle, &fd);
  51.                 }
  52.                 while (ret >= 0);
  53.  
  54.                 pCryPak->FindClose(handle);
  55.         }
  56.  
  57.         return true;
  58. }
  59.  
  60. //------------------------------------------------------------------------
  61. bool CVehicleDamagesTemplateRegistry::RegisterTemplates(const string& filename)
  62. {
  63.         XmlNodeRef table = gEnv->pSystem->LoadXmlFromFile(filename);
  64.         if (!table)
  65.                 return false;
  66.  
  67.         if (XmlNodeRef damagesGroupsTable = table->findChild("DamagesGroups"))
  68.         {
  69.                 int i = 0;
  70.                 int c = damagesGroupsTable->getChildCount();
  71.  
  72.                 for (; i < c; i++)
  73.                 {
  74.                         if (XmlNodeRef damagesGroupTable = damagesGroupsTable->getChild(i))
  75.                         {
  76.                                 string name = damagesGroupTable->getAttr("name");
  77.                                 if (!name.empty())
  78.                                         m_templates.insert(TTemplateMap::value_type(name, damagesGroupTable));
  79.                         }
  80.                 }
  81.         }
  82.  
  83.         return true;
  84. }
  85.  
  86. //------------------------------------------------------------------------
  87. bool CVehicleDamagesTemplateRegistry::UseTemplate(const string& templateName, IVehicleDamagesGroup* pDamagesGroup)
  88. {
  89.         TTemplateMap::iterator ite = m_templates.find(templateName);
  90.         if (ite != m_templates.end())
  91.         {
  92.                 CVehicleModificationParams noModifications;
  93.                 CVehicleParams tmpVehicleParams(ite->second, noModifications);
  94.                 return pDamagesGroup->ParseDamagesGroup(tmpVehicleParams);
  95.         }
  96.  
  97.         return false;
  98. }
  99.  
downloadVehicleDamagesTemplateRegistry.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