gwnavruntime/database/activedatablob.h Source File

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