gwnavruntime/navmesh/navfloortonavgraphlinks.h Source File

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