gwnavruntime/database/database.h Source File

database.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: LAPA
9 
10 #ifndef Navigation_Database_H
11 #define Navigation_Database_H
12 
23 
24 
25 namespace Kaim
26 {
27 
28 class AbstractGraphCellGrid;
29 class NavMeshGenParameters;
30 class NavMeshElementManager;
31 class NavGraphManager;
32 class ITriangleCostMap;
33 class WorkingMemory;
34 class ActiveData;
35 class NavCellGrid;
36 class NavData;
37 class Bot;
38 
39 
42 {
43  NoMargin = 0,
50 
51  RayCanGoMarginModeCount // internal
52 };
53 
54 
62 class Database : public WorldElement
63 {
66 
67 public:
68  static WorldElementType GetStaticType() { return TypeDatabase; }
69  virtual WorldElementType GetType() const { return TypeDatabase; }
70  virtual const char* GetTypeName() const { return "Database"; }
71 
72  // ---------------------------------- Public Member Functions ----------------------------------
73 
75  KyUInt32 GetDatabaseIndex() const;
76 
79  const DatabaseGenMetrics& GetDatabaseGenMetrics() const;
80 
81  DatabasePositionSpatializationRange& GetDatabasePositionSpatializationRange();
82  const DatabasePositionSpatializationRange& GetDatabasePositionSpatializationRange() const;
83  const PositionSpatializationRange& GetPositionSpatializationRange() const;
84 
89  bool IsClear() const;
90 
93  bool IsCompatibleWith(const NavData& navData) const;
94 
97  void RemoveAllNavData();
98  KyUInt32 GetAliveNavDataCount() const;
99 
100  void RemoveAllBots();
101  KyUInt32 GetBotsCount() const;
102  Bot* GetBot(KyUInt32 index) const;
103 
105  // to access this explicitly except for modifying the memory size limit of this WorkingMemory.
106  WorkingMemory* GetWorkingMemory() const;
107 
109  const CellBox& GetLastUpdateCellBox() const;
110 
115  bool HasChangedLastFrame() const;
116 
117 public: // internal
118  Database(World* world, KyUInt32 databaseIndex);
119  virtual ~Database();
120 
121  void Clear();
122 
123  virtual void DoSendVisualDebug(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent);
124 
125 
127  PerformQueryStatistics* GetPerformQueryStatistics();
128 
129  void SetEventBroadcaster(IDatabaseChangeBroadcaster* eventBroadCaster);
130  void UpdateImmediate();
131 
132  // ---------------------------------- Internally used by the NavigationLab for Database Visual Representation ----------------------------------
138 
141  void SetVisualGeometryFactory(Ptr<IVisualGeometryFactory> factory);
142 
145  void SetVisualGeometry(Ptr<IVisualGeometry> geometry);
146 
149  void BuildVisualGeometry(bool forceRebuildAll = false);
150 
152  // by this object for rendering. By default, navMesh, navGraph and abstractGraph are built. It can be changed
154  void BuildVisualGeometry(Ptr<IVisualGeometry> geometry, const DatabaseVisualGeometryBuilderConfig& config = DatabaseVisualGeometryBuilderConfig());
155 
158  DatabaseGeometryBuildingManager& GetDatabaseGeometryBuildingManager();
159 
162  IVisualGeometry* GetVisualGeometry() const;
163 
164  // ---------------------------------- Called by various components, World, Queries ----------------------------------
165 
166  ActiveData* GetActiveData() const;
167 
168  bool IsThereNavDataToBeAddedOrRemoved() const; // call by World::Update
169  bool IsDatabaseUpdatingNavData() const; // call by World::Update
170 
171  void UpdateWithDynamicNavFloors(const CellBox& enlargeUpdateCellBox);
172 
173  void RecomputeAllTriangleCostMapInBox(const CellBox& enlargeUpdateCellBox);
174 
175  void TakeSnapshotAndPrepareActiveDataUpdate(QueryProcessMode processMode);
176  void UpdateActiveDataAndClearSnapshot(); // call by World::Update
177  void UpdateBotsPathFollowing(KyFloat32 simulationTimeInSeconds); // call by World::Update
178  void UpdateBotsGenMetrics();
179 
180  KyUInt32 GetRayCanGoMarginInt(RayCanGoMarginMode marginMode);
181  KyFloat32 GetRayCanGoMarginFloat(RayCanGoMarginMode marginMode);
182 
183  void SetupGenerationMetrics(const NavMeshGenParameters& navMeshGenParameters); // called by internal members
184 
185 private:
186  friend class DatabaseUpdateManager;
187  friend class NavMeshElementManager;
188  void IncrementNavDataChangeIndex();
189 
190  void RemoveNavGraphsOfNavDataBeeingRemoved();
191  void AddNavGraphsOfNavDataBeeingAdded();
192 
193  void SnapShotOfNavDataToUpdate();
194  void ClearSnapShotOfNavDataToUpdate();
195 
196  void PrepareNavMeshInsertionOfNavDataBeeingAdded();
197  void PrepareNavMeshRemovalOfNavDataBeeingRemoved();
198  void RemoveNavMeshOfNavDataBeeingRemoved();
199 
200  void ComputeCellNextActiveNessStatus(QueryProcessMode queryProcessMode);
201  void UpdateStitchOneToOneAndLaunchRuntimeStitchQueries(QueryProcessMode queryProcessMode);
202  void UpdateActiveData();
203 
204  void PrepareAbstractGraphInsertionOfNavDataBeeingAdded();
205  void InsertAbstractGraphOfNavDataBeeingAdded();
206  void RemoveAbstractGraphOfNavDataBeeingRemoved();
207 
208  void ForceSendAllDynamicFloorsAtCellPos(VisualDebugServer &visualDebugServer);
209 
210  enum CompatibilityStatus
211  {
212  Compatibility_Untested,
213  Compatibility_Error,
214  Compatibility_Success,
215  };
216  CompatibilityStatus IsCompatibleWith(const NavData& navData, const TrackedCollection<Ptr<NavData>, MemStat_WorldFwk>& navDataCollection) const;
217 
218 public: // internal
219  KyUInt32 m_navdataChangeIdx; // 0 in an invalid Value
220  KyUInt32 m_frameIdx; // mainly to be accessed by queries to check if consecutive calls to Advance occur during the same frame
221  CellBox m_lastUpdateBox;
222 
223  DatabasePositionSpatializationRange m_positionSpatializationRange;
224  DatabaseGenMetrics m_generationMetrics;
225 
226  ActiveData* m_activeData;
227  NavCellGrid* m_navCellGrid;
228  NavMeshElementManager* m_navMeshElementManager;
229  NavGraphManager* m_navGraphManager;
230  AbstractGraphCellGrid* m_abstractGraphCellGrid;
231  WorkingMemory* m_workingMemory;
232 
233  TrackedCollection<Ptr<Bot>, MemStat_WorldFwk> m_bots;
234 
235  TrackedCollection<Ptr<ITriangleCostMap>, MemStat_WorldFwk> m_triangleCostMaps;
236 
237  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataToBeAdded;
238  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataBeeingAdded;
239  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDatas;
240  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataToBeRemoved;
241  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataBeeingRemoved;
242 
243  Ptr<IDatabaseChangeBroadcaster> m_eventBroadCaster;
244 
245  DatabaseGeometryBuildingManager m_geometryBuildingManager;
246 
249 
250 private:
251  PerformQueryStatistics* m_queryStatistics;
253  KyUInt32 m_databaseIndex; // Index of the Database in the world, set once and for all in the constructor
254 
255  // internal for update
256  CellBox m_currentNavMeshUpdateCellBox;
257  CellBox m_currentNavGraphUpdateCellBox;
258  CellBox m_currentAbstractGraphUpdateCellBox;
259  KyUInt32 m_navDataWithNavMeshElementCount;
260  KyUInt32 m_navDataWithAbstractGraphCount;
261 };
262 
263 KY_INLINE bool Database::IsClear() const { return m_generationMetrics.IsClear(); }
264 KY_INLINE KyUInt32 Database::GetDatabaseIndex() const { return m_databaseIndex; }
265 KY_INLINE KyUInt32 Database::GetBotsCount() const { return m_bots.GetCount(); }
266 KY_INLINE Bot* Database::GetBot(KyUInt32 index) const { return m_bots[index]; }
267 KY_INLINE WorkingMemory* Database::GetWorkingMemory() const { return m_workingMemory; }
268 KY_INLINE ActiveData* Database::GetActiveData() const { return m_activeData; }
269 KY_INLINE const CellBox& Database::GetLastUpdateCellBox() const { return m_lastUpdateBox; }
270 KY_INLINE bool Database::HasChangedLastFrame() const { return m_lastUpdateBox.IsValid(); }
272 KY_INLINE bool Database::IsThereNavDataToBeAddedOrRemoved() const { return m_navDataToBeAdded.GetCount() + m_navDataToBeRemoved.GetCount() != 0; }
273 KY_INLINE bool Database::IsDatabaseUpdatingNavData() const { return m_navDataBeeingAdded.GetCount() + m_navDataBeeingRemoved.GetCount() != 0; }
274 KY_INLINE KyUInt32 Database::GetAliveNavDataCount() const { return m_navDatas.GetCount() + m_navDataToBeRemoved.GetCount() + m_navDataBeeingRemoved.GetCount(); }
275 
276 KY_INLINE DatabaseGeometryBuildingManager& Database::GetDatabaseGeometryBuildingManager() { return m_geometryBuildingManager; }
277 KY_INLINE const DatabaseGenMetrics& Database::GetDatabaseGenMetrics() const { return m_generationMetrics; }
278 KY_INLINE const DatabasePositionSpatializationRange& Database::GetDatabasePositionSpatializationRange() const { return m_positionSpatializationRange; }
279 KY_INLINE DatabasePositionSpatializationRange& Database::GetDatabasePositionSpatializationRange() { return m_positionSpatializationRange; }
280 KY_INLINE const PositionSpatializationRange& Database::GetPositionSpatializationRange() const { return m_positionSpatializationRange.GetPositionSpatializationRange(); }
281 
282 KY_INLINE IVisualGeometry* Database::GetVisualGeometry() const { return m_geometryBuildingManager.GetVisualGeometry(); }
283 
284 KY_INLINE void Database::SetVisualGeometryFactory(Ptr<IVisualGeometryFactory> factory) { GetDatabaseGeometryBuildingManager().SetVisualGeometryFactory(factory); }
285 KY_INLINE void Database::SetVisualGeometry(Ptr<IVisualGeometry> geometry) { GetDatabaseGeometryBuildingManager().SetVisualGeometry(geometry); }
286 KY_INLINE void Database::IncrementNavDataChangeIndex() { m_navdataChangeIdx = m_navdataChangeIdx != KyUInt32MAXVAL ? m_navdataChangeIdx + 1 : 1; }
287 
288 KY_INLINE void Database::BuildVisualGeometry(bool forceRebuildAll) { m_geometryBuildingManager.BuildGeometry(forceRebuildAll); }
290 KY_INLINE KyUInt32 Database::GetRayCanGoMarginInt(RayCanGoMarginMode rayCanGoMarginMode)
291 {
292  static const KyUInt32 marginValues[RayCanGoMarginModeCount] = { // PixelSize | 5 cm | 10 cm | 20 cm | 30 cm
293  0, // UInt32 value for NoMargin. // ------------+------+-------+-------+-------
294  10, // UInt32 value for DiagonalStripMargin // value in cm | | | | // Just a bit less than ChannelMargin
295  15, // UInt32 value for ChannelMargin // value in cm | | | | // Very small to prevent polygon shrinking errors
296  45, // UInt32 value for PathMargin. // value in cm | 1.76 | 3.52 | 7.03 | 10.55
297  35, // UInt32 value for IdealTrajectoryMargin. // value in cm | 1.37 | 2.73 | 5.47 | 8.20
298  30, // UInt32 value for MinimalTrajectoryMargin. // value in cm | 1.17 | 2.34 | 4.69 | 7.03
299  10 // UInt32 value for MoveOnNavMeshMargin. // value in cm | 0.39 | 0.78 | 1.56 | 2.34
300  };
301  return marginValues[rayCanGoMarginMode];
302 }
303 
304 KY_INLINE KyFloat32 Database::GetRayCanGoMarginFloat(RayCanGoMarginMode rayCanGoMarginMode)
305 {
306  return GetRayCanGoMarginInt(rayCanGoMarginMode) * GetDatabaseGenMetrics().m_integerPrecision;
307 }
308 
309 KY_INLINE PerformQueryStatistics* Database::GetPerformQueryStatistics() { return m_queryStatistics; }
311 } // namespace Kaim
312 
313 #endif // Navigation_Database_H
Margin to be used when computing the DiagonalStrip used for Channel computation.
Definition: database.h:44
void SetVisualGeometryFactory(Ptr< IVisualGeometryFactory > factory)
Sets the instance of IVisualGeometryFactory that will be used by the DatabaseGeometryBuildingManager ...
Definition: database.h:309
PerformQueryStatistics * GetPerformQueryStatistics()
Return statistics on queries called on this Database.
Definition: database.h:334
NavCellGrid * m_navCellGrid
bookeeping, stitching, spatialization, NavCells version management, ...
Definition: database.h:251
const DatabaseGenMetrics & GetDatabaseGenMetrics() const
Retrieves the DatabaseGenMetrics, which offers services for converting between floating-point coordin...
Definition: database.h:302
Collection< Ptr< BaseBlobHandler > > m_visualDebugBlobCollection
(VisualDebug) store the blob ot be send during the DoSendVisualDebug call.
Definition: database.h:272
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
bool m_needToSendActiveNavData
(VisualDebug) Avoids sending all the active NavData each frame. Accessed by the NavCellGrid.
Definition: database.h:271
DatabaseGeometryBuildingManager & GetDatabaseGeometryBuildingManager()
Retrieves the instance of the DatabaseGeometryBuildingManager maintained by this object, which manage the tiling of DatabaseVisualGeometryBuilder.
Definition: database.h:301
bool IsClear() const
Returns true if the Database is not associated to any set of generation parameters.
Definition: database.h:288
Collection is a class which is a "Collection" of elements (not sorted, not unique) ...
Definition: collection.h:32
KyUInt32 GetDatabaseIndex() const
Retrieves the index of the Database in the array of Databases maintained by the World.
Definition: database.h:289
ActiveData * m_activeData
all the data that are active
Definition: database.h:250
WorkingMemory * GetWorkingMemory() const
The WorkingMemory used by default by Queries when processed outside a QueryQueue. You should not need...
Definition: database.h:292
void RemoveAllNavData()
Remove all the NavData from this Database.
DatabaseGenMetrics m_generationMetrics
generation parameters. Set by the NavMeshElementManager. Do Not Modify
Definition: database.h:248
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Margin to be used in any path computation ray can go queries to ensure the computed Path is not too c...
Definition: database.h:46
NavGraphManager * m_navGraphManager
NavGraph container.
Definition: database.h:253
Margin to be used in MoveOnNavMesh or any other actual movement computation.
Definition: database.h:49
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
RayCanGoMarginMode
Defines the different mode for the NavMesh border margin to be used in RayCanGo queries.
Definition: database.h:41
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:15
IVisualGeometry * GetVisualGeometry() const
Retrieves the instance of IVisualGeometry to which this object sends its triangles for rendering set ...
Definition: database.h:307
Definition: gamekitcrowddispersion.h:20
Margin to be used to get ray can go exactly on the NavMesh borders.
Definition: database.h:43
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
KyFloat32 m_integerPrecision
For internal use. Do not modify.
Definition: databasegenmetrics.h:182
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
const CellBox & GetLastUpdateCellBox() const
Returns a CellBox covering all NavData that has been changed on last World::Update().
Definition: database.h:294
Margin to be used in any path following ray can go queries to ensure the computed trajectory is not t...
Definition: database.h:47
void SetVisualGeometry(Ptr< IVisualGeometry > geometry)
Sets the instance of IVisualGeometry to which this object will send its triangles for rendering when ...
Definition: database.h:310
This class is not instantiated in databases when KY_BUILD_SHIPPING is defined It contains statistics ...
Definition: querystatistics.h:57
void Clear()
internal, use World::ClearDatabase(KyUInt32 databaseIndex). RemoveAll navData, bots, clear memory of cell grid, activeData and GenerationMetrics
NavMeshElementManager * m_navMeshElementManager
NavMesh container + GUID manager/sorter.
Definition: database.h:252
bool IsValid() const
Indicates whether or not the extents of the bounding box are valid.
Definition: box2i.h:154
bool IsCompatibleWith(const NavData &navData) const
Indicates whether or not the specified NavData object was created with the same generation parameters...
bool HasChangedLastFrame() const
Returns true when something has changed on last World::Update().
Definition: database.h:295
Margin to be used for Channel computation.
Definition: database.h:45
Margin to be used only to reevaluate a trajectory previously validated with can go using IdealTraject...
Definition: database.h:48
#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
void BuildVisualGeometry(bool forceRebuildAll=false)
Sends to the IVisualGeometry or to the IVisualGeometry of the DatabaseGeometryBuildingManager (depend...
Definition: database.h:313