gwnavruntime/database/database.h Source File

database.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 #pragma once
8 
19 
20 namespace Kaim
21 {
22 
23 class AbstractGraphCellGrid;
24 class NavMeshGenParameters;
25 class NavMeshElementManager;
26 class NavGraphManager;
27 class ITriangleCostMap;
28 class WorkingMemory;
29 class ActiveData;
30 class NavCellGrid;
31 class NavData;
32 class Bot;
33 class DisplayListManager;
34 class PerformQueryStatistics;
35 
38 {
39  NoMargin = 0,
46 
47  RayCanGoMarginModeCount // internal
48 };
49 
57 class Database : public WorldElement
58 {
59  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_WorldFwk)
61 
62 public:
63  static WorldElementType GetStaticType() { return TypeDatabase; }
64  virtual WorldElementType GetType() const { return TypeDatabase; }
65  virtual const char* GetTypeName() const { return "Database"; }
66 
67  // ------------------------------ Functions -----------------------------
68 
70  KyUInt32 GetDatabaseIndex() const { return m_databaseIndex; }
71 
75 
76  DatabasePositionSpatializationRange& GetDatabasePositionSpatializationRange() { return m_positionSpatializationRange; }
77  const DatabasePositionSpatializationRange& GetDatabasePositionSpatializationRange() const { return m_positionSpatializationRange; }
78  const PositionSpatializationRange& GetPositionSpatializationRange() const { return m_positionSpatializationRange.GetPositionSpatializationRange(); }
79 
80  KyResult SetSpatializationRange(KyFloat32 abovePosition, KyFloat32 belowPosition) { return m_positionSpatializationRange.SetSpatializationRange(abovePosition, belowPosition); }
81 
86  bool IsClear() const { return m_generationMetrics.IsClear(); }
87 
90  bool IsCompatibleWith(const NavData& navData) const;
91 
95  KyUInt32 GetAliveNavDataCount() const { return m_navDatas.GetCount() + m_navDataToBeRemoved.GetCount() + m_navDataBeeingRemoved.GetCount(); }
96 
97  void RemoveAllBots();
98 
99  KyUInt32 GetBotsCount() const { return m_bots.GetCount(); }
100  Bot* GetBot(KyUInt32 index) const { return m_bots[index]; }
101 
103  // to access this explicitly except for modifying the memory size limit of this WorkingMemory.
104  WorkingMemory* GetWorkingMemory() const { return m_workingMemory; }
105 
108 
110  VisualDebugServer* GetVisualDebugServer() const;
111 
112  // Get changes in database that happened since last call to ResetLastChanges()
113  // To track Database changes, you may use AddChangeListener() instead.
114  const DatabaseChange& GetChangesSinceLastReset() const { return m_lastChange; }
115  void ResetLastChanges() { return m_lastChange.ClearChange(); }
116 
117  void AddChangeListener(const Ptr<IDatabaseChangeListener>& changeListener) { m_databaseChangeListeners.PushBackUnique(changeListener); }
118  void RemoveChangeListener(const Ptr<IDatabaseChangeListener>& changeListener) { m_databaseChangeListeners.RemoveFirstOccurrence(changeListener); }
119 
120 public: // internal
121  Database(World* world, KyUInt32 databaseIndex);
122  virtual ~Database();
123 
124  void Clear();
125 
126  virtual void DoSendVisualDebug(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent);
127 
129  PerformQueryStatistics* GetPerformQueryStatistics() { return m_queryStatistics; }
130 
131  void SetEventBroadcaster(IDatabaseChangeBroadcaster* eventBroadCaster);
132  void UpdateImmediate();
133 
134  // ---------------------------------- Internally used by the NavigationLab for Database Visual Representation ----------------------------------
140 
143  void SetVisualGeometryFactory(Ptr<IVisualGeometryFactory> factory) { GetDatabaseGeometryBuildingManager().SetVisualGeometryFactory(factory); }
144 
147  void SetVisualGeometry(Ptr<IVisualGeometry> geometry) { GetDatabaseGeometryBuildingManager().SetVisualGeometry(geometry); }
148 
151  void BuildVisualGeometry(bool forceRebuildAll = false) { m_geometryBuildingManager.BuildGeometry(forceRebuildAll); }
152 
154  // by this object for rendering. By default, navMesh, navGraph and abstractGraph are built. It can be changed
156  void BuildVisualGeometry(Ptr<IVisualGeometry> geometry, const DatabaseVisualGeometryBuilderConfig& config = DatabaseVisualGeometryBuilderConfig());
157 
160  DatabaseGeometryBuildingManager& GetDatabaseGeometryBuildingManager() { return m_geometryBuildingManager; }
161 
164  IVisualGeometry* GetVisualGeometry() const { return m_geometryBuildingManager.GetVisualGeometry(); }
165 
166  IVisualGeometryFactory* GetVisualGeometryFactory() const { return m_geometryBuildingManager.GetVisualGeometryFactory(); }
167 
168  // ---------------------------------- Called by various components, World, Queries ----------------------------------
169 
170  ActiveData* GetActiveData() const { return m_activeData; }
171 
172  void RecomputeAllTriangleCostMapInBox(const CellBox& cellBox);
173 
174  // AddRemoveNavData Update phase
175  void StartNavDataAddRemoveUpdate(QueryProcessMode processMode);
176  bool IsThereNavDataAddRemovePending() const { return m_navDataToBeAdded.GetCount() + m_navDataToBeRemoved.GetCount() != 0; } // called by World::Update
177  bool IsDoingNavDataAddRemoveUpdate() const { return m_navDataBeeingAdded.GetCount() + m_navDataBeeingRemoved.GetCount() != 0; } // called by World::Update
178  void FinalizeNavDataAddRemoveUpdate(); // called by World::Update
179 
180  // TagVolumeIntegration Update phase
181  void FinalizeTagVolumeIntegrationUpdate(const CellBox& tagVolumeChangeCellBox);
182 
183  void UpdateBotsPathFollowing(KyFloat32 simulationTimeInSeconds); // call by World::Update
184  void UpdateBotsGenMetrics();
185 
186  KyUInt32 GetRayCanGoMarginInt(RayCanGoMarginMode marginMode);
187  KyFloat32 GetRayCanGoMarginFloat(RayCanGoMarginMode marginMode) { return GetRayCanGoMarginInt(marginMode) * GetDatabaseGenMetrics().m_integerPrecision; }
188 
189  void SetupGenerationMetrics(const NavMeshGenParameters& navMeshGenParameters); // called by internal members
190 
191  KyUInt32 GetActiveNavMeshChangeIdx() const { return m_activeChangeIdx.m_navMeshChangeIdx; }
192  KyUInt32 GetActiveNavGraphChangeIdx() const { return m_activeChangeIdx.m_navGraphChangeIdx; }
193  KyUInt32 GetActiveAbstractGraphChangeIdx() const { return m_activeChangeIdx.m_abstractGraphChangeIdx; }
194  KyUInt32 GetActiveDatabaseChangeIdx() const { return m_activeChangeIdx.m_anyChangeIdx; }
195 
196 private:
197  friend class DatabaseUpdateManager;
198  friend class NavMeshElementManager;
199 
200  void IncrementNavDataChangeIndex();
201 
202  // AddRemoveNavData Update phase
203  void TakeSnapShotOfNavDataAddRemoveToUpdate(); // in StartNavDataAddRemoveUpdate()
204  void ClearSnapShotOfNavDataAddRemoveToUpdate(); // in FinalizeNavDataAddRemoveUpdate()
205 
206  bool AreNavGraphsBeeingAdded(); // in StartNavDataAddRemoveUpdate()
207  void RemoveNavGraphsOfNavDataBeeingRemoved(); // in FinalizeNavDataAddRemoveUpdate()
208  void AddNavGraphsOfNavDataBeeingAdded(); // in FinalizeNavDataAddRemoveUpdate()
209 
210  bool AreAbstractGraphBeeingAdded(); // in StartNavDataAddRemoveUpdate()
211  void StartAbstractGraphInsertionOfNavDataBeeingAdded(); // in StartNavDataAddRemoveUpdate()
212  void InsertAbstractGraphOfNavDataBeeingAdded(); // in FinalizeNavDataAddRemoveUpdate()
213  void RemoveAbstractGraphOfNavDataBeeingRemoved(); // in FinalizeNavDataAddRemoveUpdate()
214 
215  void StartNavMeshInsertionOfNavDataBeeingAdded(); // in StartNavDataAddRemoveUpdate()
216  void StartNavMeshRemovalOfNavDataBeeingRemoved(); // in StartNavDataAddRemoveUpdate()
217  void RemoveNavMeshOfNavDataBeeingRemoved(); // in FinalizeNavDataAddRemoveUpdate()
218 
219  void ComputeCellNextActivenessStatus(QueryProcessMode queryProcessMode);
220  void UpdateStitchOneToOneAndLaunchRuntimeStitchQueries(QueryProcessMode queryProcessMode);
221 
222  void ForceSendAllDynamicFloorsAtCellPos(VisualDebugServer &visualDebugServer);
223 
224  void FinalizeChange();
225 
226  enum CompatibilityStatus
227  {
228  Compatibility_Untested,
229  Compatibility_Error,
230  Compatibility_Success,
231  };
232  CompatibilityStatus IsCompatibleWith(const NavData& navData, const TrackedCollection<Ptr<NavData>, MemStat_WorldFwk>& navDataCollection) const;
233 
234 public: // internal
235  KyUInt32 m_frameIdx; // mainly to be accessed by queries to check if consecutive calls to Advance occur during the same frame
236 
237  DatabasePositionSpatializationRange m_positionSpatializationRange;
239 
243  NavGraphManager* m_navGraphManager;
244  AbstractGraphCellGrid* m_abstractGraphCellGrid;
245  WorkingMemory* m_workingMemory;
246 
247  TrackedCollection<Ptr<Bot>, MemStat_WorldFwk> m_bots;
248 
249  TrackedCollection<Ptr<ITriangleCostMap>, MemStat_WorldFwk> m_triangleCostMaps;
250 
251  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataToBeAdded;
252  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataBeeingAdded;
253  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDatas;
254  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataToBeRemoved;
255  TrackedCollection<Ptr<NavData>, MemStat_WorldFwk> m_navDataBeeingRemoved;
256 
257  Ptr<IDatabaseChangeBroadcaster> m_eventBroadCaster;
258 
259  DatabaseGeometryBuildingManager m_geometryBuildingManager;
260 
263 
264  PerformQueryStatistics* m_queryStatistics;
265 
266  KyUInt32 m_databaseIndex; // Index of the Database in the world, set once and for all in the constructor
267 
268  // DatabaseChange management
269  DatabaseChangeInProgress m_changeInProgress; // changes being done in the current update phase
270  DatabaseChangeIdx m_activeChangeIdx; // changeIdx of the active data in the database
271  DatabaseChange m_lastChange; // aggregated changes since last call to ResetLastChanges();
272  Collection<Ptr<IDatabaseChangeListener> > m_databaseChangeListeners;
273 };
274 
275 KY_INLINE KyUInt32 Database::GetRayCanGoMarginInt(RayCanGoMarginMode rayCanGoMarginMode)
276 {
277  static const KyUInt32 marginValues[RayCanGoMarginModeCount] = { // PixelSize | 5 cm | 10 cm | 20 cm | 30 cm
278  0, // UInt32 value for NoMargin. // ------------+------+-------+-------+-------
279  10, // UInt32 value for DiagonalStripMargin // value in cm | | | | // Just a bit less than ChannelMargin
280  15, // UInt32 value for ChannelMargin // value in cm | | | | // Very small to prevent polygon shrinking errors
281  45, // UInt32 value for PathMargin. // value in cm | 1.76 | 3.52 | 7.03 | 10.55
282  35, // UInt32 value for IdealTrajectoryMargin. // value in cm | 1.37 | 2.73 | 5.47 | 8.20
283  30, // UInt32 value for MinimalTrajectoryMargin. // value in cm | 1.17 | 2.34 | 4.69 | 7.03
284  10 // UInt32 value for MoveOnNavMeshMargin. // value in cm | 0.39 | 0.78 | 1.56 | 2.34
285  };
286  return marginValues[rayCanGoMarginMode];
287 }
288 
289 } // namespace Kaim
290 
void RemoveAllNavDataImmediate()
Remove all the NavData from this Database.
Definition: database.cpp:581
Margin to be used when computing the DiagonalStrip used for Channel computation.
Definition: database.h:40
void SetVisualGeometryFactory(Ptr< IVisualGeometryFactory > factory)
If a IVisualGeometryFactory is provided with SetVisualGeometryFactory(), the database will use a grid...
Definition: database.h:143
NavCellGrid * m_navCellGrid
bookkeeping, stitching, spatialization, NavCells version management, ...
Definition: database.h:241
Collection< Ptr< BaseBlobHandler > > m_visualDebugBlobCollection
(VisualDebug) store the blob to be send during the DoSendVisualDebug call.
Definition: database.h:262
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:375
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
bool m_needToSendActiveNavData
(VisualDebug) Avoids sending all the active NavData each frame. Accessed by the NavCellGrid.
Definition: database.h:261
bool IsClear() const
Returns true if the Database is not associated to any set of generation parameters.
Definition: database.h:86
PerformQueryStatistics * GetPerformQueryStatistics()
Return statistics on queries called on this Database.
Definition: database.h:129
This class gathers all the navigation data that are currently active in a Database.
Definition: activedata.h:22
Collection is a class which is a "Collection" of elements (not sorted, not unique) ...
Definition: collection.h:31
KyUInt32 GetDatabaseIndex() const
Retrieves the index of the Database in the array of Databases maintained by the World.
Definition: database.h:70
DatabaseGeometryBuildingManager & GetDatabaseGeometryBuildingManager()
Retrieves the instance of the DatabaseGeometryBuildingManager maintained by this object, which manage the tiling of DatabaseVisualGeometryBuilder.
Definition: database.h:160
ActiveData * m_activeData
all the data that are active
Definition: database.h:240
IVisualGeometryFactory is an abstract base class for an object that accepts that can instantiate obje...
Definition: ivisualgeometry.h:105
TrackedCollection is a class which is a "Collection" of T=C* or T = Ptr< c="" /> (not sorted...
Definition: collection.h:77
DatabaseGenMetrics m_generationMetrics
generation parameters. Set by the NavMeshElementManager. Do Not Modify
Definition: database.h:238
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
Margin to be used in any path computation ray can go queries to ensure the computed Path is not too c...
Definition: database.h:42
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
NavGraphManager * m_navGraphManager
NavGraph container.
Definition: database.h:243
DisplayListManager * GetDisplayListManager() const
Get the DisplayListManager that is required when creating a DisplayList.
Definition: database.cpp:95
Margin to be used in MoveOnNavMesh or any other actual movement computation.
Definition: database.h:45
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:39
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
VisualDebugServer * GetVisualDebugServer() const
Get the VisualDebugServer.
Definition: database.cpp:100
RayCanGoMarginMode
Defines the different mode for the NavMesh border margin to be used in RayCanGo queries.
Definition: database.h:37
Navigation return code class.
Definition: types.h:108
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:41
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Margin to be used to get ray can go exactly on the NavMesh borders.
Definition: database.h:39
WorkingMemory * GetWorkingMemory() const
The WorkingMemory used by default by Queries when processed outside a QueryQueue. You should not need...
Definition: database.h:104
IVisualGeometry * GetVisualGeometry() const
Retrieves the instance of IVisualGeometry to which this object sends its triangles for rendering set ...
Definition: database.h:164
KyFloat32 m_integerPrecision
For internal use. Do not modify.
Definition: databasegenmetrics.h:134
const DatabaseGenMetrics & GetDatabaseGenMetrics() const
Retrieves the DatabaseGenMetrics, which offers services for converting between floating-point coordin...
Definition: database.h:74
Margin to be used in any path following ray can go queries to ensure the computed trajectory is not t...
Definition: database.h:43
void SetVisualGeometry(Ptr< IVisualGeometry > geometry)
Sets the instance of IVisualGeometry to which this object will send its triangles for rendering when ...
Definition: database.h:147
void Clear()
internal, use World::ClearDatabase(KyUInt32 databaseIndex). RemoveAll navData, bots, clear memory of cell grid, activeData and GenerationMetrics
Definition: database.cpp:74
NavMeshElementManager * m_navMeshElementManager
NavMesh container + GUID manager/sorter.
Definition: database.h:242
bool IsCompatibleWith(const NavData &navData) const
Indicates whether or not the specified NavData object was created with the same generation parameters...
Definition: database.cpp:540
Margin to be used for Channel computation.
Definition: database.h:41
Margin to be used only to reevaluate a trajectory previously validated with can go using IdealTraject...
Definition: database.h:44
This class is a runtime container for the all NavMeshElement that are created from the NavMeshElement...
Definition: navmeshelementmanager.h:23
This class gathers a set of generation parameters of one Database and manages the conversion between ...
Definition: databasegenmetrics.h:22
float KyFloat32
float
Definition: types.h:32
This class is an internal class used to manage all the NavCell in a grid.
Definition: navcellgrid.h:60
void BuildVisualGeometry(bool forceRebuildAll=false)
Sends to the IVisualGeometry or to the IVisualGeometry of the DatabaseGeometryBuildingManager (depend...
Definition: database.h:151
IVisualGeometry is an abstract base class that displays Triangles, Lines, and Texts.
Definition: ivisualgeometry.h:76