gwnavruntime/world/world.h Source File

world.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 
13 
17 
25 
26 
27 namespace Kaim
28 {
29 
30 class Database;
31 class DatabaseBinding;
32 class WorldElementSpatializer;
33 class PointOfInterest;
34 class CylinderObstacle;
35 class BoxObstacle;
36 class TagVolume;
37 class LivePath;
38 class FileOpenerBase;
39 class BotConfig;
40 class Trajectory;
41 class IAvoidanceComputer;
42 class QueryQueueArray;
43 class QueryQueue;
44 class AsyncQueryDispatcher;
45 class DatabaseUpdateManager;
46 class VisualDebugAttributesManager;
47 class BaseNavigationProfile;
48 
49 
52 class World : public RefCountBaseNTS<World, MemStat_WorldFwk>
53 {
55 
56 public:
57  // ---------------------------------- Main API Functions ----------------------------------
58 
60  explicit World(KyUInt32 databaseCount = 1);
61  virtual ~World();
62 
63  void SetUserData(void* userData);
64  void* GetUserData();
65 
66  // ---------------------------------- Update ----------------------------------
67 
73  void Update(KyFloat32 simulationTimeInSeconds = 0.016f);
74 
76  KyUInt32 GetUpdateCount() const;
77 
80 #if defined(KY_CONFIG_DEBUG_OR_DEV)
81  WorldStatistics* GetWorldStatistics();
82 #endif
83 
84  // ---------------------------------- VisualDebug ----------------------------------
88 
90  KyResult StartVisualDebug(const VisualDebugServerConfig& visualDebugServerConfig);
91  void StopVisualDebug();
92 
93  void NewVisualDebugFrame(KyUInt32 gameFrameIndex = KyUInt32MAXVAL);
94  VisualDebugServer* GetVisualDebugServer();
95 
98  VisualDebugRegistry* GetElementRegistry();
99 
102 
104  VisualDebugAttributesManager* GetAttributesManager();
105 
106 
107  // ---------------------------------- WorldElement Getters ----------------------------------
108 
109  KyUInt32 GetDatabasesCount() const;
110  Database* GetDatabase(KyUInt32 index);
111 
112  KyUInt32 GetPointsOfInterestCount() const;
114 
115  KyUInt32 GetCylinderObstaclesCount() const;
117 
118  KyUInt32 GetBoxObstaclesCount() const;
120 
121  KyUInt32 GetTagVolumesCount() const;
122  KyUInt32 GetTagVolumesToBeIntegratedCount() const;
123  KyUInt32 GetTagVolumesIntegratedCount() const;
124  KyUInt32 GetTagVolumesToBeRemovedCount() const;
128 
129  KyUInt32 GetQueryQueueArraysCount() const;
131 
132  KyUInt32 GetQueryPendingOperationCount() const;
133 
134  // ---------------------------------- NavigationProfile ----------------------------------
135 
136  KyUInt32 AddNavigationProfile(Ptr<BaseNavigationProfile> navigationProfile);
137  Ptr<BaseNavigationProfile> GetNavigationProfile(KyUInt32 profileId);
138 
139  // ---------------------------------- Async Queries ----------------------------------
140 
148  void SetAsyncQueryDispatcher(IAsyncQueryDispatcher* asyncQueryDispatcher);
149 
150  IAsyncQueryDispatcher* GetAsyncQueryDispatcher();
151 
153  void PushAsyncQuery(IQuery* query, AsyncQueryDispatchId asyncQueryDispatchId = AsyncQueryDispatchId_Default, Bot* bot = nullptr);
154 
156  void CancelAsyncQuery(IQuery* query);
157 
158  void ProcessQueuesOutsideWorldUpdate();
159 
160  void SetWorldUpdateThreadId(ThreadId threadId);
161  ThreadId GetWorldUpdateThreadId() const;
162 
163  // ---------------------------------- RemoveAll... ----------------------------------
164 
167  void RemoveAndCancellAll();
168 
169  void RemoveAllBots();
170  void RemoveAllPointsOfInterest();
171  void RemoveAllCylinderObstacles();
172  void RemoveAllBoxObstacles();
173  void RemoveAllTagVolumes();
174  // RemoveAllQueryQueueArrays function is not relevant.
175 
176  void ClearDatabase(KyUInt32 databaseIndex);
177 
178 
179  // -------- Specific optimization to the ShortcutTrajectory --------
184 
187 
195 
196  // -------- Specific optimization --------
197 
202 
203 private:
204  // World::Update() steps
205  void FlushCommandsInWorldUpdate();
206  void ProcessQueuesInWorldUpdate();
207  void FlushQueries();
208  void UpdateDatabases();
209  void UpdateSpatializations();
210  void UpdateBotsPathFollowing(KyFloat32 simulationTimeInSeconds);
211  void SendVisualDebugData(KyFloat32 simulationTimeInSeconds);
212  void UpdateStatistics(KyFloat32 worldUpdateMs);
213  void FlushCommandsOutOfWorldUpdate();
214 
215  // World::RemoveAndCancellAll() steps
216  void CancelAllQueriesAndClearCommandsInAllQueryQueueArray();
217  void ClearAllDatabases();
218 
219 public: // internal
220  void* m_userData;
221 
222  // Navigation profiles
223  KyArray<Ptr<BaseNavigationProfile> > m_navigationProfiles;
224 
225  // Update counters
226  KyUInt32 m_updateCount; // counter incremented at the very beginning of World::Update(). So it's 1 during the first World::Update().
227  KyUInt32 m_nbFramesForShortcutTrajectoryPeriodicUpdate; // Update period used specifically with ShortcutTrajectory.
228 
229  // databases
230  KyUInt32 m_databaseCount;
231  KyArray<Ptr<Database>, MemStat_WorldFwk> m_databases;
232  Ptr<DatabaseBinding> m_allDatabaseBinding;
233 
234  // CollisionWorld
235  Ptr<CollisionWorld> m_collisionWorld;
236 
237  // WorldElements
238  TrackedCollection<Ptr<PointOfInterest >, MemStat_PointOfInterest> m_pointsOfInterests;
239  TrackedCollection<Ptr<CylinderObstacle>, MemStat_CylinderObstacle> m_cylinderObstacles;
240  TrackedCollection<Ptr<BoxObstacle >, MemStat_BoxObstacle> m_boxObstacles;
241 
242  TrackedCollection<Ptr<QueryQueueArray> , MemStat_QuerySystem> m_queryQueueArrays;
243 
244  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesToBeIntegrated;
245  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesIntegrated;
246  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesToBeRemoved;
247 
248  // Spatialization
249  WorldElementSpatializer* m_worldElementSpatializer;
250 
251  // Default Profile and BotConfig
252  Ptr<BaseNavigationProfile> m_defaultNavigationProfile;
253  Ptr<BotConfig> m_defaultPathFollowerConfig;
254 
255  // Visual Debug
256  VisualDebugServerConfig m_visualDebugServerConfig;
257  VisualDebugServer* m_visualDebugServer;
258  bool m_wasConnected; // to detect a connection
259  DisplayListManager* m_displayListManager;
260  VisualDebugRegistry* m_visualDebugRegistry;
261  VisualDebugAttributesManager* m_visualDebugAttributesManager;
262 
263  // WorldStatistics
264  WorldStatistics* m_statistics;
265 
266  DatabaseUpdateManager* m_databaseUpdateManager;
267 
268  // Shared Avoidances workspace
269  AvoidanceWorkspace m_avoidanceWorkspace;
270 
271  // Multi Threading
272  Ptr<IAsyncQueryDispatcher> m_asyncQueryDispatcher;
273  bool m_isInWorldUpdate;
274  ThreadId m_worldUpdateThreadId;
275 };
276 
277 KY_INLINE void World::SetUserData(void* userData) { m_userData = userData; }
278 KY_INLINE void* World::GetUserData() { return m_userData; }
279 
280 KY_INLINE KyUInt32 World::GetUpdateCount() const { return m_updateCount; }
281 
282 #if defined(KY_CONFIG_DEBUG_OR_DEV)
283 KY_INLINE WorldStatistics* World::GetWorldStatistics() { return m_statistics; }
284 #endif
285 
286 KY_INLINE KyUInt32 World::GetDatabasesCount() const { return m_databases.GetCount(); }
287 KY_INLINE Database* World::GetDatabase(KyUInt32 index) { return m_databases[index]; }
288 
289 KY_INLINE KyUInt32 World::GetPointsOfInterestCount() const { return m_pointsOfInterests.GetCount(); }
290 KY_INLINE PointOfInterest* World::GetPointOfInterest(KyUInt32 index) { return m_pointsOfInterests[index]; }
291 
292 KY_INLINE KyUInt32 World::GetCylinderObstaclesCount() const { return m_cylinderObstacles.GetCount(); }
293 KY_INLINE CylinderObstacle* World::GetCylinderObstacle(KyUInt32 index) { return m_cylinderObstacles[index]; }
294 
295 KY_INLINE KyUInt32 World::GetBoxObstaclesCount() const { return m_boxObstacles.GetCount(); }
296 KY_INLINE BoxObstacle* World::GetBoxObstacle(KyUInt32 index) { return m_boxObstacles[index]; }
297 
298 KY_INLINE KyUInt32 World::GetTagVolumesCount() const
299 {
300  return m_tagVolumesToBeIntegrated.GetCount() + m_tagVolumesIntegrated.GetCount() + m_tagVolumesToBeRemoved.GetCount();
301 }
302 KY_INLINE KyUInt32 World::GetTagVolumesToBeIntegratedCount() const { return m_tagVolumesToBeIntegrated.GetCount(); }
303 KY_INLINE KyUInt32 World::GetTagVolumesIntegratedCount() const { return m_tagVolumesIntegrated.GetCount(); }
304 KY_INLINE KyUInt32 World::GetTagVolumesToBeRemovedCount() const { return m_tagVolumesToBeRemoved.GetCount(); }
305 KY_INLINE TagVolume* World::GetTagVolumesToBeIntegrated(KyUInt32 index) { return m_tagVolumesToBeIntegrated[index]; }
306 KY_INLINE TagVolume* World::GetTagVolumesIntegrated(KyUInt32 index) { return m_tagVolumesIntegrated[index]; }
307 KY_INLINE TagVolume* World::GetTagVolumesToBeRemoved(KyUInt32 index) { return m_tagVolumesToBeRemoved[index]; }
308 
309 KY_INLINE KyUInt32 World::GetQueryQueueArraysCount() const { return m_queryQueueArrays.GetCount(); }
310 KY_INLINE QueryQueueArray* World::GetQueryQueueArray(KyUInt32 index) { return m_queryQueueArrays[index]; }
311 
312 KY_INLINE IAsyncQueryDispatcher* World::GetAsyncQueryDispatcher() { return m_asyncQueryDispatcher; }
313 
314 KY_INLINE void World::SetWorldUpdateThreadId(ThreadId threadId) { m_worldUpdateThreadId = threadId; }
315 KY_INLINE ThreadId World::GetWorldUpdateThreadId() const { return m_worldUpdateThreadId; }
316 
317 KY_INLINE KyUInt32 World::GetNumberOfFramesForShortcutTrajectoryPeriodicUpdate() const { return m_nbFramesForShortcutTrajectoryPeriodicUpdate; }
318 KY_INLINE void World::SetNumberOfFramesForShortcutTrajectoryPeriodicUpdate(KyUInt32 numberOfFrames) { m_nbFramesForShortcutTrajectoryPeriodicUpdate = (numberOfFrames == 0 ? 1 : numberOfFrames); }
319 
320 KY_INLINE void World::NewVisualDebugFrame(KyUInt32 gameFrameIndex) { if (m_visualDebugServer) m_visualDebugServer->NewFrame(gameFrameIndex); }
321 KY_INLINE VisualDebugServer* World::GetVisualDebugServer() { return m_visualDebugServer; }
322 KY_INLINE VisualDebugRegistry* World::GetElementRegistry() { return m_visualDebugRegistry; }
323 KY_INLINE DisplayListManager* World::GetDisplayListManager() { return m_displayListManager; }
324 KY_INLINE VisualDebugAttributesManager* World::GetAttributesManager() { return m_visualDebugAttributesManager; }
325 
326 #ifdef KY_CONFIG_RELEASE
328 KY_INLINE void World::StopVisualDebug() {}
329 #endif
330 
331 } // namespace Kaim
332 
333 
AvoidanceWorkspace aggregates at once:
Definition: avoidanceworkspace.h:34
void RemoveAndCancellAll()
Remove all Bots, PointOfInterest, CylinderObstacles, BoxObstacles, TagVolumes, and NavData; and cance...
Definition: world.cpp:114
CylinderObstacles represent dynamic objects of your game engine that prevent your Bots from moving fr...
Definition: cylinderobstacle.h:76
This class is the world element that represent an active character in Autodesk Navigation.
Definition: bot.h:128
AsyncQueryDispatchId
Typically there is one QueryQueue for each AsyncQueryDispatchId.
Definition: asyncquerydispatcher.h:21
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:375
KyUInt32 GetUpdateCount() const
Retrieves the number of times Update() has been called.
Definition: world.h:280
Database * GetDatabase(KyUInt32 index)
Definition: world.h:287
void SetNumberOfFramesForShortcutTrajectoryPeriodicUpdate(KyUInt32 numberOfFrames)
Set the number of frames between two updates of the PathFollowing for all bots with TrajectoryMode_Sh...
Definition: world.h:318
void PushAsyncQuery(IQuery *query, AsyncQueryDispatchId asyncQueryDispatchId=AsyncQueryDispatchId_Default, Bot *bot=nullptr)
Pushes an IQuery in the right QueryQueue accordingly to World's IAsyncQueryDispatcher.
Definition: world.cpp:437
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
QueryQueueArray * GetQueryQueueArray(KyUInt32 index)
Definition: world.h:310
QueryQueueArray processes queries in an asynchronous, time-sliced way.
Definition: queryqueuearray.h:31
TagVolume * GetTagVolumesToBeRemoved(KyUInt32 index)
Definition: world.h:307
VisualDebugAttributesManager * GetAttributesManager()
Get the attributesManager that is required when creating an attribute group.
Definition: world.h:324
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:162
TrackedCollection is a class which is a "Collection" of T=C* or T = Ptr< c="" /> (not sorted...
Definition: collection.h:77
KyResult StartVisualDebug(const VisualDebugServerConfig &visualDebugServerConfig)
VisualDebugging is only enabled with KY_CONFIG_DEBUG and KY_CONFIG_DEV With KY_CONFIG_RELEASE, functions related to VisualDebugging are replaced by empty inlined functions for convenience, However, it can still be judicious to guard your own code that uses VisualDebugging with a check against KY_CONFIG_RELEASE.
void SetAsyncQueryDispatcher(IAsyncQueryDispatcher *asyncQueryDispatcher)
Set a new IAsyncQueryDispatcher instance to be used by this World:
Definition: world.cpp:424
void Update(KyFloat32 simulationTimeInSeconds=0.016f)
Updates the World.
Definition: world.cpp:152
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
This class is a runtime container for Autodesk Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:52
TagVolume * GetTagVolumesToBeIntegrated(KyUInt32 index)
Definition: world.h:305
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:119
Configure the VisualDebugServer.
Definition: visualdebugserver.h:46
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
void ForceClearWorkingMemory()
Cancel all queries and only free WorkingMemory for all databases and query queues owned by this world...
Definition: world.cpp:126
BoxObstacle * GetBoxObstacle(KyUInt32 index)
Definition: world.h:296
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KY_ERROR
use result == KY_ERROR to test for error
Definition: types.h:132
PointOfInterest * GetPointOfInterest(KyUInt32 index)
Definition: world.h:290
World::PushAsyncQuery(IQuery* query) pushes the Query in the QueryQueue.
Definition: asyncquerydispatcher.h:41
KyUInt32 GetNumberOfFramesForShortcutTrajectoryPeriodicUpdate() const
Theses functions are only useful for bots with ShortcutTrajectory.
Definition: world.h:317
PointOfInterest is a tagged position spatialized into the NavMesh.
Definition: pointofinterest.h:71
DisplayListManager * GetDisplayListManager()
Get the DisplayListManager that is required when creating a DisplayList.
Definition: world.h:323
void CancelAsyncQuery(IQuery *query)
This function should be called only for queries currently in a query queue which can be checked by ca...
Definition: world.cpp:452
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:127
VisualDebugRegistry * GetElementRegistry()
Returns the registry in this World of instances of WorldElement that can be visually debugged in the ...
Definition: world.h:322
TagVolume * GetTagVolumesIntegrated(KyUInt32 index)
Definition: world.h:306
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
CylinderObstacle * GetCylinderObstacle(KyUInt32 index)
Definition: world.h:293
Abstract class for all queries.
Definition: iquery.h:123
float KyFloat32
float
Definition: types.h:32