gwnavruntime/queries/utils/pathclampercontext.h Source File

pathclampercontext.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 namespace Kaim
16 {
17 
18 typedef KyUInt16 ClampNodeIndex;
19 static const ClampNodeIndex ClampNodeIndex_Invalid = KyUInt16MAXVAL;
20 
21 class ClampNode
22 {
23 public:
24  ClampNode();
25  ClampNode(const Vec3f& pos, NodeTypeAndRawPtrDataIdx nodeTypeAndRawPtrDataIdx, ClampNodeIndex predecessorIdx, ClampNodeIndex nextNodeIdx);
26  ClampNode(const Vec3f& pos, const WorldIntegerPos& integerPos, NodeTypeAndRawPtrDataIdx nodeTypeAndRawPtrDataIdx, ClampNodeIndex predecessorIdx, ClampNodeIndex nextNodeIdx);
27 
28  PathNodeType GetNodeType() const;
29  KyUInt32 GetIdxOfRawPtrData() const;
30 
31  void SetNodeType(PathNodeType nodeType);
32  void SetIdxOfRawPtrData(KyUInt32 indexOfRawPtrData);
33 
34  Vec3f m_nodePosition;
35  WorldIntegerPos m_nodeIntegerPos;
36  NodeTypeAndRawPtrDataIdx m_nodeTypeAndRawPtrDataIdx; // 32 bits
37  ClampNodeIndex m_predecessorNodeIdx; // 16 bits
38  ClampNodeIndex m_nextNodeIdx; // 16bits
39 };
40 
41 class PathRefinerContext;
42 class BaseRayCanGoQuery;
43 class Channel;
44 
45 enum ClampResult
46 {
47  ClampResult_SUCCESS,
48  ClampResult_FAIL_MEMORYLIMIT,
49  ClampResult_FAIL_CANGOHIT
50 };
51 
52 class PathClamperContext
53 {
54  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_QueryWorkingMem)
55 public:
56 
57  enum PathClamperStatus
58  {
59  Initialisation,
60  NeedToComputeIntersections,
61  ProcessingIntersections
62  };
63 
64  PathClamperContext();
65  ~PathClamperContext() { ReleaseWorkingMemory(); }
66 
67  void ReleaseWorkingMemory()
68  {
69  m_triangleRawPtrNodes.ReleaseWorkingMemoryBuffer();
70  m_vertexRawPtrNodes.ReleaseWorkingMemoryBuffer();
71  m_clampNodes.ReleaseWorkingMemoryBuffer();
72  m_currentDestNavTrianglePtr.Invalidate();
73  m_clamperStatus = Initialisation;
74  m_currentClampNodeIdx = ClampNodeIndex_Invalid;
75  m_currentIntersectionLastIndex = KyUInt32MAXVAL;
76  m_startNavGraphEdgePtr = NavGraphEdgePtr();
77  m_destNavGraphEdgePtr = NavGraphEdgePtr();
78  }
79 
80  KyResult InitFromRefinerContext(WorkingMemory* workingMemory, PathRefinerContext* pathRefinerContext, PathClamperFlagMask pathClamperFlagMask);
81  KyResult InitFromCanGo(WorkingMemory* workingMemory, BaseRayCanGoQuery& baseRayCanGoQuery, PathClamperFlagMask pathClamperFlagMask);
82  KyResult InitFromChannel(Database* database, WorkingMemory* workingMemory, const Channel& channel, PathClamperFlagMask pathClamperFlagMask);
83 
84  bool IsClampingDone() const { return m_currentClampNodeIdx == 0; } // node of index 0 is the destination node
85 
86  bool MustAddPointToStartOrDestClampNode(ClampNode* startOrDestClampNode, const Vec3f& queryInputPosition) const;
87 
88 public:
89  WorkingMemArray<ClampNode> m_clampNodes;
90  WorkingMemArray<NavTriangleRawPtr> m_triangleRawPtrNodes;
91  WorkingMemArray<NavGraphVertexRawPtr> m_vertexRawPtrNodes;
92 
93  PathClamperStatus m_clamperStatus;
94  ClampNodeIndex m_currentClampNodeIdx;
95  KyUInt32 m_currentIntersectionLastIndex;
96  NavTrianglePtr m_currentDestNavTrianglePtr;
97  NavGraphEdgePtr m_startNavGraphEdgePtr;
98  NavGraphEdgePtr m_destNavGraphEdgePtr;
99 
100 public: // internal
101  Vec3f m_currentStartPos;
102  NavTriangleRawPtr m_currentStartTriangleRawPtr;
103  WorldIntegerPos m_currentStartIntegerPos;
104  KyUInt16 m_currentVertexIdx;
105  KyUInt16 m_currentIdxInTriangleBuffer;
106 
107  PathClamperFlagMask m_pathClamperFlagMask;
108 };
109 
110 
111 
112 
113 KY_INLINE ClampNode::ClampNode() :
114 m_predecessorNodeIdx(ClampNodeIndex_Invalid),
115  m_nextNodeIdx(ClampNodeIndex_Invalid)
116 {}
117 
118 KY_INLINE ClampNode::ClampNode(const Vec3f& pos, NodeTypeAndRawPtrDataIdx nodeTypeAndRawPtrDataIdx, ClampNodeIndex predecessorIdx, ClampNodeIndex nextNodeIdx) :
119  m_nodePosition(pos),
120  m_nodeTypeAndRawPtrDataIdx(nodeTypeAndRawPtrDataIdx),
121  m_predecessorNodeIdx(predecessorIdx),
122  m_nextNodeIdx(nextNodeIdx)
123 {}
124 KY_INLINE ClampNode::ClampNode(const Vec3f& pos, const WorldIntegerPos& integerPos, NodeTypeAndRawPtrDataIdx nodeTypeAndRawPtrDataIdx, ClampNodeIndex predecessorIdx, ClampNodeIndex nextNodeIdx) :
125  m_nodePosition(pos),
126  m_nodeIntegerPos(integerPos),
127  m_nodeTypeAndRawPtrDataIdx(nodeTypeAndRawPtrDataIdx),
128  m_predecessorNodeIdx(predecessorIdx),
129  m_nextNodeIdx(nextNodeIdx)
130 {}
131 
132 KY_INLINE PathNodeType ClampNode::GetNodeType() const { return m_nodeTypeAndRawPtrDataIdx.GetNodeType(); }
133 KY_INLINE KyUInt32 ClampNode::GetIdxOfRawPtrData() const { return m_nodeTypeAndRawPtrDataIdx.GetIdxOfRawPtrData(); }
134 
135 KY_INLINE void ClampNode::SetNodeType(PathNodeType nodeType) { m_nodeTypeAndRawPtrDataIdx.SetNodeType(nodeType); }
136 KY_INLINE void ClampNode::SetIdxOfRawPtrData(KyUInt32 indexOfRawPtrData) { m_nodeTypeAndRawPtrDataIdx.SetIdxOfRawPtrData(indexOfRawPtrData); }
137 
138 }
139 
140 
141 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
std::uint16_t KyUInt16
uint16_t
Definition: types.h:28
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KyUInt16MAXVAL
KyUInt16 max value
Definition: types.h:67
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68