gwnavgamekit/gamekitnavtaglayercosttable.h Source File

gamekitnavtaglayercosttable.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: BRGR - secondary contact:
9 #ifndef Navigation_GameKitNavTagLayerCollection_H
10 #define Navigation_GameKitNavTagLayerCollection_H
11 
16 
17 namespace Kaim
18 {
19 
20 // INTERNAL CLASS: Implementation details of GameKitNavTagLayerCostInternal
21 class GameKitNavTagLayerCost;
22 
23 // INTERNAL CLASS: Implementation details of GameKitNavTagLayerCostTable
24 // This class ensures by encapsulation that m_traversableLayerMask is always updated
25 // when cost multipliers are modified via SetLayerCostMultiplier()
26 class GameKitNavTagLayerCostInternal
27 {
28  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_GameKit)
29 public: // internal
30  // ----- only used by GameKitNavTagLayerCostable -----
31  GameKitNavTagLayerCostInternal();
32  GameKitNavTagLayerCostInternal(const GameKitNavTagLayerCostInternal& other);
33  ~GameKitNavTagLayerCostInternal();
34  void operator=(const GameKitNavTagLayerCostInternal& other);
35 
36  // Negative value means the layer is deactivated and its absolute value gives the original cost multiplier, so layer can be de/activated without losing the original cost
37  // Cost should always be changed via this function since it maintains m_traversableLayerMask
38  void SetLayerCostMultiplier(KyUInt32 layerID, KyFloat32 costMultiplier);
39  const KyFloat32* GetLayerCostMultiplier(KyUInt32 layerID) const;
40 
41  KyUInt32 GetTraversableLayerMask() const { return m_traversableLayerMask; }
42 
44  void Clear();
45 
46 private:
47  KyFloat32* GetCostMultiplier(KyUInt32 layerID);
48 
49 private:
50  KyUInt32 m_traversableLayerMask; // guarantees O(1) lookup to check traversability of layerIDs < 32
51  KyArray<GameKitNavTagLayerCost> m_layersAndCosts; // layerID
52 };
53 
54 
55 class GameKitNavTagLayerCostTable : public RefCountBase<GameKitNavTagLayerCostTable, MemStat_GameKit>
56 {
57 public:
60  void SetLayerCostMultiplier(KyUInt32 layerID, KyFloat32 costMultiplier);
61 
63  void AllowLayer(KyUInt32 layerID);
64 
66  void ForbidLayer(KyUInt32 layerID);
67 
69  void Clear() { m_navTagLayers.Clear(); }
70 
71 public: // internal
72  bool CanTraverseLayer(KyUInt32 layerID, KyFloat32* costMultiplier) const;
73 
74  // For testing purpose only
75  KyUInt32 GetTraversableLayerMask() const { return m_navTagLayers.GetTraversableLayerMask(); }
76 
77 private:
78  GameKitNavTagLayerCostInternal m_navTagLayers;
79 };
80 
81 }
82 
83 #endif
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