gwnavruntime/queries/multidestinationpathfinderquery.h Source File

multidestinationpathfinderquery.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 #ifndef Navigation_MultiDestinationPathFinderQuery_H
9 #define Navigation_MultiDestinationPathFinderQuery_H
10 
16 #include "gwnavruntime/path/path.h"
18 #include "gwnavruntime/math/box2iiterator.h"
19 
20 
21 namespace Kaim
22 {
23 
24 template<class TraverseLogic>
25 class MultiDestinationPathFinderQuery : public BaseMultiDestinationPathFinderQuery
26 {
27 public:
28 
29  // ---------------------------------- Public Member Functions ----------------------------------
30 
31  MultiDestinationPathFinderQuery();
32  virtual ~MultiDestinationPathFinderQuery();
33 
34  // ---------------------------------- Query framework functions ----------------------------------
35 
38  virtual void Advance(WorkingMemory* workingMemory);
39 
40  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = KY_NULL);
41 
42 public: //Internal
43  bool HasNavDataChanged();
44 
45 protected:
46  void SetFinish(WorkingMemory* workingMemory);
47  KyResult ComputeStartGraphEdgeOrGraphVertexOrTriangle(PathFinderQueryUtils& queryUtils);
48  KyResult ComputeStartTriangle(PathFinderQueryUtils& queryUtils);
49  KyResult ComputeDestTriangleIfNeeded(PathFinderQueryUtils& queryUtils);
50  KyResult InitializeContextAndStartNode(PathFinderQueryUtils& queryUtils);
51  KyResult InitAllDestinationNodes();
52  KyResult InitDestinationNodeFromDestNavGraphEdge(PathFinderPoint& dest);
53  KyResult InitDestinationNodeFromDestNavGraphVertex(PathFinderPoint& dest);
54  KyResult InitDestinationNodeFromDestNavTriangle(PathFinderPoint& dest);
55  KyResult InitTraversalFromStartNode(PathFinderQueryUtils& queryUtils);
56  void InitPropagationBounds();
57 
58  KyResult CheckNavDataChangeFromAstarContext(WorkingMemory* workingMemory);
59  KyResult CheckNavDataChange(WorkingMemory* workingMemory);
60 
61  bool ShouldReturnAfterTryingCanGo(WorkingMemory* workingMemory);
62 
63  bool HasExplorationReachedAllDestNodes();
64  bool HasExplorationReachedAtLeastADestNode();
65 
66  void ComputeRawCosts();
67  void BuildRawPaths();
68  PathEdgeType GetPathEdgeType(const AStarNode& predecessorNode, const AStarNode& node);
69 
70  bool ProcessFirstDestination();
71  bool UpdateResultAndSelectFirstDestination();
72  bool ProcessNextDestination(WorkingMemory* workingMemory);
73 
74  KyUInt32 CountAbstractGraphNodes(WorkingMemory* workingMemory, AStarNodeIndex destNodeIdx);
75  bool BuildAbstractPath(WorkingMemory* workingMemory);
76 
77 protected:
78  class TraversalCustomizer
79  {
80  public:
81  typedef TraverseLogic TLogic;
82 
83  TraversalCustomizer();
84 
85  bool CanTraverse(const NavTriangleRawPtr& triangleRawPtr, KyFloat32* costMultiplier);
86  bool CanTraverse(const NavGraphEdgeRawPtr& edgeRawPtr, KyFloat32* costMultiplier);
87  bool CanEnterNavTag(const NavTag& exitNavTag, const NavTag& enterNavTag, const Vec3f& pos);
88  KyFloat32 GetHeuristicFromNodePosition(const Vec3f& nodePosition);
89 
90  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
91  bool ShouldVisitNode(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
92  bool IsNodeOutsidePropagationBounds(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
93  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& halfEdge, NavHalfEdgeRawPtr& pairHalfEdgeOfNewNode);
94  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr& navGraphVertexRawPtr);
95  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
96  bool ShouldOpenNavTriangleUnderAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
97  Vec3f ComputeNodePositionOnHalfEdge(AStarTraversalContext* aStarTraversalContext, const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex predecessorNodeIndex);
98  KyResult OnNavTriangleExplored(AStarTraversalContext* aStarTraversalContext, const NavTriangleRawPtr& navTriangleRawPtr, AStarNodeIndex currentNodeIndex);
99  KyResult OnNavGraphEdgeExplored(AStarTraversalContext* aStarTraversalContext, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr, AStarNodeIndex currentNodeIndex);
100 
101  MultiDestinationPathFinderQuery<TraverseLogic>* m_query;
102  void* m_traverseLogicUserData;
103  };
104 
105  AStarTraversal<TraversalCustomizer> m_traversal;
106  KyArray<MonodirectionalRayCanGoQuery<TraverseLogic> > m_rayCanGoQueries;
107  KyUInt32 m_currentProcessedDestIdx;
108 };
109 
110 }
111 
113 
114 #endif //Navigation_MultiDestinationPathFinderQuery_H
115 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
PathEdgeType
Defines the different kind of PathEdge within a Path.
Definition: path.h:26
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43