gwnavruntime/abstractgraph/identifiers/abstractgraphnoderawptr.h Source File

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