Plasma Engine  2.0
Loading...
Searching...
No Matches
GridNavmesh.h
1#pragma once
2
3#include <Foundation/Containers/Deque.h>
4#include <Foundation/Math/Rect.h>
5#include <Utilities/DataStructures/GameGrid.h>
6
8class PL_UTILITIES_DLL plGridNavmesh
9{
10public:
12 {
13 PL_DECLARE_POD_TYPE();
14
17
19 plUInt32 m_uiFirstEdge;
20
22 plUInt32 m_uiNumEdges;
23 };
24
25 struct AreaEdge
26 {
27 PL_DECLARE_POD_TYPE();
28
32
35 };
36
39 using CellComparator = bool (*)(plUInt32, plUInt32, void*);
40
43 using CellBlocked = bool (*)(plUInt32, void*);
44
46 template <class CellData>
47 void CreateFromGrid(
48 const plGameGrid<CellData>& grid, CellComparator isSameCellType, void* pPassThroughSame, CellBlocked isCellBlocked, void* pPassThroughBlocked);
49
51 plInt32 GetAreaAt(const plVec2I32& vCoord) const { return m_NodesGrid.GetCell(vCoord); }
52
54 plUInt32 GetNumConvexAreas() const { return m_ConvexAreas.GetCount(); }
55
57 const ConvexArea& GetConvexArea(plInt32 iArea) const { return m_ConvexAreas[iArea]; }
58
60 plUInt32 GetNumAreaEdges() const { return m_GraphEdges.GetCount(); }
61
63 const AreaEdge& GetAreaEdge(plInt32 iAreaEdge) const { return m_GraphEdges[iAreaEdge]; }
64
65private:
66 void UpdateRegion(plRectU32 region, CellComparator IsSameCellType, void* pPassThrough1, CellBlocked IsCellBlocked, void* pPassThrough2);
67
68 void Optimize(plRectU32 region, CellComparator IsSameCellType, void* pPassThrough);
69 bool OptimizeBoxes(plRectU32 region, CellComparator IsSameCellType, void* pPassThrough, plUInt32 uiIntervalX, plUInt32 uiIntervalY,
70 plUInt32 uiWidth, plUInt32 uiHeight, plUInt32 uiOffsetX = 0, plUInt32 uiOffsetY = 0);
71 bool CanCreateArea(plRectU32 region, CellComparator IsSameCellType, void* pPassThrough) const;
72
73 bool CanMergeRight(plInt32 x, plInt32 y, CellComparator IsSameCellType, void* pPassThrough, plRectU32& out_Result) const;
74 bool CanMergeDown(plInt32 x, plInt32 y, CellComparator IsSameCellType, void* pPassThrough, plRectU32& out_Result) const;
75 bool MergeBestFit(plRectU32 region, CellComparator IsSameCellType, void* pPassThrough);
76
77 void CreateGraphEdges();
78 void CreateGraphEdges(ConvexArea& Area);
79
80 plRectU32 GetCellBBox(plInt32 x, plInt32 y) const;
81 void Merge(const plRectU32& rect);
82 void CreateNodes(plRectU32 region, CellBlocked IsCellBlocked, void* pPassThrough);
83
84 plGameGrid<plInt32> m_NodesGrid;
85 plDynamicArray<ConvexArea> m_ConvexAreas;
86 plDeque<AreaEdge> m_GraphEdges;
87};
88
89#include <Utilities/PathFinding/Implementation/GridNavmesh_inl.h>
Definition Deque.h:270
Definition DynamicArray.h:81
plGameGrid is a general purpose 2D grid structure that has several convenience functions which are of...
Definition GameGrid.h:13
Takes an plGameGrid and creates an optimized navmesh structure from it, that is more efficient for pa...
Definition GridNavmesh.h:9
bool(*)(plUInt32, plUInt32, void *) CellComparator
Callback that determines whether the cell with index uiCell1 and the cell with index uiCell2 represen...
Definition GridNavmesh.h:39
plUInt32 GetNumConvexAreas() const
Returns the number of convex areas that this navmesh consists of.
Definition GridNavmesh.h:54
plInt32 GetAreaAt(const plVec2I32 &vCoord) const
Returns the index of the ConvexArea at the given cell coordinates. Negative, if the cell is blocked.
Definition GridNavmesh.h:51
const AreaEdge & GetAreaEdge(plInt32 iAreaEdge) const
Returns the given area edge by index.
Definition GridNavmesh.h:63
plUInt32 GetNumAreaEdges() const
Returns the number of edges between convex areas.
Definition GridNavmesh.h:60
bool(*)(plUInt32, void *) CellBlocked
Callback that determines whether the cell with index uiCell is blocked entirely (for every type of un...
Definition GridNavmesh.h:43
const ConvexArea & GetConvexArea(plInt32 iArea) const
Returns the given convex area by index.
Definition GridNavmesh.h:57
Definition GridNavmesh.h:26
plInt32 m_iNeighborArea
The index of the area that can be reached over this edge. This is always a valid index.
Definition GridNavmesh.h:34
plRectU16 m_EdgeRect
Definition GridNavmesh.h:31
Definition GridNavmesh.h:12
plRectU32 m_Rect
The space that is enclosed by this convex area.
Definition GridNavmesh.h:16
plUInt32 m_uiFirstEdge
The first AreaEdge that belongs to this ConvexArea.
Definition GridNavmesh.h:19
plUInt32 m_uiNumEdges
The number of AreaEdge's that belong to this ConvexArea.
Definition GridNavmesh.h:22