gwnavgeneration/generator/generator.h Source File

generator.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 
12 
28 
29 
30 namespace Kaim
31 {
32 
33 class IParallelForInterface;
34 class CollisionInterfaceFactory;
35 class NavMeshElementBlob;
36 class GeneratorSectorBuilder;
37 class GeneratorNavDataElement;
38 
39 
56 class Generator : public RefCountBaseNTS<Generator, MemStat_NavDataGen>
57 {
58  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
59 
60 friend class NavDataIndexBlobBuilder_FromGenerator;
61 
62 public:
74  Generator(Ptr<GeneratorInputProducer> producer,
75  Ptr<IParallelForInterface> parallelForInterface = nullptr,
76  Ptr<ITlsAlloc> tlsAlloc = nullptr,
77  Ptr<ICollisionInterface> collisionInterface = nullptr);
78 
82  Generator(Ptr<GeneratorInputProducer> producer, Ptr<IGeneratorGlue> generatorGlue);
83 
84  ~Generator();
85 
86 public:
87  // ------------------------------ Configuration ------------------------------
88 
91  void SetFileOpener(FileOpenerBase* fileOpener);
92 
99  void SetOutputDirectory(const char* absoluteOutputBaseDir, const char* relativeOutputDir);
100 
102  const String& GetAbsoluteOutputDirectory() const { return m_sys.GetAbsoluteOutputDirectory(); }
103 
104  // ---------------------------------- Generation ----------------------------------
105 
109 
110  // ---------------------------------- Reporting ----------------------------------
111 
113  template <class OSTREAM> void LogConfiguration(OSTREAM& os);
114 
116  const GeneratorReport& GetGeneratorReport() const { return m_report; }
117 
119  const GeneratorProfiling& GetGeneratorProfiling() const { return m_generatorProfiling; }
120 
121  // ---------------------------------- Internal Access Only ----------------------------------
122 
123  GeneratorSystem& Sys() { return m_sys; }
124  const KyArray<Ptr<GeneratorSectorBuilder> >& GetSectorBuilders() const { return m_sectorBuilders; }
125 
126 private:
127  void ClearGeneratedData();
128  void ClearSectors();
129 
130  KyResult AddSector(Ptr<GeneratorSector> sector);
131 
132  void Init(Ptr<IParallelForInterface> parallelFor, Ptr<ITlsAlloc> tlsAlloc, Ptr<ICollisionInterface> collisionInterface);
133 
134  KyResult GenerateInit(GeneratorInputOutput& generatorInputOutput);
135  bool CheckUserConfig(const GeneratorParameters& config) const;
136  bool CheckSysConfig() const;
137 
138  KyResult GenerateNavData();
139  KyResult ProduceSectorInputs();
140  void MakeGlobalGrid();
141  void MakeNavDataElements();
142  KyResult GenerateRawNavCells();
143  KyResult PerformSeedOrSurfaceFiltering();
144  KyResult PerformIntegrationOfTagvolumes();
145  KyResult MakeOutputBlobAggregates();
146  void ComputeStatistics();
147  KyResult BuildOutputDataIndex();
148  KyResult UpdateAndSaveGeneratorInputOutput();
149 
150  void AddInputCellInfosContributingToSingleGuid(
151  KyUInt32 mainIdx, const InputCellInfoArrayAtPos* inputCellInfoArrayAtPos, InputCellInfoArrayAtPos* contributingInputCellInfoArrayAtPos);
152 
153  bool IsGuidCompoundExclusive(const GeneratorGuidCompound& guidCompound) const;
154  void UpdateGeneratorInputOutput();
155  KyResult SaveGeneratorInputOutput();
156  KyResult SaveDatabaseDescriptorIndex();
157 
158  KyResult ProduceSectorInputs_FromChangedPatchs();
159  KyResult ProduceSectorInputs_FromSectorsOverlappingWithChangedPatches();
160  KyResult ProduceSectorInputs_FromChangedSectors();
161  KyResult ProduceSectorInputs_FromSectorsOverlappingWithChangedRegularSectors();
162 
163  void MakeNavDataElementsAtCellPos(const InputCellInfoArrayAtPos* cellsAtPos);
164  void RemoveInputTilesTempDir();
165 
166  KyResult MakeAbstractGraphs();
167 
168 public: //internal
169  void RemoveInputTilesPartTempDir();
170 
171 private:
172  Ptr<GeneratorInputProducer> m_producer;
173  Ptr<IGeneratorGlue> m_generatorGlue; // Ptr stored so that the passed glue is not deleted while being used
174  GeneratorSystem m_sys;
175  DefaultFileOpener m_defaultFileOpener;
176  KyArray<Ptr<GeneratorSectorBuilder> > m_sectorBuilders;
177  GeneratorSectorList m_sectorList;
178  InputCellInfoGrid m_inputCellGrid;
179  KyArray<GeneratorGuidCompound> m_exclusiveGuids;
180  GeneratorReport m_report;
181  GeneratorProfiling m_generatorProfiling;
182  KyArray<CellPos> m_patchedCellPositions;
183 };
184 
185 
186 template <class OSTREAM>
187 inline void Generator::LogConfiguration(OSTREAM& os)
188 {
189  os << KY_LOG_BIG_TITLE_BEGIN("", "Generator Configuration Info");
190 
191  os << m_sys;
192  os << m_sys.Config();
193  os << m_sys.RunOptions();
194 
195  for (KyUInt32 sectorIdx = 0; sectorIdx < m_sectorBuilders.GetCount(); ++sectorIdx)
196  {
197  os << KY_LOG_SMALL_TITLE_BEGIN("", "Sector " << sectorIdx <<" Info");
198  m_sectorBuilders[sectorIdx]->LogConfiguration(os);
199  os << KY_LOG_SMALL_TITLE_END("", "Sector " << sectorIdx <<" Info");
200  }
201 
202  os << KY_LOG_BIG_TITLE_END("", "Generator Configuration Info");
203 }
204 
205 
206 }
207 
208 
Base interface for a class that opens a file on disk.
Definition: fileopener.h:30
The GeneratorReport class encapsulates a detailed report of all activities carried out during a call ...
Definition: generatorreport.h:106
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
const GeneratorReport & GetGeneratorReport() const
Retrieves a detailed record of the results of the last call to Generate().
Definition: generator.h:116
KyResult Generate(GeneratorInputOutput &config)
Launch the generation of the sectors stored in config, using the config parameters and runOptions als...
Definition: generator.cpp:220
const String & GetAbsoluteOutputDirectory() const
returns absoluteOutputBaseDir/relativeOutputDir set by SetOutputDirectory()
Definition: generator.h:102
GeneratorSystem gathers everything that is global across a generation: configuration, options...
Definition: generatorsystem.h:45
The Generator is the principal class in the NavData generation system.
Definition: generator.h:56
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Navigation return code class.
Definition: types.h:108
const GeneratorProfiling & GetGeneratorProfiling() const
Get some profiling information about the time taken by the various steps of the generation.
Definition: generator.h:119
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Generator(Ptr< GeneratorInputProducer > producer, Ptr< IParallelForInterface > parallelForInterface=nullptr, Ptr< ITlsAlloc > tlsAlloc=nullptr, Ptr< ICollisionInterface > collisionInterface=nullptr)
Constructs a new Generator initialized with the provided information.
Definition: generator.cpp:42
The GeneratorInputOutput class is a central element of the generation.
Definition: generatorinputoutput.h:35
void SetFileOpener(FileOpenerBase *fileOpener)
Sets the Kaim::FileOpenerBase derived class that will be used to open any files.
Definition: generator.cpp:71
void SetOutputDirectory(const char *absoluteOutputBaseDir, const char *relativeOutputDir)
Sets the directory used for the generation.
Definition: generator.cpp:65
void LogConfiguration(OSTREAM &os)
Creates a detailed record of all configuration parameters and sector information, and writes the reco...
Definition: generator.h:187