BVB Source Codes

CRYENGINE Show VehicleSystem_FactoryRegistration.cpp Source code

Return Download CRYENGINE: download VehicleSystem_FactoryRegistration.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 "VehicleSystem.h"
  5.  
  6. #include "Vehicle.h"
  7.  
  8. #include "VehicleDamageBehaviorAISignal.h"
  9. #include "VehicleDamageBehaviorDestroy.h"
  10. #include "VehicleDamageBehaviorDetachPart.h"
  11. #include "VehicleDamageBehaviorEffect.h"
  12. #include "VehicleDamageBehaviorGroup.h"
  13. #include "VehicleDamageBehaviorHitPassenger.h"
  14. #include "VehicleDamageBehaviorImpulse.h"
  15. #include "VehicleDamageBehaviorMovementNotification.h"
  16. #include "VehicleDamageBehaviorSink.h"
  17. #include "VehicleDamageBehaviorSpawnDebris.h"
  18. #include "VehicleDamageBehaviorIndicator.h"
  19. #include "VehicleDamageBehaviorDisableSeatAction.h"
  20.  
  21. #include "VehiclePartBase.h"
  22. #include "VehiclePartAnimated.h"
  23. #include "VehiclePartAnimatedJoint.h"
  24. #include "VehiclePartLight.h"
  25. #include "VehiclePartPulsingLight.h"
  26. #include "VehiclePartMassBox.h"
  27. #include "VehiclePartStatic.h"
  28. #include "VehiclePartSubPart.h"
  29. #include "VehiclePartSubPartWheel.h"
  30. #include "VehiclePartSuspensionPart.h"
  31. #include "VehiclePartTread.h"
  32. #include "VehiclePartAttachment.h"
  33. #include "VehiclePartEntity.h"
  34. #include "VehiclePartEntityDelayedDetach.h"
  35. #include "VehiclePartParticleEffect.h"
  36. #include "VehiclePartAnimatedChar.h"
  37. #include "VehiclePartWaterRipplesGenerator.h"
  38. #include "VehiclePartDetachedEntity.h"
  39.  
  40. #include "VehicleSeatSerializer.h"
  41.  
  42. #include "VehicleSeatActionLights.h"
  43. #include "VehicleSeatActionMovement.h"
  44. #include "VehicleSeatActionPassengerIK.h"
  45. #include "VehicleSeatActionRotateTurret.h"
  46. #include "VehicleSeatActionSound.h"
  47. #include "VehicleSeatActionSteeringWheel.h"
  48. #include "VehicleSeatActionWeapons.h"
  49. #include "VehicleSeatActionWeaponsBone.h"
  50. #include "VehicleSeatActionAnimation.h"
  51. #include "VehicleSeatActionPassiveAnimation.h"
  52. #include "VehicleSeatActionOrientatePartToView.h"
  53. #include "VehicleSeatActionOrientateBoneToView.h"
  54. #include "VehicleSeatActionRotateBone.h"
  55. #include "VehicleSeatActionShakeParts.h"
  56.  
  57. #include "VehicleUsableActionEnter.h"
  58. #include "VehicleUsableActionFlip.h"
  59.  
  60. #include "VehicleViewActionThirdPerson.h"
  61. #include "VehicleViewSteer.h"
  62. #include "VehicleViewFirstPerson.h"
  63. #include "VehicleViewThirdPerson.h"
  64.  
  65. #include "CryAction.h"
  66.  
  67. //------------------------------------------------------------------------
  68. void CVehicleSystem::RegisterVehicles(IGameFramework* gameFramework)
  69. {
  70.         IEntityClassRegistry::SEntityClassDesc serializerClass;
  71.         serializerClass.sName = "VehicleSeatSerializer";
  72.         serializerClass.sScriptFile = "";
  73.         serializerClass.flags = ECLF_INVISIBLE;
  74.  
  75.         static IGameFramework::CGameObjectExtensionCreator<CVehicleSeatSerializer> createVehicleSeatSerializer;
  76.         CCryAction::GetCryAction()->GetIGameObjectSystem()->RegisterExtension(serializerClass.sName, &createVehicleSeatSerializer, &serializerClass);
  77.  
  78.         // register the detached part entity
  79.  
  80.         IEntityClassRegistry::SEntityClassDesc detachedPartClass;
  81.         detachedPartClass.sName = "VehiclePartDetached";
  82.         detachedPartClass.sScriptFile = "Scripts/Entities/Vehicles/VehiclePartDetached.lua";
  83.         detachedPartClass.flags = ECLF_INVISIBLE;
  84.  
  85.         static IGameFramework::CGameObjectExtensionCreator<CVehiclePartDetachedEntity> createVehicleDetachedPartEntity;
  86.         CCryAction::GetCryAction()->GetIGameObjectSystem()->RegisterExtension(detachedPartClass.sName, &createVehicleDetachedPartEntity, &detachedPartClass);
  87.  
  88.         // register all the vehicles
  89.  
  90.         ICryPak* pack = gEnv->pCryPak;
  91.         _finddata_t fd;
  92.         int res;
  93.         intptr_t handle;
  94.         std::set<string> setVehicles;
  95.  
  96.         string sExt(".xml");
  97.         string sPath("Scripts/Entities/Vehicles/Implementations/Xml/");
  98.  
  99.         if ((handle = pack->FindFirst(sPath + string("*") + sExt, &fd)) != -1)
  100.         {
  101.                 do
  102.                 {
  103.                         if (XmlNodeRef root = GetISystem()->LoadXmlFromFile(sPath + string(fd.name)))
  104.                         {
  105.                                 const char* name = root->getAttr("name");
  106.                                 if (name[0])
  107.                                 {
  108.                                         // Allow the name to contain relative path, but use only the name part as class name.
  109.                                         string className(PathUtil::GetFile(name));
  110.  
  111.                                         // register only once
  112.                                         std::pair<std::set<string>::iterator, bool> result = setVehicles.insert(className);
  113.                                         if (result.second)
  114.                                         {
  115.                                                 IEntityClassRegistry::SEntityClassDesc vehicleClass;
  116.                                                 vehicleClass.sName = className.c_str();
  117.  
  118.                                                 char scriptName[1024];
  119.  
  120.                                                 const char* isOld = root->getAttr("isOld");
  121.                                                 if (!strcmp("1", isOld))
  122.                                                         cry_sprintf(scriptName, "Scripts/Entities/Vehicles/Old/VehiclePool.lua");
  123.                                                 else
  124.                                                         cry_sprintf(scriptName, "Scripts/Entities/Vehicles/VehiclePool.lua");
  125.  
  126.                                                 bool show = true;
  127.                                                 if (root->getAttr("show", show))
  128.                                                 {
  129.                                                         if (!show && VehicleCVars().v_show_all == 0)
  130.                                                                 vehicleClass.flags |= ECLF_INVISIBLE;
  131.                                                 }
  132.  
  133.                                                 vehicleClass.sScriptFile = scriptName;
  134.  
  135.                                                 static IGameFramework::CGameObjectExtensionCreator<CVehicle> vehicleCreator;
  136.                                                 CCryAction::GetCryAction()->GetIGameObjectSystem()->RegisterExtension(name, &vehicleCreator, &vehicleClass);
  137.                                                 m_classes.insert(TVehicleClassMap::value_type(name, &vehicleCreator));
  138.                                         }
  139.                                         else
  140.                                                 CryLog("Vehicle <%s> already registered", name);
  141.                                 }
  142.                                 else
  143.                                 {
  144.                                         CryLog("VehicleSystem: %s is missing 'name' attribute, skipping", fd.name);
  145.                                 }
  146.                         }
  147.                         res = pack->FindNext(handle, &fd);
  148.                 }
  149.                 while (res >= 0);
  150.  
  151.                 pack->FindClose(handle);
  152.         }
  153.  
  154. #define REGISTER_VEHICLEOBJECT(name, obj)                    \
  155.   REGISTER_FACTORY((IVehicleSystem*)this, name, obj, false); \
  156.   obj::m_objectId = this->AssignVehicleObjectId(name);
  157.  
  158.         // register other factories
  159.  
  160.         // vehicle views
  161.         REGISTER_VEHICLEOBJECT("ActionThirdPerson", CVehicleViewActionThirdPerson);
  162.         REGISTER_VEHICLEOBJECT("SteerThirdPerson", CVehicleViewSteer);
  163.         REGISTER_VEHICLEOBJECT("FirstPerson", CVehicleViewFirstPerson);
  164.         REGISTER_VEHICLEOBJECT("ThirdPerson", CVehicleViewThirdPerson);
  165.  
  166.         // vehicle parts
  167.         REGISTER_VEHICLEOBJECT("Base", CVehiclePartBase);
  168.         REGISTER_VEHICLEOBJECT("Animated", CVehiclePartAnimated);
  169.         REGISTER_VEHICLEOBJECT("AnimatedJoint", CVehiclePartAnimatedJoint);
  170.         REGISTER_VEHICLEOBJECT("SuspensionPart", CVehiclePartSuspensionPart);
  171.         REGISTER_VEHICLEOBJECT("Light", CVehiclePartLight);
  172.         REGISTER_VEHICLEOBJECT("PulsingLight", CVehiclePartPulsingLight);
  173.         REGISTER_VEHICLEOBJECT("MassBox", CVehiclePartMassBox);
  174.         REGISTER_VEHICLEOBJECT("Static", CVehiclePartStatic);
  175.         REGISTER_VEHICLEOBJECT("SubPart", CVehiclePartSubPart);
  176.         REGISTER_VEHICLEOBJECT("SubPartWheel", CVehiclePartSubPartWheel);
  177.         REGISTER_VEHICLEOBJECT("Tread", CVehiclePartTread);
  178.         REGISTER_VEHICLEOBJECT("EntityAttachment", CVehiclePartEntityAttachment);
  179.         REGISTER_VEHICLEOBJECT("Entity", CVehiclePartEntity);
  180.         REGISTER_VEHICLEOBJECT("EntityDelayedDetach", CVehiclePartEntityDelayedDetach);
  181.         REGISTER_VEHICLEOBJECT("ParticleEffect", CVehiclePartParticleEffect);
  182.         REGISTER_VEHICLEOBJECT("AnimatedChar", CVehiclePartAnimatedChar);
  183.         REGISTER_VEHICLEOBJECT("WaterRipplesGenerator", CVehiclePartWaterRipplesGenerator);
  184.  
  185.         // vehicle damage behaviors
  186.         REGISTER_VEHICLEOBJECT("AISignal", CVehicleDamageBehaviorAISignal);
  187.         REGISTER_VEHICLEOBJECT("Destroy", CVehicleDamageBehaviorDestroy);
  188.         REGISTER_VEHICLEOBJECT("DetachPart", CVehicleDamageBehaviorDetachPart);
  189.         REGISTER_VEHICLEOBJECT("Effect", CVehicleDamageBehaviorEffect);
  190.         REGISTER_VEHICLEOBJECT("Group", CVehicleDamageBehaviorGroup);
  191.         REGISTER_VEHICLEOBJECT("HitPassenger", CVehicleDamageBehaviorHitPassenger);
  192.         REGISTER_VEHICLEOBJECT("Impulse", CVehicleDamageBehaviorImpulse);
  193.         REGISTER_VEHICLEOBJECT("Indicator", CVehicleDamageBehaviorIndicator);
  194.         REGISTER_VEHICLEOBJECT("MovementNotification", CVehicleDamageBehaviorMovementNotification);
  195.         REGISTER_VEHICLEOBJECT("Sink", CVehicleDamageBehaviorSink);
  196.         REGISTER_VEHICLEOBJECT("SpawnDebris", CVehicleDamageBehaviorSpawnDebris);
  197.         REGISTER_VEHICLEOBJECT("DisableSeatAction", CVehicleDamageBehaviorDisableSeatAction);
  198.  
  199.         // seat actions
  200.         REGISTER_VEHICLEOBJECT("Lights", CVehicleSeatActionLights);
  201.         REGISTER_VEHICLEOBJECT("Movement", CVehicleSeatActionMovement);
  202.         REGISTER_VEHICLEOBJECT("PassengerIK", CVehicleSeatActionPassengerIK);
  203.         REGISTER_VEHICLEOBJECT("RotateTurret", CVehicleSeatActionRotateTurret);
  204.         REGISTER_VEHICLEOBJECT("Sound", CVehicleSeatActionSound);
  205.         REGISTER_VEHICLEOBJECT("SteeringWheel", CVehicleSeatActionSteeringWheel);
  206.         REGISTER_VEHICLEOBJECT("Weapons", CVehicleSeatActionWeapons);
  207.         REGISTER_VEHICLEOBJECT("WeaponsBone", CVehicleSeatActionWeaponsBone);
  208.         REGISTER_VEHICLEOBJECT("Animation", CVehicleSeatActionAnimation);
  209.         REGISTER_VEHICLEOBJECT("PassiveAnimation", CVehicleSeatActionPassiveAnimation);
  210.         REGISTER_VEHICLEOBJECT("OrientatePartToView", CVehicleSeatActionOrientatePartToView);
  211.         REGISTER_VEHICLEOBJECT("OrientateBoneToView", CVehicleSeatActionOrientateBoneToView);
  212.         REGISTER_VEHICLEOBJECT("RotateBone", CVehicleSeatActionRotateBone);
  213.         REGISTER_VEHICLEOBJECT("ShakeParts", CVehicleSeatActionShakeParts);
  214.  
  215.         // actions
  216.         REGISTER_FACTORY((IVehicleSystem*)this, "Enter", CVehicleUsableActionEnter, false);
  217.         REGISTER_FACTORY((IVehicleSystem*)this, "Flip", CVehicleUsableActionFlip, false);
  218. }
  219.  
downloadVehicleSystem_FactoryRegistration.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