gwnavruntime/querysystem/workingmemcontainers/trianglestatusingrid.h Source File

trianglestatusingrid.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 
13 
14 namespace Kaim
15 {
16 
17 class TriangleStatusInGrid
18 {
19  // NavCell -> NavFloor -> 1 bit per Triangle
20  typedef BitFieldInBuffer FloorBits;
21  typedef ArrayInBuffer<FloorBits> CellBits;
22 
23 public:
24  TriangleStatusInGrid(WorkingMemory* workingMemory, const CellBox& cellBox) : m_allocBuffer(workingMemory), m_cellBox(cellBox)
25  {
26  MakeEmpty();
27  }
28 
29  void MakeEmpty();
30 
31  // CellBits
32  CellBits* AllocCellBitsArray(KyUInt32 numberOfNavCell)
33  {
34  CellBits* ptr = m_allocBuffer.AllocInBuffer<CellBits>(numberOfNavCell, 0xFF);
35  m_cellBitsArrayOffset = m_allocBuffer.GetOffset(ptr);
36  return ptr;
37  }
38  CellBits* GetCellBitsArray() const { return m_allocBuffer.GetPtr<CellBits>(m_cellBitsArrayOffset); }
39  CellBits* GetCellBits(const CellPos& cellPos) const { return GetCellBitsArray() + m_cellBox.GetRowMajorIndex(cellPos); }
40 
41  // CellBits -> FloorBits
42  FloorBits* AllocFloorBitsArray(KyUInt32 numberOfFloors) { return m_allocBuffer.AllocInBuffer<FloorBits>(numberOfFloors, 0xFF); }
43 
44  TraversalResult OpenNodeIfNew(ActiveData& activeData, const NavTriangleRawPtr& triangleRawPtr, bool& nodeWasNew);
45 
46  bool IsTriangleOpen(const NavTriangleRawPtr& triangleRawPtr) const;
47  bool IsTriangleOpen_Unsafe(const NavTriangleRawPtr& triangleRawPtr) const;
48 
49  bool IsInitialized() const { return m_allocBuffer.IsInitialized(); }
50 
51  void ReleaseWorkingMemoryBuffer() { m_allocBuffer.ReleaseWorkingMemoryBuffer(); }
52 
53 public:
54  AllocatorBuffer m_allocBuffer;
55  CellBox m_cellBox;
56  KyUInt32 m_cellBitsArrayOffset;
57 };
58 
59 KY_INLINE bool TriangleStatusInGrid::IsTriangleOpen_Unsafe(const NavTriangleRawPtr& triangleRawPtr) const
60 {
61  KY_DEBUG_ASSERTN(m_cellBox.DoesContain(triangleRawPtr.GetCellPos()), ("Invalid CellBox"));
62 
63  NavFloor* navFloor = triangleRawPtr.GetNavFloor();
64  const CellPos& cellPos = navFloor->GetCellPos();
65 
66  CellBits* cellBits = GetCellBits(cellPos);
67  KY_DEBUG_ASSERTN(cellBits->IsValid(), ("Unsafe mode, it should never happen"));
68 
69  FloorBits* floorBits = cellBits->Get(navFloor->GetIndexInCollection());
70  KY_DEBUG_ASSERTN(floorBits->IsValid(), ("Unsafe mode, it should never happen"));
71 
72  return floorBits->IsBitSet(triangleRawPtr.GetTriangleIdx());
73 }
74 
75 }
76 
77 
78 
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
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17