gwnavgamekit/gamekitnavtaglayercosttable.h Source File

gamekitnavtaglayercosttable.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 
8 #pragma once
9 
14 
15 namespace Kaim
16 {
17 
18 // INTERNAL CLASS: Implementation details of GameKitNavTagLayerCostInternal
19 class GameKitNavTagLayerCost;
20 
21 // INTERNAL CLASS: Implementation details of GameKitNavTagLayerCostTable
22 // This class ensures by encapsulation that m_traversableLayerMask is always updated
23 // when cost multipliers are modified via SetLayerCostMultiplier()
24 class GameKitNavTagLayerCostInternal
25 {
26  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_GameKit)
27 public: // internal
28  // ----- only used by GameKitNavTagLayerCostTable -----
29  GameKitNavTagLayerCostInternal();
30  GameKitNavTagLayerCostInternal(const GameKitNavTagLayerCostInternal& other);
31  ~GameKitNavTagLayerCostInternal();
32  void operator=(const GameKitNavTagLayerCostInternal& other);
33 
34  // 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
35  // Cost should always be changed via this function since it maintains m_traversableLayerMask
36  void SetLayerCostMultiplier(KyUInt32 layerID, KyFloat32 costMultiplier);
37  const KyFloat32* GetLayerCostMultiplier(KyUInt32 layerID) const;
38 
39  KyUInt32 GetTraversableLayerMask() const { return m_traversableLayerMask; }
40 
42  void Clear();
43 
44 private:
45  KyFloat32* GetCostMultiplier(KyUInt32 layerID);
46 
47 private:
48  KyUInt32 m_traversableLayerMask; // guarantees O(1) lookup to check traversability of layerIDs < 32
49  KyArray<GameKitNavTagLayerCost> m_layersAndCosts; // layerID
50 };
51 
52 
53 class GameKitNavTagLayerCostTable : public RefCountBase<GameKitNavTagLayerCostTable, MemStat_GameKit>
54 {
55 public:
58  void SetLayerCostMultiplier(KyUInt32 layerID, KyFloat32 costMultiplier);
59 
61  void AllowLayer(KyUInt32 layerID);
62 
64  void ForbidLayer(KyUInt32 layerID);
65 
67  void Clear() { m_navTagLayers.Clear(); }
68 
69 public: // internal
70  bool CanTraverseLayer(KyUInt32 layerID, KyFloat32* costMultiplier) const;
71 
72  // For testing purpose only
73  KyUInt32 GetTraversableLayerMask() const { return m_navTagLayers.GetTraversableLayerMask(); }
74 
75 private:
76  GameKitNavTagLayerCostInternal m_navTagLayers;
77 };
78 
79 }
80 
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