gwnavgamekit/gamekitcrowddispersion.h Source File

gamekitcrowddispersion.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 #pragma once
8 
10 
15 
16 namespace Kaim
17 {
18 
19 class NavGraphBlob;
20 class NavGraphEdgeRawPtr;
21 class TagVolume;
22 class GameKitNavTag;
23 class NavData;
24 class DisplayList;
25 
26 class GameKitCrowdDispersionInput
27 {
28 public:
29  GameKitCrowdDispersionInput() : m_botSpeed(-1.f) {}
30  GameKitCrowdDispersionInput(const Vec3f& botPosition, KyFloat32 botSpeed) : m_botPosition(botPosition), m_botSpeed(botSpeed) {}
31 public:
32  Vec3f m_botPosition;
33  KyFloat32 m_botSpeed;
34 };
35 
36 // Count the number of bots depending on their distance to a position
37 class GameKitCrowdDispersionNavTagInfo : public RefCountBase<GameKitCrowdDispersionNavTagInfo, MemStat_GameKit>
38 {
39  KY_CLASS_WITHOUT_COPY(GameKitCrowdDispersionNavTagInfo)
40 
41 public:
42  GameKitCrowdDispersionNavTagInfo(const Vec3f& position = Vec3f(), KyFloat32 edgeLength = 1.0f, KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
43 
44  KyUInt32 GetSlotIndex(const GameKitCrowdDispersionInput& input);
45 
46  KyFloat32 GetAdditionalCostMultiplier(const GameKitCrowdDispersionInput& input);
47 
48  void Register(const GameKitCrowdDispersionInput& input);
49 
50  void Unregister(const GameKitCrowdDispersionInput& input);
51 
52  KyUInt32 GetSlotCount() const { return m_botCountInSlots.GetCount(); }
53 
54  KyFloat32 GetFirstArrivalTime() const { return m_firstArrivalTime; }
55  KyUInt32 GetBotCountInSlot(KyUInt32 slotIndex) const { return m_botCountInSlots[slotIndex]; }
56  KyUInt32 GetMaxConcurrentBotCount() const { return m_maxConcurrentBotCount; }
57 
58  void SendVisualDebug(DisplayList& displayList, const GameKitCrowdDispersionInput& input);
59 
60 private:
61  KyUInt32 m_maxConcurrentBotCount;
62  Vec3f m_position;
63  KyFloat32 m_smartObjectLength; // only here to return a cost multiplier instead of a plain cost
64  KyFloat32 m_slotDuration; // should be a distance
65 
66  KyFloat32 m_firstArrivalTime; // gives the arrival time of the first interval (factor of m_slotDuration)
67  CircularArray<KyUInt32> m_botCountInSlots;
68 };
69 
70 
73 {
74 public:
76  GameKitCrowdDispersionNavTagId(const NavTag& navTag);
77  GameKitCrowdDispersionNavTagId(const DynamicNavTag& navTag);
78 
79  bool operator==(const GameKitCrowdDispersionNavTagId& other) const { return m_layerIndex == other.m_layerIndex && m_smartObjectID == other.m_smartObjectID;}
80  bool operator!=(const GameKitCrowdDispersionNavTagId& other) const { return (*this == other) == false;}
81 
82  bool IsValid() const { return *this != GameKitCrowdDispersionNavTagId(); }
83 
84 public:
85  KyUInt32 m_layerIndex;
86  KyUInt32 m_smartObjectID;
87 };
88 
90 class GameKitCrowdDispersionNavTagHashMap : public RefCountBase<GameKitCrowdDispersionNavTagHashMap, MemStat_GameKit>
91 {
92  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_GameKit)
93 
94 public:
95  const Ptr<GameKitCrowdDispersionNavTagInfo> Get(const GameKitCrowdDispersionNavTagId& navTagId) const;
96  Ptr<GameKitCrowdDispersionNavTagInfo> Get(const GameKitCrowdDispersionNavTagId& navTagId);
97  bool Get(const GameKitCrowdDispersionNavTagId& navTagId, Ptr<GameKitCrowdDispersionNavTagInfo>* crowdDispersionNavTag) const;
98 
100  KyResult Add(const TagVolume* tagVolume, Vec3f expectedTraversedPoints[2], KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
101 
103  KyResult Add(const TagVolume* tagVolume, KyFloat32 length, KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
104 
108  KyResult Add(const NavGraphEdgeRawPtr& graphEdge, KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
109 
111  void Add(const NavData* navGraphOnlyNavData, KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
112 
113  KyResult Add(const GameKitCrowdDispersionNavTagId& navTagId, Ptr<GameKitCrowdDispersionNavTagInfo> navTagCrowdDispersion);
114  void Remove(const GameKitCrowdDispersionNavTagId& navTagId);
115 
116  void Clear();
117 
118 public: // internal
119  void Add(const NavGraphBlob* navGraphBlob, KyUInt32 maxConcurrentBotCount = 1, KyFloat32 m_slotDuration = 0.5f);
120 
121  typedef Hash<GameKitCrowdDispersionNavTagId, Ptr<GameKitCrowdDispersionNavTagInfo> >::ConstIterator ConstIterator;
122  ConstIterator Begin() const;
123  ConstIterator End() const;
124 
125 private:
126  Hash<GameKitCrowdDispersionNavTagId, Ptr<GameKitCrowdDispersionNavTagInfo> > m_hash;
127 };
128 
129 }
130 
The NavGraphBlob contains the static data of a NavGraph.
Definition: navgraphblob.h:19
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyResult Add(const TagVolume *tagVolume, Vec3f expectedTraversedPoints[2], KyUInt32 maxConcurrentBotCount=1, KyFloat32 m_slotDuration=0.5f)
Extract id from TagVolume.
Definition: gamekitcrowddispersion.cpp:165
Used to uniquely identify GameKitNavTag, c.f. GameKitNavTag for more information. ...
Definition: gamekitcrowddispersion.h:72
Each instance of this class uniquely identifies a single NavGraphEdge in a NavGraph.
Definition: navgraphedgerawptr.h:26
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
Associate information to push variety into paths found to an id based on GameKitNavTag.
Definition: gamekitcrowddispersion.h:90
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
This class represents runtime-defined volumes with customized NavTag.
Definition: tagvolume.h:119
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:39
Define an interpretation of NavTag specific to GameKit.
Definition: gamekitnavtag.h:21
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16