Plasma Engine  2.0
Loading...
Searching...
No Matches
NavMesh.h
1#pragma once
2
3#include <AiPlugin/Navigation/NavigationConfig.h>
4#include <DetourNavMesh.h>
5#include <DetourNavMeshQuery.h>
6#include <Foundation/Containers/Deque.h>
7#include <Foundation/Containers/DynamicArray.h>
8#include <Foundation/Containers/Map.h>
9#include <Foundation/Math/Vec2.h>
10#include <Foundation/Types/RefCounted.h>
11#include <Foundation/Types/SharedPtr.h>
12#include <Recast.h>
13#include <RendererCore/Debug/DebugRendererContext.h>
14
16
18class dtNavMesh;
19
22{
23 PL_DECLARE_POD_TYPE();
24
25 plAiNavMeshTriangle() = default;
26 plAiNavMeshTriangle(plInt32 a, plInt32 b, plInt32 c)
27 {
28 m_VertexIdx[0] = a;
29 m_VertexIdx[1] = b;
30 m_VertexIdx[2] = c;
31 }
32
33 plInt32 m_VertexIdx[3];
34};
35
38{
39 plDynamicArray<plVec3> m_Vertices;
41 plDynamicArray<plUInt8> m_TriangleAreaIDs;
42};
43
46{
49
50 plUInt8 m_FlagRequested : 1;
51 plUInt8 m_FlagInvalidate : 1;
52 plUInt8 m_FlagUpdateAvailable : 1;
53 plUInt8 m_FlagUsable : 1;
54
55 plDataBuffer m_NavmeshDataCur;
56 plDataBuffer m_NavmeshDataNew;
57 dtTileRef m_TileRef = 0;
58};
59
69class PL_AIPLUGIN_DLL plAiNavMesh final
70{
71 PL_DISALLOW_COPY_AND_ASSIGN(plAiNavMesh);
72
73public:
74 plAiNavMesh(plUInt32 uiNumSectorsX, plUInt32 uiNumSectorsY, float fSectorMetersXY, const plAiNavmeshConfig& navmeshConfig);
76
77 using SectorID = plUInt32;
78
79 plVec2I32 CalculateSectorCoord(float fPositionX, float fPositionY) const;
80 plVec2 GetSectorPositionOffset(plVec2I32 vCoord) const;
81 plBoundingBox GetSectorBounds(plVec2I32 vCoord, float fMinZ = 0.0f, float fMaxZ = 1.0f) const;
82 float GetSectorSize() const { return m_fSectorMetersXY; }
83 SectorID CalculateSectorID(plVec2I32 vCoord) const { return vCoord.y * m_uiNumSectorsX + vCoord.x; }
84 plVec2I32 CalculateSectorCoord(SectorID sectorID) const;
85
86 const plAiNavMeshSector* GetSector(SectorID sectorID) const;
87
91 bool RequestSector(SectorID sectorID);
92
96 bool RequestSector(const plVec2& vCenter, const plVec2& vHalfExtents);
97
103 void InvalidateSector(SectorID sectorID, bool bRebuildAsSoonAsPossible);
104
110 void InvalidateSector(const plVec2& vCenter, const plVec2& vHalfExtents, bool bRebuildAsSoonAsPossible);
111
112 void FinalizeSectorUpdates();
113
114 SectorID RetrieveRequestedSector();
115 void BuildSector(SectorID sectorID, const plNavmeshGeoWorldModuleInterface* pGeo);
116
117 const dtNavMesh* GetDetourNavMesh() const { return m_pNavMesh; }
118
119 void DebugDraw(plDebugRendererContext context, const plAiNavigationConfig& config);
120
121 const plAiNavmeshConfig& GetConfig() const { return m_NavmeshConfig; }
122
123private:
124 void DebugDrawSector(plDebugRendererContext context, const plAiNavigationConfig& config, int iTileIdx);
125
126 plAiNavmeshConfig m_NavmeshConfig;
127
128 plUInt32 m_uiNumSectorsX = 0;
129 plUInt32 m_uiNumSectorsY = 0;
130 float m_fSectorMetersXY = 0;
131 float m_fInvSectorMetersXY = 0;
132
133 dtNavMesh* m_pNavMesh = nullptr;
135 plDeque<SectorID> m_RequestedSectors;
136
137 plMutex m_Mutex;
138 plDynamicArray<SectorID> m_UpdatingSectors;
139
140 plDynamicArray<SectorID> m_UnloadingSectors;
141};
A navmesh generated with a specific configuration.
Definition NavMesh.h:70
Used in plDebugRenderer to determine where debug geometry should be rendered.
Definition DebugRendererContext.h:11
Definition Deque.h:270
Definition Map.h:408
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
A world module that retrieves triangle data that should be used for building navmeshes at runtime.
Definition NavmeshGeoWorldModule.h:22
Stores the geometry from which a navmesh should be generated.
Definition NavMesh.h:38
State about a single sector (tile / cell) of an plAiNavMesh.
Definition NavMesh.h:46
Stores indices for a triangle.
Definition NavMesh.h:22
Definition NavigationConfig.h:44
Definition NavigationConfig.h:11