gwnavruntime/queries/blobs/astarqueryblob.h Source File

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