gwnavruntime/world/asyncquerydispatcher.h Source File

asyncquerydispatcher.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_AsyncQueryDispatcher_H
10 #define Navigation_AsyncQueryDispatcher_H
11 
12 
15 
16 
17 namespace Kaim
18 {
19 
20 class Bot;
21 
24 {
25  AsyncQueryDispatchId_Default = 0,
26  AsyncQueryDispatchId_PathFinder = 1,
27  AsyncQueryDispatchId_DynamicNavMesh = 2,
28  AsyncQueryDispatchId_PathFollower = 3,
29 
30  AsyncQueryDispatchId_Count
31 };
32 
33 
34 enum AsyncQueryDispatcherType
35 {
36  AsyncQueryDispatcherType_Unknown = 0,
37  AsyncQueryDispatcherType_Default,
38  AsyncQueryDispatcherType_FirstCustom
39 };
40 
43 class IAsyncQueryDispatcher : public RefCountBase<IAsyncQueryDispatcher, MemStat_QuerySystem>
44 {
45 public:
46  IAsyncQueryDispatcher() : m_world(KY_NULL) {}
47 
48  void SetWorld(World* world) { m_world = world; }
49  World* GetWorld() { return m_world; }
50 
51  virtual void AddQueryQueuesToWorld() = 0;
52  virtual void RemoveQueryQueuesFromWorld() = 0;
53 
54  virtual QueryQueue* GetQueue(IQuery* query, AsyncQueryDispatchId asyncQueryDispatchId = AsyncQueryDispatchId_Default, Bot* bot = KY_NULL) = 0;
55 
56  virtual ~IAsyncQueryDispatcher() {}
57 
58 protected:
59  World* m_world;
60 };
61 
62 
63 class AsyncQueryDispatcherInitConfig
64 {
65 public:
66  // By default, only one queryQueue is created in the mainThread
67  AsyncQueryDispatcherInitConfig()
68  : m_createWorkerQueryQueueArray(false)
69  , m_useWorkerQueryQueueByDefault(false)
70  , m_usePathFinderQueryQueue(true)
71  , m_useDynamicNavMeshQueryQueue(true)
72  , m_usePathFollowerQueryQueue(true)
73  {}
74 
75  bool m_createWorkerQueryQueueArray;
76  bool m_useWorkerQueryQueueByDefault;
77 
78  bool m_usePathFinderQueryQueue; // if false create only one queue: m_defaultQueryQueueConfig
79  bool m_useDynamicNavMeshQueryQueue; // if false create only two queues: m_defaultQueryQueueConfig and m_pathFinderQueryQueueConfig
80  bool m_usePathFollowerQueryQueue; // if false create only three queues: m_defaultQueryQueueConfig, m_pathFinderQueryQueueConfig and m_dynamicNavMeshQueryQueueConfig
81 
82  QueryQueueConfig m_defaultQueryQueueConfig; // will be queue[0]
83  QueryQueueConfig m_pathFinderQueryQueueConfig; // will be queue[1]
84  QueryQueueConfig m_dynamicNavMeshQueryQueueConfig; // will be queue[2]
85  QueryQueueConfig m_pathFollowerQueryQueueConfig; // will be queue[3]
86 };
87 
89 class AsyncQueryDispatcher : public IAsyncQueryDispatcher
90 {
91 public:
92  AsyncQueryDispatcher(const AsyncQueryDispatcherInitConfig& initConfig);
93 
94  virtual ~AsyncQueryDispatcher();
95 
96  virtual void AddQueryQueuesToWorld();
97  virtual void RemoveQueryQueuesFromWorld();
98 
99  virtual QueryQueue* GetQueue(IQuery* query, AsyncQueryDispatchId asyncQueryDispatchId = AsyncQueryDispatchId_Default, Bot* bot = KY_NULL);
100 
101  // change on the fly
102  void UseWorker(bool useWorkerQueryQueue) { m_useWorkerQueryQueue = useWorkerQueryQueue; }
103 
104 private:
105  void InitQueryQueueArray(QueryQueueArray* queryQueueArray, QueryQueueArrayProcess queryQueueArrayProcessThread);
106  QueryQueue* GetQueueInArray(QueryQueueArray* queryQueueArray, AsyncQueryDispatchId asyncQueryDispatchId);
107  void RemoveQueryQueuesFromWorldImpl();
108 
109 private:
110  AsyncQueryDispatcherInitConfig m_initConfig;
111  Ptr<QueryQueueArray> m_mainQueryQueueArray;
112  Ptr<QueryQueueArray> m_workerQueryQueueArray;
113  bool m_useWorkerQueryQueue;
114 };
115 
116 
117 } // namespace Kaim
118 
119 #endif
120 
This class is the world element that represent an active character in Gameware Navigation.
Definition: bot.h:150
AsyncQueryDispatchId
Typically there is one QueryQueue for each AsyncQueryDispatchId.
Definition: asyncquerydispatcher.h:23
Default implementation of IAsyncQueryDispatcher.
Definition: asyncquerydispatcher.h:93
QueryQueueArray processes queries in an asynchronous, time-sliced way.
Definition: queryqueuearray.h:38
QueryQueue processes queries in an asynchronous, time-sliced way, within a QueryQueueArray.
Definition: queryqueue.h:79
#define KY_NULL
Null value.
Definition: types.h:247
This class is a runtime container for Gameware Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:54
Definition: gamekitcrowddispersion.h:20
World::PushAsyncQuery(IQuery* query) pushes the Query in the QueryQueue.
Definition: asyncquerydispatcher.h:44
Abstract class for all queries.
Definition: iquery.h:133