gwnavruntime/abstractgraph/identifiers/abstractgraphnoderawptr.h Source File

abstractgraphnoderawptr.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 #ifndef Navigation_AbstractGraphNodeRawPtr_H
8 #define Navigation_AbstractGraphNodeRawPtr_H
9 
10 
16 
17 
18 
19 namespace Kaim
20 {
21 
22 class NavHalfEdgeRawPtr;
23 
24 class AbstractGraphNodeRawPtr
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
27 public:
28  AbstractGraphNodeRawPtr() { Invalidate(); }
29  AbstractGraphNodeRawPtr(AbstractGraph* abstractGraph, AbstractGraphNodeIdx nodeIdx) { Set(abstractGraph, nodeIdx); }
30 
31  KyResult InitFromNavHalfEdgeRawPtr(const NavHalfEdgeRawPtr& navHalfEdgeRawPtr);
32 
33  bool IsValid() const { return m_abstractGraph != KY_NULL && m_nodeIdx < AbstractGraphNodeIdx_Invalid; }
34  void Invalidate();
35 
36  void Set(AbstractGraph* abstractGraph, AbstractGraphNodeIdx nodeIdx);
37 
38  KyFloat32 GetNeighborCost(AbstractGraphNodeIdx abstractGraphNodeIdx) const;
39 
40  AbstractGraphNodeRawPtr GetPairedAbstractGraphNodeRawPtr() const;
41  const AbstractGraphNodeLink& GetAbstractGraphNodeLink() const;
42  NavFloorIdx GetOriginalNavFloorIdx() const;
43  CellPos GetCellPos() const;
44  CardinalDir GetCellBoundary() const;
45 
46  Vec3f GetPosition() const;
47 
48  AbstractGraphCellGrid* GetAbstractGraphCellGrid() const;
49 public:
50  AbstractGraph* m_abstractGraph;
51  AbstractGraphNodeIdx m_nodeIdx;
52 };
53 
54 
55 
56 KY_INLINE void AbstractGraphNodeRawPtr::Invalidate()
57 {
58  m_abstractGraph = KY_NULL;
59  m_nodeIdx = AbstractGraphNodeIdx_Invalid;
60 }
61 
62 KY_INLINE void AbstractGraphNodeRawPtr::Set(AbstractGraph* abstractGraph, AbstractGraphNodeIdx nodeIdx)
63 {
64  m_abstractGraph = abstractGraph;
65  m_nodeIdx = nodeIdx;
66 }
67 
68 KY_INLINE KyFloat32 AbstractGraphNodeRawPtr::GetNeighborCost(AbstractGraphNodeIdx abstractGraphNodeIdx) const
69 {
70  return m_abstractGraph->GetNeighborCost(m_nodeIdx, abstractGraphNodeIdx);
71 }
72 
73 KY_INLINE const AbstractGraphNodeLink& AbstractGraphNodeRawPtr::GetAbstractGraphNodeLink() const { return m_abstractGraph->m_links[m_nodeIdx]; }
74 KY_INLINE AbstractGraphNodeRawPtr AbstractGraphNodeRawPtr::GetPairedAbstractGraphNodeRawPtr() const
75 {
76  const LoadedAbstractGraphNodeIdx& pairedNodeIdx = GetAbstractGraphNodeLink().m_pairedNodeIdx;
77  if (pairedNodeIdx.IsValid() == false)
78  return AbstractGraphNodeRawPtr();
79 
80  AbstractGraphNodeRawPtr pairedNode;
81  pairedNode.m_abstractGraph = GetAbstractGraphCellGrid()->GetAbstractGraph(pairedNodeIdx);
82  pairedNode.m_nodeIdx = pairedNodeIdx.m_nodeIdx;
83  return pairedNode;
84 }
85 
86 KY_INLINE AbstractGraphCellGrid* AbstractGraphNodeRawPtr::GetAbstractGraphCellGrid() const { return m_abstractGraph->GetAbstractGraphCellGrid(); }
87 
88 KY_INLINE NavFloorIdx AbstractGraphNodeRawPtr::GetOriginalNavFloorIdx() const
89 {
90  const AbstractGraphCellFloorIndices& indices = m_abstractGraph->m_blob->m_graphNodeIdxToGraphCellFloorIndices.GetValues()[m_nodeIdx];
91  const AbstractGraphCellBlob* abstractCellBlob = m_abstractGraph->m_blob->m_abstractCells.GetValues()[indices.m_abstractCellIdx].Ptr();
92  return abstractCellBlob->m_abstractFloors.GetValues()[indices.m_abstractFloorIdx].Ptr()->m_originalNavFloorIdx;
93 }
94 
95 KY_INLINE CellPos AbstractGraphNodeRawPtr::GetCellPos() const
96 {
97  const AbstractGraphCellFloorIndices& indices = m_abstractGraph->m_blob->m_graphNodeIdxToGraphCellFloorIndices.GetValues()[m_nodeIdx];
98  const AbstractGraphCellBlob* abstractCellBlob = m_abstractGraph->m_blob->m_abstractCells.GetValues()[indices.m_abstractCellIdx].Ptr();
99  return abstractCellBlob->m_cellPos;
100 }
101 
102 KY_INLINE CardinalDir AbstractGraphNodeRawPtr::GetCellBoundary() const
103 {
104  const AbstractGraphCellFloorIndices& indices = m_abstractGraph->m_blob->m_graphNodeIdxToGraphCellFloorIndices.GetValues()[m_nodeIdx];
105  const AbstractGraphCellBlob* abstractCellBlob = m_abstractGraph->m_blob->m_abstractCells.GetValues()[indices.m_abstractCellIdx].Ptr();
106  const AbstractGraphFloorBlob* abstractFloorBlob = abstractCellBlob->m_abstractFloors.GetValues()[indices.m_abstractFloorIdx].Ptr();
107  return abstractFloorBlob->GetCellBoundaryDir(m_nodeIdx);
108 }
109 
110 KY_INLINE Vec3f AbstractGraphNodeRawPtr::GetPosition() const
111 {
112  return m_abstractGraph->GetNodePosition(m_nodeIdx);
113 }
114 
115 
116 }
117 
118 #endif
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
#define KY_NULL
Null value.
Definition: types.h:247
KyUInt32 CardinalDir
Defines a type that refers to one of the cardinal points on the compass:
Definition: cardinaldir.h:23
KyUInt32 NavFloorIdx
An index that uniquely identifies a single NavFloor within the set of NavFloors owned by a NavCell...
Definition: navmeshtypes.h:115
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43