gwnavruntime/queries/utils/astartypes.h Source File

astartypes.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 
10 
15 
19 
20 namespace Kaim
21 {
22 
23 typedef KyUInt32 AStarNodeIndex;
24 static const AStarNodeIndex AStarNodeIndex_Invalid = KyUInt32MAXVAL;
25 static const AStarNodeIndex AStarNodeIndex_StartNode = 0;
26 static const AStarNodeIndex AStarNodeIndex_DestNode = 1;
27 
28 typedef KyUInt8 PathNodeType;
29 static const PathNodeType NodeType_Invalid = KyUInt8MAXVAL;
30 static const PathNodeType NodeType_NavMeshEdge = 0;
31 static const PathNodeType NodeType_NavGraphVertex = 1;
32 static const PathNodeType NodeType_AbstractGraphNode = 2;
33 static const PathNodeType NodeType_FreePositionOnNavMesh = 3;
34 static const PathNodeType NodeType_FreePositionOnGraphEdge = 4;
35 
36 class NodeTypeAndRawPtrDataIdx
37 {
38 public:
39  NodeTypeAndRawPtrDataIdx() : m_data(KyUInt32MAXVAL) {}
40  NodeTypeAndRawPtrDataIdx(PathNodeType aStarNodeType, KyUInt32 indexOfRawPtrData) :
41  m_data((indexOfRawPtrData & 0x1FFFFFFF) | (aStarNodeType << 29))
42  {
43  KY_ASSERT((aStarNodeType & 0xFFFFFFF8) == 0);
44  }
45 
46  PathNodeType GetNodeType() const { return (PathNodeType)(m_data >> 29); }
47  KyUInt32 GetIdxOfRawPtrData() const { return m_data & 0x1FFFFFFF; }
48  void SetNodeType(PathNodeType nodeType) { m_data = (m_data & 0x1FFFFFFF) | (nodeType << 29); }
49 
50  void SetIdxOfRawPtrData(KyUInt32 indexOfRawPtrData) { m_data = (indexOfRawPtrData & 0x1FFFFFFF) | (GetNodeType() << 29); }
51 private:
52  KyUInt32 m_data; // 32 bits : 3 bit for type (see AstarNodeType), 29 bits for Idx
53 };
54 
55 class AStarNode
56 {
57  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
58 public:
59  AStarNode() :
60  m_costFromStart(KyFloat32MAXVAL),
61  m_estimatedCostToDest(0.f),
62  m_costMultiplierFromPredecessor(1.f),
63  m_indexOfPredecessor(AStarNodeIndex_Invalid),
64  m_indexInBinaryHeap(IndexInBinHeap_UnSet)
65  {}
66 
67  AStarNode(AStarNodeIndex indexOfPredecessor, const Vec3f& pos, PathNodeType aStarNodeType, KyUInt32 indexOfRawPtrData) :
68  m_nodePosition(pos),
69  m_costFromStart(KyFloat32MAXVAL),
70  m_estimatedCostToDest(0.f),
71  m_costMultiplierFromPredecessor(1.f),
72  m_nodeTypeAndRawPtrDataIdx(aStarNodeType, indexOfRawPtrData),
73  m_indexOfPredecessor(indexOfPredecessor),
74  m_indexInBinaryHeap(IndexInBinHeap_UnSet)
75  {}
76 
77  AStarNodeIndex GetIndexOfPredecessor() const { return m_indexOfPredecessor; }
78  void SetIndexOfPredecessor(AStarNodeIndex indexOfPredecessor) { m_indexOfPredecessor = indexOfPredecessor; }
79 
80  PathNodeType GetNodeType() const { return m_nodeTypeAndRawPtrDataIdx.GetNodeType(); }
81  KyUInt32 GetIdxOfRawPtrData() const { return m_nodeTypeAndRawPtrDataIdx.GetIdxOfRawPtrData(); }
82 
83  void SetNodeType(PathNodeType nodeType) { m_nodeTypeAndRawPtrDataIdx.SetNodeType(nodeType); }
84  void SetIdxOfRawPtrData(KyUInt32 indexOfRawPtrData) { m_nodeTypeAndRawPtrDataIdx.SetIdxOfRawPtrData(indexOfRawPtrData); }
85 
86 public:
87  Vec3f m_nodePosition;
88  KyFloat32 m_costFromStart;
89  KyFloat32 m_estimatedCostToDest;
90  KyFloat32 m_costMultiplierFromPredecessor;
91  NodeTypeAndRawPtrDataIdx m_nodeTypeAndRawPtrDataIdx; // 32 bits
92  AStarNodeIndex m_indexOfPredecessor; // 32bits
93  IndexInBinHeap m_indexInBinaryHeap; // 16bits
94 
95 };
96 
97 class NavTag;
98 
99 
100 }
101 
102 
103 
#define KyFloat32MAXVAL
KyFloat32 max value
Definition: types.h:71
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 KyUInt8MAXVAL
KyUInt8 max value
Definition: types.h:66
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
float KyFloat32
float
Definition: types.h:32