gwnavruntime/spatialization/spatializedpoint.h Source File

spatializedpoint.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: LAPA - secondary contact: JUBA
9 #ifndef Navigation_SpatializedPoint_H
10 #define Navigation_SpatializedPoint_H
11 
12 
17 
18 namespace Kaim
19 {
20 
21 class World;
22 class DatabaseBinding;
23 class Database;
24 class PositionSpatializationRange;
25 class WorldIntegerPos;
26 class NavTrianglePtr;
27 
28 class Bot;
29 class CylinderObstacle;
30 class BoxObstacle;
31 class PointOfInterest;
32 
33 
36 {
37  SpatializedPointObjectType_Undefined = 0,
38  SpatializedPointObjectType_Bot,
39  SpatializedPointObjectType_CylinderObstacle,
40  SpatializedPointObjectType_BoxObstacle,
41  SpatializedPointObjectType_PointOfInterest,
42 
43  SpatializedPointObjectType_Count
44 };
45 
46 enum SpatializationUpdateCoherency
47 {
48  SpatializationUpdateCoherency_Maximum, // The update is conservative, the current floor is favored
49  SpatializationUpdateCoherency_Minimum, // The update won't favor current floor, so it will ease vertical transition
50 };
51 
52 // INTERNAL CLASS: Point spatialization in one Database. The point is either:
53 // - in a NavMesh triangle
54 // - outside any NavData.
55 class PointDbSpatialization
56 {
57  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Spatialization)
58 public:
59  PointDbSpatialization();
60 
61  void Invalidate();
62 
63  KyResult UpdateFromPrevious(Database* database, const PositionSpatializationRange& spatializationRange, const Vec3f& oldPosition, const PointDbSpatialization& oldDbSpatialization,
64  const Vec3f& newPosition, WorldIntegerPos& newPositionInteger);
65 
66  void UpdateFromScratch(Database* database, const PositionSpatializationRange& spatializationRange, const Vec3f& newPosition, const WorldIntegerPos* newPositionInteger = KY_NULL);
67 
68 public:
69  static PositionSpatializationRange GetPositionSpatializationRange(const Database* database, SpatializationUpdateCoherency updateMode, KyFloat32 height = 0.f);
70 
71 public:
72  KyUInt32 m_navDataChangeIdx;
73  NavTriangleRawPtr m_navTriangle;
74 };
75 
76 // INTERNAL CLASS: Point spatialization into all databases defined by a DatabaseBinding.
77 // The position must be maintained by the user of this class.
78 // Note that validity of PointDbSpatialization is the responsibility of the user of this class since it uses NavTriangleRawPtr!
79 class PointSpatialization
80 {
81  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Spatialization)
82  KY_CLASS_WITHOUT_COPY(PointSpatialization)
83 
84 public:
85  PointSpatialization() : m_pointDbSpatialization(KY_NULL) {}
86 
87  void Init(DatabaseBinding* databaseBinding);
88  void Clear();
89 
90  void Invalidate(KyUInt32 index);
91  void InvalidateAllDbSpatializations();
92 
93  NavTrianglePtr GetNavTrianglePtr(Database* database) const;
94 
95 public: // internal
96  // Note that SpatializedPoint does not use this function since SpatializedPoint::UpdateSpatialization also needs to update NavFloors, it is only used by the Bot to lazily update the spatialization out of world update
97  bool UpdateSpatialization(const Vec3f& currentPosition, const PointSpatialization* updatedCurrentSpatialization, const Vec3f& newPosition, SpatializationUpdateCoherency updateMode, KyFloat32 height);
98 
99 private:
100  void CreateDbSpatializationPoints();
101  void DestroyDbSpatializationPoints();
102 
103 public: // internal
104  Ptr<DatabaseBinding> m_databaseBinding;
105  PointDbSpatialization* m_pointDbSpatialization; // array indexed like m_databaseBinding
106 };
107 
109 class SpatializedPointInitConfig
110 {
111 public:
112  // ---------------------------------- Main API Functions ----------------------------------
113 
114  SpatializedPointInitConfig() { SetDefaults(); }
115 
117  void SetDefaults();
118 
119 
120  // ---------------------------------- Initialization ----------------------------------
121 
122  void InitFromBot(Ptr<DatabaseBinding> databaseBinding, Bot* bot, KyFloat32 height);
123  void InitFromCylinderObstacle(Ptr<DatabaseBinding> databaseBinding, CylinderObstacle* cylinderObstacle, KyFloat32 height);
124  void InitFromBoxObstacle(Ptr<DatabaseBinding> databaseBinding, BoxObstacle* boxObstacle, KyUInt32 indexInObject, KyFloat32 height);
125  void InitFromPointOfInterest(Ptr<DatabaseBinding> databaseBinding, PointOfInterest* pointOfInterest, KyFloat32 height);
126 
127 
128  // ---------------------------------- Public Data Members ----------------------------------
129 
133  Ptr<DatabaseBinding> m_databaseBinding;
134 
135  void* m_object;
136  SpatializedPointObjectType m_objectType;
137  KyUInt32 m_indexInObject;
138 
139  KyFloat32 m_height;
140 };
141 
142 
146 class SpatializedPoint: public RefCountBase<SpatializedPoint, MemStat_Spatialization>
147 {
148  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Spatialization)
150 
151 public:
152  // ---------------------------------- Main API Functions ----------------------------------
153 
155  ~SpatializedPoint();
156 
157  void Init(const SpatializedPointInitConfig& initConfig);
158  void Clear();
159  void Invalidate(KyUInt32 boundDatabaseIdx);
160  void InvalidateAllDbSpatializations();
161 
162 
163  // ---------------------------------- Getters ----------------------------------
164 
165  const DatabaseBinding* GetDatabaseBinding() const;
166  KyUInt32 GetDbSpatializationCount() const;
167  PointDbSpatialization& GetDbSpatialization(KyUInt32 boundDatabaseIdx) ;
168  const PointDbSpatialization& GetDbSpatialization(KyUInt32 boundDatabaseIdx) const;
169  const Vec3f& GetPosition() const;
170  KyFloat32 GetHeight() const;
171  void* GetObject() const;
172  SpatializedPointObjectType GetObjectType() const;
173  KyUInt32 GetIndexInObject() const;
174 
175  NavTrianglePtr GetNavTrianglePtr(Database* database) const;
176 
177 
178 public: // internal
179  // Just sets the position. Does not update any spatialization information.
180  void SetPosition(const Vec3f& position);
181 
182  // Just sets the height. Does not update any spatialization information.
183  void SetHeight(KyFloat32 height);
184 
185  // Computes new spatialization of PointDbSpatialization,
186  // and updated NavFloors that contained and now contains the SpatializedPoint.
187  // inputOutputIntermediateSpatialization must have been computed for newPos on the same DatabaseBinding, it will serve both as input spatialization but will also be refreshed if necessary.
188  // Returns Spatialization has changed, i.e. at least one PointDbSpatialization is spatialized differently
189  bool UpdateSpatialization(const Vec3f& newPosition, SpatializationUpdateCoherency updateMode = SpatializationUpdateCoherency_Maximum, PointSpatialization* inputOutputUpdatedSpatialization = KY_NULL);
190 
191  // When a navFloor is deactivated, this function will invalidate all
192  // references to it in this SpatializedPoint.
193  void OnNavFloorDeActivation(NavFloor* navFloor);
194 
195  static const char* GetObjectTypeDescrition(SpatializedPointObjectType objectType);
196 
197  const PointSpatialization& GetPointSpatialization() const;
198 
199 private:
200  Vec3f m_position; // position last time the spatialization was updated, shared by all databases
201  PointSpatialization m_pointSpatialization;
202  void* m_object;
203  SpatializedPointObjectType m_objectType;
204  KyUInt32 m_indexInObject;
205  KyFloat32 m_height;
206  bool m_wasSpatializationInvalidatedOutOfUpdate;
207 };
208 
209 
210 KY_INLINE void SpatializedPointInitConfig::SetDefaults()
211 {
212  m_databaseBinding = KY_NULL;
213  m_object = KY_NULL;
214  m_objectType = SpatializedPointObjectType_Undefined;
215  m_indexInObject = 0;
216 }
217 
218 KY_INLINE PointDbSpatialization::PointDbSpatialization() : m_navDataChangeIdx(KyUInt32MAXVAL) {}
219 
220 KY_INLINE void PointDbSpatialization::Invalidate()
221 {
222  m_navTriangle.Invalidate();
223 }
224 
225 KY_INLINE void SpatializedPointInitConfig::InitFromBot(Ptr<DatabaseBinding> databaseBinding, Bot* bot, KyFloat32 height)
226 {
227  m_databaseBinding = databaseBinding;
228  m_object = bot;
229  m_objectType = SpatializedPointObjectType_Bot;
230  m_indexInObject = 0;
231  m_height = height;
232 }
233 
234 KY_INLINE void SpatializedPointInitConfig::InitFromCylinderObstacle(Ptr<DatabaseBinding> databaseBinding, CylinderObstacle* cylinderObstacle, KyFloat32 height)
235 {
236  m_databaseBinding = databaseBinding;
237  m_object = cylinderObstacle;
238  m_objectType = SpatializedPointObjectType_CylinderObstacle;
239  m_indexInObject = 0;
240  m_height = height;
241 }
242 
243 KY_INLINE void SpatializedPointInitConfig::InitFromBoxObstacle(Ptr<DatabaseBinding> databaseBinding, BoxObstacle* boxObstacle, KyUInt32 indexInObject, KyFloat32 height)
244 {
245  m_databaseBinding = databaseBinding;
246  m_object = boxObstacle;
247  m_objectType = SpatializedPointObjectType_BoxObstacle;
248  m_indexInObject = indexInObject;
249  m_height = height;
250 }
251 
252 KY_INLINE void SpatializedPointInitConfig::InitFromPointOfInterest(Ptr<DatabaseBinding> databaseBinding, PointOfInterest* pointOfInterest, KyFloat32 height)
253 {
254  m_databaseBinding = databaseBinding;
255  m_object = pointOfInterest;
256  m_objectType = SpatializedPointObjectType_PointOfInterest;
257  m_indexInObject = 0;
258  m_height = height;
259 }
260 
261 KY_INLINE SpatializedPoint::SpatializedPoint()
262  : m_object(KY_NULL)
263  , m_objectType(SpatializedPointObjectType_Undefined)
264  , m_indexInObject(0)
265  , m_wasSpatializationInvalidatedOutOfUpdate(true)
266 {}
267 
268 KY_INLINE SpatializedPoint::~SpatializedPoint() { Clear(); }
269 
270 KY_INLINE const DatabaseBinding* SpatializedPoint::GetDatabaseBinding() const { return m_pointSpatialization.m_databaseBinding; }
271 KY_INLINE KyUInt32 SpatializedPoint::GetDbSpatializationCount() const { return m_pointSpatialization.m_databaseBinding->GetBoundDatabaseCount(); }
272 KY_INLINE const Vec3f& SpatializedPoint::GetPosition() const { return m_position; }
273 KY_INLINE KyFloat32 SpatializedPoint::GetHeight() const { return m_height; }
274 KY_INLINE void* SpatializedPoint::GetObject() const { return m_object; }
275 KY_INLINE SpatializedPointObjectType SpatializedPoint::GetObjectType() const { return m_objectType; }
276 KY_INLINE KyUInt32 SpatializedPoint::GetIndexInObject() const { return m_indexInObject; }
277 KY_INLINE PointDbSpatialization& SpatializedPoint::GetDbSpatialization(KyUInt32 boundDatabaseIdx) { return m_pointSpatialization.m_pointDbSpatialization[boundDatabaseIdx]; }
278 KY_INLINE const PointDbSpatialization& SpatializedPoint::GetDbSpatialization(KyUInt32 boundDatabaseIdx) const { return m_pointSpatialization.m_pointDbSpatialization[boundDatabaseIdx]; }
279 
280 KY_INLINE void SpatializedPoint::SetPosition(const Vec3f& position) { m_position = position; }
281 KY_INLINE void SpatializedPoint::SetHeight(KyFloat32 height) { m_height = height; }
282 
283 KY_INLINE const PointSpatialization& SpatializedPoint::GetPointSpatialization() const { return m_pointSpatialization; }
284 
285 
286 } // namespace Kaim
287 
288 #endif // Navigation_SpatializedPoint_H
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
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class is a runtime wrapper of a NavFloorBlob, it gathers all the runtime information associated ...
Definition: navfloor.h:40
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Ptr< DatabaseBinding > m_databaseBinding
Defines the Databases in which the SpatializedPoint will be spatialized.
Definition: spatializedpoint.h:158
Class used to initialize a SpatializedPoint.
Definition: spatializedpoint.h:120
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
DatabaseBinding is a collection of the databases to be used for world elements spatialization.
Definition: databasebinding.h:24
SpatializedPointObjectType
Enumerates the possible object types the SpatializedPoint refers to.
Definition: spatializedpoint.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:22
PointOfInterest is a tagged position spatialized into the NavMesh.
Definition: pointofinterest.h:86
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Internal class used for point spatialization in NavData.
Definition: spatializedpoint.h:171
Each instance of the BoxObstacle class represents a dynamic, physical object in your game engine that...
Definition: boxobstacle.h:139
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23