summaryrefslogtreecommitdiff
path: root/Runtime/NavMesh/OffMeshLink.h
blob: 26d31cf377dd867ebe81d4d55d0e05d1f2214ed0 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef RUNTIME_OFFMESHLINK
#define RUNTIME_OFFMESHLINK

#include "Runtime/GameCode/Behaviour.h"
#include "Runtime/Graphics/Transform.h"
#include "NavMeshTypes.h"

class dtNavMesh;



class OffMeshLink : public Behaviour
{
public:
	REGISTER_DERIVED_CLASS (OffMeshLink, Behaviour)
	DECLARE_OBJECT_SERIALIZE (OffMeshLink)

	OffMeshLink (MemLabelId& label, ObjectCreationMode mode);
	// ~OffMeshLink (); declared by a macro

	inline void SetManagerHandle (int handle);
	inline float GetCostOverride () const;
	void SetCostOverride (float costOverride);

	inline bool GetBiDirectional () const;
	void SetBiDirectional (bool bidirectional);

	inline bool GetActivated () const;
	void SetActivated (bool activated);

	bool GetOccupied () const;

	inline UInt32 GetNavMeshLayer () const;
	void SetNavMeshLayer (UInt32 layer);

	inline void ClearDynamicPolyRef ();
	inline bool ClearStaticPolyRef ();

	inline Transform* GetStartTransform () const;
	inline void SetStartTransform (Transform* t);

	inline Transform* GetEndTransform () const;
	inline void SetEndTransform (Transform* t);

	void OnNavMeshCleanup ();
	void OnNavMeshChanged ();
	void UpdatePositions ();
	void UpdateMovedPositions ();

	inline bool GetAutoUpdatePositions () const;
	inline void SetAutoUpdatePositions (bool autoUpdate);

protected:
	virtual void AwakeFromLoad (AwakeFromLoadMode mode);
	virtual void AddToManager ();
	virtual void RemoveFromManager ();
	virtual void Reset ();
	virtual void SmartReset ();

private:
	void EnableDynamic ();
	void DisableDynamic (bool unregister = true);
	void DisableStatic ();
	void CheckDynamicPositions ();
	inline dtPolyRef GetStaticOrDynamicPolyRef () const;

	PPtr<Transform> m_Start;
	PPtr<Transform> m_End;

	UInt32 m_NavMeshLayer;
	bool m_AutoUpdatePositions;
	bool m_ShouldUpdateDynamic;

	dtPolyRef m_StaticPolyRef;
	dtPolyRef m_DynamicPolyRef;
	int m_ManagerHandle;
	float m_CostOverride;
	bool m_BiDirectional;
	bool m_Activated;
};


inline void OffMeshLink::SetManagerHandle (int handle)
{
	m_ManagerHandle = handle;
}

inline float OffMeshLink::GetCostOverride () const
{
	return m_CostOverride;
}

inline bool OffMeshLink::GetBiDirectional () const
{
	return m_BiDirectional;
}

inline bool OffMeshLink::GetActivated () const
{
	return m_Activated;
}

inline UInt32 OffMeshLink::GetNavMeshLayer () const
{
	return m_NavMeshLayer;
}

inline void OffMeshLink::ClearDynamicPolyRef ()
{
	m_DynamicPolyRef = 0;
}

inline bool OffMeshLink::ClearStaticPolyRef ()
{
	if (m_StaticPolyRef == 0)
	{
		return false;
	}
	m_StaticPolyRef = 0;
	SetDirty ();
	return true;
}

inline Transform* OffMeshLink::GetStartTransform () const
{
	return m_Start;
}

inline void OffMeshLink::SetStartTransform (Transform* t)
{
	if (t == m_Start)
	{
		return;
	}
	m_Start = t;
	SetDirty ();
}

inline Transform* OffMeshLink::GetEndTransform () const
{
	return m_End;
}

inline void OffMeshLink::SetEndTransform (Transform* t)
{
	if (t == m_End)
	{
		return;
	}
	m_End = t;
	SetDirty ();
}

inline bool OffMeshLink::GetAutoUpdatePositions () const
{
	return m_AutoUpdatePositions;
}

inline void OffMeshLink::SetAutoUpdatePositions (bool autoUpdate)
{
	m_AutoUpdatePositions = autoUpdate;
	SetDirty ();
}

inline dtPolyRef OffMeshLink::GetStaticOrDynamicPolyRef () const
{
	return m_StaticPolyRef ? m_StaticPolyRef : m_DynamicPolyRef;
}

#endif