gwnavruntime/dynamicnavmesh/navfloorsweeplinetypes.h Source File

navfloorsweeplinetypes.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 
9 
10 #include <assert.h>
17 
18 
19 namespace Kaim
20 {
21 
22 class SweepLineOutputEdgePiece
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
25 public:
26  SweepLineOutputEdgePiece(): m_correspondingRawInputEdgeIdx(KyUInt32MAXVAL), m_navTagIndex(KyUInt32MAXVAL), m_userData(nullptr) {}
27  SweepLineOutputEdgePiece(const EdgePoints& subSegment, const InputEdge& parentEdge) :
28  m_rawInputEdgePiece(subSegment, parentEdge), m_correspondingRawInputEdgeIdx(KyUInt32MAXVAL), m_navTagIndex(KyUInt32MAXVAL), m_userData(nullptr) {}
29 
30  const InputEdgeProperty& ParentProperty() const { return m_rawInputEdgePiece.ParentProperty(); }
31  bool IsVertical() const { return m_rawInputEdgePiece.IsVertical(); }
32  KyInt32 GetCount() const { return m_rawInputEdgePiece.GetCount(); }
33  const Vec2i& GetEdgeStart() const { return m_rawInputEdgePiece.GetEdgeStart(); }
34  const Vec2i& GetEdgeEnd() const { return m_rawInputEdgePiece.GetEdgeEnd(); }
35  const Vec2i& GetOriginalStart() const { return m_rawInputEdgePiece.GetOriginalStart(); }
36  const Vec2i& GetOriginalEnd() const { return m_rawInputEdgePiece.GetOriginalEnd(); }
37 
38 public:
39  InputEdgePiece m_rawInputEdgePiece;
40  KyUInt32 m_correspondingRawInputEdgeIdx;
41  KyUInt32 m_navTagIndex;
42  mutable void* m_userData;
43 };
44 
45 class SweepLineOutput
46 {
47  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
48  KY_CLASS_WITHOUT_COPY(SweepLineOutput)
49 public:
50  SweepLineOutput() {}
51 
52  inline void Insert(InputEdgePiece& elem, KyUInt32 navTagIdx)
53  {
54  SweepLineOutputEdgePiece& newElem = m_rawResults.PushDefault();
55  newElem.m_rawInputEdgePiece = elem;
56 
57  newElem.m_correspondingRawInputEdgeIdx = elem.m_index;
58  newElem.m_rawInputEdgePiece.m_index = m_rawResults.GetCount() - 1;
59  newElem.m_navTagIndex = navTagIdx;
60 
61  const Vec2i& edgeStart = elem.m_extremities.m_start;
62  const Vec2i& edgeEnd = elem.m_extremities.m_end;
63 
64  // Make sure we don't have edges outside of the cell box (0-255 max)
65  KY_ASSERT(edgeEnd.x >= 0 && edgeEnd.x <= KyUInt8MAXVAL && edgeEnd.y >= 0 && edgeEnd.y <= KyUInt8MAXVAL);
66  KY_ASSERT(edgeStart.x >= 0 && edgeStart.x <= KyUInt8MAXVAL && edgeStart.y >= 0 && edgeStart.y <= KyUInt8MAXVAL);
67 
68  if (edgeEnd < edgeStart)
69  {
70  //swap
71  Alg::Swap(newElem.m_rawInputEdgePiece.m_extremities.m_start, newElem.m_rawInputEdgePiece.m_extremities.m_end);
72  newElem.m_rawInputEdgePiece.m_count *= -1;
73  }
74 
75  KyUInt32 thisNavTagIndexPos = 0;
76  for (; thisNavTagIndexPos < m_navTagIndexes.GetCount(); ++thisNavTagIndexPos)
77  {
78  if(m_navTagIndexes[thisNavTagIndexPos] == navTagIdx)
79  {
80  m_elemByNavTag[thisNavTagIndexPos].PushBack(newElem.m_rawInputEdgePiece.m_index);
81  return;
82  }
83  }
84 
85  KY_ASSERT(thisNavTagIndexPos == m_navTagIndexes.GetCount());
86  m_navTagIndexes.PushBack(navTagIdx);
87  m_elemByNavTag.PushDefault().PushBack(newElem.m_rawInputEdgePiece.m_index);
88  KY_ASSERT(m_elemByNavTag.GetCount() == m_navTagIndexes.GetCount());
89  }
90 
91  void Clear()
92  {
93  m_rawResults.Clear();
94  m_navTagIndexes.Clear();
95  m_elemByNavTag.Clear();
96  }
97 public:
98  KyArray<SweepLineOutputEdgePiece> m_rawResults;
99  KyArray<KyUInt32> m_navTagIndexes; // m_elemByNavTag.GetCount() == m_navTagIndexes.GetCount()
100  KyArray<KyArray<KyUInt32> > m_elemByNavTag; // m_elemByNavTag.GetCount() == m_navTagIndexes.GetCount(), an array idx or MergerRawInputEdgePiece in m_rawResults per navTagIndexes
101 };
102 
103 
104 struct SweeplineProperty
105 {
106  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
107 
108 public:
109  SweeplineProperty() : m_halfEdge(nullptr), m_count(0) {}
110  SweeplineProperty(const InputEdgePiece& he) : m_halfEdge(&he), m_count(he.GetCount()) {}
111 
112  bool operator <(const SweeplineProperty& rhs) const { return m_halfEdge->ParentProperty() < rhs.m_halfEdge->ParentProperty(); }
113 
114 public:
115  const InputEdgePiece* m_halfEdge;
116  KyInt32 m_count;
117 };
118 
119 static inline bool ArePropertiesFromSameContour(const SweeplineProperty& prop1, const SweeplineProperty& prop2)
120 { return prop1.m_halfEdge->ParentProperty() == prop2.m_halfEdge->ParentProperty(); }
121 
122 class ScanDataElement
123 {
124  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
125 public:
126  ScanDataElement() : m_edge(nullptr), m_propertyList(nullptr) {}
127  ScanDataElement(const InputEdgePiece& edge, SharedPoolList<SweeplineProperty>* properties) : m_edge(&edge), m_propertyList(properties) {}
128 
129 public:
130  const InputEdgePiece* m_edge;
131  SharedPoolList<SweeplineProperty>* m_propertyList;
132 };
133 
134 } //namespace Kaim
135 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#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
#define KyUInt8MAXVAL
KyUInt8 max value
Definition: types.h:66
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68