gwnavgeneration/input/inputtilecontributionatpos.h Source File

inputtilecontributionatpos.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 
14 
15 
16 namespace Kaim
17 {
18 
19 class GeneratorSystem;
20 class GeneratorSectorBuilder;
21 class CellGenerator;
22 
23 typedef Vec2i TilePos;
24 
25 class InputTileContributionAtPos
26 {
27  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
28  friend class InputTileCache;
29 
30 public:
31  class InputTileInfo
32  {
33  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
34  public:
35  InputTileInfo() : m_sectorBuilder(nullptr), m_inputTileBlob(nullptr) {} // To make KyArray happy
36  InputTileInfo(GeneratorSectorBuilder* sectorBuilder) : m_sectorBuilder(sectorBuilder), m_inputTileBlob(nullptr) {}
37  InputCellBlob* GetInputCellBlob(const CellPos& cellPos) const
38  {
39  KY_ASSERT(m_inputTileBlob != nullptr);
40  return m_inputTileBlob->GetInputCellBlob(cellPos);
41  }
42  public:
43  GeneratorSectorBuilder* m_sectorBuilder;
44  InputTileBlob* m_inputTileBlob;
45  };
46 
47 public:
48  InputTileContributionAtPos(KyInt32 x, KyInt32 y) // counter intuitive constructor to match the DynamicGrid concept
49  : m_tilePos(x, y) {}
50 
51  void Init(KyUInt32 inputTileSizeInNbCells);
52 
53  void AddCellContribution(const CellPos& cellPos, GeneratorSectorBuilder* sectorBuilder);
54 
55  const TilePos& GetTilePos() const { return m_tilePos; }
56  const CellBox& GetTileCellBox() const { return m_tileCellBox; }
57 
58  // Must be called after InputTileCache::Load(inputTileContributionAtPos) was called
59  void GetInputCellBlobsAtCellPos(const CellPos& cellPos, KyArrayPOD<const InputCellBlob*>& inputCellBlob);
60  KyUInt32 GetInputCellBlobsCountAtCellPos(const CellPos& cellPos);
61 
62  KyUInt32 GetContributingCellCount();
63 
64  void ClearInputTileBlobs();
65 
66 private:
67  TilePos m_tilePos;
68  CellBox m_tileCellBox;
69  KyArray<InputTileInfo> m_inputTileInfos;
70  KyArray<KyArray<GeneratorSectorBuilder*> > m_contributingSectorRowMajorMatrix; // Matrix in m_tileCellBox
71 };
72 
73 
74 class InputTileCacheEntry
75 {
76  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
77 
78 public:
79  InputTileCacheEntry() : m_sectorBuilder(nullptr) {}
80 
81  bool operator==(const InputTileCacheEntry& other)
82  {
83  return m_sectorBuilder == other.m_sectorBuilder
84  && m_tilePos == other.m_tilePos;
85  }
86 
87 public:
88  GeneratorSectorBuilder* m_sectorBuilder;
89  TilePos m_tilePos;
90  Ptr<BlobHandler<InputTileBlob> > m_inputTileBlobHandler;
91 };
92 
93 
94 // InputTileCache allows to load InputTile from files.
95 // InputTileCache works as a least recently used cache for loaded InputTiles.
96 // InputTileCache is created on the stack at the beginning of GenerateSectors()
97 class InputTileCache
98 {
99  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
100 
101 public:
102  InputTileCache(GeneratorSystem* sys, KyUInt32 memoryLimitInMegaBytes = 100)
103  : m_sys(sys)
104  , m_memoryLimitInMegaBytes(memoryLimitInMegaBytes)
105  , m_currentMemoryUsageInMegaBytes(0)
106  {}
107 
108  KyResult Load(InputTileContributionAtPos& inputTileContributionAtPos);
109 
110  void UnloadAll();
111 
112 private:
113  InputTileBlob* Load(GeneratorSectorBuilder* sectorBuilder, const TilePos& tilePos);
114 
115  //void UnloadLeastRecentlyUsed();
116  //void Unload(InputTileInfo& inputTileInfo);
117 
118 public:
119  GeneratorSystem* m_sys;
120  KyUInt32 m_memoryLimitInMegaBytes;
121  KyUInt32 m_currentMemoryUsageInMegaBytes;
122 
123  KyArray<InputTileCacheEntry> m_entries;
124 };
125 
126 
127 }
128 
129 
130 
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
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