summaryrefslogtreecommitdiff
path: root/Runtime/NavMesh/NavMeshManager.h
blob: e761ef73fad6c02a51b9e90973d2e679e05ddee0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once

#include "Runtime/BaseClasses/GameManager.h"

class CrowdProfiler;
class HeightMeshQuery;
class NavMeshAgent;
class NavMeshCarving;
class NavMeshObstacle;
class OffMeshLink;
class dtCrowd;
class dtNavMesh;
class dtNavMeshQuery;
struct dtCrowdAgentDebugInfo;
struct dtMeshHeader;


class NavMeshManager
{
public:

	NavMeshManager ();
	~NavMeshManager ();

	// NavMeshModule Interface
	virtual void Update ();

	void Initialize (const dtNavMesh* navMesh, const HeightMeshQuery* heightMeshQuery);
	void CleanupMeshDependencies (const dtNavMesh* mesh);
	void CleanupMeshDependencies ();

	inline dtCrowd* GetCrowdSystem ();
	inline NavMeshCarving* GetCarvingSystem ();
	const dtNavMeshQuery* GetInternalNavMeshQuery () const;
	const dtNavMesh* GetInternalNavMesh () const;

	void RegisterAgent (NavMeshAgent& agent, int& handle);
	void UnregisterAgent (int& handle);

	void RegisterObstacle (NavMeshObstacle& obstacle, int& handle);
	void UnregisterObstacle (int& handle);

	void RegisterOffMeshLink (OffMeshLink& link, int& handle);
	void UnregisterOffMeshLink (int& handle);

	void UpdateAllNavMeshAgentCosts (int layerIndex, float layerCost);

#if UNITY_EDITOR
	inline dtCrowdAgentDebugInfo* GetInternalDebugInfo ();
#endif

private:
	const dtMeshHeader* GetNavMeshHeader (const dtNavMesh* navmesh);
	bool InitializeCrowdSystem (const dtNavMesh* navmesh, const HeightMeshQuery* heightMeshQuery, const dtMeshHeader* header);
	void InitializeObstacleSamplingQuality ();
	void InitializeCarvingSystem ();

	void NotifyNavMeshChanged ();
	void NotifyNavMeshCleanup ();
	void UpdateCrowdSystem (float deltaTime);
	void UpdateCarving ();
	void UpdateDynamicLinks ();
	void InvalidateDynamicLinks ();

	dynamic_array<NavMeshAgent*> m_Agents;
	dynamic_array<NavMeshObstacle*> m_Obstacles;
	dynamic_array<OffMeshLink*> m_Links;

	NavMeshCarving* m_CarvingSystem;

	dtCrowd* m_CrowdSystem;
	dtCrowdAgentDebugInfo* m_CrowdAgentDebugInfo;
	CrowdProfiler* m_Profiler;
	static const int kInitialAgentCount;
};

inline dtCrowd* NavMeshManager::GetCrowdSystem ()
{
	return m_CrowdSystem;
}

inline NavMeshCarving* NavMeshManager::GetCarvingSystem ()
{
	return m_CarvingSystem;
}

#if UNITY_EDITOR
inline dtCrowdAgentDebugInfo* NavMeshManager::GetInternalDebugInfo ()
{
	return m_CrowdAgentDebugInfo;
}
#endif // UNITY_EDITOR

NavMeshManager& GetNavMeshManager ();
void InitializeNavMeshManager ();
void CleanupNavMeshManager ();