gwnavgeneration/input/inputtilecontributionatpos.h Source File

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