gwnavruntime/navmesh/navfloortonavgraphlinks.h Source File

navfloortonavgraphlinks.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: LAPA
9 
10 #ifndef Navigation_NavFloorToNavGraphLinks_H
11 #define Navigation_NavFloorToNavGraphLinks_H
12 
15 
16 namespace Kaim
17 {
18 
19 class NavGraphLink;
20 class NavGraphVertexRawPtr;
21 
22 typedef TrackedCollection<NavGraphLink*, MemStat_NavData> NavGraphLinkCollection;
23 
24 class NavFloorToNavGraphLinks
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
27 
28 public:
29  static KY_INLINE KyUInt32 GetNumberOfWordsForTriangleLinkStatus(KyUInt32 numberOfTriangle) { return BitFieldUtils::GetWordsCount(numberOfTriangle); }
30 
31 public:
32  NavFloorToNavGraphLinks();
33  ~NavFloorToNavGraphLinks();
34 
35  void Clear();
36  KyUInt32 GetCount() const;
37  NavGraphLink* GetNavGraphLink(KyUInt32 index);
38  const NavGraphLink* GetNavGraphLink(KyUInt32 index) const;
39 
40  void AddNavGraphLink(NavGraphLink* navGraphlinkToAdd);
41  void RemoveNavGraphLink(NavGraphLink* navGraphlinkToRemove);
42 
43  bool IsTriangleLinkedToGraph(NavTriangleIdx navTriangleIdx) const;
44  void SetTriangleAsLinked(NavTriangleIdx navTriangleIdx);
45  void SetTriangleAsNotLinked(NavTriangleIdx navTriangleIdx);
46  void SetAllTriangleAsNotLinked(KyUInt32 triangleCount);
47 
48  void SetOffsetForTriangleLinkStatus(char* memoryStartForStatus, KyUInt32 triangleCount);
49 
50  void OnNavFloorDeActivate(KyUInt32 navFloorTriangleCount);
51 private:
52  KyUInt32* GetBitFieldWords();
53  const KyUInt32* GetBitFieldWords() const;
54 public:
55  KyInt32 m_offsetToBitField; // KyUInt32* bitfiled = (KyUInt32*)this + m_offsetToBitField
56  NavGraphLinkCollection m_navGraphLinks;
57 };
58 
59 KY_INLINE NavFloorToNavGraphLinks::NavFloorToNavGraphLinks() : m_offsetToBitField(KyInt32MAXVAL) {}
60 KY_INLINE NavFloorToNavGraphLinks::~NavFloorToNavGraphLinks() { Clear(); }
61 
62 KY_INLINE void NavFloorToNavGraphLinks::Clear() { m_navGraphLinks.Clear(); }
63 KY_INLINE KyUInt32 NavFloorToNavGraphLinks::GetCount() const { return m_navGraphLinks.GetCount(); }
64 KY_INLINE NavGraphLink* NavFloorToNavGraphLinks::GetNavGraphLink(KyUInt32 index) { return m_navGraphLinks[index]; }
65 KY_INLINE const NavGraphLink* NavFloorToNavGraphLinks::GetNavGraphLink(KyUInt32 index) const { return m_navGraphLinks[index]; }
66 
67 KY_INLINE void NavFloorToNavGraphLinks::AddNavGraphLink(NavGraphLink* navGraphlinkToAdd)
68 {
69  KY_DEBUG_ERRORN_IF(m_navGraphLinks.DoesContain(navGraphlinkToAdd), ("this link already exists"));
70  KY_LOG_ERROR_IF(navGraphlinkToAdd->m_navTriangleRawPtr.IsValid() == false, ("this link is not valid"));
71  KY_LOG_ERROR_IF(navGraphlinkToAdd->m_navGraphVertexRawPtr.IsValid() == false, ("this link is not valid"));
72  m_navGraphLinks.PushBack(navGraphlinkToAdd);
73  SetTriangleAsLinked(navGraphlinkToAdd->m_navTriangleRawPtr.GetTriangleIdx());
74 }
75 
76 KY_INLINE bool NavFloorToNavGraphLinks::IsTriangleLinkedToGraph(NavTriangleIdx navTriangleIdx) const { return BitFieldUtils::IsBitSet(GetBitFieldWords(), navTriangleIdx); }
77 KY_INLINE void NavFloorToNavGraphLinks::SetTriangleAsLinked(NavTriangleIdx navTriangleIdx) { BitFieldUtils::SetBit(GetBitFieldWords(), navTriangleIdx); }
78 KY_INLINE void NavFloorToNavGraphLinks::SetTriangleAsNotLinked(NavTriangleIdx navTriangleIdx) { BitFieldUtils::UnsetBit(GetBitFieldWords(), navTriangleIdx); }
79 KY_INLINE void NavFloorToNavGraphLinks::SetAllTriangleAsNotLinked(KyUInt32 triangleCount)
80 {
81  memset(GetBitFieldWords(), 0, sizeof(KyUInt32) * GetNumberOfWordsForTriangleLinkStatus(triangleCount));
82 }
83 
84 KY_INLINE void NavFloorToNavGraphLinks::SetOffsetForTriangleLinkStatus(char* memoryStartForStatus, KyUInt32 triangleCount)
85 {
86  m_offsetToBitField = (KyInt32)(memoryStartForStatus - (char*)this);
87  SetAllTriangleAsNotLinked(triangleCount);
88 }
89 
90 KY_INLINE KyUInt32* NavFloorToNavGraphLinks::GetBitFieldWords() { return (KyUInt32*)((char*)this + m_offsetToBitField); }
91 KY_INLINE const KyUInt32* NavFloorToNavGraphLinks::GetBitFieldWords() const { return (const KyUInt32*)((const char*)this + m_offsetToBitField); }
92 
93 }
94 
95 #endif // Navigation_NavFloorToNavGraphLinks_H
KyUInt32 NavTriangleIdx
An index that uniquely identifies a single triangle within the set of triangles owned by a NavFloor...
Definition: navmeshtypes.h:100
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KyInt32MAXVAL
The maximum value that can be stored in the KyInt32 variable type.
Definition: types.h:224
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36