gwnavruntime/database/navtag.h Source File

navtag.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 
15 
16 namespace Kaim
17 {
18 
19 typedef KyUInt32 NavTagIdx;
20 static const NavTagIdx NavTagIdx_Invalid = KyUInt32MAXVAL;
21 
22 class NavTag;
23 
24 enum NavTagBitFlag
25 {
26  NAVTAG_IS_EXCLUSIVE_BIT = 0,
27  NAVTAG_IS_ON_NAVGRAPH_BIT = 1,
28  NAVTAG_IS_FROM_GENERATION = 2,
29  NAVTAG_IS_GENERATION_DEFAULT = 3, // only relevant if from generation
30 };
31 
32 class DynamicNavTag
33 {
34  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
35 public:
36  static Color GetDefaultColor() { return Color::Orange; }
37  static Color GetExclusiveColor() { return Color::Red; }
38 
39  DynamicNavTag() { Clear(); }
40 
41  void Clear()
42  {
43  m_flags = 0;
44  m_blindDataArray.Clear();
45  SetColor(GetDefaultColor());
46  }
47 
48  void Init(const KyUInt32* blindDataBuffer, KyUInt32 blindDataCount);
49 
50  void InitFromBlob(const NavTag& navTag);
51 
52  bool operator<(const DynamicNavTag& other) const;
53  bool operator==(const DynamicNavTag& other) const; // NavTags are compared using the values in the blind array
54  bool operator!=(const DynamicNavTag& other) const { return !operator==(other); }
55 
56  bool operator<(const NavTag& other) const;
57  bool operator==(const NavTag& other) const { return IsEqualToNavTag(other); }
58  bool operator!=(const NavTag& other) const { return !operator==(other); }
59 
60 
61  bool IsEqualToNavTag(const NavTag& other) const;
62 
63  KyUInt32 GetWordCount() const { return m_blindDataArray.GetCount(); }
64  const KyUInt32* GetWords() const { return m_blindDataArray.GetDataPtr(); }
65  KyUInt32 GetWord(KyUInt32 wordIdx) const { return m_blindDataArray[wordIdx]; }
66 
67  bool IsEmpty() const { return IsExclusive() == false && m_blindDataArray.IsEmpty(); }
68  bool IsExclusive() const { return IsBitSetInMask<NAVTAG_IS_EXCLUSIVE_BIT>(m_flags); }
69  bool IsWalkable() const { return IsExclusive() == false; }
70  bool IsOnNavGraph() const { return IsBitSetInMask<NAVTAG_IS_ON_NAVGRAPH_BIT>(m_flags); }
71  bool IsOnNavMesh() const { return IsOnNavGraph() == false; }
72  bool IsFromGeneration() const { return IsBitSetInMask<NAVTAG_IS_FROM_GENERATION>(m_flags); }
73  bool IsFromRuntime() const { return IsFromGeneration() == false; }
74  bool IsGenerationDefault() const { return IsBitSetInMask<NAVTAG_IS_GENERATION_DEFAULT>(m_flags); }
75 
76  Color GetColor() const { return Color(m_colorR, m_colorG, m_colorB); }
77 
78  void SetAsExclusive()
79  {
80  SetBitInMask<NAVTAG_IS_EXCLUSIVE_BIT>(m_flags);
81  m_blindDataArray.Clear();
82  SetColor(GetExclusiveColor());
83  }
84 
85  void SetAsWalkable()
86  {
87  UnSetBitInMask<NAVTAG_IS_EXCLUSIVE_BIT>(m_flags);
88  if (GetColor() == GetExclusiveColor())
89  SetColor(GetDefaultColor());
90  }
91 
92  void SetColor(Color color) { SetColor(color.r, color.g, color.b); }
93  void SetColor(KyUInt8 r, KyUInt8 g, KyUInt8 b)
94  {
95  m_colorR = r;
96  m_colorG = g;
97  m_colorB = b;
98  }
99 
100 public: // Deprecated
101  KY_DEPRECATED(Color GetVisualColor() const) { return GetColor(); }
102  KY_DEPRECATED(static Color GetDefaultVisualColor()) { return GetDefaultColor(); }
103  KY_DEPRECATED(static Color GetExclusiveVisualColor()) { return GetExclusiveColor(); }
104 
105 public: // internal
106  void SetOnNavGraph() { SetBitInMask<NAVTAG_IS_ON_NAVGRAPH_BIT>(m_flags); }
107  void SetOnNavMesh() { UnSetBitInMask<NAVTAG_IS_ON_NAVGRAPH_BIT>(m_flags); }
108  void SetFromGeneration() { SetBitInMask<NAVTAG_IS_FROM_GENERATION>(m_flags); }
109  void SetAsGenerationDefault() { SetBitInMask<NAVTAG_IS_GENERATION_DEFAULT>(m_flags); }
110 
111 public:
112  KyArrayPOD<KyUInt32> m_blindDataArray;
113  KyUInt8 m_flags; // tells if the navTag is exclusive, if it is on the navMesh, or on the navGrah ...
114  KyUInt8 m_colorR;
115  KyUInt8 m_colorG;
116  KyUInt8 m_colorB;
117 };
118 
119 class NavTag
120 {
121  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
122  KY_ROOT_BLOB_CLASS(NavData, NavTag, 1)
123  KY_CLASS_WITHOUT_COPY(NavTag)
124 public:
125  static Color GetDefaultColor() { return DynamicNavTag::GetDefaultColor(); }
126  static Color GetExclusiveColor() { return DynamicNavTag::GetExclusiveColor(); }
127 
128  NavTag() {}
129 
130  bool operator==(const NavTag& other) const;
131  bool operator!=(const NavTag& other) const { return !operator==(other); }
132 
134  bool operator<(const NavTag& other) const;
135 
136  bool operator<(const DynamicNavTag& other) const;
137  bool operator==(const DynamicNavTag& other) const { return other.operator==(*this); }
138  bool operator!=(const DynamicNavTag& other) const { return !operator==(other); }
139 
140  KyUInt32 GetWordCount() const { return m_blindData.GetCount(); }
141  const KyUInt32* GetWords() const { return m_blindData.GetValues(); }
142  KyUInt32 GetWord(KyUInt32 wordIdx) const { return GetWords()[wordIdx]; }
143  KyUInt32 GetByteSize() const { return KyUInt32((char*)(m_blindData.GetValues() + m_blindData.GetCount()) - (char*)this); }
144 
145  bool IsDefault() const { return m_blindData.GetCount() == 0; }
146  bool IsExclusive() const { return IsBitSetInMask<NAVTAG_IS_EXCLUSIVE_BIT>(m_flags); }
147  bool IsWalkable() const { return IsExclusive() == false; }
148  bool IsOnNavGraph() const { return IsBitSetInMask<NAVTAG_IS_ON_NAVGRAPH_BIT>(m_flags); }
149  bool IsOnNavMesh() const { return IsOnNavGraph() == false; }
150  bool IsFromGeneration() const { return IsBitSetInMask<NAVTAG_IS_FROM_GENERATION>(m_flags); }
151  bool IsFromRuntime() const { return IsFromGeneration() == false; }
152  bool IsGenerationDefault() const { return IsBitSetInMask<NAVTAG_IS_GENERATION_DEFAULT>(m_flags); }
153 
154  Color GetColor() const { return Color(m_colorR, m_colorG, m_colorB); }
155 
156 public: // Deprecated
157  KY_DEPRECATED(Color GetVisualColor() const) { return GetColor(); }
158  KY_DEPRECATED(static Color GetDefaultVisualColor()) { return GetDefaultColor(); }
159  KY_DEPRECATED(static Color GetExclusivetVisualColor()) { return GetExclusiveColor(); }
160 
161 
162 public:
163  BlobArray<KyUInt32> m_blindData;
164  KyUInt8 m_flags; // tells if the navTag is exclusive, if it is on the navMesh, or on the navGrah
165  KyUInt8 m_colorR;
166  KyUInt8 m_colorG;
167  KyUInt8 m_colorB;
168 };
169 
170 
171 inline void SwapEndianness(Endianness::Target e, NavTag& self)
172 {
173  SwapEndianness(e, self.m_blindData);
174  SwapEndianness(e, self.m_flags);
175  SwapEndianness(e, self.m_colorR);
176  SwapEndianness(e, self.m_colorG);
177  SwapEndianness(e, self.m_colorB);
178 }
179 
180 class NavTagBlobBuilder : public BaseBlobBuilder<NavTag>
181 {
182 public:
183  NavTagBlobBuilder(const DynamicNavTag& navTag) : m_navTag(&navTag) {}
184 private:
185  void DoBuild();
186 
187  const DynamicNavTag* m_navTag;
188 };
189 
190 class NavTagCopier : public BaseBlobBuilder<NavTag>
191 {
192 public:
193  NavTagCopier(const NavTag& navTag) : m_navTag(&navTag) {}
194 private:
195  void DoBuild();
196  const NavTag* m_navTag;
197 };
198 
199 }
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
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
#define KY_DEPRECATED(expr)
The compiler issues a warning when a deprecated function or typedef is used.
Definition: types.h:93
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::uint8_t KyUInt8
uint8_t
Definition: types.h:27
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68