gwnavruntime/querysystem/workingmemcontainers/navfloorandnavgraphedgestatusingrid.h Source File

navfloorandnavgraphedgestatusingrid.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 
11 
12 namespace Kaim
13 {
14 
15 class NavFloorAndNavGraphEdgeStatusInGrid
16 {
17 public:
18  // NavCell -> 1 bit per NavFloor
19  typedef BitFieldInBuffer CellBits; // for 1 cell
20 
21  // NavGraph -> Vertex -> 1 bit per OutEdge
22  typedef BitFieldInBuffer VertexBits; // for 1 vertex
23  typedef ArrayInBuffer<VertexBits> GraphBits; // in 1 graph
24 
25 public:
26  NavFloorAndNavGraphEdgeStatusInGrid() : m_numberOfNavGraph(0) {}
27 
28  NavFloorAndNavGraphEdgeStatusInGrid(WorkingMemory* workingMemory, ActiveData* activeData, const CellBox& cellBox)
29  : m_allocBuffer()
30  , m_numberOfNavGraph(0)
31  , m_cellBitsArrayOffset(0)
32  , m_graphBitsArrayOffset(0)
33  {
34  Init(workingMemory, activeData, cellBox);
35  }
36 
37  void Init(WorkingMemory* workingMemory, ActiveData* activeData, const CellBox& cellBox)
38  {
39  m_allocBuffer.Init(workingMemory);
40  m_cellBox = cellBox;
41  m_numberOfNavGraph = activeData->GetNavGraphCount();
42 
43  MakeEmpty();
44  }
45 
46  void ReleaseWorkingMemoryBuffer() { m_allocBuffer.ReleaseWorkingMemoryBuffer(); }
47 
48  void MakeEmpty();
49 
50  // CellBits
51  CellBits* AllocCellBitsArray(KyUInt32 numberOfNavCell)
52  {
53  CellBits* ptr = m_allocBuffer.AllocInBuffer<CellBits>(numberOfNavCell, 0xFF);
54  m_cellBitsArrayOffset = m_allocBuffer.GetOffset(ptr);
55  return ptr;
56  }
57  CellBits* GetCellBitsArray() const { return m_allocBuffer.GetPtr<CellBits>(m_cellBitsArrayOffset); }
58  CellBits* GetCellBits(const CellPos& cellPos) const { return GetCellBitsArray() + m_cellBox.GetRowMajorIndex(cellPos); }
59 
60  // GraphBits
61  GraphBits* AllocGraphBitsArray(KyUInt32 numberOfGraphs)
62  {
63  GraphBits* ptr = m_allocBuffer.AllocInBuffer<GraphBits>(numberOfGraphs, 0xFF);
64  m_graphBitsArrayOffset = m_allocBuffer.GetOffset(ptr);
65  return ptr;
66  }
67  GraphBits* GetGraphBitsArray() const { return m_allocBuffer.GetPtr<GraphBits>(m_graphBitsArrayOffset); }
68  GraphBits* GetGraphBits(NavGraphIdxInActiveData idx) const { return GetGraphBitsArray() + idx; }
69 
70  // GraphBits -> VertexBits
71  VertexBits* AllocVertexBitsArray(KyUInt32 numberOfOutgoingEdges) { return m_allocBuffer.AllocInBuffer<VertexBits>(numberOfOutgoingEdges, 0xFF); }
72 
73  // NavFloor
74  KyResult OpenNode(ActiveData& activeData, const NavFloorRawPtr& navFloorRawPtr);
75  bool IsNodeOpen(const NavFloorRawPtr& navFloorRawPtr) const;
76 
77  // GraphEdges
78  KyResult OpenNode(ActiveData& activeData, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr);
79  bool IsNodeOpen(const NavGraphEdgeRawPtr& navGraphEdgeRawPtr) const;
80 
81  bool IsInitialized() const { return m_allocBuffer.IsInitialized(); }
82 
83 public:
84  AllocatorBuffer m_allocBuffer;
85  CellBox m_cellBox;
86  KyUInt32 m_numberOfNavGraph;
87  KyUInt32 m_cellBitsArrayOffset;
88  KyUInt32 m_graphBitsArrayOffset;
89 };
90 
91 
92 
93 }
94 
95 
96 
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
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17