gwnavruntime/path/path.h Source File

path.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 
15 namespace Kaim
16 {
17 class DatabaseGenMetrics;
18 class ChannelArray;
19 
23 {
33  PathEdgeType_Count,
34 };
35 
37 inline const char* ToString(PathEdgeType e)
38 {
39  static const char* s_strs[] =
40  {
41  "PathEdgeType_Undefined",
42  "PathEdgeType_OnNavMesh",
43  "PathEdgeType_OnNavGraph",
44  "PathEdgeType_FromOutsideToNavMesh",
45  "PathEdgeType_FromNavMeshToOutside",
46  "PathEdgeType_FromOutsideToNavGraph",
47  "PathEdgeType_FromNavGraphToOutside",
48  "PathEdgeType_OutsideAlongGraphEdge",
49  "PathEdgeType_AbstractEdge"
50  };
51  const KyInt32 enumCount = PathEdgeType_Count;
52  KY_COMPILER_ASSERT(enumCount == sizeof(s_strs) / sizeof(const char*));
53  KyInt32 idx = (KyInt32)e;
54  return idx >= 0 && idx < enumCount ? s_strs[idx] : "PathEdgeType_UNKNOWN";
55 }
56 
58 template <class OSTREAM>
59 inline OSTREAM& operator<<(OSTREAM& os, PathEdgeType e) { os << ToString(e); return os; }
60 
62 class Path
63 {
64  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Path)
66 
67  Path();
68 
69 public:
72  {
73  public:
74  // ------------------------------ Public -----------------------------
75  CreateConfig(KyUInt32 nodesCount = 0) : m_nodesCount(nodesCount) {}
76 
77  KyUInt32 m_nodesCount;
78  // ------------------------------ end -----------------------------
79  };
80 
81 
82  // ------------------------------ Path Creation ------------------------------
83 
86  static Ptr<Path> CreatePath(const CreateConfig& createConfig);
87 
88  void SetNavigationProfileId(KyUInt32 navigationProfileId) { m_navigationProfileId = navigationProfileId; }
89  KyUInt32 GetNavigationProfileId() const { return m_navigationProfileId; }
90 
91  // ------------------------------ Get Counts ------------------------------
92 
93  KyUInt32 GetNodeCount() const { return m_nodesCount; }
94  KyUInt32 GetEdgeCount() const { return m_edgesCount; }
95 
96  // ------------------------------ Get Cost and Distance ------------------------------
97 
100  KyFloat32 GetPathDistance() const { return m_pathDistance; }
101 
104  KyFloat32 GetPathCost() const { return m_pathCost; }
105 
106  // ------------------------------ Get Node Data ------------------------------
107 
108  const Vec3f& GetPathStartPosition() const { return GetNodePosition(0); }
109  const Vec3f& GetPathEndPosition() const { return GetNodePosition(GetNodeCount() - 1); }
110 
111  const Vec3f* GetNodePositionBuffer() const { return m_nodePositions; }
112 
113  const Vec3f& GetNodePosition(KyUInt32 nodeIdx) const { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodePositions[nodeIdx]; }
114  Vec3f& GetNodePosition(KyUInt32 nodeIdx) { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodePositions[nodeIdx]; }
115 
116  const WorldIntegerPos* GetNodeIntegerPositionBuffer() const { return m_nodeIntegerPositions; }
117 
118  const WorldIntegerPos& GetNodeIntegerPosition(KyUInt32 nodeIdx) const { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeIntegerPositions[nodeIdx]; }
119  WorldIntegerPos& GetNodeIntegerPosition(KyUInt32 nodeIdx) { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeIntegerPositions[nodeIdx]; }
120 
121  const NavTrianglePtr& GetNodeNavTrianglePtr(KyUInt32 nodeIdx) const { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeTrianglePtrs[nodeIdx]; }
122  NavTrianglePtr& GetNodeNavTrianglePtr(KyUInt32 nodeIdx) { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeTrianglePtrs[nodeIdx]; }
123 
124  const NavGraphVertexPtr& GetNodeNavGraphVertexPtr(KyUInt32 nodeIdx) const { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeGraphVertexPtrs[nodeIdx]; }
125  NavGraphVertexPtr& GetNodeNavGraphVertexPtr(KyUInt32 nodeIdx) { KY_ASSERT(nodeIdx < m_nodesCount); return m_nodeGraphVertexPtrs[nodeIdx]; }
126 
127  bool HasEpsilonEdges() const;
128 
129  // ------------------------------ Get Edge Data ------------------------------
130 
131  const Vec3f& GetPathEdgeStartPosition(KyUInt32 edgeIdx) const { return GetNodePosition(edgeIdx); }
132  const Vec3f& GetPathEdgeEndPosition(KyUInt32 edgeIdx) const { return GetNodePosition(edgeIdx + 1); }
133 
134  const NavTrianglePtr& GetPathEdgeStartNavTrianglePtr(KyUInt32 edgeIdx) const { return GetNodeNavTrianglePtr(edgeIdx); }
135  const NavTrianglePtr& GetPathEdgeEndNavTrianglePtr(KyUInt32 edgeIdx) const { return GetNodeNavTrianglePtr(edgeIdx + 1); }
136 
137  const NavGraphEdgePtr& GetEdgeNavGraphEdgePtr(KyUInt32 edgeIdx) const { KY_ASSERT(edgeIdx < m_edgesCount); return m_edgeNavGraphEdgePtr[edgeIdx]; }
138  NavGraphEdgePtr& GetEdgeNavGraphEdgePtr(KyUInt32 edgeIdx) { KY_ASSERT(edgeIdx < m_edgesCount); return m_edgeNavGraphEdgePtr[edgeIdx]; }
139 
140  PathEdgeType GetPathEdgeType(KyUInt32 edgeIdx) const { return (PathEdgeType)m_edgeTypes[edgeIdx]; }
141 
142  // ------------------------------ Set Node Data ------------------------------
143 
144  void SetNodePosition (KyUInt32 nodeIdx, const Vec3f& position ) { KY_ASSERT(nodeIdx < m_nodesCount); m_nodePositions[nodeIdx] = position; }
145  void SetNodeIntegerPosition (KyUInt32 nodeIdx, const WorldIntegerPos& integerPos ) { KY_ASSERT(nodeIdx < m_nodesCount); m_nodeIntegerPositions[nodeIdx] = integerPos; }
146  void SetNodeNavTrianglePtr (KyUInt32 nodeIdx, const NavTrianglePtr& navTrianglePtr ) { KY_ASSERT(nodeIdx < m_nodesCount); m_nodeTrianglePtrs[nodeIdx] = navTrianglePtr; }
147  void SetNodeNavGraphVertexPtr(KyUInt32 nodeIdx, const NavGraphVertexPtr& navGraphVertexPtr) { KY_ASSERT(nodeIdx < m_nodesCount); m_nodeGraphVertexPtrs[nodeIdx] = navGraphVertexPtr; }
148 
149  void SetNodePosition3fAndInteger(KyUInt32 nodeIdx, const Vec3f& position, const WorldIntegerPos& integerPos);
150 
151  // ------------------------------ Set Edge Data ------------------------------
152 
153  void SetEdgeNavGraphEdgePtr(KyUInt32 edgeIdx, const NavGraphEdgePtr& navGraphEdgePtr) { m_edgeNavGraphEdgePtr[edgeIdx] = navGraphEdgePtr; }
154  void SetPathEdgeType(KyUInt32 edgeIdx, PathEdgeType edgeType) { KY_ASSERT(edgeType < PathEdgeType_Count); m_edgeTypes[edgeIdx] = (KyUInt8)edgeType; }
155 
156  void SetPathCostAndDistance(KyFloat32 pathCost, KyFloat32 pathDistance) { m_pathCost = pathCost; m_pathDistance = pathDistance; }
157 
158  const CellBox& GetPathCellBox() const { return m_pathCellBox; }
159  CellBox& GetPathCellBox() { return m_pathCellBox; }
160 
161  void SetPathCellBox(const CellBox& cellBox) { m_pathCellBox = cellBox; }
162 
163  void ComputeAllNodeIntegerPositionAndPathCellBox(const DatabaseGenMetrics& genMetrics);
164 
165  KyUInt32 GetByteSize() const { return m_byteSize; }
166 
167 private:
168  static KyUInt32 ComputeByteSize(const CreateConfig& createConfig);
169 
170  void InitBuffers();
171  void ClearAllBeforeDestruction();
172 
173  template <class T> void ClearBufferCPP(T*& buffer, KyUInt32 count);
174  template <class T> void ClearBufferPOD(T*& buffer, KyUInt32 count);
175  template <class T> void InitBufferCPP(T*& buffer, KyUInt32 count, char*& memory);
176  template <class T> void InitBufferPOD(T*& buffer, KyUInt32 count, char*& memory);
177 
178 public:
179  // ------------------------------ Public Data Members ------------------------------
180 
185 
187  Ptr<ChannelArray> m_channelArray;
188 
189 private:
190  KyUInt32 m_navigationProfileId;
191 
192  KyUInt32 m_byteSize;
193 
194  KyUInt32 m_nodesCount;
195  KyUInt32 m_edgesCount;
196 
197  KyFloat32 m_pathDistance;
198  KyFloat32 m_pathCost;
199 
200  CellBox m_pathCellBox;
201 
202  Vec3f* m_nodePositions;
203  WorldIntegerPos* m_nodeIntegerPositions;
204  NavTrianglePtr* m_nodeTrianglePtrs;
205  NavGraphVertexPtr* m_nodeGraphVertexPtrs;
206 
207  NavGraphEdgePtr* m_edgeNavGraphEdgePtr;
208  KyUInt8* m_edgeTypes;
209 
210  KyUInt32 RefCount; // consider thread-safetyness here with mutable std::atomic<int> RefCount;
211 
212 public: // internal
213 
214  // Lifetime - separate implementation due to Create function
215  void AddRef() { ++RefCount; }
216  void Release();
217 
218  // Debug method only.
219  int GetRefCount() const { return RefCount; }
220 };
221 
222 
223 }
224 
226 
227 
228 
static Ptr< Path > CreatePath(const CreateConfig &createConfig)
Creates a Path instance and allocates necessary memory accordingly to the information provided throug...
Definition: path.cpp:79
The PathEdgeType has not yet been set for the corresponding PathEdge.
Definition: path.h:24
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
The PathEdge is going from the NavMesh to outside.
Definition: path.h:28
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
A class that configures the creation of a Path.
Definition: path.h:71
The PathEdge is going along an a NavGraphEdge but not starting nor ending at one of the NavGraphVerte...
Definition: path.h:31
Database * m_database
The Database on which the Path has been computed.
Definition: path.h:184
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The PathEdge is coming from outside to a NavGraphVertex.
Definition: path.h:29
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
The PathEdge corresponds to a NavGraph edge.
Definition: path.h:26
The PathEdge is coming from outside to the NavMesh.
Definition: path.h:27
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexptr.h:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
Utilities for dealing with NavData coordinates, which are expressed in a world space based on integer...
Definition: worldintegerpos.h:19
KyFloat32 GetPathCost() const
Retrieves the total sum of the cost calculated for each segment of the path by a RayCanGoQuery.
Definition: path.h:104
PathEdgeType
Defines the different kind of PathEdge within a Path.
Definition: path.h:22
The PathEdge has been computed on the NavMesh.
Definition: path.h:25
The PathEdge is going from a NavGraphVertex to outside.
Definition: path.h:30
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:17
Ptr< ChannelArray > m_channelArray
The ChannelArray maintaining Channels around the path sections laying on the NavMesh.
Definition: path.h:187
KyFloat32 GetPathDistance() const
Retrieves the total sum of the distance covered by each segment of the path.
Definition: path.h:100
Each instance of this class uniquely identifies a single and mono-directionnal NavGraphEdge in a NavG...
Definition: navgraphedgeptr.h:20
std::uint8_t KyUInt8
uint8_t
Definition: types.h:27
The PathEdge is from an abstract Path.
Definition: path.h:32
The class representing a path.
Definition: path.h:62
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16