gwnavruntime/world/asyncquerydispatcher.h Source File

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