gwnavruntime/database/databasechange.h Source File

databasechange.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 
12 
13 namespace Kaim
14 {
15 
16 class NavData;
17 
18 
19 class DatabaseChangeIdx
20 {
21 public:
22  DatabaseChangeIdx();
23  KyUInt32 m_navMeshChangeIdx; // incremented if NavMesh changed during Database::Update()
24  KyUInt32 m_navGraphChangeIdx; // incremented if NavGraphs were added/removed during Database::Update()
25  KyUInt32 m_abstractGraphChangeIdx; // incremented if NavGraphs changed during Database::Update()
26  KyUInt32 m_anyChangeIdx;
27 };
28 
29 
30 class DatabaseChange
31 {
32 public:
33  DatabaseChange();
34  ~DatabaseChange();
35 
36  void ClearChange();
37 
38  // ChangeCellBoxes
39  const CellBox& GetAddRemoveNavMeshChangeCellBox() const { return m_addRemoveNavMeshChangeCellBox; }
40  const CellBox& GetTagVolumeNavMeshChangeCellBox() const { return m_tagVolumeNavMeshChangeCellBox; }
41  const CellBox& GetNavMeshChangeCellBox() const { return m_navMeshChangeCellBox; }
42  const CellBox& GetNavGraphChangeCellBox() const { return m_navGraphChangeCellBox; }
43  const CellBox& GetAbstractGraphChangeCellBox() const { return m_abstractGraphChangeCellBox; }
44  const CellBox& GetAnyChangeCellBox() const { return m_anyChangeCellBox; }
45 
46  // ChangeIdx
47  KyUInt32 GetNavMeshChangeIdx() const { return m_changeIdx.m_navMeshChangeIdx; }
48  KyUInt32 GetNavGraphChangeIdx() const { return m_changeIdx.m_navGraphChangeIdx; }
49  KyUInt32 GetAbstractGraphChangeIdx() const { return m_changeIdx.m_abstractGraphChangeIdx; }
50  KyUInt32 GetAnyChangeIdx() const { return m_changeIdx.m_anyChangeIdx; }
51 
52  // IsChanged
53  bool IsAddRemoveNavMeshChanged() const { return m_addRemoveNavMeshChanged; }
54  bool IsTagVolumeNavMeshChangeCellBox() const { return m_tagVolumeNavMeshChanged; }
55  bool IsNavMeshChanged() const { return m_navMeshChanged; }
56  bool IsNavGraphChanged() const { return m_navGraphChanged; }
57  bool IsAbstractGraphChanged() const { return m_abstractGraphChanged; }
58  bool IsAnyChanged() const { return m_anyChanged; }
59 
60  const KyArray<Ptr<NavData> >& GetAddedNavDatas() const { return m_addedNavDatas; }
61  const KyArray<Ptr<NavData> >& GetRemovedNavDatas() const { return m_removedNavDatas; }
62 
63 protected:
64  DatabaseChangeIdx m_changeIdx;
65 
66  // navMesh changes
67  CellBox m_addRemoveNavMeshChangeCellBox;
68  CellBox m_tagVolumeNavMeshChangeCellBox;
69  CellBox m_navMeshChangeCellBox;
70  CellBox m_navGraphChangeCellBox;
71  CellBox m_abstractGraphChangeCellBox;
72  CellBox m_anyChangeCellBox;
73 
74  bool m_addRemoveNavMeshChanged;
75  bool m_tagVolumeNavMeshChanged;
76  bool m_navMeshChanged;
77  bool m_navGraphChanged;
78  bool m_abstractGraphChanged;
79  bool m_anyChanged;
80 
81  KyArray<Ptr<NavData> > m_addedNavDatas;
82  KyArray<Ptr<NavData> > m_removedNavDatas;
83 
84  friend class DatabaseChangeInProgress;
85 };
86 
87 class IDatabaseChangeListener : public RefCountBase<IDatabaseChangeListener, MemStat_WorldFwk>
88 {
89 public:
90  virtual ~IDatabaseChangeListener() {}
91  virtual void OnDatabaseChange(const DatabaseChange& change) = 0;
92 };
93 
94 // DatabaseChangeInProgress and DatabaseChange could be the same class
95 // but it's more clear to have a dedicated class to the InProgress use case
96 class DatabaseChangeInProgress : public DatabaseChange
97 {
98 public:
99  // Add NavMesh change
100  void AddRemoveNavMeshChange(const CellBox& cellBox);
101  void TagVolumeNavMeshChange(const CellBox& cellBox);
102 
103  void NavMeshChange(const CellBox& cellBox);
104  //void NavMeshChange();
105 
106  // Add NavGraph change
107  void NavGraphChange(const CellBox& cellBox);
108  void NavGraphChange();
109 
110  // Add AbstractGraph change
111  void AbstractGraphChange(const CellBox& cellBox);
112  void AbstractGraphChange();
113 
114  void PushAddedNavData(Ptr<NavData>& navData);
115  void PushRemovedNavData(Ptr<NavData>& navData);
116  void ComputeAnyChangeCellBox();
117 
118  void CopyChangeIdxTo(DatabaseChangeIdx& changeIdx) const { changeIdx = m_changeIdx; }
119 
120  void AggregateTo(DatabaseChange& change) const;
121 
122 private:
123  void AnyChange(const CellBox& cellBox);
124  void AnyChange();
125 };
126 
127 
128 
129 
130 }
131 
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
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17