gwnavruntime/world/world.h Source File

world.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: GUAL - secondary contact: NOBODY
9 #ifndef Navigation_World_H
10 #define Navigation_World_H
11 
15 
19 
27 
28 
29 namespace Kaim
30 {
31 
32 class Database;
33 class DatabaseBinding;
34 class WorldElementSpatializer;
35 class PointOfInterest;
36 class CylinderObstacle;
37 class BoxObstacle;
38 class TagVolume;
39 class LivePath;
40 class FileOpenerBase;
41 class BotConfig;
42 class Trajectory;
43 class IAvoidanceComputer;
44 class QueryQueueArray;
45 class QueryQueue;
46 class AsyncQueryDispatcher;
47 class DatabaseUpdateManager;
48 class VisualDebugAttributesManager;
49 class BaseNavigationProfile;
50 
51 
54 class World : public RefCountBaseNTS<World, MemStat_WorldFwk>
55 {
57 
58 public:
59  // ---------------------------------- Main API Functions ----------------------------------
60 
62  explicit World(KyUInt32 databaseCount = 1);
63  virtual ~World();
64 
65  void SetUserData(void* userData);
66  void* GetUserData();
67 
68  // ---------------------------------- Update ----------------------------------
69 
75  void Update(KyFloat32 simulationTimeInSeconds = 0.016f);
76 
78  KyUInt32 GetUpdateCount() const;
79 
82  WorldStatistics* GetWorldStatistics();
83 
84  // ---------------------------------- VisualDebug ----------------------------------
88 
90  KyResult StartVisualDebug(const VisualDebugServerConfig& visualDebugServerConfig);
91  void StopVisualDebug();
92 
93  VisualDebugServer* GetVisualDebugServer();
94 
97  VisualDebugRegistry* GetElementRegistry();
98 
101 
103  VisualDebugAttributesManager* GetAttributesManager();
104 
105 
106  // ---------------------------------- WorldElement Getters ----------------------------------
107 
108  KyUInt32 GetDatabasesCount() const;
109  Database* GetDatabase(KyUInt32 index);
110 
111  KyUInt32 GetPointsOfInterestCount() const;
113 
114  KyUInt32 GetCylinderObstaclesCount() const;
116 
117  KyUInt32 GetBoxObstaclesCount() const;
119 
120  KyUInt32 GetTagVolumesCount() const;
121  KyUInt32 GetTagVolumesToBeIntegratedCount() const;
122  KyUInt32 GetTagVolumesIntegratedCount() const;
123  KyUInt32 GetTagVolumesToBeRemovedCount() const;
127 
128  KyUInt32 GetQueryQueueArraysCount() const;
130 
131  KyUInt32 GetQueryPendingOperationCount() const;
132 
133  // ---------------------------------- NavigationProfile ----------------------------------
134 
137  KyUInt32 AddNavigationProfile(Ptr<BaseNavigationProfile> navigationProfile);
138  Ptr<BaseNavigationProfile> GetNavigationProfile(KyUInt32 profileId);
139 
140  // ---------------------------------- Async Queries ----------------------------------
141 
149  void SetAsyncQueryDispatcher(IAsyncQueryDispatcher* asyncQueryDispatcher);
150 
151  IAsyncQueryDispatcher* GetAsyncQueryDispatcher();
152 
154  void PushAsyncQuery(IQuery* query, AsyncQueryDispatchId asyncQueryDispatchId = AsyncQueryDispatchId_Default, Bot* bot = KY_NULL);
155 
156  void CancelAsyncQuery(IQuery* query);
157 
158  void ProcessQueuesOutsideWorldUpdate();
159 
160  void SetWorldUpdateThreadId(ThreadId threadId);
161  ThreadId GetWorldUpdateThreadId() const;
162 
163 
164  // ---------------------------------- RemoveAll... ----------------------------------
165 
168  void RemoveAndCancellAll();
169 
170  void RemoveAllBots();
171  void RemoveAllPointsOfInterest();
172  void RemoveAllCylinderObstacles();
173  void RemoveAllBoxObstacles();
174  void RemoveAllTagVolumes();
175  // RemoveAllQueryQueueArrays function is not relevant.
176 
177  void ClearDatabase(KyUInt32 databaseIndex);
178 
179 
180  // -------- Specific optimization to the ShortcutTrajectory --------
185 
188 
196 
197 private:
198  // World::Update() steps
199  void FlushCommandsInWorldUpdate();
200  void ProcessQueuesInWorldUpdate();
201  void FlushQueries();
202  void UpdateDatabases();
203  void UpdateSpatializations();
204  void UpdateBotsPathFollowing(KyFloat32 simulationTimeInSeconds);
205  void SendVisualDebugData(KyFloat32 simulationTimeInSeconds);
206  void UpdateStatistics(KyFloat32 worldUpdateMs);
207  void FlushCommandsOutOfWorldUpdate();
208 
209  // World::RemoveAndCancellAll() steps
210  void CancelAllQueriesAndClearCommandsInAllQueryQueueArray();
211  void ClearAllDatabases();
212 
213 public: // internal
214  void* m_userData;
215 
216  // Navigation profiles
217  KyArray<Ptr<BaseNavigationProfile> > m_navigationProfiles;
218 
219  // Update counters
220  KyUInt32 m_updateCount; // counter incremented on each call to Update(), used for timeslicing
221  KyUInt32 m_nbFramesForShortcutTrajectoryPeriodicUpdate; // Update period used specifically with ShortcutTrajectory, cf. SetNumberOfFramesForShortcutTrajectoryPeriodicUpdate
222 
223  // databases
224  KyUInt32 m_databaseCount;
225  KyArray<Ptr<Database>, MemStat_WorldFwk> m_databases;
226  Ptr<DatabaseBinding> m_allDatabaseBinding;
227 
228  // CollisionWorld
229  Ptr<CollisionWorld> m_collisionWorld;
230 
231  // WorldElements
232  TrackedCollection<Ptr<PointOfInterest >, MemStat_PointOfInterest> m_pointsOfInterests;
233  TrackedCollection<Ptr<CylinderObstacle>, MemStat_CylinderObstacle> m_cylinderObstacles;
234  TrackedCollection<Ptr<BoxObstacle >, MemStat_BoxObstacle> m_boxObstacles;
235 
236  TrackedCollection<Ptr<QueryQueueArray> , MemStat_QuerySystem> m_queryQueueArrays;
237 
238  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesToBeIntegrated;
239  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesIntegrated;
240  TrackedCollection<Ptr<TagVolume>, MemStat_TagVolume> m_tagVolumesToBeRemoved;
241 
242  // Spatialization
243  WorldElementSpatializer* m_worldElementSpatializer;
244 
245  // Default Profile and BotConfig
246  Ptr<BaseNavigationProfile> m_defaultNavigationProfile;
247  Ptr<BotConfig> m_defaultPathFollowerConfig;
248 
249  // Visual Debug
250  VisualDebugServerConfig m_visualDebugServerConfig;
251  VisualDebugServer* m_visualDebugServer;
252  bool m_wasConnected; // to detect a connection
253  DisplayListManager* m_displayListManager;
254  VisualDebugRegistry* m_visualDebugRegistry;
255  VisualDebugAttributesManager* m_visualDebugAttributesManager;
256 
257  // WorldStatistics
258  WorldStatistics* m_statistics;
259 
260  DatabaseUpdateManager* m_databaseUpdateManager;
261 
262  // Shared Avoidances workspace
263  AvoidanceWorkspace m_avoidanceWorkspace;
264 
265  // Multi Threading
266  Ptr<IAsyncQueryDispatcher> m_asyncQueryDispatcher;
267  bool m_isInWorldUpdate;
268  ThreadId m_worldUpdateThreadId;
269 };
270 
271 KY_INLINE void World::SetUserData(void* userData) { m_userData = userData; }
272 KY_INLINE void* World::GetUserData() { return m_userData; }
273 
274 KY_INLINE KyUInt32 World::GetUpdateCount() const { return m_updateCount; }
275 KY_INLINE WorldStatistics* World::GetWorldStatistics() { return m_statistics; }
276 
277 KY_INLINE KyUInt32 World::GetDatabasesCount() const { return m_databases.GetCount(); }
278 KY_INLINE Database* World::GetDatabase(KyUInt32 index) { return m_databases[index]; }
279 
280 KY_INLINE KyUInt32 World::GetPointsOfInterestCount() const { return m_pointsOfInterests.GetCount(); }
281 KY_INLINE PointOfInterest* World::GetPointOfInterest(KyUInt32 index) { return m_pointsOfInterests[index]; }
282 
283 KY_INLINE KyUInt32 World::GetCylinderObstaclesCount() const { return m_cylinderObstacles.GetCount(); }
284 KY_INLINE CylinderObstacle* World::GetCylinderObstacle(KyUInt32 index) { return m_cylinderObstacles[index]; }
285 
286 KY_INLINE KyUInt32 World::GetBoxObstaclesCount() const { return m_boxObstacles.GetCount(); }
287 KY_INLINE BoxObstacle* World::GetBoxObstacle(KyUInt32 index) { return m_boxObstacles[index]; }
288 
289 KY_INLINE KyUInt32 World::GetTagVolumesCount() const
290 {
291  return m_tagVolumesToBeIntegrated.GetCount() + m_tagVolumesIntegrated.GetCount() + m_tagVolumesToBeRemoved.GetCount();
292 }
293 KY_INLINE KyUInt32 World::GetTagVolumesToBeIntegratedCount() const { return m_tagVolumesToBeIntegrated.GetCount(); }
294 KY_INLINE KyUInt32 World::GetTagVolumesIntegratedCount() const { return m_tagVolumesIntegrated.GetCount(); }
295 KY_INLINE KyUInt32 World::GetTagVolumesToBeRemovedCount() const { return m_tagVolumesToBeRemoved.GetCount(); }
296 KY_INLINE TagVolume* World::GetTagVolumesToBeIntegrated(KyUInt32 index) { return m_tagVolumesToBeIntegrated[index]; }
297 KY_INLINE TagVolume* World::GetTagVolumesIntegrated(KyUInt32 index) { return m_tagVolumesIntegrated[index]; }
298 KY_INLINE TagVolume* World::GetTagVolumesToBeRemoved(KyUInt32 index) { return m_tagVolumesToBeRemoved[index]; }
299 
300 KY_INLINE KyUInt32 World::GetQueryQueueArraysCount() const { return m_queryQueueArrays.GetCount(); }
301 KY_INLINE QueryQueueArray* World::GetQueryQueueArray(KyUInt32 index) { return m_queryQueueArrays[index]; }
302 
303 KY_INLINE IAsyncQueryDispatcher* World::GetAsyncQueryDispatcher() { return m_asyncQueryDispatcher; }
304 
305 KY_INLINE void World::SetWorldUpdateThreadId(ThreadId threadId) { m_worldUpdateThreadId = threadId; }
306 KY_INLINE ThreadId World::GetWorldUpdateThreadId() const { return m_worldUpdateThreadId; }
307 
308 KY_INLINE KyUInt32 World::GetNumberOfFramesForShortcutTrajectoryPeriodicUpdate() const { return m_nbFramesForShortcutTrajectoryPeriodicUpdate; }
309 KY_INLINE void World::SetNumberOfFramesForShortcutTrajectoryPeriodicUpdate(KyUInt32 numberOfFrames) { m_nbFramesForShortcutTrajectoryPeriodicUpdate = (numberOfFrames == 0 ? 1 : numberOfFrames); }
310 
311 KY_INLINE VisualDebugServer* World::GetVisualDebugServer() { return m_visualDebugServer; }
312 KY_INLINE VisualDebugRegistry* World::GetElementRegistry() { return m_visualDebugRegistry; }
313 KY_INLINE DisplayListManager* World::GetDisplayListManager() { return m_displayListManager; }
314 KY_INLINE VisualDebugAttributesManager* World::GetAttributesManager() { return m_visualDebugAttributesManager; }
315 
316 #ifdef KY_BUILD_SHIPPING
317 KY_INLINE KyResult World::StartVisualDebug(const VisualDebugServerConfig&) { return KY_ERROR; }
318 KY_INLINE void World::StopVisualDebug() {}
319 #endif
321 } // namespace Kaim
322 
323 #endif //Navigation_World_H
AvoidanceWorkspace aggregates at once:
Definition: avoidanceworkspace.h:38
void RemoveAndCancellAll()
Remove all Bots, PointOfInterest, CylinderObstacles, BoxObstacles, TagVolumes, and NavData; and cance...
CylinderObstacles represent dynamic objects of your game engine that prevent your Bots from moving fr...
Definition: cylinderobstacle.h:87
This class is the world element that represent an active character in Gameware Navigation.
Definition: bot.h:150
World(KyUInt32 databaseCount=1)
AsyncQueryDispatchId
Typically there is one QueryQueue for each AsyncQueryDispatchId.
Definition: asyncquerydispatcher.h:23
KyUInt32 AddNavigationProfile(Ptr< BaseNavigationProfile > navigationProfile)
If TraverseLogic of the NavigationProfile has obsolete functions, navigationProfile won't be added an...
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:409
KyUInt32 GetUpdateCount() const
Retrieves the number of times Update() has been called.
Definition: world.h:320
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Database * GetDatabase(KyUInt32 index)
Definition: world.h:324
void SetNumberOfFramesForShortcutTrajectoryPeriodicUpdate(KyUInt32 numberOfFrames)
Set the number of frames between two updates of the PathFollowing for all bots with TrajectoryMode_Sh...
Definition: world.h:355
QueryQueueArray * GetQueryQueueArray(KyUInt32 index)
Definition: world.h:347
QueryQueueArray processes queries in an asynchronous, time-sliced way.
Definition: queryqueuearray.h:38
TagVolume * GetTagVolumesToBeRemoved(KyUInt32 index)
Definition: world.h:344
VisualDebugAttributesManager * GetAttributesManager()
Get the attributesManager that is required when creating an attribute group.
Definition: world.h:360
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:118
#define KY_NULL
Null value.
Definition: types.h:247
TrackedCollection is a class which is a "Collection" of T=C* or T = Ptr< c="" /> (not sorted...
Definition: collection.h:87
KyResult StartVisualDebug(const VisualDebugServerConfig &visualDebugServerConfig)
Starts the visual debug server. You can start it at any time.
void SetAsyncQueryDispatcher(IAsyncQueryDispatcher *asyncQueryDispatcher)
Set a new IAsyncQueryDispatcher instance to be used by this World:
void Update(KyFloat32 simulationTimeInSeconds=0.016f)
Updates the World.
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
This class is a runtime container for Gameware Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:54
TagVolume * GetTagVolumesToBeIntegrated(KyUInt32 index)
Definition: world.h:342
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:108
Configure the VisualDebugServer.
Definition: visualdebugserver.h:48
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
BoxObstacle * GetBoxObstacle(KyUInt32 index)
Definition: world.h:333
Definition: gamekitcrowddispersion.h:20
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
The VisualDebugServer manages the sending of data to clients.
Definition: visualdebugserver.h:254
void PushAsyncQuery(IQuery *query, AsyncQueryDispatchId asyncQueryDispatchId=AsyncQueryDispatchId_Default, Bot *bot=0)
Pushes an IQuery in the right QueryQueue accordingly to World's IAsyncQueryDispatcher.
PointOfInterest * GetPointOfInterest(KyUInt32 index)
Definition: world.h:327
World::PushAsyncQuery(IQuery* query) pushes the Query in the QueryQueue.
Definition: asyncquerydispatcher.h:44
KyUInt32 GetNumberOfFramesForShortcutTrajectoryPeriodicUpdate() const
Gives the number of frames between two updates of the PathFollowing for each bot. ...
Definition: world.h:354
PointOfInterest is a tagged position spatialized into the NavMesh.
Definition: pointofinterest.h:86
DisplayListManager * GetDisplayListManager()
Get the DisplayListManager that is required when creating a ScopedDisplayList.
Definition: world.h:359
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
WorldStatistics * GetWorldStatistics()
Returns statistics on CPU consumption during Update() and its steps.
Definition: world.h:321
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:139
VisualDebugRegistry * GetElementRegistry()
Returns the registry in this World of instances of WorldElement that can be visually debugged in Game...
Definition: world.h:358
TagVolume * GetTagVolumesIntegrated(KyUInt32 index)
Definition: world.h:343
CylinderObstacle * GetCylinderObstacle(KyUInt32 index)
Definition: world.h:330
Abstract class for all queries.
Definition: iquery.h:133
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43