gwnavruntime/querysystem/workingmemcontainers/trianglestatusingrid.h Source File

trianglestatusingrid.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_TriangleStatusInGrid_H
8 #define Navigation_TriangleStatusInGrid_H
9 
13 
14 namespace Kaim
15 {
16 
17 class TriangleStatusInGrid
18 {
19  // to access Triangle Status
20  // From CellPos we allocate some memory in the buffer for NavFloors (IntermediateStatusAccessor)
21  // and then for each navFloor we allocate memory for triangles status (IndexedStatus)
22  typedef StatusInGridBase::IndexedStatus NavFloorToTriangles;
23  typedef StatusInGridBase::IntermediateStatusAccessor<NavFloorToTriangles> CellPosToNavFloors;
24 
25 public:
26  TriangleStatusInGrid(WorkingMemory* workingMemory, const CellBox& cellBox) :
27  m_statusInGridBase(workingMemory, cellBox)
28  {
29  MakeEmpty();
30  }
31 
32  void MakeEmpty();
33 
34  KY_INLINE NavFloorToTriangles* AllocateNavFloorToTriangles(KyUInt32 numberofFloors);
35  KY_INLINE CellPosToNavFloors* AllocateCellPosToNavCells(KyUInt32 numberOfNavCell);
36  KY_INLINE CellPosToNavFloors* GetCellPosToNavFloors(const CellPos& cellPos);
37 
38  TraversalResult OpenNodeIfNew(ActiveData& activeData, const NavTriangleRawPtr& triangleRawPtr, bool& nodeWasNew);
39  bool IsTriangleOpen(const NavTriangleRawPtr& triangleRawPtr) const;
40 
41  KY_INLINE bool IsTriangleOpen_Unsafe(const NavTriangleRawPtr& triangleRawPtr) const;
42 
43  KY_INLINE bool IsInitialized() const { return m_statusInGridBase.IsInitialized(); }
44 
45  void ReleaseWorkingMemoryBuffer() { m_statusInGridBase.ReleaseWorkingMemoryBuffer(); }
46 public:
47  StatusInGridBase m_statusInGridBase;
48 };
49 
50 KY_INLINE TriangleStatusInGrid::NavFloorToTriangles* TriangleStatusInGrid::AllocateNavFloorToTriangles(KyUInt32 numberofFloors)
51 {
52  return (NavFloorToTriangles*)m_statusInGridBase.AllocateInBufferAndMemset(sizeof(NavFloorToTriangles), numberofFloors, 0xFF);
53 }
54 
55 KY_INLINE TriangleStatusInGrid::CellPosToNavFloors* TriangleStatusInGrid::AllocateCellPosToNavCells(KyUInt32 numberOfNavCell)
56 {
57  return (CellPosToNavFloors*)m_statusInGridBase.AllocateInBufferAndMemset(sizeof(CellPosToNavFloors), numberOfNavCell, 0xFF);
58 }
59 
60 KY_INLINE bool TriangleStatusInGrid::IsTriangleOpen_Unsafe(const NavTriangleRawPtr& triangleRawPtr) const
61 {
62  KY_DEBUG_ASSERTN(m_statusInGridBase.m_cellBox.IsInside(triangleRawPtr.GetCellPos()), ("Invalid CellBox"));
63 
64  NavFloor* navFloor = triangleRawPtr.GetNavFloor();
65  const CellPos& cellPos = navFloor->GetCellPos();
66 
67  CellPosToNavFloors& cellPosToNavFloors = ((CellPosToNavFloors*)m_statusInGridBase.GetBuffer())[m_statusInGridBase.m_cellBox.GetRowMajorIndex(cellPos)];
68  KY_DEBUG_ASSERTN(cellPosToNavFloors.IsValid(), ("Unsafe mode, it should never happen"));
69 
70  NavFloorToTriangles& navFloorToTriangles = *cellPosToNavFloors.GetUnderlyingObject(navFloor->GetIndexInCollection());
71  KY_DEBUG_ASSERTN(navFloorToTriangles.IsValid(), ("Unsafe mode, it should never happen"));
72 
73  return navFloorToTriangles.IsNodeOpen(triangleRawPtr.GetTriangleIdx());
74 }
75 
76 KY_INLINE TriangleStatusInGrid::CellPosToNavFloors* TriangleStatusInGrid::GetCellPosToNavFloors(const CellPos& cellPos)
77 {
78  return (CellPosToNavFloors*)m_statusInGridBase.GetBuffer() + m_statusInGridBase.m_cellBox.GetRowMajorIndex(cellPos);
79 }
80 
81 }
82 
83 
84 #endif
85 
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
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36