gwnavruntime/queries/querydynamicoutput.h Source File

querydynamicoutput.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_QueryDynamicOutput_H
10 #define Navigation_QueryDynamicOutput_H
11 
19 
20 
21 namespace Kaim
22 {
23 
24 
27 {
29  QUERY_SAVE_FLOORS = 1 << 1,
36  QUERY_SAVE_TRIANGLES_AND_SUBSEGMENTS = QUERY_SAVE_TRIANGLES | QUERY_SAVE_NAVTAGSUBSEGMENTS,
37 };
38 
39 class WorkingMemory;
40 
41 template <class T>
42 class QueryOutputBuffer_Impl
43 {
44 public:
45  QueryOutputBuffer_Impl() : m_buffer(KY_NULL), m_count(0) {}
46  void ClearBuffer();
47  void InitBuffer(KyUInt32 count, char*& memory);
48  KyUInt32 GetCount() const;
49  const T& Get(KyUInt32 index) const;
50  T& Get(KyUInt32 index);
51  void Set(KyUInt32 index, const T& object);
52 
53  T* m_buffer;
54  KyUInt32 m_count;
55 };
56 
57 
58 
60 class QueryDynamicOutput
61 {
62  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_QueryOutput)
64 
65 public:
66  class Config
67  {
68  public:
69  Config();
70  bool IsZero() const;
71  public:
72  KyUInt32 m_floorCount;
73  KyUInt32 m_triangleCount;
74  KyUInt32 m_navTagSubSegmentCount;
75  KyUInt32 m_costMultiplierSubSegmentCount;
76  KyUInt32 m_halfEdgeIntersectionCount;
77  KyUInt32 m_spatializedPointCount;
78  KyUInt32 m_tagVolumeCount;
79  };
80 
81  // ---------------------------------- Main API functions ----------------------------------
82 
83  KyUInt32 GetNavFloorPtrCount() const;
84  KyUInt32 GetNavTrianglePtrCount() const;
85  KyUInt32 GetNavTagSubSegmentCount() const;
86  KyUInt32 GetCostMultiplierSubSegmentCount() const;
87  KyUInt32 GetHalfEdgeIntersectionCount() const;
88  KyUInt32 GetSpatializedPointCount() const;
89  KyUInt32 GetTagVolumeCount() const;
90 
91  const NavTrianglePtr& GetNavTrianglePtr(KyUInt32 trianglePtrIndex) const;
92  NavTrianglePtr& GetNavTrianglePtr(KyUInt32 trianglePtrIndex);
93 
94  const NavFloorPtr& GetNavFloorPtr(KyUInt32 floorPtrIndex) const;
95  NavFloorPtr& GetNavFloorPtr(KyUInt32 floorPtrIndex);
96 
97  const NavTagSubSegment& GetNavTagSubSegment(KyUInt32 navTagSubSegmentIndex) const;
98  NavTagSubSegment& GetNavTagSubSegment(KyUInt32 navTagSubSegmentIndex);
99 
100  const CostMultiplierSubSegment& GetCostMultiplierSubSegment(KyUInt32 costMultSubSegmentIdx) const;
101  CostMultiplierSubSegment& GetCostMultiplierSubSegment(KyUInt32 costMultSubSegmentIdx);
102 
103  const HalfEdgeIntersection& GetHalfEdgeIntersection(KyUInt32 halfEdgeIntersectionIndex) const;
104  HalfEdgeIntersection& GetHalfEdgeIntersection(KyUInt32 halfEdgeIntersectionIndex);
105 
106  const Ptr<SpatializedPoint>& GetSpatializedPoint(KyUInt32 spatializedPointIndex) const;
107  Ptr<SpatializedPoint>& GetSpatializedPoint(KyUInt32 spatializedPointIndex);
108 
109  const Ptr<TagVolume>& GetTagVolume(KyUInt32 tagVolumeIdx) const;
110  Ptr<TagVolume>& GetTagVolume(KyUInt32 tagVolumeIdx);
111 
112  void SetNavTrianglePtr (KyUInt32 trianglePtrIndex, const NavTrianglePtr& navTrianglePtr);
113  void SetNavTagSubSegment (KyUInt32 navTagSubSegmentIndex, const NavTagSubSegment& navTagSubSegment);
114  void SetCostMultiplierSubSegment(KyUInt32 costMultSubSegmentIdx, const CostMultiplierSubSegment& costMultSubSegment);
115  void SetHalfEdgeIntersection (KyUInt32 halfEdgeIntersectionIndex, const HalfEdgeIntersection& halfEdgeIntersection);
116  void SetNavFloorPtr (KyUInt32 floorPtrIndex, const NavFloorPtr& navFloorPtr);
117  void SetSpatializedPoint (KyUInt32 spatializedPointIndex, const Ptr<SpatializedPoint>& spatializedPoint);
118  void SetTagVolume (KyUInt32 tagVolumeIndex, const Ptr<TagVolume>& tagVolume);
119 
120  static KyUInt32 ComputeByteSize(const Config& config);
121  static Ptr<QueryDynamicOutput> Create(const Config& config);
122 
123  void ClearBuffers();
124  bool IsEnoughMemoryForStoringDynamicOutput(const Config& config);
125  void InitBuffers( const Config& config);
126 
127  bool IsEmpty() const;
128 
129 private:
130  QueryOutputBuffer_Impl<NavFloorPtr > m_navFloorPtrs;
131  QueryOutputBuffer_Impl<NavTrianglePtr > m_navTrianglePtrs;
132  QueryOutputBuffer_Impl<NavTagSubSegment > m_navTagSubSegments;
133  QueryOutputBuffer_Impl<HalfEdgeIntersection > m_halfEgdeIntersections;
134  QueryOutputBuffer_Impl<CostMultiplierSubSegment> m_costMultSubSegments;
135  QueryOutputBuffer_Impl<Ptr<SpatializedPoint> > m_spatializedPoints;
136  QueryOutputBuffer_Impl<Ptr<TagVolume> > m_tagVolumes;
137 
138  KyUInt32 m_byteSize;
139  KyUInt32 RefCount; // consider thread-safetyness here with mutable AtomicInt<int> RefCount;
140 
141 
142 public:
143  // Lifetime - separate implementation due to Create function
144  KY_INLINE void AddRef() { RefCount ++; }
145  KY_INLINE void Release()
146  {
147  if (RefCount-- == 1)
148  {
149  ClearBuffers();
150  KY_FREE(this);
151  }
152  }
153 
154  // Debug method only.
155  int GetRefCount() const { return RefCount; }
156 };
157 
158 class ScopedDynamicOutput
159 {
160 public:
161  ScopedDynamicOutput(Ptr<QueryDynamicOutput>& dynamicOutput);
162  ~ScopedDynamicOutput();
163 
164  KyResult Init(WorkingMemory* workingMemory, DynamicOutputMode outputMode);
165 
166 private:
167  void CopyCrossedDataIntoDynamicOutput();
168 
169  Ptr<QueryDynamicOutput>* m_queryDynamicOutput;
170 public://Internal
171  WorkingMemArray<NavFloorRawPtr> m_navFloorRawPtrs;
172  WorkingMemArray<NavTriangleRawPtr> m_navTriangleRawPtrs;
173  WorkingMemArray<RawNavTagSubSegment> m_rawNavTagSubSegments;
174  WorkingMemArray<CostMultiplierSubSegment> m_costMultiplierSubSegments;
175  WorkingMemArray<RawHalfEdgeIntersection> m_rawHalfEdgeIntersections;
176  WorkingMemArray<SpatializedPoint*> m_spatializedPoints;
177  WorkingMemArray<TagVolume*> m_tagVolumes;
178 };
179 
180 
181 } // namespace Kaim
182 
183 
185 
186 #endif //Navigation_QueryDynamicOutput_H
187 
This class gather the data encountered along some query process.
Definition: querydynamicoutput.h:61
Each instance of this class uniquely identifies a single NavFloor.
Definition: navfloorptr.h:21
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class represents a NavTag sub-segment of a ray (within a RayCastQuery or a RayCanGoQuery, carried out against the NavMesh).
Definition: navtagsubsegment.h:52
#define KY_NULL
Null value.
Definition: types.h:247
DynamicOutputMode
Enumerates possible ways of storing crossed data from a query in a QueryDynamicOutput object...
Definition: querydynamicoutput.h:26
Indicates that QueryDynamicOutput will be used to store CostMultiplierSubSegment. ...
Definition: querydynamicoutput.h:34
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
Indicates that QueryDynamicOutput will not be used to store anything.
Definition: querydynamicoutput.h:28
This class represents a CostMultiplier sub-segment of a ray (within a RayCastQuery or a RayCanGoQuery...
Definition: costmultipliersubsegment.h:25
Indicates that QueryDynamicOutput will be used to store Vec3f.
Definition: querydynamicoutput.h:32
Indicates that QueryDynamicOutput will be used to store NavFloorTrianglePtr.
Definition: querydynamicoutput.h:30
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:22
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Indicates that QueryDynamicOutput will be used to store NavTagSubSegment.
Definition: querydynamicoutput.h:31
Indicates that QueryDynamicOutput will be used to store CostMultiplierSubSegment. ...
Definition: querydynamicoutput.h:35
Indicates that QueryDynamicOutput will be used to store CostMultiplierSubSegment. ...
Definition: querydynamicoutput.h:33
This class represents an intersection between an NavHalfEdge and a ray (within a RayCastQuery or a Ra...
Definition: halfedgeintersection.h:44
Indicates that QueryDynamicOutput will be used to store NavFloorPtr.
Definition: querydynamicoutput.h:29