gwnavruntime/queries/astarquery.h Source File

astarquery.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 
15 #include "gwnavruntime/path/path.h"
18 
19 namespace Kaim
20 {
21 
60 
61 
62 template<class TraverseLogic>
63 class AStarQuery : public BaseAStarQuery
64 {
65 public:
66  AStarQuery();
67  virtual ~AStarQuery() {}
68 
69  virtual void Advance(WorkingMemory* workingMemory);
70 
71  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = nullptr);
72 
73 public: // internal
74  bool TraversalHasVisitedNavDataChanged();
75 
76 protected:
77  void Advance_(WorkingMemory* workingMemory);
78 
79  void SetFinish(WorkingMemory* workingMemory);
80  KyResult ComputeStartGraphEdgeOrGraphVertexOrTriangle(PathFinderQueryUtils& queryUtils);
81  KyResult ComputeStartTriangle(PathFinderQueryUtils& queryUtils);
82  KyResult ComputeDestTriangleIfNeeded(PathFinderQueryUtils& queryUtils);
83  KyResult InitializeContextAndStartNode(PathFinderQueryUtils& queryUtils);
84  KyResult InitDestinationNode();
85  KyResult InitDestinationNodeFromDestNavGraphEdge();
86  KyResult InitDestinationNodeFromDestNavGraphVertex();
87  KyResult InitDestinationNodeFromDestNavTriangle();
88  KyResult InitTraversalFromStartNode(PathFinderQueryUtils& queryUtils);
89  void InitPropagationBounds();
90 
91  KyResult CheckNavDataChangeDuringTraversal(WorkingMemory* workingMemory);
92  KyResult CheckNavDataChangeAfterTraversal(WorkingMemory* workingMemory);
93  bool HasExplorationReachedDestNode();
94 
95  bool ShouldReturnAfterTryingCanGo(WorkingMemory* workingMemory);
96 
97  KyUInt32 CountAbstractGraphNodes(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestinationNodeIdx);
98  void BuildAbstractPath(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestAStarNodeIndex);
99 
100 protected:
101  class TraversalCustomizer
102  {
103  public:
104  typedef TraverseLogic TLogic;
105 
106  TraversalCustomizer() : m_astarQuery(nullptr), m_traverseLogicUserData(nullptr) {}
107 
108  bool CanTraverse(const NavTriangleRawPtr& triangleRawPtr, KyFloat32* costMultiplier) { return triangleRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
109  bool CanTraverse(const NavGraphEdgeRawPtr& edgeRawPtr, KyFloat32* costMultiplier) { return edgeRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
110  bool CanEnterNavTag(const NavTag& exitNavTag, const NavTag& enterNavTag, const Vec3f& pos) { return TLogic::CanEnterNavTag(m_traverseLogicUserData, exitNavTag, enterNavTag, pos); }
111  KyFloat32 GetHeuristicFromNodePosition(const Vec3f& nodePosition) { return TLogic::GetHeuristicFromDistanceToDest(m_traverseLogicUserData, Distance(nodePosition, m_astarQuery->m_destInsidePos3f)); }
112 
113  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
114  bool ShouldVisitNode(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
115  bool IsNodeOutsidePropagationBounds(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
116  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& halfEdge, NavHalfEdgeRawPtr& pairHalfEdgeOfNewNode);
117  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr& ) { return true; }
118  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr& ) { return true; }
119  bool ShouldOpenNavTriangleUnderAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
120  Vec3f ComputeNodePositionOnHalfEdge(AStarTraversalContext* aStarTraversalContext, const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex predecessorNodeIndex);
121  KyResult OnNavTriangleExplored(AStarTraversalContext* aStarTraversalContext, const NavTriangleRawPtr& navTriangleRawPtr, AStarNodeIndex currentNodeIndex);
122  KyResult OnNavGraphEdgeExplored(AStarTraversalContext* aStarTraversalContext, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr, AStarNodeIndex currentNodeIndex);
123 
124  OrientedBox2d m_propagationBox;
125  AStarQuery<TraverseLogic>* m_astarQuery;
126  NavTriangleRawPtr m_destTriangleRawPtr;
127  NavGraphEdgeRawPtr m_destNavGraphEdgeRawPtr[2];
129  };
130 
131  AStarTraversal<TraversalCustomizer> m_traversal;
132 };
133 
134 }
135 
137 
138 
Base class for AstarQuery.
Definition: baseastarquery.h:105
KyFloat32 Distance(const Vec2f &A, const Vec2f &B)
Returns the distance between A and B.
Definition: vec2f.h:138
OrientedBox2d is a 3d box with rotation constrained to be along Z.
Definition: orientedbox2d.h:26
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
This class is an helper used internally by the PathFinder Queries to factorize Code.
Definition: pathfinderqueryutils.h:35
void * GetTraverseLogicUserData() const
Gets m_traverseLogicUserData.
Definition: iquery.h:170
virtual void Advance(WorkingMemory *workingMemory)
This function is called by the QueryQueue to process one step on the query.
Definition: astarquery.inl:98
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: astarquery.inl:25
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Runs an A-star algorithm to find a Path through the navigation data (NavMesh & NavGraph) from a start...
Definition: astarquery.h:63
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