gwnavgeneration/generator/generatorsector.h Source File

generatorsector.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 
16 
17 namespace Kaim
18 {
19 
20 class GeneratorSectorBlob;
21 class GeneratorFileSystem;
22 class BlobFieldsMapping;
23 
25 class GeneratorSectorRefCountedUserData : public Kaim::RefCountBase<GeneratorSectorRefCountedUserData, Kaim::MemStat_NavDataGen>
26 {
27 public:
28  virtual const char* GetType() const = 0;
29 
30  bool Isa(const char* type) const { return SFstrcmp(GetType(), type) == 0; }
31 
33 };
34 
39 class GeneratorSector : public RefCountBaseNTS<GeneratorSector, MemStat_NavDataGen>
40 {
41  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
42 
43 friend class Generator;
44 friend class GeneratorSectorBuilder;
45 friend class GeneratorSectorBlobBuilder;
46 friend class GeneratorSectorListBlob;
47 
48 public:
50  GeneratorSector(const KyGuid& sectorGuid, const char* sectorName);
51  void Clear();
52 
56  enum ClearPointedDataMode { CLEAR_NONE = 0, CLEAR_NAVDATA = 1, CLEAR_USERDATA = 2, CLEAR_ALL_POINTED_DATA = 3 };
57  void ClearPointedData(ClearPointedDataMode clearPointedDataMode);
58 
59 public:
60  const char* GetName() const { return m_sectorName.ToCStr(); }
61  const String& GetNameString() const { return m_sectorName; }
62 
63  const KyGuid& GetGuid() const { return m_sectorGuid; };
64  String GetGuidString() const;
65 
66  void SetInputSource(GenFlags::SectorInputSource inputSource) { m_inputSource = inputSource; }
68 
69  void SetProduceInputMask(GenFlags::ProduceInputMask produceInputMask) { m_produceInputMask = produceInputMask; }
70  GenFlags::ProduceInputMask GetProduceInputMask() const { return (GenFlags::ProduceInputMask)m_produceInputMask; }
71 
72  void SetSectorChange(GenFlags::SectorChange sectorChange) { m_sectorChange = sectorChange; }
73  GenFlags::SectorChange GetSectorChange() const { return (GenFlags::SectorChange)m_sectorChange; }
74 
75  void SetClientInputSaveEnabled(bool isClientInputSaveEnabled) { m_isClientInputSaveEnabled = isClientInputSaveEnabled; }
76  bool GetClientInputSaveEnabled() const { return m_isClientInputSaveEnabled; }
77 
78  void SetColDataBuildMode(GenFlags::SectorColDataBuildMode colDataBuildMode) { m_colDataBuildMode = colDataBuildMode; }
80 
81  void AddInputFileName(const char* inputFileName) { m_inputFileNames.PushBack(String(inputFileName)); }
82 
83  void AddInputSeedPoint(const Vec3f& position) { m_additionalSeedPoints.PushBack(position); }
84  void AddInputSeedPointInClientCoordinates(const Vec3f& client_position, const CoordSystem& coordSystem) { AddInputSeedPoint(coordSystem.ClientToNavigation_Pos(client_position)); }
85 
86  void AddInputTagVolume(const ClientInputTagVolume& clientInputTagVolume) { m_additionalTagVolumes.PushBack(clientInputTagVolume); }
87 
88  bool IsNavDataCellBoxSet() const { return m_navDataCellBox.IsValid(); }
89 
90  String GetAbsoluteOutputFileName(const GeneratorFileSystem& fileSystem, const String& extension) const;
91  String GetRelativeOutputFileName(const GeneratorFileSystem& fileSystem, const String& extension) const;
92 
95  Ptr<NavData> GetNavData() { return m_navData; }
96 
98  Ptr<NavData> GetNavDataPatch() { return m_navDataPatch; }
99 
102  Ptr<CollisionData> GetColData() { return m_colData; }
103 
105  KyResult SaveNavData(const char* filename, FileOpenerBase* fileOpener = nullptr, Endianness::Type endianness = Endianness::LittleEndian);
106 
107 private:
108  void InitBlobFieldsMapping(BlobFieldsMapping& mapping);
109  void InitFromBlob(const GeneratorSectorBlob& blob);
110 
111 public:
112  // ---------- High level description of the sector, once these parameters has been set, they must not change. ----------
114  String m_sectorName;
116  bool m_isPatch;
117 
118  // ---------- How to produce the sector generation inputs. These parameters are mostly used in your implementation of GeneratorInputProducer::ProduceSectorInputs() ----------
119  // How to produce the inputs. Your derivation of GeneratorInputProducer passed to the Generator constructor has the responsibility to produce inputs.
120  // But the following parameters affect the process.
126 
130  void* m_userData;
131  Ptr<GeneratorSectorRefCountedUserData> m_refCountedUserData;
132 
133  // ---------- Generation Outputs ----------
138  Ptr<NavData> m_navData;
139  Ptr<NavData> m_navDataPatch;
140  Ptr<CollisionData> m_colData;
141 
142  // ---------- Previous generation outputs, which are useful for iterative generations ----------
146 };
147 
148 
149 inline String GeneratorSector::GetGuidString() const
150 {
151  char guidChars[37];
152  m_sectorGuid.ToString(guidChars);
153  return String(guidChars);
154 }
155 
156 }
157 
158 
159 
Ptr< GeneratorSectorRefCountedUserData > m_refCountedUserData
Allows to point to your own sector data. Typically to be used in GeneratorInputProducer::ProduceSecto...
Definition: generatorsector.h:131
Ptr< NavData > m_navDataPatch
Generated NavData. Relevant when m_isPatch=true and m_patchOperation!=PATCH_NO_CHANGE.
Definition: generatorsector.h:139
Ptr< CollisionData > m_colData
Will be accessible when generation is done through GetColData(). nullptr until then.
Definition: generatorsector.h:140
Ptr< CollisionData > GetColData()
Retrieve a pointer to the ColData that was generated for this sector, or nullptr if the ColData is no...
Definition: generatorsector.h:102
const char * GetName() const
Retrieves the name set for this sector as char*.
Definition: generatorsector.h:60
Base interface for a class that opens a file on disk.
Definition: fileopener.h:30
KyGuid m_sectorGuid
The sector GUID.
Definition: generatorsector.h:113
Ptr< NavData > GetNavData()
Retrieve a pointer to the NavData that was generated for this sector, or nullptr if the navdata is no...
Definition: generatorsector.h:95
String m_clientInputAbsoluteFileName
Indicates Set by the Generator when the ClientInput is saved.
Definition: generatorsector.h:134
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
bool m_isClientInputSaveEnabled
Indicates whether to save ClientInput file.
Definition: generatorsector.h:124
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Maintains generation data for each sector.
Definition: generatorsectorbuilder.h:39
SectorColDataBuildMode
Describes whether or not CollisionData should be saved on a per-sector basis.
Definition: genflags.h:41
Ptr< NavData > m_navData
Generated NavData. Relevant when m_isPatch=false and m_buildMode=SECTOR_CHANGE.
Definition: generatorsector.h:138
Used to serialize GeneratorInputOutput.
Definition: generatorsectorconfigblob.h:56
KyArray< ClientInputTagVolume > m_additionalTagVolumes
Optional. Will be fed automatically to the Sector. Sometimes easier than producing TagVolumes in Gene...
Definition: generatorsector.h:129
KyArray< CellPos > m_previousPatchCellPosList
From previous generation, the list of CellPos that were impacted by the Patch inputs. Empty if m_isPatch is false or if the Patch is new.
Definition: generatorsector.h:143
The Generator is the principal class in the NavData generation system.
Definition: generator.h:56
SectorInputSource
Describes where the Generator will get its input for each sector.
Definition: genflags.h:15
Used to serialize GeneratorInputOutput. Corresponds to GeneratorSector.
Definition: generatorsectorconfigblob.h:25
KyArray< Vec3f > m_additionalSeedPoints
Optional. Will be fed automatically to the Sector. Sometimes easier than producing seedPoints in Gene...
Definition: generatorsector.h:128
KyUInt32 m_produceInputMask
GenFlags::ProduceInputMask. Read when producing input from ClientInput. default = GenFlags::ProduceIn...
Definition: generatorsector.h:122
bool m_isPatch
Indicates if the Sector is a Patch.
Definition: generatorsector.h:116
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
KyArray< String > m_inputFileNames
Optional. To be used in GeneratorInputProducer::ProduceSectorInputs().
Definition: generatorsector.h:127
KyUInt32 m_colDataBuildMode
GenFlags::SectorColDataBuildMode.
Definition: generatorsector.h:125
String m_sectorName
The sector Name.
Definition: generatorsector.h:114
Little-endian format (used, for example, for Windows, Linux).
Definition: endianness.h:22
String m_navDataAbsoluteFileName
Set by the Generator when the NavData is saved. Relevant when isPatch is false.
Definition: generatorsector.h:135
KyUInt32 m_inputSource
GenFlags::SectorInputSource. Indicates whether GeneratorInputProducer::ProduceSectorInputs() is calle...
Definition: generatorsector.h:121
Navigation return code class.
Definition: types.h:108
KyResult SaveNavData(const char *filename, FileOpenerBase *fileOpener=nullptr, Endianness::Type endianness=Endianness::LittleEndian)
If NavData was generated, save it to the specified location.
Definition: generatorsector.cpp:111
SectorChange
Describes what the generation does about a sector.
Definition: genflags.h:26
The GeneratorSector class provides a definition for a single sector to be treated by the Generator...
Definition: generatorsector.h:39
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
The KyGuid class represents a globally unique ID.
Definition: kyguid.h:20
Base class for the optional m_refCountedUserData that allows to refCount your user data...
Definition: generatorsector.h:25
KyArray< Vec3f > m_previousSeedPoints
From previous generation, the sector SeedPoints. Currently not used except to maintain Blob compatibi...
Definition: generatorsector.h:145
void ToString(char guidString[]) const
Converts this GUID to a string.
Definition: kyguid.cpp:157
Type
Enumerates possible endianness types.
Definition: endianness.h:20
String m_colDataAbsoluteFileName
Set by the Generator when the ColData is saved.
Definition: generatorsector.h:137
CellBox m_navDataCellBox
Optional, limits the NavData generation to this CellBox. Relevant when pipeline uses tiles as sectors...
Definition: generatorsector.h:115
String m_navDataPatchAbsoluteFileName
Set by the Generator when the NavDataPatch is saved.
Definition: generatorsector.h:136
used to serialize GeneratorInputOutput
Definition: generatorsectorlistblob.h:21
CellBox m_previousInputCellBox
From previous generation, the AABB of CellPos that were impacted by the Sector or Patch Inputs...
Definition: generatorsector.h:144
Ptr< NavData > GetNavDataPatch()
Retrieve a pointer to the NavDataPatch that was generated for this sector, or nullptr if the navDataP...
Definition: generatorsector.h:98
ClearPointedDataMode
Reset the GeneratorSector as if is was just default constructed.
Definition: generatorsector.h:56
const String & GetNameString() const
Retrieves the name set for this sector as String.
Definition: generatorsector.h:61
KyUInt32 m_sectorChange
What has changed in the sector since previous generation.
Definition: generatorsector.h:123
void * m_userData
Allows to point to your own sector data. Typically to be used in GeneratorInputProducer::ProduceSecto...
Definition: generatorsector.h:130
String GetGuidString() const
Retrieves the GUID set for this sector.
Definition: generatorsector.h:149