gwnavruntime/database/activedatablob.h Source File

activedatablob.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 enum ActiveSectorType
18 {
19  ActiveSectorType_NavMesh = 0,
20  ActiveSectorType_NavGraph = 1,
21  ActiveSectorType_AbstractGraph = 2,
22  ActiveSectorType_Undefined = KyUInt8MAXVAL,
23 };
24 
25 class ActiveSectorBlob
26 {
27 public:
28  ActiveSectorBlob() {}
29 
30  KyGuid m_guid;
31  BlobArray<char> m_sectorName;
32  BlobArray<char> m_sectorRelativeDir;
33  KyUInt8 m_activeSectorType; // cf. ActiveSectorType
34 };
35 
36 inline void SwapEndianness(Endianness::Target e, ActiveSectorBlob& self)
37 {
38  SwapEndianness(e, self.m_guid);
39  SwapEndianness(e, self.m_sectorName);
40  SwapEndianness(e, self.m_sectorRelativeDir);
41  SwapEndianness(e, self.m_activeSectorType);
42 }
43 
44 class ActiveSectorBlobBuilder : public BaseBlobBuilder<ActiveSectorBlob>
45 {
46 public:
47  static ActiveSectorType GetActiveSectorType(const NavData* navData)
48  {
49  if (navData->GetNavMeshElementBlobCollection().GetCount() != 0)
50  return ActiveSectorType_NavMesh;
51  else if (navData->GetNavGraphBlobCollection().GetCount() != 0)
52  return ActiveSectorType_NavGraph;
53  else if (navData->GetAbstractGraphBlobCollection().GetCount() != 0)
54  return ActiveSectorType_AbstractGraph;
55  return ActiveSectorType_Undefined;
56  }
57 
58 public:
59  ActiveSectorBlobBuilder(const KyGuid& guid, const String& sectorName, const String& sectorRelativeDir, ActiveSectorType activeSectorType)
60  : m_guid(guid), m_sectorName(sectorName), m_sectorRelativeDir(sectorRelativeDir), m_activeSectorType(activeSectorType) {}
61 
62  void DoBuild()
63  {
64  BLOB_SET(m_blob->m_guid, m_guid);
65  BLOB_STRING(m_blob->m_sectorName, m_sectorName.ToCStr());
66  BLOB_STRING(m_blob->m_sectorRelativeDir, m_sectorRelativeDir.ToCStr());
67  BLOB_SET(m_blob->m_activeSectorType, ((KyUInt8)m_activeSectorType));
68  }
69 
70  KyGuid m_guid;
71  String m_sectorName;
72  String m_sectorRelativeDir;
73  ActiveSectorType m_activeSectorType;
74 };
75 
76 class ActiveDataBlob
77 {
78  KY_ROOT_BLOB_CLASS(NavData, ActiveDataBlob, 0)
79  KY_CLASS_WITHOUT_COPY(ActiveDataBlob)
80 
81 public:
82  ActiveDataBlob() : m_databaseIndex(KyUInt32MAXVAL) {}
83 
84  KyUInt32 m_databaseIndex;
85  BlobArray<ActiveSectorBlob> m_activeSectors;
86 };
87 
88 inline void SwapEndianness(Endianness::Target e, ActiveDataBlob& self)
89 {
90  SwapEndianness(e, self.m_databaseIndex);
91  SwapEndianness(e, self.m_activeSectors);
92 }
93 
94 class ActiveDataBlobBuilder : public BaseBlobBuilder<ActiveDataBlob>
95 {
96 public:
97  ActiveDataBlobBuilder(const Database* db) : m_db(db) {}
98 
99  void DoBuild()
100  {
101  if (m_db == nullptr)
102  return;
103 
104  BLOB_SET(m_blob->m_databaseIndex, m_db->GetDatabaseIndex());
105 
106  KyArray<Kaim::NavData*> navDataToBuild;
107  for (KyUInt32 i = 0; i < m_db->m_navDatas.GetCount(); ++i)
108  {
109  Kaim::NavData* navData = m_db->m_navDatas[i];
110  if (navData->GetSectorName() != "")
111  {
112  navDataToBuild.PushBack(navData);
113  }
114  }
115 
116  ActiveSectorBlob* activeSectors = BLOB_ARRAY(m_blob->m_activeSectors, navDataToBuild.GetCount());
117  for (KyUInt32 i = 0; i < navDataToBuild.GetCount(); ++i)
118  {
119  NavData* navData = navDataToBuild[i];
120  KY_DEBUG_ERRORN_IF(navData->GetSectorName() == "", ("Error in ActiveDataBlobBuilder, we should not build ActiveDataBlob for this navData"));
121 
122  const KyGuid* guid = navData->GetMainGuid();
123  if (guid == nullptr)
124  guid = &KyGuid::GetInvalidGuid();
125 
126  ActiveSectorType sectorType = ActiveSectorBlobBuilder::GetActiveSectorType(navData);
127  BLOB_BUILD(activeSectors[i], ActiveSectorBlobBuilder(*guid, navData->m_sectorDescriptor.m_sectorName, navData->m_sectorDescriptor.m_generatorRelativeOutputDirectory, sectorType));
128  }
129  }
130 
131  const Database* m_db;
132 };
133 
134 // Used to be sent from the NavigationLab
135 // Not used anymore since supporting identification of Graph-only NavData based on NavData.m_sectorDescriptor.m_sectorName
136 // since such NavData has no guid (since there's no navmesh)
137 class ActiveGuidsBlob
138 {
139  KY_ROOT_BLOB_CLASS(NavData, ActiveGuidsBlob, 0)
140  KY_CLASS_WITHOUT_COPY(ActiveGuidsBlob)
141 
142 public:
143  ActiveGuidsBlob() {}
144 
145  BlobArray<KyGuid> m_guids;
146 };
147 
148 inline void SwapEndianness(Endianness::Target e, ActiveGuidsBlob& self)
149 {
150  SwapEndianness(e, self.m_guids);
151 }
152 
153 class ActiveGuidsBlobBuilder : public BaseBlobBuilder<ActiveGuidsBlob>
154 {
155 
156 public:
157  ActiveGuidsBlobBuilder(KyArray<KyGuid, MemStat_NavData>* activeGuids) : m_activeGuids(activeGuids) {}
158 
159  void DoBuild()
160  {
161  if (m_activeGuids == nullptr)
162  return;
163 
164  BLOB_ARRAY_COPY_2(m_blob->m_guids, (*m_activeGuids));
165  }
166 
167  KyArray<KyGuid, MemStat_NavData>* m_activeGuids;
168 };
169 
170 
171 
172 }
173 
#define BLOB_SET(blob, value)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:130
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define BLOB_BUILD(blob, builder)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:175
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The NavData class is the object containing navigation data that will be added to one Database...
Definition: navdata.h:39
#define KyUInt8MAXVAL
KyUInt8 max value
Definition: types.h:66
ActiveSectorBlob * m_blob
The blob maintained by this builder. Only modify using the macros listed under DoBuild().
Definition: baseblobbuilder.h:113
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
static const KyGuid & GetInvalidGuid()
Returns the invalid KyGuid value.
Definition: kyguid.cpp:21
#define BLOB_ARRAY_COPY_2(blobArray, ky_array)
same as BLOB_ARRAY_COPY but uses Kaim::Array as input
Definition: baseblobbuilder.h:155
#define BLOB_STRING(str, src)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:166
const String & GetSectorName() const
Returns the Name passed to Kaim::GeneratorSector.
Definition: navdata.cpp:494
#define BLOB_ARRAY(blobArray, count)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:139
std::uint8_t KyUInt8
uint8_t
Definition: types.h:27
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68