gwnavruntime/database/databaseupdatemanager.h Source File

databaseupdatemanager.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 #ifndef Navigation_DatabaseUpdateManager_H
8 #define Navigation_DatabaseUpdateManager_H
9 
16 
17 namespace Kaim
18 {
19 
20 class World;
21 class Database;
22 class TagVolume;
23 
24 class DynamicNavMeshQuery;
25 class MakeNavFloorStitchQuery;
26 class QueryCounterOnDone;
27 typedef Collection<Ptr<TagVolume>, MemStat_NavData> TagVolumeCollection;
28 class NavCell;
29 
30 enum DatabaseUpdateStatus
31 {
32  DatabaseUpdateManagerIdle = 0,
33 
34  UpdatingNavDataInDatabases_ProcessingNavData = 1,
35  UpdatingNavDataInDatabases_WaitingDynamicNavMeshQueries = 2,
36  UpdatingNavDataInDatabases_PerformingStitchOneToOne = 3,
37  UpdatingNavDataInDatabases_WaitingRunTimeStitchQueries = 4,
38  UpdatingNavDataInDatabases_FinalizeNavDataUpdate = 5,
39 
40  UpdatingTagVolumeIntegration_ProcessingTagVolumes = 6,
41  UpdatingTagVolumeIntegration_WaitingDynamicNavMeshQueries = 7,
42  UpdatingTagVolumeIntegration_ProcessingDynNavMeshResults = 8,
43  UpdatingTagVolumeIntegration_WaitingRunTimeStitchQueries = 9,
44  UpdatingTagVolumeIntegration_FinalizeTagVolumeUpdate = 10,
45 
46  CancellingTagVolumeIntegration = 11
47 };
48 
49 class DatabaseUpdateManager
50 {
51  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_DynamicNavMesh)
52 
53 public:
54  explicit DatabaseUpdateManager(World* world);
55  ~DatabaseUpdateManager();
56 
57  void Update();
58 
59  // if you specify a databaseIdx, only this database will be updated
60  void FullNavDataAddRemoveUpdate(KyUInt32 databaseIdx = KyUInt32MAXVAL);
61  void FullTagVolumeIntegrationUpdate();
62 
63  // Warning ! cancels all the asynchronous query and launch them synchronously
64  void ForceUpdateToCompleteSynchronously();
65 
66  // call on World::RemoveAllTagvolumes
67  void CancelTagVolumeIntegrationUpdate();
68 
69  void ToggleDebugRender(bool toggle);
70 
71  bool IsIdle() const;
72  bool IsUpdatingNavData() const;
73  bool IsUpdatingTagVolumeIntegration() const;
74 public:
75  void UpdateFrameIdxInAllDatabases();
76  void PerformNextUpdateStepAccordingToStatus(QueryProcessMode processMode);
77 
78  bool IsThereNavDataToAddedOrRemovedInOneDatabase();
79  void StartNewNavDataUpdateInDatabase(QueryProcessMode processMode);
80  void PerformStitchOneToOne(QueryProcessMode processMode);
81  void FinalizeNavDataAddRemoveUpdate();
82 
83  bool IsThereNewTagVolumesToIntegrateOrDeIntegrate();
84  void StartNewTagVolumeIntegrationUpdate(QueryProcessMode processMode);
85  void CreateDynamicNavMeshQueriesForDatabase(KyUInt32 databaseIdx, QueryProcessMode queryProcessMode);
86  void ProcessDynamicNavMeshQueryResults(QueryProcessMode queryProcessMode);
87  void FinalizeTagVolumeIntegrationUpdate();
88 
89  void Clear();
90 
91  void CreateMakeNavFloorStitchQuery(Database* database, NavCell* navCell, QueryProcessMode queryProcessMode);
92  void CreateDynamicNavMeshQuery(Database* database, NavCell* navCell,
93  const TagVolumeCollection* integratedTagVolumesAtCellPos, const TagVolumeCollection* newTagVolumes, QueryProcessMode queryProcessMode);
94 
95  KyUInt32 GetNumberOfWaitingDynamicNavMeshQueries() const { return m_dynamicNavmeshQueriesInProcess; }
96  KyUInt32 GetNumberOfWaitingRunTimeStitchQueries() const { return m_stitchQueriesInProcess; }
97 
98  void RunSynchronouslyAllNonFinishedQueries();
99 
100  // Call by the database when NavLMesh are added in case of the Database was Empty.
101  bool IsThereWaitingTagVolumesInDatabase(KyUInt32 databaseIdx);
102  void EnlargeCellBoxAccordingToWaitingTagVolumes(KyUInt32 databaseIdx, CellBox& currentNavMeshUpdateCellBox);
103  void SpatializeWaitingTagVolumesInNavCellGrid(KyUInt32 databaseIdx);
104 private:
105  void RenderDisplayLists();
106  void ClearDebugRender();
107 
108  void DebugTagVolumeInUpdateDisplayList();
109 
110  void SnapshotOfTagVolumesToIntegrateAndToRemove();
111  void ComputeCellBoxOfTagvolumeToIntegratePerDatabase();
112  void MarkAllCellsConcernedByTagVolumeIntegrationUpdate(TagVolume* tagVolume);
113  void MarkAllCellsConcernedByUpdateInDatabase(Database* database, const CellBox& tagVolumeCellBox);
114 
115  void PushNewIntegratedTagVolumeInCellBox(TagVolume* tagVolume, Database* database, const CellBox& cellBoxInDatabase);
116  void RemoveDeIntegratedTagVolumeFromCellBox(TagVolume* tagVolume, Database* database, const CellBox& cellBoxInDatabase);
117 
118  void PostProcessIntegratedTagVolumes();
119  void PostProcessDeIntegratedTagVolumes();
120 
121  void CancelAllQueries();
122 
123  void PrintErrorMessageForFaillingDynamicNavMeshQueries();
124 public:
125  World* m_world;
126 
127  DatabaseUpdateStatus m_status;
128 
129  KyArray<CellBox, MemStat_DynamicNavMesh> m_cellBoxOfUpdateInDatabase; // indexed on databaseIdx
130  KyArray<CellBox, MemStat_DynamicNavMesh> m_cellBoxOfTagvolumeToIntegrate; // indexed on databaseIdx
131 
132  KyArray<Collection<Ptr<TagVolume>, MemStat_DynamicNavMesh>, MemStat_DynamicNavMesh> m_waitingTagVolumesPerDatabase; // indexed on databaseIdx
133 
134  KyArray<KyArray<Ptr<DynamicNavMeshQuery>, MemStat_DynamicNavMesh>, MemStat_DynamicNavMesh> m_dynNavMeshQueriesPerDatabase; // indexed on databaseIdx
135  KyArray<KyArray<Ptr<MakeNavFloorStitchQuery>, MemStat_DynamicNavMesh>, MemStat_DynamicNavMesh> m_stitchQueriesPerDatabase; // indexed on databaseIdx
136 
137  AtomicInt<int> m_dynamicNavmeshQueriesInProcess;
138  AtomicInt<int> m_stitchQueriesInProcess;
139 
140  Ptr<QueryCounterOnDone> m_OnDoneForDynamicNavMeshQueries;
141  Ptr<QueryCounterOnDone> m_OnDoneForRunTimeStitchQueries;
142 
143  TagVolumeCollection m_tagVolumesInDeIntegration;
144  TagVolumeCollection m_tagVolumesInIntegration;
145 
146  // for visualDebugManager (debug)
147  bool m_debugDisplayListsEnabled;
148  KyArray<ScopedDisplayList*> m_debugDisplayLists;
149 };
150 
151 KY_INLINE bool DatabaseUpdateManager::IsIdle() const { return m_status == DatabaseUpdateManagerIdle; }
152 KY_INLINE bool DatabaseUpdateManager::IsUpdatingNavData() const
153 {
154  return m_status >= UpdatingNavDataInDatabases_ProcessingNavData && m_status <= UpdatingNavDataInDatabases_FinalizeNavDataUpdate;
155 }
156 
157 KY_INLINE bool DatabaseUpdateManager::IsUpdatingTagVolumeIntegration() const
158 {
159  return m_status >= UpdatingTagVolumeIntegration_ProcessingTagVolumes && m_status <= UpdatingTagVolumeIntegration_FinalizeTagVolumeUpdate;
160 }
161 
162 KY_INLINE bool DatabaseUpdateManager::IsThereWaitingTagVolumesInDatabase(KyUInt32 databaseIdx)
163 {
164  return m_waitingTagVolumesPerDatabase[databaseIdx].GetCount() != 0;
165 }
166 
167 } // namespace Kaim
168 
169 #endif //Navigation_DatabaseUpdateManager_H
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
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
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226