gwnavruntime/navdata/navdata.h Source File

navdata.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 // primary contact: JUBA - secondary contact: GUAL
8 #ifndef Navigation_NavData_H
9 #define Navigation_NavData_H
10 
15 
16 namespace Kaim
17 {
18 
19 class NavMeshElement;
20 class NavMeshElementBlob;
21 class NavGraph;
22 class NavGraphBlob;
23 class NavGraphBlobBuilder;
24 class AbstractGraph;
25 class AbstractGraphBlob;
26 class Database;
27 class VisualDebugServer;
28 class KyGuid;
29 
41 class NavData : public WorldElement
42 {
43  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
45 
46 public:
47  static WorldElementType GetStaticType() { return TypeNavData; }
48  virtual WorldElementType GetType() const { return TypeNavData; }
49  virtual const char* GetTypeName() const { return "NavData"; }
50  virtual void DoSendVisualDebug(VisualDebugServer& server, VisualDebugSendChangeEvent changeEvent);
51 
52  // ---------------------------------- Public Member Functions ----------------------------------
53 
54 
57  enum DatabaseStatus
58  {
59  NotReferencedInAnyDatabase = 0,
60  ToBeAdded_NotAlive = 1,
61  BeingAdded_NotAlive = 2,
62  AddedToDabase_Alive = 3,
63  ToBeRemoved_Alive = 4,
64  BeingRemoved_Alive = 5
65  };
66 
67 
68  NavData(Database* database = KY_NULL); // call Init
69  virtual ~NavData();
70 
71  Database* GetDatabase() const;
72  DatabaseStatus GetDatabaseStatus() const;
73 
76  const KyGuid* GetMainGuid() const;
77 
81  const String& GetSectorName() const;
84  const String& GetGeneratorRelativeOutputDirectory() const;
85 
86  // ---------------------------------- Memory loading or sharing Functions ----------------------------------
87 
90  KyResult Load(const char* fileName, FileOpenerBase* fileOpener = KY_NULL);
91  KyResult Load(File* file);
92  KyResult LoadFromMemory(void* memory);
93 
96  KyResult Save(const char* fileName, FileOpenerBase* fileOpener = KY_NULL, Endianness::Type endianness = Endianness::BigEndian);
97 
100  void SetBlobAggregate(BlobAggregate* BlobAggregate);
101 
102 
103  // ---------------------------------- Main API Functions ----------------------------------
104 
108  KyResult Init(Database* database);
109 
113  KyResult AddNavGraph(NavGraphBlobBuilder* navGraphBlobBuilder);
114 
124 
132 
141 
149 
154  bool IsAliveInDatabase() const;
155 
159  bool IsCompatibleWith(const NavData& navData) const;
160 
161 public: //internal
162  void ComputeCellBoxOfNavMeshes();
163  void ComputeCellBoxOfNavGraphs();
164  void ComputeCellBoxOfAbstractGraphs();
165 
166  void OnNavDataBeeingAdded();
167  void OnNavDataAdditionFinished();
168  void OnNavDataBeeingRemoved();
169  void OnNavDataRemoveFinished();
170 
171  BlobAggregate::Collection<NavMeshElementBlob> GetNavMeshElementBlobCollection() const;
172  BlobAggregate::Collection<NavGraphBlob> GetNavGraphBlobCollection() const;
173  BlobAggregate::Collection<AbstractGraphBlob> GetAbstractGraphBlobCollection() const;
174 
175  void OnLinkInfoChange();
176 
177  void AddSectorDescriptorToBlobAggregate();
178  KyUInt32 GetMainNavMeshElementIndexInCollection() const;
179 
180 public: //internal
181  Database* m_database;
182  DatabaseStatus m_databaseStatus;
183  Ptr<BlobAggregate> m_blobAggregate; // do not set m_blobAggregate directly, use SetBlobAggregate()
187  CellBox m_navDataCellBox;
188  SectorDescriptor m_sectorDescriptor;
189 
190  enum VisualDebugStatus { VisualDebugStatus_NothingToSend, VisualDebugStatus_SendALL, VisualDebugStatus_SendGraphLinkInfo };
191  VisualDebugStatus m_visualDebugStatus; // visual debug purpose
192 };
193 
194 KY_INLINE NavData::NavData(Database* database)
195  : m_database(KY_NULL)
196  , m_databaseStatus(NotReferencedInAnyDatabase)
197  , m_visualDebugStatus(VisualDebugStatus_NothingToSend)
198 {
199  Init(database);
200 }
201 
202 KY_INLINE NavData::~NavData() {}
203 
204 KY_INLINE bool NavData::IsAliveInDatabase() const
205 { return m_databaseStatus == AddedToDabase_Alive || m_databaseStatus == ToBeRemoved_Alive || m_databaseStatus == BeingRemoved_Alive; }
206 
207 KY_INLINE NavData::DatabaseStatus NavData::GetDatabaseStatus() const { return m_databaseStatus; }
208 KY_INLINE Database* NavData::GetDatabase() const { return m_database; }
209 
210 KY_INLINE void NavData::OnNavDataBeeingAdded() { m_databaseStatus = NavData::BeingAdded_NotAlive; }
211 KY_INLINE void NavData::OnNavDataBeeingRemoved() { m_databaseStatus = NavData::BeingRemoved_Alive; }
212 
213 KY_INLINE void NavData::OnNavDataAdditionFinished()
214 {
215  m_databaseStatus = NavData::AddedToDabase_Alive;
216  m_visualDebugStatus = VisualDebugStatus_SendALL;
217  RegisterToVisualDebug();
218 }
219 
220 KY_INLINE void NavData::OnNavDataRemoveFinished()
221 {
222  m_databaseStatus = NavData::NotReferencedInAnyDatabase;
223  UnRegisterFromVisualDebug();
224 }
225 
226 KY_INLINE void NavData::OnLinkInfoChange()
227 {
228  if (m_visualDebugStatus == VisualDebugStatus_NothingToSend)
229  m_visualDebugStatus = VisualDebugStatus_SendGraphLinkInfo;
230 }
231 
232 
233 }
234 
235 
236 #endif
237 
General purpose array for movable objects that DOES NOT require construction/destruction.
Definition: kyarray.h:156
Base interface for a class that opens a file on disk.
Definition: fileopener.h:35
KyResult Save(const char *fileName, FileOpenerBase *fileOpener=0, Endianness::Type endianness=Endianness::BigEndian)
This function is here to save a graph-only NavData, at runtime or in Generation Post Process...
Easy to write/read version of SectorDescriptorBlob.
Definition: sectordescriptor.h:49
KyResult AddToDatabaseAsync()
This function does not modify the alive NavData in the Database immediately, the NavData won't be imm...
This class represents a two-dimensional axis-aligned bounding box whose dimensions are stored using 3...
Definition: box2i.h:119
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
KyResult AddNavGraph(NavGraphBlobBuilder *navGraphBlobBuilder)
This function creates and add a NavGraphBlob to the BlobAggregate of this NavData.
KyResult Load(const char *fileName, FileOpenerBase *fileOpener=0)
To use in single World scenario, or multi world scenario without NavData memory sharing.
const String & GetSectorName() const
Returns the Name passed to Kaim::GeneratorSector.
const KyGuid * GetMainGuid() const
Gives the Guid used to identify the NavMesh contained in this NavData.
void SetBlobAggregate(BlobAggregate *BlobAggregate)
To use in multi World scenario with NavData memory sharing.
KyResult Init(Database *database)
Associates current instance to a Database.
#define KY_NULL
Null value.
Definition: types.h:247
KyResult RemoveFromDatabaseAsync()
This function does not modify the alive NavData in the Database immediately.
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Big-endian format (used, for example, for PlayStation 3, Xbox 360).
Definition: endianness.h:31
KyResult RemoveFromDatabaseImmediate()
Remove the NavData from the Database outside the World::Update().
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:44
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
bool IsCompatibleWith(const NavData &navData) const
Indicates whether the specified NavData was created with the same generation parameters as this objec...
WorldElementType
Enumerates the WorldElement types.
Definition: worldelementtype.h:15
Definition: gamekitcrowddispersion.h:20
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:22
bool IsAliveInDatabase() const
Indicates whether the specified NavData has been effectively added to the Database and not effectivel...
Definition: navdata.h:247
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
KyResult AddToDatabaseImmediate()
Add the NavData to the Database outside the World::Update().
Type
Enumerates possible endianness types.
Definition: endianness.h:28
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
const String & GetGeneratorRelativeOutputDirectory() const
Returns the relative output directory used to load the file when visual debugging.
This class allows you to build a NavGraph, which you can then add to the NavData for a sector...
Definition: navgraphblobbuilder.h:25
DatabaseStatus
Enumerates the different status a NavData can have in one Database.
Definition: navdata.h:66