gwnavruntime/navdata/navdata.h Source File

navdata.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 
13 
14 namespace Kaim
15 {
16 
17 class NavMeshElement;
18 class NavMeshElementBlob;
19 class NavGraph;
20 class NavGraphBlob;
21 class NavGraphBlobBuilder;
22 class AbstractGraph;
23 class AbstractGraphBlob;
24 class Database;
25 class VisualDebugServer;
26 class KyGuid;
27 
39 class NavData : public WorldElement
40 {
41  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
43 
44 public:
45  static WorldElementType GetStaticType() { return TypeNavData; }
46  virtual WorldElementType GetType() const { return TypeNavData; }
47  virtual const char* GetTypeName() const { return "NavData"; }
48  virtual void DoSendVisualDebug(VisualDebugServer& server, VisualDebugSendChangeEvent changeEvent);
49 
50  // ------------------------------ Functions -----------------------------
51 
52 
56  {
57  NotReferencedInAnyDatabase = 0,
58  ToBeAdded_NotAlive = 1,
59  BeingAdded_NotAlive = 2,
60  AddedToDabase_Alive = 3,
61  ToBeRemoved_Alive = 4,
62  BeingRemoved_Alive = 5
63  };
64 
65 
66  NavData(Database* database = nullptr); // call Init
67  virtual ~NavData() {}
68 
69  Database* GetDatabase() const;
70  DatabaseStatus GetDatabaseStatus() const;
71 
74  const KyGuid* GetMainGuid() const;
75 
79  const String& GetSectorName() const;
82  const String& GetGeneratorRelativeOutputDirectory() const;
83 
84  // ---------------------------------- Memory loading or sharing Functions ----------------------------------
85 
88  KyResult Load(const char* fileName, FileOpenerBase* fileOpener = nullptr, FileHandler::ErrorReportMode errorReportMode = FileHandler::DO_ERROR_REPORT);
89  KyResult Load(File* file);
90  KyResult LoadFromMemory(void* memory);
91 
94  KyResult Save(const char* fileName, FileOpenerBase* fileOpener = nullptr, Endianness::Type endianness = Endianness::LittleEndian);
95 
98  void SetBlobAggregate(BlobAggregate* BlobAggregate);
99 
100 
101  // ---------------------------------- Main API Functions ----------------------------------
102 
106  KyResult Init(Database* database);
107 
111  KyResult AddNavGraph(NavGraphBlobBuilder* navGraphBlobBuilder);
112 
122 
130 
139 
147 
152  bool IsAliveInDatabase() const;
153 
157  bool IsCompatibleWith(const NavData& navData) const;
158 
159 public: //internal
160  void ComputeCellBoxOfNavMeshes();
161  void ComputeCellBoxOfNavGraphs();
162  void ComputeCellBoxOfAbstractGraphs();
163 
164  void OnNavDataBeeingAdded();
165  void OnNavDataAdditionFinished();
166  void OnNavDataBeeingRemoved();
167  void OnNavDataRemoveFinished();
168 
169  BlobAggregate::Collection<NavMeshElementBlob> GetNavMeshElementBlobCollection() const;
170  BlobAggregate::Collection<NavGraphBlob> GetNavGraphBlobCollection() const;
171  BlobAggregate::Collection<AbstractGraphBlob> GetAbstractGraphBlobCollection() const;
172 
173  void OnLinkInfoChange();
174 
175  void AddSectorDescriptorToBlobAggregate();
176  KyUInt32 GetMainNavMeshElementIndexInCollection() const;
177 
178 public: //internal
179  Database* m_database;
180  DatabaseStatus m_databaseStatus;
181  Ptr<BlobAggregate> m_blobAggregate; // do not set m_blobAggregate directly, use SetBlobAggregate()
182  KyArrayPOD<NavMeshElement* , MemStat_NavData> m_navMeshElements;
183  KyArrayPOD<NavGraph*, MemStat_NavData> m_navGraphs;
184  KyArrayPOD<AbstractGraph*, MemStat_NavData> m_abstractGraphs;
185  CellBox m_navDataCellBox;
186  SectorDescriptor m_sectorDescriptor;
187 
188  enum VisualDebugStatus { VisualDebugStatus_NothingToSend, VisualDebugStatus_SendALL, VisualDebugStatus_SendGraphLinkInfo };
189  VisualDebugStatus m_visualDebugStatus; // visual debug purpose
190 };
191 
192 KY_INLINE NavData::NavData(Database* database)
193  : m_database(nullptr)
194  , m_databaseStatus(NotReferencedInAnyDatabase)
195  , m_visualDebugStatus(VisualDebugStatus_NothingToSend)
196 {
197  Init(database);
198 }
199 
200 KY_INLINE bool NavData::IsAliveInDatabase() const
201 { return m_databaseStatus == AddedToDabase_Alive || m_databaseStatus == ToBeRemoved_Alive || m_databaseStatus == BeingRemoved_Alive; }
202 
203 KY_INLINE NavData::DatabaseStatus NavData::GetDatabaseStatus() const { return m_databaseStatus; }
204 KY_INLINE Database* NavData::GetDatabase() const { return m_database; }
205 
206 KY_INLINE void NavData::OnNavDataBeeingAdded() { m_databaseStatus = NavData::BeingAdded_NotAlive; }
207 KY_INLINE void NavData::OnNavDataBeeingRemoved() { m_databaseStatus = NavData::BeingRemoved_Alive; }
208 
209 KY_INLINE void NavData::OnNavDataAdditionFinished()
210 {
211  m_databaseStatus = NavData::AddedToDabase_Alive;
212  m_visualDebugStatus = VisualDebugStatus_SendALL;
213  RegisterToVisualDebug();
214 }
215 
216 KY_INLINE void NavData::OnNavDataRemoveFinished()
217 {
218  m_databaseStatus = NavData::NotReferencedInAnyDatabase;
219  UnRegisterFromVisualDebug();
220 }
221 
222 KY_INLINE void NavData::OnLinkInfoChange()
223 {
224  if (m_visualDebugStatus == VisualDebugStatus_NothingToSend)
225  m_visualDebugStatus = VisualDebugStatus_SendGraphLinkInfo;
226 }
227 
228 
229 }
230 
231 
232 
const String & GetGeneratorRelativeOutputDirectory() const
Returns the relative output directory used to load the file when visual debugging.
Definition: navdata.cpp:499
KyResult AddToDatabaseAsync()
This function does not modify the alive NavData in the Database immediately, the NavData won't be imm...
Definition: navdata.cpp:152
KyResult AddNavGraph(NavGraphBlobBuilder *navGraphBlobBuilder)
This function creates and add a NavGraphBlob to the BlobAggregate of this NavData.
Definition: navdata.cpp:367
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
void SetBlobAggregate(BlobAggregate *BlobAggregate)
To use in multi World scenario with NavData memory sharing.
Definition: navdata.cpp:64
KyResult Init(Database *database)
Associates current instance to a Database.
Definition: navdata.cpp:111
KyResult RemoveFromDatabaseAsync()
This function does not modify the alive NavData in the Database immediately.
Definition: navdata.cpp:217
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
KyResult Save(const char *fileName, FileOpenerBase *fileOpener=nullptr, Endianness::Type endianness=Endianness::LittleEndian)
This function is here to save a graph-only NavData, at runtime or in Generation Post Process...
Definition: navdata.cpp:81
const KyGuid * GetMainGuid() const
Gives the Guid used to identify the NavMesh contained in this NavData.
Definition: navdata.cpp:469
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
KyResult RemoveFromDatabaseImmediate()
Remove the NavData from the Database outside the World::Update().
Definition: navdata.cpp:291
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:39
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
Little-endian format (used, for example, for Windows, Linux).
Definition: endianness.h:22
Navigation return code class.
Definition: types.h:108
bool IsCompatibleWith(const NavData &navData) const
Indicates whether the specified NavData was created with the same generation parameters as this objec...
Definition: navdata.cpp:300
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:13
Base internal class used to represent elements that can be added to a World, such as instances of Dat...
Definition: worldelement.h:41
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
bool IsAliveInDatabase() const
Indicates whether the specified NavData has been effectively added to the Database and not effectivel...
Definition: navdata.h:200
KyResult Load(const char *fileName, FileOpenerBase *fileOpener=nullptr, FileHandler::ErrorReportMode errorReportMode=FileHandler::DO_ERROR_REPORT)
To use in single World scenario, or multi world scenario without NavData memory sharing.
Definition: navdata.cpp:28
const String & GetSectorName() const
Returns the Name passed to Kaim::GeneratorSector.
Definition: navdata.cpp:494
KyResult AddToDatabaseImmediate()
Add the NavData to the Database outside the World::Update().
Definition: navdata.cpp:279
Type
Enumerates possible endianness types.
Definition: endianness.h:20
DatabaseStatus
Enumerates the different status a NavData can have in one Database.
Definition: navdata.h:55