gwnavruntime/navmesh/dynamicnavfloor.h Source File

dynamicnavfloor.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 
16 namespace Kaim
17 {
18 
19 // ----------------------------
20 // ----- DynamicNavVertex -----
21 // ----------------------------
22 class DynamicNavVertex
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
25 
26 public:
27  DynamicNavVertex() :
28  m_pixelPos(InvalidPixelCoord, InvalidPixelCoord),
29  m_altitude(KyFloat32MAXVAL),
30  m_first(KyUInt32MAXVAL)
31  {}
32 
33  DynamicNavVertex(const PixelPos& pixelPos, KyFloat32 alt) :
34  m_pixelPos(pixelPos),
35  m_altitude(alt),
36  m_first(KyUInt32MAXVAL)
37  {}
38 
39  bool operator==(const DynamicNavVertex& other) const
40  {
41  return m_pixelPos == other.m_pixelPos && m_altitude == other.m_altitude;
42  }
43  bool operator!=(const DynamicNavVertex& other) const
44  {
45  return !operator==(other);
46  }
47 public:
48  PixelPos m_pixelPos;
49  KyFloat32 m_altitude;
50  KyUInt32 m_first; // first outgoing edge
51 };
52 
53 // ------------------------------
54 // ----- DynamicNavTriangle -----
55 // ------------------------------
56 class DynamicNavTriangle
57 {
58 public:
59  DynamicNavTriangle() : m_edge(KyUInt32MAXVAL) {}
60  DynamicNavTriangle(KyUInt32 edge) : m_edge(edge) {}
61 
62 public:
63  KyUInt32 m_edge; // one edge around the face
64 };
65 
66 // --------------------------
67 // ----- DynamicNavHalfEdge -----
68 // --------------------------
69 
70 enum DynamicNavHalfEdgeType
71 {
72  DynamicNavHalfEdgeType_Normal = 0,
73  DynamicNavHalfEdgeType_Wall = 1,
74  DynamicNavHalfEdgeType_Hole = 2,
75  DynamicNavHalfEdgeType_FloorBoundary = 3,
76  DynamicNavHalfEdgeType_CellBoundary = 4,
77 
78  DynamicNavHalfEdgeType_Invalid = 0xFFFFFFFF
79 };
80 
81 class DynamicNavHalfEdge
82 {
83 public:
84  DynamicNavHalfEdge()
85  : m_idx(KyUInt32MAXVAL)
86  , m_start(KyUInt32MAXVAL)
87  , m_end(KyUInt32MAXVAL)
88  , m_face(KyUInt32MAXVAL)
89  , m_next(KyUInt32MAXVAL)
90  , m_type(DynamicNavHalfEdgeType_Invalid)
91  , m_pair(KyUInt32MAXVAL)
92  , m_cardinalDir(CardinalDir_INVALID)
93  , m_stitch1To1EdgeIdx(KyUInt32MAXVAL) {}
94 public:
95  KyUInt32 m_idx;
96  KyUInt32 m_start; // start vertex
97  KyUInt32 m_end; // end vertex (added by LS for dynamicFloorBuilder)
98  KyUInt32 m_face; // the adjacent face
99  KyUInt32 m_next; // next edge
100  DynamicNavHalfEdgeType m_type; // 0 = normal, 1 = wall, 2 = hole, 3 = Floor boundary, 4 = cell boundary
101 
102  // if m_type == Normal : pair edge idx in the same floor
103  // if m_type == FloorBoundary || m_type == CellBoundary, UNUSED
104  KyUInt32 m_pair;
105 
106  CardinalDir m_cardinalDir; // use for edge of type == 3 (cell boundary) only. The cardinal dir of the side of the cell
107 
108  mutable KyUInt32 m_stitch1To1EdgeIdx;
109 };
110 
111 // --------------------------
112 // ----- DynamicNavFloor -----
113 // --------------------------
114 class DynamicNavFloor
115 {
116  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
117 public:
118  enum PixelPosRelativeCoordSystem
119  {
120  PIXELPOS_ABSOLUTE,
121  PIXELPOS_RELATIVE_TO_CELL
122  };
123 
124 public:
125  DynamicNavFloor();
126  DynamicNavFloor(MemoryHeap* memoryHeap);
127 
128  void Clear();
129 
130  KyUInt32 AddIntVertex(const Vec2i& position, KyFloat32 altitude);
131  KyUInt32 AddIntVertex(const Vec2i& position); // Do not forget to call ComputeAltitudeRange() once the altitude has been set for each vertex
132  // for legacy. Create a vertex a position but without pixel pos.
133  KyUInt32 AddVertex3f(const Vec3f& position);
134 
135  KyUInt32 AddTriangle(KyUInt32 idxV1, KyUInt32 idxV2, KyUInt32 idxV3);
136  KyUInt32 AddHalfEdge(KyUInt32 start, KyUInt32 end, KyUInt32 face, DynamicNavHalfEdgeType type = DynamicNavHalfEdgeType_Normal);
137  KyResult MakeEdgesOpposite(KyUInt32 idxEdge1, KyUInt32 idxEdge2);
138 
139  // ---- Edge -----
140  KyUInt32 GetNextEdgeIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_next; }
141  KyUInt32 GetPrevEdgeIdx(KyUInt32 edgeIdx) const { return GetNextEdgeIdx(GetNextEdgeIdx(edgeIdx)); }
142  KyUInt32 GetOppositeEdgeIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_pair; }
143  KyUInt32 GetStartVertexIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_start; }
144  KyUInt32 GetFaceIdx(KyUInt32 edgeIdx) const { return m_edges[edgeIdx].m_face; }
145 
146  // ---- Face -----
147  KyUInt32 GetEdgeIdx(KyUInt32 triangleIdx) const { return m_triangles[triangleIdx].m_edge; }
148 
149  // ---- Vertex -----
150  KyUInt32 GetFirstEdgeIdx(KyUInt32 vertexIdx) const { return m_vertices[vertexIdx].m_first; }
151 
152  const DynamicNavVertex& GetNavVertex(KyUInt32 vertexIdx) const { return m_vertices[vertexIdx]; }
153 
154  KyUInt32 ComputeNextBorderEdgeIdx(KyUInt32 edgeIdx) const;
155  KyUInt32 GetNumberOfFloorBoundaryEdges() const;
156 
157  bool AreIndexesWithinBounds() const;
158  // search m_navTagArray for Navtag.
159  // If this particular navtag is not present, It will be added.
160  // returns the index in m_navTagArray where tag was found or added.
161  KyUInt32 FindOrAddNavtag(const NavTag* tag);
162 
163  void ComputeAltitudeRange();
164 
165 public:
166  KyUInt32 m_idx;
167 
168  KyArrayDH<DynamicNavTriangle> m_triangles;
169  KyArrayDH_POD<DynamicNavVertex> m_vertices;
170  KyArrayDH_POD<DynamicNavHalfEdge> m_edges;
171  KyArrayDH_POD<KyUInt32> m_navTagIndexes;
172  KyArrayDH_POD<const NavTag*> m_navTagArray;
173 
174  FloorAltitudeRange m_altitudeRange;
175 };
176 
177 KY_INLINE DynamicNavFloor::DynamicNavFloor() :
178  m_idx(KyUInt32MAXVAL),
179  m_triangles(nullptr),
180  m_vertices(nullptr),
181  m_edges(nullptr),
182  m_navTagIndexes(nullptr),
183  m_navTagArray(nullptr)
184 {
185  Clear();
186 }
187 
188 KY_INLINE DynamicNavFloor::DynamicNavFloor(MemoryHeap* memoryHeap) :
189  m_idx(KyUInt32MAXVAL),
190  m_triangles(memoryHeap),
191  m_vertices(memoryHeap),
192  m_edges(memoryHeap),
193  m_navTagIndexes(memoryHeap),
194  m_navTagArray(memoryHeap)
195 {
196  Clear();
197 }
198 
199 KY_INLINE void DynamicNavFloor::Clear()
200 {
201  m_vertices.Clear();
202  m_triangles.Clear();
203  m_edges.Clear();
204  m_navTagIndexes.Clear();
205  m_navTagArray.Clear();
206  m_altitudeRange.Clear();
207 }
208 
209 } // namespace Kaim
210 
211 
212 
#define KyFloat32MAXVAL
KyFloat32 max value
Definition: types.h:71
static const KyInt32 InvalidPixelCoord
Represents an invalidPixelCoord object.
Definition: navmeshtypes.h:27
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:15
static const CardinalDir CardinalDir_INVALID
Invalid cardinal direction.
Definition: cardinaldir.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
float KyFloat32
float
Definition: types.h:32