gwnavgeneration/input/clientinputconsumer.h Source File

clientinputconsumer.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 
18 
19 namespace Kaim
20 {
21 
22 class GeneratorSystem;
23 class SpatializedSectorInput;
24 class SectorInputData;
25 class GeneratorSector;
26 class GeneratorInputProducer;
27 class Pair_Vec3f_i;
28 
29 // interesting statistics, can be used to check if there was a OneMeter problem
30 class ClientInputConsumerStatistics
31 {
32  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
33 public:
34  ClientInputConsumerStatistics() { Clear(); }
35 
36  void Clear()
37  {
38  m_nbConsumedTriangles = 0;
39  m_consumedSurface2d = 0;
40  m_nbConsumedVolumes = 0;
41  }
42 
43  KyUInt32 GetNbConsumedTriangles() { return m_nbConsumedTriangles; }
44  KyFloat32 GetConsumedSurface2d() { return m_consumedSurface2d; }
45  KyFloat32 GetAverageConsumedTriangleSurface2d() { return m_consumedSurface2d / (KyFloat32)m_nbConsumedTriangles; }
46  void GetConsumedTrianglesBoundingBox(Box3f& box) { box = m_consumedTrianglesBoundingBox; }
47 
48 public:
49  KyInt32 m_nbConsumedTriangles;
50  KyFloat32 m_consumedSurface2d;
51  Box3f m_consumedTrianglesBoundingBox;
52  KyUInt32 m_nbConsumedVolumes;
53 };
54 
63 {
64  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
65  friend class GeneratorSectorBuilder;
66  friend class SectorInputData;
67 
68 public:
69  // ClientInputConsumer will initialize
70  // seedPoints with what is passed to ConsumeSeedPoint()
71  // inputMeshBuilder with what is passed to ConsumeTriangle...()
72  // indexedMeshes with what is passed to ConsumeIndexedMesh()
73  // heightfield with what is passed to ConsumeHeightfield()
74  ClientInputConsumer(GeneratorSystem* sys, Ptr<GeneratorSector> sector, KyArray<Vec3f>* seedPoints, KyArray<TagVolumeInitConfig>* tagVolumeConfigs,
75  IndexedMeshBlobBuilder* inputMeshBuilder, KyArray<Ptr<IndexedMesh>>* indexedMeshes, Ptr<HeightField>* heightfield);
76 
78 
79 public:
80  // ---------------------------------- Consumption ----------------------------------
81 
83  KyResult ConsumeTriangle(const Vec3f& A, const Vec3f& B, const Vec3f& C);
84 
86  KyResult ConsumeTriangle(const Vec3f& client_A, const Vec3f& client_B, const Vec3f& client_C, const CoordSystem& clientCoordSystem);
87 
89  KyResult ConsumeTriangle(const Vec3f& A, const Vec3f& B, const Vec3f& C, const DynamicNavTag& navTag);
90 
93  const Vec3f& client_A, const Vec3f& client_B, const Vec3f& client_C, const DynamicNavTag& navTag, const CoordSystem& clientCoordSystem);
94 
97  KyResult ConsumeTagVolume(const ClientInputTagVolume& inputTagVolume);
98 
104  KyResult ConsumeSeedPoint(const Vec3f& position);
105 
107  KyResult ConsumeSeedPointInClientCoordinates(const Vec3f& client_position, const CoordSystem& clientCoordSystem) { return ConsumeSeedPoint(clientCoordSystem.ClientToNavigation_Pos(client_position)); }
108 
109  KyResult ConsumeHeightField(Ptr<HeightField> heightfield);
110  KyResult ConsumeHeightFieldFile(const String& heightfieldFileName);
111 
112  KyResult ConsumeIndexedMesh(Ptr<IndexedMesh> indexedMesh);
113  KyResult ConsumeIndexedMeshFile(const String& indexedMeshFileName);
114 
116  ClientInputConsumerStatistics& GetStats() { return m_stats; }
117 
118  Color GetNavTagColor(const DynamicNavTag& dynamicNavTag) const;
119 public: // Deprecated:
120  KY_DEPRECATED(Color GetNavTagVisualColor(const DynamicNavTag& dynamicNavTag) const) { return GetNavTagColor(dynamicNavTag); }
121 
122 private:
124  void Flush();
125  KyResult SaveClientInput(const String& fullFileName);
126  KyResult FlushClientInput();
127  void TestWarningOnLowMemoryModeNbTriangles();
128  bool IsTriangleSlopeWalkable(const Vec3f& A, const Vec3f& B, const Vec3f& C);
129  void ConsumeSmallEnoughTriangle(const Triangle3fi& triangle, bool isTriangleSlopeWalkable, const DynamicNavTag& dynamicNavTag, Color navTagColor);
130 
131 public:
132  ClientInputConsumerStatistics m_stats;
134 
135 private: // ---------------------------------- Internal ----------------------------------
136  Ptr<GeneratorSector> m_sector;
137 
138  // computed (or read) directly from m_sys->m_genIO->m_params
139  DynamicNavTag m_defaultNavTag;
142 
143  DynamicClientInputChunk m_dynamicClientInputChunk;
145 
146  KyUInt32 m_clientInputFlushSize;
147  KyUInt32 m_clientInputPushedSize;
148 
149  KyUInt32 m_warnOnLowMemoryModeNbTriangles;
150 
151  SpatializedSectorInput* m_spatializedSectorInput;
153  KyArray<TagVolumeInitConfig>* m_tagVolumeConfigs;
154 
157 
158  IndexedMeshBlobBuilder* m_inputMeshBuilder;
160  Ptr<HeightField>* m_heightfield;
161 };
162 
163 
164 inline KyResult ClientInputConsumer::ConsumeTriangle(const Vec3f& A, const Vec3f& B, const Vec3f& C)
165 {
166  return ConsumeTriangle(A, B, C, m_defaultNavTag);
167 }
168 
169 inline KyResult ClientInputConsumer::ConsumeTriangle(const Vec3f& client_A, const Vec3f& client_B, const Vec3f& client_C, const CoordSystem& clientCoordSystem)
170 {
171  return ConsumeTriangle(client_A, client_B, client_C, m_defaultNavTag, clientCoordSystem);
172 }
173 
174 
175 }
176 
177 
178 
void Flush()
internal usage by GeneratorSectorBuilder
Definition: clientinputconsumer.cpp:351
ClientInputConsumerStatistics m_stats
Maintains statistics about the data added to this object. Do not modify.
Definition: clientinputconsumer.h:132
The ClientInputConsumer class is one of the primary components of the NavData generation system...
Definition: clientinputconsumer.h:62
KyArray< Ptr< IndexedMesh > > * m_indexedMeshes
Internal member: Consumed IndexedMesh in Navigation coordinates.
Definition: clientinputconsumer.h:159
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Maintains generation data for each sector.
Definition: generatorsectorbuilder.h:39
KyUInt32 m_clientInputFlushCount
Internal member: Count how many times the ClientInput was flushed.
Definition: clientinputconsumer.h:144
GeneratorSystem gathers everything that is global across a generation: configuration, options...
Definition: generatorsystem.h:45
This class maintains the mapping between the system of coordinate axes used by the client game engine...
Definition: coordsystem.h:119
Ptr< HeightField > * m_heightfield
Internal member: Consumed heightField in Navigation coordinates.
Definition: clientinputconsumer.h:160
bool m_backFaceTrianglesWalkable
Internal member: Accessed using ToggleBackfaceTriangleFiltering.
Definition: clientinputconsumer.h:140
General purpose array for movable objects that require explicit construction/destruction.
Definition: kyarray.h:162
ClientInputConsumerStatistics & GetStats()
Retrieves information about the triangles consumed by this object.
Definition: clientinputconsumer.h:116
KyResult ConsumeTagVolume(const ClientInputTagVolume &inputTagVolume)
Provides a single tag volume to the ClientInputConsumer.
Definition: clientinputconsumer.cpp:221
SpatializedSectorInput * m_spatializedSectorInput
Internal member:sSpatialized input in Navigation coordinates.
Definition: clientinputconsumer.h:151
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
KyResult ConsumeSeedPoint(const Vec3f &position)
Provides a seed point that identifies a walkable area of the terrain.
Definition: clientinputconsumer.cpp:246
Maintains the InputCellBlobs spatialized per CellPos for 1 SectorInput.
Definition: sectorinputdata.h:43
KyResult ConsumeSeedPointInClientCoordinates(const Vec3f &client_position, const CoordSystem &clientCoordSystem)
Identical to previous function but uses vertices in client coordinate system that must be specified i...
Definition: clientinputconsumer.h:107
DynamicClientInputChunk m_dynamicClientInputChunk
Internal member: Original input chunk.
Definition: clientinputconsumer.h:143
KyArray< Triangle3fi > m_tessellatedStack
Temporary buffer for tessellated - in Navigation coordinates.
Definition: clientinputconsumer.h:156
#define KY_DEPRECATED(expr)
The compiler issues a warning when a deprecated function or typedef is used.
Definition: types.h:93
Navigation return code class.
Definition: types.h:108
KyFloat32 m_cosSlopeMax
Internal member: cosinus of maximum slope.
Definition: clientinputconsumer.h:141
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
RGBA color.
Definition: color.h:16
GeneratorSystem * m_sys
Fast access to the Generator-related information.
Definition: clientinputconsumer.h:133
DynamicNavTag m_defaultNavTag
shortcut for m_sys m_genParams.m_defaultNavTag;
Definition: clientinputconsumer.h:139
std::int32_t KyInt32
int32_t
Definition: types.h:24
KyArray< Triangle3fi > m_tessellatedOutput
Temporary buffer for tessellated triangles - in Navigation coordinates.
Definition: clientinputconsumer.h:155
Ptr< GeneratorSector > m_sector
Internal member: The sector being processed.
Definition: clientinputconsumer.h:136
KyArray< Vec3f > * m_seedPoints
Internal member: Consumed seedpoints in Navigation coordinates.
Definition: clientinputconsumer.h:152
void ClientToNavigation_Pos(const Vec3f &clientPos, Vec3f &navigationPos) const
Convert positions or any other vectors which length have to be scaled when converted.
Definition: coordsystem.inl:78
KyResult ConsumeTriangle(const Vec3f &A, const Vec3f &B, const Vec3f &C)
A, B and C are in Navigation coordinate system. m_defaultNavTag is used.
Definition: clientinputconsumer.h:164
Represents a volume using a two-dimensional polyline extruded vertically along the "up" axis associat...
Definition: clientinputtagvolume.h:25
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16