BVB Source Codes

CRYENGINE Show FlyHelpers_TacticalPointLanguageExtender.cpp Source code

Return Download CRYENGINE: download FlyHelpers_TacticalPointLanguageExtender.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 "FlyHelpers_TacticalPointLanguageExtender.h"
  5. #include "FlyHelpers_Path.h"
  6.  
  7. #include <PipeUser.h>
  8.  
  9. namespace FlyHelpers
  10. {
  11.  
  12. //////////////////////////////////////////////////////////////////////////
  13. void CTacticalPointLanguageExtender::Initialize()
  14. {
  15.         if (gEnv->pAISystem->GetTacticalPointSystem())
  16.         {
  17.                 RegisterWithTacticalPointSystem();
  18.                 RegisterQueries();
  19.         }
  20. }
  21.  
  22. //////////////////////////////////////////////////////////////////////////
  23. void CTacticalPointLanguageExtender::Deinitialize()
  24. {
  25.         if (gEnv->pAISystem->GetTacticalPointSystem())
  26.         {
  27.                 UnregisterFromTacticalPointSystem();
  28.         }
  29. }
  30.  
  31. //////////////////////////////////////////////////////////////////////////
  32. bool CTacticalPointLanguageExtender::GeneratePoints(TGenerateParameters& parameters, SGenerateDetails& details, TObjectType obj, const Vec3& objectPos, TObjectType auxObject, const Vec3& auxObjectPos) const
  33. {
  34.         const static uint32 s_pointsInDesignerPathCrc = CCrc32::Compute("pointsInDesignerPath");
  35.         const uint32 queryNameCrc = CCrc32::Compute(parameters.query);
  36.  
  37.         if (queryNameCrc == s_pointsInDesignerPathCrc)
  38.         {
  39.                 IF_UNLIKELY (details.fDensity <= 1.0f)
  40.                 {
  41.                         return false;
  42.                 }
  43.  
  44.                 IEntity* pEntity = obj->GetEntity();
  45.                 CRY_ASSERT(pEntity);
  46.  
  47.                 IAIObject* pAiObject = pEntity->GetAI();
  48.                 IF_UNLIKELY (!pAiObject)
  49.                 {
  50.                         return false;
  51.                 }
  52.  
  53.                 CPipeUser* pPipeUser = pAiObject->CastToCPipeUser();
  54.                 IF_UNLIKELY (!pPipeUser)
  55.                 {
  56.                         return false;
  57.                 }
  58.  
  59.                 const char* pathName = pPipeUser->GetPathToFollow();
  60.                 CRY_ASSERT(pathName);
  61.  
  62.                 SShape path;
  63.                 const bool getPathSuccess = gAIEnv.pNavigation->GetDesignerPath(pathName, path);
  64.                 IF_UNLIKELY (!getPathSuccess)
  65.                 {
  66.                         return false;
  67.                 }
  68.  
  69.                 const bool isValidPath = (!path.shape.empty());
  70.                 IF_UNLIKELY (!isValidPath)
  71.                 {
  72.                         return false;
  73.                 }
  74.  
  75.                 // TODO: Remove unnecessary creation of this path?
  76.                 FlyHelpers::Path flyPath;
  77.                 for (size_t i = 0; i < path.shape.size(); ++i)
  78.                 {
  79.                         const Vec3& point = path.shape[i];
  80.                         flyPath.AddPoint(point);
  81.                 }
  82.  
  83.                 // TODO: Make this an option, or get this property by other means.
  84.                 const bool shouldConsiderAsLoopingPath = true;
  85.                 if (shouldConsiderAsLoopingPath)
  86.                 {
  87.                         flyPath.MakeLooping();
  88.                 }
  89.  
  90.                 const size_t segmentCount = flyPath.GetSegmentCount();
  91.                 for (size_t i = 0; i < flyPath.GetSegmentCount(); ++i)
  92.                 {
  93.                         const Lineseg segment = flyPath.GetSegment(i);
  94.                         const float length = flyPath.GetSegmentLength(i);
  95.  
  96.                         CRY_ASSERT(0 < length);
  97.                         const float advance = details.fDensity / length;
  98.  
  99.                         float sampled = 0;
  100.                         while (sampled < 1.0f)
  101.                         {
  102.                                 parameters.result->AddPoint(segment.GetPoint(sampled));
  103.                                 sampled += advance;
  104.                         }
  105.                 }
  106.  
  107.                 return true;
  108.         }
  109.         return false;
  110. }
  111.  
  112. //////////////////////////////////////////////////////////////////////////
  113. void CTacticalPointLanguageExtender::RegisterWithTacticalPointSystem()
  114. {
  115.         ITacticalPointSystem* pTacticalPointSystem = gEnv->pAISystem->GetTacticalPointSystem();
  116.         CRY_ASSERT(pTacticalPointSystem);
  117.  
  118.         const bool successfullyAddedLanguageExtender = pTacticalPointSystem->AddLanguageExtender(this);
  119.         CRY_ASSERT_MESSAGE(successfullyAddedLanguageExtender, "Failed to add tactical point language extender.");
  120. }
  121.  
  122. //////////////////////////////////////////////////////////////////////////
  123. void CTacticalPointLanguageExtender::RegisterQueries()
  124. {
  125.         ITacticalPointSystem* pTacticalPointSystem = gEnv->pAISystem->GetTacticalPointSystem();
  126.         CRY_ASSERT(pTacticalPointSystem);
  127.  
  128.         pTacticalPointSystem->ExtendQueryLanguage("pointsInDesignerPath", eTPQT_GENERATOR, eTPQC_IGNORE);
  129. }
  130.  
  131. //////////////////////////////////////////////////////////////////////////
  132. void CTacticalPointLanguageExtender::UnregisterFromTacticalPointSystem()
  133. {
  134.         ITacticalPointSystem* pTacticalPointSystem = gEnv->pAISystem->GetTacticalPointSystem();
  135.         CRY_ASSERT(pTacticalPointSystem);
  136.  
  137.         const bool successfullyRemovedLanguageExtender = pTacticalPointSystem->RemoveLanguageExtender(this);
  138.         CRY_ASSERT_MESSAGE(successfullyRemovedLanguageExtender, "Failed to remove tactical point language extender.");
  139. }
  140.  
  141. }
  142.  
downloadFlyHelpers_TacticalPointLanguageExtender.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