gwnavgeneration/generator/generatorparameters.h Source File

generatorparameters.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 
14 
15 namespace Kaim
16 {
17 
18 class BlobAggregate;
19 class DatabaseGenMetrics;
20 
21 class GeneratorNormalizedParameters
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 
25 public:
26  GeneratorNormalizedParameters();
27  void Clear();
28  bool IsValid() const;
29 
30 public:
31  KyFloat32 m_normalizedRasterPrecision; // NearestInt(GeneratorParameters::m_entityRadius / GeneratorParameters::m_rasterPrecision)
32  KyUInt32 m_cellSizeInPixel;
33  KyUInt32 m_entityRadiusInPixel;
34  KyUInt32 m_distanceFromWallsInPixel;
35  KyUInt32 m_distanceFromHolesInPixel;
36  KyFloat32 m_normalizedCellSize;
37  KyFloat32 m_normalizedEntityRadius;
38 };
39 
40 
41 class GeneratorParametersBlob
42 {
43  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
44  KY_ROOT_BLOB_CLASS(Generator, GeneratorParametersBlob, 0)
45  KY_CLASS_WITHOUT_COPY(GeneratorParametersBlob)
46 public:
47  GeneratorParametersBlob() {}
48  BlobFieldArray m_fields;
49  NavTag m_defaultNavTag;
50  Color m_emptyDefaultNavTagColor;
51  Color m_nonEmptyDefaultNavTagColor;
52  Color m_nonDefaultNavTagColor;
53 };
54 inline void SwapEndianness(Endianness::Target e, GeneratorParametersBlob& self)
55 {
56  SwapEndianness(e, self.m_fields);
57  SwapEndianness(e, self.m_defaultNavTag);
58  SwapEndianness(e, self.m_emptyDefaultNavTagColor);
59  SwapEndianness(e, self.m_nonEmptyDefaultNavTagColor);
60  SwapEndianness(e, self.m_nonDefaultNavTagColor);
61 }
62 
63 
68 {
69  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
70 public:
71  // The binary backward compatibility of the GeneratorParameters blob is ensured by its nature (BlobFieldMapping)
72  // However, when a parameter is added or renamed its value will be set to the default value (from Ctor)
73  // when loading older versions of configs (from older clientInput).
74  // This behavior might have some random effects.
75  enum { Version = 1 };
76 
77 public:
78  // ------------------------------ Functions -----------------------------
79 
81  void Clear();
82  void SetDefaultValues() { Clear(); }
83 
84  void SetDefaultNavTag(const KyArrayPOD<KyUInt32>& blindDataArray) { SetDefaultNavTag(blindDataArray.GetDataPtr(), blindDataArray.GetCount()); }
85  void SetDefaultNavTag(const KyUInt32* blindDataBuffer, KyUInt32 blindDataCount);
86  void SetEmptyDefaultNavTagColor(Color color);
87  void SetNonEmptyDefaultNavTagColor(Color color);
88  void SetNonDefaultNavTagColor(Color color);
89 
90  const DynamicNavTag& GetDefaultNavTag() const { return m_defaultNavTag; }
91 
92 public: // internal
93  void ComputeNormalizedParams();
94 
95  // Helper function allowing to transform a genParams to its runtime equivalent
96  void ComputeDatabaseGenMetrics(DatabaseGenMetrics& genMetrics) const;
97 
98  void BuildBlob(BlobHandler<GeneratorParametersBlob>& handler) const;
99 
100  KyResult ReadFromBlobHandler(BlobHandler<GeneratorParametersBlob>& handler) { return ReadFromBlob(*handler.Blob()); }
101  KyResult ReadFromAggregate(BlobAggregate& aggregate);
102 
103  bool operator==(const GeneratorParameters& other) const;
104  bool operator!=(const GeneratorParameters& other) const { return !operator==(other); }
105 
106  void InitBlobFieldMapping(BlobFieldsMapping& mapping, KyUInt32& version);
107  void InitBlobFieldMapping(BlobFieldsMapping& mapping, KyUInt32& version) const;
108 
109  KyResult ReadFromBlob(const GeneratorParametersBlob& blob);
110 
111 public:
116 
122 
127 
134 
142 
149 
154 
158 
159  // computed in ComputeNormalizedParams(), do not set directly
160  GeneratorNormalizedParameters m_normalizedParameters;
161 
162 private:
164  DynamicNavTag m_defaultNavTag;
165 };
166 
167 
168 template <class OSTREAM>
169 inline OSTREAM& operator<<(OSTREAM& os, GeneratorParameters& params)
170 {
171  BlobFieldsMapping mapping;
172  KyUInt32 version = 0;
173  params.InitBlobFieldMapping(mapping, version);
174 
175  os << KY_LOG_SMALL_TITLE_BEGIN("", "GeneratorParameters Info");
176  os << mapping;
177  // os << m_defaultNavTag;
178  os << KY_LOG_SMALL_TITLE_END("", "GeneratorParameters Info");
179  return os;
180 }
181 
182 
183 class GeneratorParametersBlobBuilder : public BaseBlobBuilder<GeneratorParametersBlob>
184 {
185 public:
186  GeneratorParametersBlobBuilder(const GeneratorParameters* params) : m_params(params) {}
187 
188 private:
189  virtual void DoBuild();
190 
191  const GeneratorParameters* m_params;
192 };
193 
194 } // namespace Kaim
195 
KyFloat32 m_stepMax
The maximum difference in altitude that the character can traverse in its normal movement.
Definition: generatorparameters.h:126
KyFloat32 m_cellSize
Determines the approximate width and length of each cell in the grid used to partition the NavMesh in...
Definition: generatorparameters.h:148
GeneratorAdvancedParameters m_advancedParameters
Contains more advanced configuration parameters.
Definition: generatorparameters.h:157
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
KyFloat32 m_entityHeight
The height of the character.
Definition: generatorparameters.h:115
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
This class provides information about Autodesk Navigation version.
Definition: version.h:17
The GeneratorAdvancedParameters class is used by the GeneratorParameters class to maintain a set of c...
Definition: generatoradvancedparameters.h:30
DynamicNavTag m_defaultNavTag
Specifies the default NavTag that will be applied to all input triangles that do not otherwise have a...
Definition: generatorparameters.h:164
KyFloat32 m_entityRadius
The radius (or half-width) of the character.
Definition: generatorparameters.h:121
KyFloat32 m_altitudeTolerance
Determines the maximum difference in altitude that may exist between the NavMesh and the original ter...
Definition: generatorparameters.h:153
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
void SetDefaultValues()
alias for Clear()
Definition: generatorparameters.h:82
The GeneratorParameters class contains configuration parameters that control the characteristics of t...
Definition: generatorparameters.h:67
KyFloat32 m_slopeMax
The maximum slope that the character can traverse in its normal movement.
Definition: generatorparameters.h:133
KyFloat32 m_rasterPrecision
Determines the approximate width and length of each pixel used to rasterize the input triangles...
Definition: generatorparameters.h:141
float KyFloat32
float
Definition: types.h:32