gwnavruntime/queries/bestgraphvertexpathfinderquery.h Source File

bestgraphvertexpathfinderquery.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 #pragma once
9 
14 
15 
16 namespace Kaim
17 {
18 
19 class PathFinderQueryUtils;
20 
21 enum OnGraphVertexVisitedResult
22 {
23  OnGraphVertexVisited_IgnoreVertex_GoOn,
24  OnGraphVertexVisited_IgnoreVertex_StopWithBestSoFar,
25  OnGraphVertexVisited_StopOnThisVertex,
26  OnGraphVertexVisited_VertexIsTheBestSoFar_GoOn,
27  OnGraphVertexVisited_NeedToCheckRefinePathToThisVertex
28 };
29 
30 enum OnPathToGraphVertexComputedResult
31 {
32  OnPathToGraphVertexComputed_IgnoreVertex_GoOn,
33  OnPathToGraphVertexComputed_IgnoreVertex_StopWithBestSoFar,
34  OnPathToGraphVertexComputed_StopOnThisVertex,
35  OnPathToGraphVertexComputed_VertexIsTheBestSoFar_GoOn,
36 };
37 
55 
56 template<class VertexFinderLogic>
58 {
59 public:
60  // ------------------------------ Functions -----------------------------
61 
63  : BaseBestGraphVertexPathFinderQuery() , m_traversal(TraversalCustomizer())
64  {
65  m_traversal.m_traversalParams = &m_traversalParams;
66  }
67 
68  virtual ~BestGraphVertexPathFinderQuery() {}
69 
70  // ---------------------------------- Query framework functions ----------------------------------
71 
74  virtual void Advance(WorkingMemory* workingMemory);
75 
76  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = nullptr);
77 
78 public: // internal
79  bool TraversalHasVisitedNavDataChanged();
80 
81 protected:
82  void SetFinish(WorkingMemory* workingMemory);
83  KyResult ComputeStartGraphEdgeOrGraphVertexOrTriangle(PathFinderQueryUtils& queryUtils);
84  KyResult ComputeStartTriangle(PathFinderQueryUtils& queryUtils);
85 
86  KyResult CheckNavDataChangeDuringTraversal(WorkingMemory* workingMemory);
87  KyResult CheckNavDataChangeAfterTraversal(WorkingMemory* workingMemory);
88  KyResult InitTraversalFromStartNode(PathFinderQueryUtils& queryUtils);
89  KyResult InitializeContextAndStartNode(PathFinderQueryUtils& queryUtils);
90 
91 protected:
92  class TraversalCustomizer
93  {
94  public:
95  typedef VertexFinderLogic TLogic;
96 
97  TraversalCustomizer() : m_maxRadius(0.0f), m_traverseLogicUserData(nullptr) {}
98 
99  bool CanTraverse(const NavTriangleRawPtr& triangleRawPtr, KyFloat32* costMultiplier) {return triangleRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
100  bool CanTraverse(const NavGraphEdgeRawPtr& edgeRawPtr, KyFloat32* costMultiplier) { return edgeRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
101  bool CanEnterNavTag(const NavTag& exitNavTag, const NavTag& enterNavTag, const Vec3f& pos) { return TLogic::CanEnterNavTag(m_traverseLogicUserData, exitNavTag, enterNavTag, pos); }
102  KyFloat32 GetHeuristicFromNodePosition(const Vec3f& ) { return 0.0f; }
103 
104  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
105 
106  bool ShouldVisitNode(AStarTraversalContext*, AStarNodeIndex) { return true; }
107 
108  bool IsNodeOutsidePropagationBounds(AStarTraversalContext* astarContext, AStarNodeIndex nodeIndex)
109  {
110  if (m_maxRadius == 0.0f)
111  return false;
112  const AStarNode& astarNode = astarContext->m_aStarNodes[nodeIndex];
113  return SquareDistance(astarNode.m_nodePosition, m_startPos) > m_maxRadius * m_maxRadius;
114  }
115 
116  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& , NavHalfEdgeRawPtr& ) { return true; }
117  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr& ) { return true; }
118  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr& ) { return false; }
119  bool ShouldOpenNavTriangleUnderAbstractGraphNode(const AbstractGraphNodeRawPtr& ) { return false; }
120 
121  Vec3f ComputeNodePositionOnHalfEdge(AStarTraversalContext*, const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex)
122  {
123  return (endPosOfEdge + startPosOfEdge) * 0.5f;
124  }
125 
126  KyResult OnNavTriangleExplored(AStarTraversalContext*, const NavTriangleRawPtr&, AStarNodeIndex) { return KY_SUCCESS; }
127  KyResult OnNavGraphEdgeExplored(AStarTraversalContext*, const NavGraphEdgeRawPtr&, AStarNodeIndex) { return KY_SUCCESS; }
128 
129  Vec3f m_startPos;
130  KyFloat32 m_maxRadius;
132  };
133 
134  AStarTraversal<TraversalCustomizer> m_traversal;
135 };
136 
137 }
138 
140 
141 
This query propagates outward through the NavMesh from the starting position.
Definition: bestgraphvertexpathfinderquery.h:57
Base class for BestGraphVertexPathFinderQuery.
Definition: basebestgraphvertexpathfinderquery.h:47
This class is an helper used internally by the PathFinder Queries to factorize Code.
Definition: pathfinderqueryutils.h:35
virtual void Advance(WorkingMemory *workingMemory)
Performs a single iteration of the PathFinder.
Definition: bestgraphvertexpathfinderquery.inl:24
void * GetTraverseLogicUserData() const
Gets m_traverseLogicUserData.
Definition: iquery.h:170
KyFloat32 SquareDistance(const Vec2f &A, const Vec2f &B)
Returns the square of the distance between A and B.
Definition: vec2f.h:130
Each instance of this class uniquely identifies a single NavGraphEdge in a NavGraph.
Definition: navgraphedgerawptr.h:26
virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory *workingMemory=nullptr)
Called when a query is canceled in FlushCommands while its status is QueryInProcess to make sure that...
Definition: bestgraphvertexpathfinderquery.inl:13
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Identifies a single NavTriangle in a NavFloor.
Definition: navtrianglerawptr.h:21
void * m_traverseLogicUserData
This userData is typically passed by the Bot.
Definition: iquery.h:236
Each instance of this class uniquely identifies a single NavHalfEdge in a NavFloor.
Definition: navhalfedgerawptr.h:23
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexrawptr.h:27
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16