gwnavruntime/navmesh/itrianglecostmap.h Source File

itrianglecostmap.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: JUBA - secondary contact: GUAL
9 #ifndef Navigation_TriangleCostMap_H
10 #define Navigation_TriangleCostMap_H
11 
12 
22 #include "gwnavruntime/math/box2iiterator.h"
26 
27 namespace Kaim
28 {
29 
30 class ActiveNavFloorCollection;
31 class NavTriangleRawPtr;
32 class TriangleCostInCell;
33 class Box2f;
34 class Database;
35 
36 class ITriangleCostMap : public RefCountBase<ITriangleCostMap, MemStat_CostMap>
37 {
38  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CostMap)
39 public:
40  ITriangleCostMap();
41  virtual ~ITriangleCostMap();
42 
43  // This function is called by the Database each time something changed in the cellBox
44  // covered by the TriangleCostMap (NavData add/remove or dynamicNavmesh).
45  // In Your implementation you have to called one of the InitCostMap function
46  // before calling SetCostMultiplier on each triangle you want to set a custom costmultiplier
47  // \Pre this triangleCostMap must have been bound to a Database first.
48  virtual void Recompute() = 0;
49 
50 protected:
51 
52  // ----- Helper Functions to be called in Recompute
53 
60  template<class CostMultiplierComputer>
61  void InitAndBrowseAllTrianglesInBox3f(CostMultiplierComputer& compute, const Box3f& aabb);
62 
77  template<class CostMultiplierComputer>
78  void InitAndPropagateInTrianglesFromPosInVolume(CostMultiplierComputer& compute, const Box3f& aabb, const Vec3f& inputPosition);
79 
80 public:
81  void BindToDatabase(Database* database);
82  void UnbindFromDatabase();
83  bool IsBindToADatabase() const { return m_database != KY_NULL; }
84 
85  void SetCostMultiplier(const NavTriangleRawPtr& triangle, KyFloat32 costMultiplier);
86  KyFloat32 GetCostMultiplier(const NavTriangleRawPtr& triangle) const;
87 
88  const CellBox& GetCellBox() const { return m_cellBox; }
89 
90 protected:
91  // return true if the data structure is initialized and ready to use
92  // returns false if the costMap was not bind to a database or if there is no triangle to set
93  // a costMultipler to (that can happen if your box in outside the data !)
94  bool InitCostMapForBox3f(const Box3f& aabb);
95 
96  // test if the navFloor intersects the Box3f
97  bool DoesNavFloorIntersectBox3f(NavFloor* navFloor, const Box3f& aabb) const;
98 
99 protected:
100  Database* m_database;
101  char* m_bufferOfCostsInCell;
102  KyUInt32 m_sizeOfBuffer; /*< For internal use. Do not modify. */
103  CellBox m_cellBox;
104 public: // Internal
105  KyUInt32 ComputeBufferSizeForCellBox(KyUInt32 elementCountInBuffe) const;
106 
107  void InitFromNewCellBox();
108 
109  void InitBuffer(KyUInt32 newElementCount);
110 
111  void AllocateMemory(KyUInt32 newElementCount);
112  void ReleaseMemory(); // Release the memory
113 
114  // for O(1) remove from database collections
115  KyUInt32 GetIndexInCollection() const { return m_indexInCollection; }
116  void SetIndexInCollection(KyUInt32 indexInCollection) { m_indexInCollection = indexInCollection; }
117  KyUInt32 m_indexInCollection; // for O(1) remove from database collections
118 };
119 
120 
121 }
122 
124 
125 #endif
126 
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43