gwnavruntime/queries/multidestinationpathfinderquery.h Source File

multidestinationpathfinderquery.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 #pragma once
8 
14 #include "gwnavruntime/path/path.h"
17 
18 namespace Kaim
19 {
20 
21 template<class TraverseLogic>
22 class MultiDestinationPathFinderQuery : public BaseMultiDestinationPathFinderQuery
23 {
24 public:
25 
26  // ------------------------------ Functions -----------------------------
27 
28  MultiDestinationPathFinderQuery();
29  virtual ~MultiDestinationPathFinderQuery();
30 
31  // ---------------------------------- Query framework functions ----------------------------------
32 
35  virtual void Advance(WorkingMemory* workingMemory);
36 
37  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = nullptr);
38 
39 public: // internal
40  bool TraversalHasVisitedNavDataChanged();
41 
42 protected:
43  void SetFinish(WorkingMemory* workingMemory);
44  KyResult ComputeStartGraphEdgeOrGraphVertexOrTriangle(PathFinderQueryUtils& queryUtils);
45  KyResult ComputeStartTriangle(PathFinderQueryUtils& queryUtils);
46  KyResult ComputeDestTriangleIfNeeded(PathFinderQueryUtils& queryUtils);
47  KyResult InitializeContextAndStartNode(PathFinderQueryUtils& queryUtils);
48  KyResult InitAllDestinationNodes();
49  KyResult InitDestinationNodeFromDestNavGraphEdge(PathFinderPoint& dest);
50  KyResult InitDestinationNodeFromDestNavGraphVertex(PathFinderPoint& dest);
51  KyResult InitDestinationNodeFromDestNavTriangle(PathFinderPoint& dest);
52  KyResult InitTraversalFromStartNode(PathFinderQueryUtils& queryUtils);
53  void InitPropagationBounds();
54 
55  KyResult CheckNavDataChangeDuringTraversal(WorkingMemory* workingMemory);
56  KyResult CheckNavDataChangeAfterTraversal(WorkingMemory* workingMemory);
57 
58  bool ShouldReturnAfterTryingCanGo(WorkingMemory* workingMemory);
59 
60  bool HasExplorationReachedAllDestNodes();
61  bool HasExplorationReachedAtLeastADestNode();
62 
63  void ComputeRawCosts();
64  void BuildRawPaths();
65  PathEdgeType GetPathEdgeType(const AStarNode& predecessorNode, const AStarNode& node);
66 
67  bool ProcessFirstDestination();
68  bool UpdateResultAndSelectFirstDestination();
69  bool ProcessNextDestination(WorkingMemory* workingMemory);
70 
71  KyUInt32 CountAbstractGraphNodes(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestAStarNodeIndex);
72  void BuildAbstractPath(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestAStarNodeIndex);
73 
74 protected:
75  class TraversalCustomizer
76  {
77  public:
78  typedef TraverseLogic TLogic;
79 
80  TraversalCustomizer() : m_query(nullptr), m_traverseLogicUserData(nullptr) {}
81 
82  bool CanTraverse(const NavTriangleRawPtr& triangleRawPtr, KyFloat32* costMultiplier) { return triangleRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
83  bool CanTraverse(const NavGraphEdgeRawPtr& edgeRawPtr, KyFloat32* costMultiplier) { return edgeRawPtr.CanBeTraversed<TLogic>(m_traverseLogicUserData, costMultiplier); }
84  bool CanEnterNavTag(const NavTag& exitNavTag, const NavTag& enterNavTag, const Vec3f& pos) { return TLogic::CanEnterNavTag(m_traverseLogicUserData, exitNavTag, enterNavTag, pos); }
85  KyFloat32 GetHeuristicFromNodePosition(const Vec3f&) { return 0.0f; }
86 
87  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
88  bool ShouldVisitNode(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
89  bool IsNodeOutsidePropagationBounds(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
90 
91  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& halfEdge, NavHalfEdgeRawPtr& pairHalfEdgeOfNewNode);
92  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr&) { return true; }
93  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr&) { return true; }
94  bool ShouldOpenNavTriangleUnderAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
95 
96  Vec3f ComputeNodePositionOnHalfEdge(AStarTraversalContext* aStarTraversalContext, const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex predecessorNodeIndex);
97  KyResult OnNavTriangleExplored(AStarTraversalContext* aStarTraversalContext, const NavTriangleRawPtr& navTriangleRawPtr, AStarNodeIndex currentNodeIndex);
98  KyResult OnNavGraphEdgeExplored(AStarTraversalContext* aStarTraversalContext, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr, AStarNodeIndex currentNodeIndex);
99 
100  MultiDestinationPathFinderQuery<TraverseLogic>* m_query;
101  void* m_traverseLogicUserData;
102  };
103 
104  AStarTraversal<TraversalCustomizer> m_traversal;
105  KyArray<MonodirectionalRayCanGoQuery<TraverseLogic> > m_rayCanGoQueries;
106  KyUInt32 m_currentProcessedDestIdx;
107 };
108 
109 }
110 
112 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32