gwnavgeneration/input/spatializedsectorinput.h Source File

spatializedsectorinput.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 
8 #pragma once
9 
15 
16 
17 namespace Kaim
18 {
19 
20 class GeneratorSystem;
21 class Triangle3i;
22 class TaggedTriangle3i;
23 class SectorInputData;
24 
25 /*
26 cells are indexed this way
27  | | | | |
28 --+-----+-----+-----+-----+--
29  |-2, 1|-1, 1| 0, 1| 1, 1|
30  | | | | |
31 --+-----+-----+-----+-----+--
32  |-2, 0|-1, 0| 0, 0| 1, 0|
33  | | | | |
34 --+-----+-----#-----+-----+--
35  |-2,-1|-1,-1| 0,-1| 1,-1|
36  | | | | |
37 --+-----+-----+-----+---- +--
38  |-2,-2|-1,-2| 0,-2| 1,-2|
39  | | | | |
40 --+-----+-----+-----+-----+--
41  | | | | |
42 
43 a cell contains at least all triangles that intersect with
44 [cell_min - enlargement, cell_max + enlargement]
45  | | | |
46  | +---------+ |
47 --+---|-+-----+-|---+--
48  | | | | | |
49  | | | | | |
50 --+---|-+-----+-|---+--
51  | +---------+ |
52  | | | |
53  >-<
54  enlargement
55 */
56 
57 class DynInputCellArrayAtTilePos
58 {
59  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
60 public:
61  DynInputCellArrayAtTilePos(KyInt32 x, KyInt32 y) : m_x(x), m_y(y) {}
62  KyArrayPOD<DynamicInputCell*> m_dynInputCells;
63  KyInt32 m_x;
64  KyInt32 m_y;
65 };
66 
67 // tile part filenames at tilePos (x, y)
68 class TilePartFileNameArrayAtTilePos
69 {
70  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
71 public:
72  TilePartFileNameArrayAtTilePos(KyInt32 x, KyInt32 y) : m_x(x), m_y(y) {}
73  KyArray<String> m_filenames;
74  KyInt32 m_x;
75  KyInt32 m_y;
76 };
77 
78 // Spatializes the input triangles into m_dynInputCellGrid.
79 // SpatializedSectorInput is a member of ClientInputConsumer. So there is one SpatializedSectorInput per Sector.
80 // Note that ClientInputConsumer is instantiated on the stack in GeneratorSectorBuilder::ProduceInputs().
81 // SpatializedSectorInput is just a temporary data, once production/consumption of the inputs are done,
82 // inputs reside in SectorInput (for each Sector).
83 // if Tiling is enabled
84 // DynamicInputCells are spatialized into m_dynInputCellArrayTileGrid;
85 // When a given number of triangles are pushed, m_dynInputCellGrid and m_dynInputCellArrayTileGrid
86 // are copied to tilePart files referenced by m_tilePartFileNameArrayTileGrid
87 class SpatializedSectorInput
88 {
89  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
90 
91 public:
92  SpatializedSectorInput(GeneratorSystem* sys);
93 
94  ~SpatializedSectorInput() { ClearAll(); }
95 
96  void SetName(const String& name) { m_sectorName = name; }
97 
98  void SetInputTileFlushSize(KyUInt32 inputTileFlushSize) { m_inputTilesFlushSize = inputTileFlushSize; }
99 
100  void ClearAll()
101  {
102  ClearCellAndTileGrids();
103  ClearFlushedTiledFileNames();
104  }
105 
106  void ClearCellAndTileGrids();
107 
108  void ClearFlushedTiledFileNames();
109 
110  void PushTriangle(const DynamicTaggedTriangle3i& inputTriangle);
111 
112  DynamicInputCell* GetCell(CellCoord x, CellCoord y) { return m_dynInputCellGrid.Get(x, y); }
113 
114  DynamicInputCell** GetCells() { return m_dynInputCellGrid.GetElements(); }
115 
116  KyUInt32 GetCellsCount() const { return m_dynInputCellGrid.GetElementsCount(); }
117 
118  KyResult FlushTiles();
119 
120  void RemovePartsTempDirectory();
121 
122 private:
123  String GetTilePartDirName();
124  String GetTilePartFileName(KyInt32 x, KyInt32 y, KyUInt32 partIndex);
125 
126 public:
127  GeneratorSystem* m_sys;
128 
129  KyUInt32 m_inputTilesPushedSize; // in bytes. If a triangle overlap 4 cells, then it will be pushed 4 times
130  KyUInt32 m_inputTilesFlushSize; // in bytes
131 
132  DenseGridAndArrayOfRawPtr<DynamicInputCell> m_dynInputCellGrid;
133 
134  DenseGridAndArrayOfRawPtr<DynInputCellArrayAtTilePos> m_dynInputCellArrayTileGrid; // grid of m_nbCellsByInputTile * cellSize
135  DenseGridAndArrayOfRawPtr<TilePartFileNameArrayAtTilePos> m_tilePartFileNameArrayTileGrid; // grid of m_nbCellsByInputTile * cellSize. Saves the parts saved so far.
136 
137  KyGuid m_sectorGuid;
138  String m_sectorName;
139 };
140 
141 }
142 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#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
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24
KyInt32 CellCoord
A type that represents the placement of a cell on one axis of a 2D grid.
Definition: navmeshtypes.h:29