gwnavruntime/querysystem/workingmemcontainers/navfloorandnavgraphedgestatusingrid.h Source File

navfloorandnavgraphedgestatusingrid.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 #ifndef Navigation_NavFloorAndNavGraphEdgeStatusInGrid_H
8 #define Navigation_NavFloorAndNavGraphEdgeStatusInGrid_H
9 
12 
13 namespace Kaim
14 {
15 
16 class NavFloorAndNavGraphEdgeStatusInGrid
17 {
18 public:
19  // for navFloor, directly from cellPos to NavFloorStatus : no intermediate class
20  typedef StatusInGridBase::IndexedStatus CellPosToNavFloorsStatus;
21 
22  // to access NavGraphEdge status
23  // From NavGraph we allocate some memory in the buffer for NavGraphVertex (IntermediateStatusAccessor)
24  // and then for each NavGraphVertex we allocate memory for outgoing NavGraphEdge status (IndexedStatus)
25  typedef StatusInGridBase::IndexedStatus NavGraphVertexToOutGoingEdgeStatus;
26  typedef StatusInGridBase::IntermediateStatusAccessor<NavGraphVertexToOutGoingEdgeStatus> NavGraphToNavGraphVertex;
27 
28 public:
29  NavFloorAndNavGraphEdgeStatusInGrid() : m_numberOfNavGraph(0) {}
30 
31  NavFloorAndNavGraphEdgeStatusInGrid(WorkingMemory* workingMemory, ActiveData* activeData) :
32  m_statusInGridBase(), m_numberOfNavGraph(0)
33  {
34  Init(workingMemory, activeData);
35  }
36 
37  void Init(WorkingMemory* workingMemory, ActiveData* activeData)
38  {
39  m_statusInGridBase.Init(workingMemory, activeData->GetCellBox());
40  m_numberOfNavGraph = activeData->GetNavGraphCount();
41 
42  MakeEmpty();
43  }
44 
45  void ReleaseWorkingMemoryBuffer() { m_statusInGridBase.ReleaseWorkingMemoryBuffer(); }
46  void MakeEmpty();
47 
48  KY_INLINE CellPosToNavFloorsStatus* AllocateCellPosToNavFloorsStatus(KyUInt32 numberOfNavCell);
49  KY_INLINE NavGraphToNavGraphVertex* AllocateNavGraphToNavGraphVertex(KyUInt32 numberOfGraphs);
50  KY_INLINE NavGraphVertexToOutGoingEdgeStatus* AllocateNavGraphVertexToEdgeStatus(KyUInt32 numberOfOutgoingEdges);
51 
52  KY_INLINE CellPosToNavFloorsStatus* GetCellPosToNavFloorsStatus_Unsafe(const CellPos& cellPos) const;
53  KY_INLINE NavGraphToNavGraphVertex* GetNavGraphToNavGraphVertex_Unsafe(NavGraphIdxInActiveData navGraphIdxInActiveData) const;
54 
55  KyResult OpenNode(ActiveData& activeData, const NavFloorRawPtr& navFloorRawPtr);
56  bool IsNodeOpen(const NavFloorRawPtr& navFloorRawPtr) const;
57 
58  KyResult OpenNode(ActiveData& activeData, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr);
59  bool IsNodeOpen(const NavGraphEdgeRawPtr& navGraphEdgeRawPtr) const;
60 
61  KY_INLINE bool IsInitialized() const { return m_statusInGridBase.IsInitialized(); }
62 public:
63  StatusInGridBase m_statusInGridBase;
64  KyUInt32 m_numberOfNavGraph;
65 };
66 
67 KY_INLINE NavFloorAndNavGraphEdgeStatusInGrid::CellPosToNavFloorsStatus* NavFloorAndNavGraphEdgeStatusInGrid::AllocateCellPosToNavFloorsStatus(KyUInt32 numberOfNavCell)
68 {
69  return (CellPosToNavFloorsStatus*)m_statusInGridBase.AllocateInBufferAndMemset(sizeof(CellPosToNavFloorsStatus), numberOfNavCell, 0xFF);
70 }
71 
72 KY_INLINE NavFloorAndNavGraphEdgeStatusInGrid::NavGraphToNavGraphVertex* NavFloorAndNavGraphEdgeStatusInGrid::AllocateNavGraphToNavGraphVertex(KyUInt32 numberOfGraphs)
73 {
74  return (NavGraphToNavGraphVertex*)m_statusInGridBase.AllocateInBufferAndMemset(sizeof(NavGraphToNavGraphVertex), numberOfGraphs, 0xFF);
75 }
76 
77 KY_INLINE NavFloorAndNavGraphEdgeStatusInGrid::NavGraphVertexToOutGoingEdgeStatus* NavFloorAndNavGraphEdgeStatusInGrid::AllocateNavGraphVertexToEdgeStatus(KyUInt32 numberOfOutgoingEdges)
78 {
79  return (NavGraphVertexToOutGoingEdgeStatus*)m_statusInGridBase.AllocateInBufferAndMemset(sizeof(NavGraphVertexToOutGoingEdgeStatus), numberOfOutgoingEdges, 0xFF);
80 }
81 
82 
83 KY_INLINE NavFloorAndNavGraphEdgeStatusInGrid::CellPosToNavFloorsStatus*
84  NavFloorAndNavGraphEdgeStatusInGrid::GetCellPosToNavFloorsStatus_Unsafe(const CellPos& cellPos) const
85 {
86  CellPosToNavFloorsStatus* memoryStartForGrid = (CellPosToNavFloorsStatus*)((NavGraphToNavGraphVertex*)m_statusInGridBase.GetBuffer() + m_numberOfNavGraph);
87  return memoryStartForGrid + m_statusInGridBase.m_cellBox.GetRowMajorIndex(cellPos);
88 }
89 
90 KY_INLINE NavFloorAndNavGraphEdgeStatusInGrid::NavGraphToNavGraphVertex*
91  NavFloorAndNavGraphEdgeStatusInGrid::GetNavGraphToNavGraphVertex_Unsafe(NavGraphIdxInActiveData navGraphIdxInActiveData) const
92 {
93  NavGraphToNavGraphVertex* memoryStartForGraphs = (NavGraphToNavGraphVertex*)m_statusInGridBase.GetBuffer();
94  return &memoryStartForGraphs[navGraphIdxInActiveData];
95 }
96 
97 }
98 
99 
100 #endif
101 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36