gwnavruntime/queries/blobs/astarqueryblob.h Source File

astarqueryblob.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 
16 
17 namespace Kaim
18 {
19 
20 class AStarQueryOutputBlob
21 {
22  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
23 
24 public:
25  AStarQueryOutputBlob() : m_result(0) {}
26  AStarQueryResult GetResult() const { return (AStarQueryResult)m_result; }
27 
28 public:
29  KyUInt32 m_result;
30  TimeSlicedQueryInfoBlob m_timeSlicedQueryInfo;
31  NavTriangleBlob m_startTriangle;
32  NavTriangleBlob m_destTriangle;
33  PathBlob m_pathBlob;
34  PathBlob m_abstractPathBlob;
35 };
36 inline void SwapEndianness(Endianness::Target e, AStarQueryOutputBlob& self)
37 {
38  SwapEndianness(e, self.m_result);
39  SwapEndianness(e, self.m_timeSlicedQueryInfo);
40  SwapEndianness(e, self.m_startTriangle);
41  SwapEndianness(e, self.m_destTriangle);
42  SwapEndianness(e, self.m_pathBlob);
43  SwapEndianness(e, self.m_abstractPathBlob);
44 }
45 
46 
47 class AStarQueryOutputBlobBuilder : public BaseBlobBuilder<AStarQueryOutputBlob>
48 {
49 public:
50  AStarQueryOutputBlobBuilder(BaseAStarQuery* query) { m_query = query; }
51  virtual void DoBuild()
52  {
53  BLOB_SET(m_blob->m_result, (KyUInt32)m_query->GetResult());
54  BLOB_BUILD(m_blob->m_timeSlicedQueryInfo, TimeSlicedQueryBlobBuilder(m_query));
55  BLOB_BUILD(m_blob->m_startTriangle, NavTriangleBlobBuilder(m_query->GetStartTrianglePtr()));
56  BLOB_BUILD(m_blob->m_destTriangle, NavTriangleBlobBuilder(m_query->GetDestTrianglePtr()));
57 
58  if (m_query->GetResult() == ASTAR_DONE_PATH_FOUND)
59  {
60  BLOB_BUILD(m_blob->m_pathBlob, PathBlobBuilder(m_query->GetPath()));
61  BLOB_BUILD(m_blob->m_abstractPathBlob, PathBlobBuilder(m_query->GetAbstractPath()));
62  }
63  }
64 
65 private:
66  BaseAStarQuery* m_query;
67 };
68 
69 class AStarQueryBlob
70 {
71  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
72  KY_ROOT_BLOB_CLASS(Query, AStarQueryBlob, 3)
73 public:
74  AStarQueryBlob() : m_queryInfoId(KyUInt32MAXVAL), m_databaseIdx(KyUInt32MAXVAL) {}
75 
76 public:
77  KyUInt32 m_queryInfoId;
78 
79  KyUInt32 m_databaseIdx;
80  KyFloat32 m_fromOutsideNavMeshDistance;
81  KyFloat32 m_toOutsideNavMeshDistance;
82  KyFloat32 m_propagationBoxExtent;
83  KyUInt8 m_tryCanGoMode;
84  KyUInt8 m_channelMode;
85  KyUInt8 m_abstractGraphTraversalMode;
86 
87  FullDebug m_fullDebug;
88 
89  Vec3f m_startPos3f;
90  Vec3f m_destPos3f;
91  PositionSpatializationRange m_positionSpatializationRange;
92  BlobRef<AStarQueryOutputBlob> m_queryOutput;
93 
94 };
95 inline void SwapEndianness(Endianness::Target e, AStarQueryBlob& self)
96 {
97  SwapEndianness(e, self.m_queryInfoId);
98 
99  SwapEndianness(e, self.m_databaseIdx);
100  SwapEndianness(e, self.m_fromOutsideNavMeshDistance);
101  SwapEndianness(e, self.m_toOutsideNavMeshDistance);
102  SwapEndianness(e, self.m_propagationBoxExtent);
103  SwapEndianness(e, self.m_tryCanGoMode);
104  SwapEndianness(e, self.m_channelMode);
105  SwapEndianness(e, self.m_abstractGraphTraversalMode);
106  SwapEndianness(e, self.m_fullDebug);
107 
108  SwapEndianness(e, self.m_startPos3f);
109  SwapEndianness(e, self.m_destPos3f);
110  SwapEndianness(e, self.m_positionSpatializationRange);
111  SwapEndianness(e, self.m_queryOutput);
112 }
113 
114 
115 
116 class AStarQueryBlobBuilder : public BaseBlobBuilder<AStarQueryBlob>
117 {
118 public:
119  AStarQueryBlobBuilder(BaseAStarQuery* query) { m_query = query; }
120  virtual void DoBuild()
121  {
122  BLOB_SET(m_blob->m_queryInfoId, m_query->m_queryInfoId);
123 
124  if (m_query->m_database != nullptr)
125  {
126  BLOB_SET(m_blob->m_databaseIdx , m_query->m_database->GetDatabaseIndex());
127  BLOB_SET(m_blob->m_startPos3f , m_query->GetStartPos());
128  BLOB_SET(m_blob->m_destPos3f , m_query->GetDestPos());
129  BLOB_SET(m_blob->m_positionSpatializationRange , m_query->GetPositionSpatializationRange());
130  BLOB_SET(m_blob->m_fromOutsideNavMeshDistance , m_query->GetFromOutsideNavMeshDistance());
131  BLOB_SET(m_blob->m_toOutsideNavMeshDistance , m_query->GetToOutsideNavMeshDistance());
132  BLOB_SET(m_blob->m_propagationBoxExtent , m_query->GetPropagationBoxExtent());
133  BLOB_SET(m_blob->m_tryCanGoMode , (KyUInt8)m_query->GetTryCanGoMode());
134  BLOB_SET(m_blob->m_channelMode , (KyUInt8)m_query->GetComputeChannelMode());
135  BLOB_SET(m_blob->m_abstractGraphTraversalMode , (KyUInt8)m_query->GetAbstractGraphTraversalMode());
136  BLOB_SET(m_blob->m_fullDebug , m_query->m_fullDebug);
137 
138  switch (m_query->GetResult())
139  {
140  case ASTAR_NOT_INITIALIZED :
141  case ASTAR_NOT_PROCESSED :
142  break;
143  default:
144  BUILD_REFERENCED_BLOB(m_blob->m_queryOutput, AStarQueryOutputBlobBuilder(m_query));
145  break;
146  }
147  }
148  }
149 
150 private:
151  BaseAStarQuery* m_query;
152 };
153 }
154 
#define BLOB_SET(blob, value)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:130
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define BLOB_BUILD(blob, builder)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:175
Indicates the query has not yet been launched.
Definition: baseastarquery.h:30
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
Indicates the query has not yet been initialized.
Definition: baseastarquery.h:29
AStarQueryOutputBlob * m_blob
The blob maintained by this builder. Only modify using the macros listed under DoBuild().
Definition: baseblobbuilder.h:113
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Indicates that a path has been found between the start and destination.
Definition: baseastarquery.h:57
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
#define BUILD_REFERENCED_BLOB(blobRef, builder)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:182
AStarQueryResult
Enumerates the possible results of an AStarQuery.
Definition: baseastarquery.h:27