gwnavruntime/queries/utils/astartypes.h Source File

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