gwnavruntime/navmesh/itrianglecostmap.h Source File

itrianglecostmap.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 
22 
23 namespace Kaim
24 {
25 
26 class ActiveNavFloorCollection;
27 class NavTriangleRawPtr;
28 class TriangleCostInCell;
29 class Box2f;
30 class Database;
31 
32 class ITriangleCostMap : public RefCountBase<ITriangleCostMap, MemStat_CostMap>
33 {
34  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_CostMap)
35 public:
36  ITriangleCostMap();
37  virtual ~ITriangleCostMap();
38 
39  // This function is called by the Database each time something changed in the cellBox
40  // covered by the TriangleCostMap (NavData add/remove or dynamicNavmesh).
41  // In Your implementation you have to called one of the InitCostMap function
42  // before calling SetCostMultiplier on each triangle you want to set a custom costmultiplier
43  // \Pre this triangleCostMap must have been bound to a Database first.
44  virtual void Recompute() = 0;
45 
46 protected:
47 
48  // ----- Helper Functions to be called in Recompute
49 
56  template<class CostMultiplierComputer>
57  void InitAndBrowseAllTrianglesInBox3f(CostMultiplierComputer& compute, const Box3f& aabb);
58 
73  template<class CostMultiplierComputer>
74  void InitAndPropagateInTrianglesFromPosInVolume(CostMultiplierComputer& compute, const Box3f& aabb, const Vec3f& inputPosition);
75 
76 public:
77  void BindToDatabase(Database* database);
78  void UnbindFromDatabase();
79  bool IsBindToADatabase() const { return m_database != nullptr; }
80 
81  void SetCostMultiplier(const NavTriangleRawPtr& triangle, KyFloat32 costMultiplier);
82  KyFloat32 GetCostMultiplier(const NavTriangleRawPtr& triangle) const;
83 
84  const CellBox& GetCellBox() const { return m_cellBox; }
85 
86 protected:
87  // return true if the data structure is initialized and ready to use
88  // returns false if the costMap was not bind to a database or if there is no triangle to set
89  // a costMultiplier to (that can happen if your box in outside the data !)
90  bool InitCostMapForBox3f(const Box3f& aabb);
91 
92  // test if the navFloor intersects the Box3f
93  bool DoesNavFloorIntersectBox3f(NavFloor* navFloor, const Box3f& aabb) const;
94 
95 protected:
96  Database* m_database;
97  char* m_bufferOfCostsInCell;
98  KyUInt32 m_sizeOfBuffer; /*< For internal use. Do not modify. */
99  CellBox m_cellBox;
100 public: // internal
101  KyUInt32 ComputeBufferSizeForCellBox(KyUInt32 elementCountInBuffe) const;
102 
103  void InitFromNewCellBox();
104 
105  void InitBuffer(KyUInt32 newElementCount);
106 
107  void AllocateMemory(KyUInt32 newElementCount);
108  void ReleaseMemory(); // Release the memory
109 
110  // for O(1) remove from database collections
111  KyUInt32 GetIndexInCollection() const { return m_indexInCollection; }
112  void SetIndexInCollection(KyUInt32 indexInCollection) { m_indexInCollection = indexInCollection; }
113  KyUInt32 m_indexInCollection; // for O(1) remove from database collections
114 };
115 
116 
117 }
118 
120 
121 
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32