gwnavruntime/queries/utils/pathclampercontext.h Source File

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