gwnavruntime/queries/dynamicnavmeshquery.h Source File

dynamicnavmeshquery.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 
20 
21 
22 namespace Kaim
23 {
24 class TriangulatorOutput;
25 class DisplayList;
26 class TagVolume;
27 class SweepLineOutput;
28 class TriangulatorOutput;
29 class DynamicNavFloor;
30 
31 typedef Collection<Ptr<TagVolume>, MemStat_NavData> TagVolumeCollection;
32 
33 enum MergerDebugDisplayListType
34 {
35  MERGER_DEBUG_DISPLAYLIST_INPUT_TAGVOLUMES,
36  MERGER_DEBUG_DISPLAYLIST_ROUND_SNAPPING,
37  MERGER_DEBUG_DISPLAYLIST_EDGE_CULLING,
38  MERGER_DEBUG_DISPLAYLIST_POLYGON_SCAN_INPUT,
39  MERGER_DEBUG_DISPLAYLIST_POLYGON_SCAN_OUTPUT,
40  MERGER_DEBUG_DISPLAYLIST_TRIANGULATION,
41  MERGER_DEBUG_DISPLAYLIST_COUNT
42 };
43 
46 {
49 
50  DYNNAVMESH_COLLECT_TAGVOLUME_FOR_NAVFLOOR, // 2
51  DYNNAVMESH_EXTRACTING_ALL_NAVTAGS, // 3
52  DYNNAVMESH_EXTRACTING_TAGVOLUMES_CONTOURS, // 4
53  DYNNAVMESH_EXTRACTING_NAVFLOOR_CONTOUR, // 5
54  DYNNAVMESH_ROUND_SNAPPING, // 6
55  DYNNAVMESH_SWEEP_LINE_SORT_INPUT, // 7
56  DYNNAVMESH_SWEEP_LINE_SCAN, // 8
57  DYNNAVMESH_SWEEP_LINE_SORT_OUTPUT, // 9
58  DYNNAVMESH_BUILD_POLYGONS_INIT, // 10
59  DYNNAVMESH_BUILD_POLYGONS_PROCESS, // 11
60  DYNNAVMESH_TRIANGULATE_POLYGONS_INIT, // 12
61  DYNNAVMESH_TRIANGULATE_POLYGONS_PROCESS, // 13
62  DYNNAVMESH_BUILD_DYNAMIC_NAVFLOOR, // 14
63  DYNNAVMESH_BUILD_FIX_VERTEX_ALTITUDES, // 15
64  DYNNAVMESH_BUILD_NAVFLOORBLOB, // 16
65 
75 
77 };
78 
82 {
83 public:
84  // ------------------------------ Functions -----------------------------
85 
86  static QueryType GetStaticType() { return TypeDynamicNavMesh; }
87  virtual QueryType GetType() const { return TypeDynamicNavMesh; }
88 
90  virtual ~DynamicNavMeshQuery();
91 
94  void BindToDatabase(Database* database);
95 
96  void Initialize(NavCell* navCell, const TagVolumeCollection* integratedTagVolumesAtCellPos, const TagVolumeCollection* newTagVolumes);
97 
98  virtual void Advance(WorkingMemory* workingMemory);
99 
100  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = nullptr);
101 
102  const PixelPos& GetCellOriginPixel() const { return m_cellOriginPixel; }
103 
104  DynamicNavMeshQueryResult GetResult() const { return m_result; };
105  void SetResult(DynamicNavMeshQueryResult result) { m_result = result; };
106 
107  // ------------------------------ debug and profile -----------------------------
108  void SetDebugDisplayLists(KyArray<DisplayList*> displayLists) { m_debugDisplayLists = displayLists; }
109  const DynamicNavMeshQueryStats& GetStats() const { return m_stats; }
110 
111 private:
112  // Main function
113  // does the following:
114  // 0. ExtractInputDataFromNavFloor
115  // 1. BreakEdgeIntersections
116  // 2. TagAndCullEdges
117  // 3. TriangulatePolygonWithHoles
118  // 4. ComputeVerticesAltitudesFromNavFloor
119  // 5. BuildNavFloorFromTriangulatorOutput
120 
121  // And here are the signatures
122 
123  // Core functions
124  KyResult TagAndCullEdges(WorkingMemory* workingMemory);
125  KyResult SortSweepLineOutput(WorkingMemory* workingMemory);
126 
127  enum InitBuildPolygonResult { InitBuildPolygonResult_ReadyToBuild, InitBuildPolygonResult_NothingToDo } ;
128  KyResult InitBuildPolygon(WorkingMemory* workingMemory, InitBuildPolygonResult& initBuildPolygonResult);
129  enum BuildPolygonResult { BuildPolygonsResult_Finish, BuildPolygonsResult_InProcess} ;
130  KyResult BuildPolygon(WorkingMemory* workingMemory, BuildPolygonResult& buildPolygonsResult);
131 
132  KyResult InitPolygonTriangulation(WorkingMemory* workingMemory);
133 
134  KyResult PreparePolygonWithHolesTriangulation(WorkingMemory* workingMemory);
135 
136  enum TriangulatePoygonResult { TriangulatePoygonResult_Finish, TriangulatePoygonResult_GoOn } ;
137  KyResult TriangulatePoygon(WorkingMemory* workingMemory, TriangulatePoygonResult& triangulatePoygonResult);
138 
139  KyResult ComputeVerticesAltitudes(WorkingMemory* workingMemory);
140  KyResult FillDynamicNavFloorFromTriangulatorOutputs(WorkingMemory* workingMemory, KyArrayPOD<const SweepLineOutputEdgePiece*>& edgesForEdges);
141  KyResult FixHalfEdgeTypeInDynamicNavFloor(WorkingMemory* workingMemory, const KyArrayPOD<const SweepLineOutputEdgePiece*>& edgesForEdges);
142 
143  // Output build
144  KyResult BuildNavFloorFromTriangulatorOutput(WorkingMemory* workingMemory);
145 
146  KyResult BuildFinalBlobFromDynamicNavFloor(WorkingMemory* workingMemory);
147 
148  // local accessors and utilities
149  enum CollectTagVolumeResult { CollectTagVolume_NothingToDo, CollectTagVolume_NeedToComputeDynamicNavFloor, CollectTagVolume_NeedToRestoreStaticNavFloor };
150  KyResult CollectTagVolumesImpactingNavCell(WorkingMemArray<TagVolume*>& allTagVolumes, CollectTagVolumeResult& collectTagVolumeResult);
151  KyResult CollectTagVolumesToIntegrateImpactingNavCell(WorkingMemArray<TagVolume*>& allTagVolumes, const CellPos& cellPos, KyUInt32& newTagVolumeCount);
152  KyResult CollectTagVolumesToRemoveImpactingNavCell(WorkingMemArray<TagVolume*>& allTagVolumes, KyUInt32& tagVolumeToRemoveCount);
153 
154  void SetResultAndFinish(DynamicNavMeshQueryResult result, WorkingMemory* workingMemory)
155  {
156  SetResult(result);
157  SetFinish(workingMemory);
158  }
159 
160  void SetFinish(WorkingMemory* workingMemory);
161 
162 public: // internal
163  DisplayList* GetDisplayList(KyUInt32 index) const;
164 
165 public:
166  // input Data
167  NavCell* m_navCell;
168  PixelPos m_cellOriginPixel;
169  const TagVolumeCollection* m_integratedTagVolumesAtCellPos;
170  const TagVolumeCollection* m_newTagVolumes;
171 
174 
175 private:
177 
178  // debug and profile
179  KyArray<DisplayList*> m_debugDisplayLists;
180  DynamicNavMeshQueryStats m_stats;
181 };
182 
183 KY_INLINE DisplayList* DynamicNavMeshQuery::GetDisplayList(KyUInt32 index) const
184 {
185 #if defined(KY_CONFIG_DEBUG_OR_DEV)
186  return m_debugDisplayLists.GetCount() > index ? m_debugDisplayLists[index] : nullptr;
187 #else
188  KY_UNUSED(index);
189  return nullptr;
190 #endif
191 }
192 }
193 
194 
195 
196 
197 
198 
Indicates the query was successfully processed.
Definition: dynamicnavmeshquery.h:76
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Indicates an error occurred while computing the altitude of the dynamic navmesh.
Definition: dynamicnavmeshquery.h:72
Indicates an unknown error occurred during the query processing.
Definition: dynamicnavmeshquery.h:74
DynamicNavMeshQueryResult m_result
Updated during processing to indicate the result of the query.
Definition: dynamicnavmeshquery.h:176
Indicates an error occurred while culling edges.
Definition: dynamicnavmeshquery.h:69
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:162
Indicates an error occurred while building polygons from culled edges.
Definition: dynamicnavmeshquery.h:70
KyArray< Ptr< BlobHandler< NavFloorBlob > > > m_resultNavfloorHandlers
Output NavFloors with TagVolumes integrated remains to size 0 if nothing changed in this...
Definition: dynamicnavmeshquery.h:173
This class is a runtime wrapper of a NavCellBlob.
Definition: navcell.h:27
Indicates that the navfloor currently being processed is no longer valid.
Definition: dynamicnavmeshquery.h:66
Base class for all the queries that need to be time-sliced.
Definition: iquery.h:262
The DynamicNavMeshQuery is used to recompute a NavCell impacted by newly projected TagVolumes or remo...
Definition: dynamicnavmeshquery.h:81
QueryType
Enumerates all the type of query.
Definition: iquery.h:25
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
Indicates an error occurred while triangulating the newly obtained polygons.
Definition: dynamicnavmeshquery.h:71
Indicates that insufficient working memory caused the query to stop.
Definition: dynamicnavmeshquery.h:67
DisplayList is used to push text, lines or shapes for rendering in the NavigationLab e...
Definition: displaylist.h:128
Navigation return code class.
Definition: types.h:108
2d vector using KyInt32
Definition: vec2i.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Indicates that.
Definition: dynamicnavmeshquery.h:73
virtual void Advance(WorkingMemory *workingMemory)
This function is called by the QueryQueue to process one step on the query.
Definition: dynamicnavmeshquery.cpp:110
Indicates that the query has not yet been initialized.
Definition: iquery.h:295
void BindToDatabase(Database *database)
Binds the query with the specified Database, clears all the inputs and outputs and sets all other par...
Definition: dynamicnavmeshquery.cpp:55
Indicates the query has not yet been launched.
Definition: dynamicnavmeshquery.h:48
virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory *workingMemory=nullptr)
Called when a query is canceled in FlushCommands while its status is QueryInProcess to make sure that...
Definition: dynamicnavmeshquery.cpp:90
DynamicNavMeshQueryResult
Enumerates the possible results of a DynamicNavMeshQuery.
Definition: dynamicnavmeshquery.h:45
Indicates that the query has not yet been launched.
Definition: iquery.h:296
virtual QueryType GetType() const
Get query type.
Definition: dynamicnavmeshquery.h:87
Indicates the query has not yet been initialized.
Definition: dynamicnavmeshquery.h:47
void Initialize()
Should be called by the derived class before trying to perform the query or to push it in a QueryQueu...
Definition: iquery.h:273
Indicates an error occurred while computing the intersections.
Definition: dynamicnavmeshquery.h:68