Elin Decompiled Documentation EA 23.317 Nightly
Loading...
Searching...
No Matches
Algorithms.PathFinder Class Reference
Inheritance diagram for Algorithms.PathFinder:
IPathfinder

Classes

class  ComparePFNodeMatrix
 
struct  PathFinderNodeFast
 

Public Member Functions

static unsafe bool ZeroMemory (byte *destination, int length)
 
void Init (IPathfindGrid _grid, WeightCell[,] _weightMap, int size)
 
void FindPath (PathProgress path)
 
void FindPath (PathProgress progress)
 
void Init (IPathfindGrid _grid, WeightCell[,] _weightMap, int size)
 

Public Attributes

bool debug
 
bool Diagonals
 
bool PunishChangeDirection
 
float HeavyDiagonals = 1f
 
bool TieBreaker
 
HeuristicFormula mFormula = HeuristicFormula.Manhattan
 
int total
 
WeightCell[,] weightMap
 

Private Member Functions

void _FindPath (PathProgress path)
 

Private Attributes

IPathfindGrid grid
 
IPathfindWalker walker
 
int mHEstimate = 2
 
PriorityQueueB< int > mOpen
 
bool mStop
 
bool mStopped = true
 
int mHoriz
 
bool mReopenCloseNodes = true
 
PathFinderNodeFast[] mCalcGrid
 
byte mOpenNodeValue = 1
 
byte mCloseNodeValue = 2
 
PathManager.MoveType moveType
 
int mH
 
int mLocation
 
int mNewLocation
 
ushort mLocationX
 
ushort mLocationZ
 
ushort mNewLocationX
 
ushort mNewLocationZ
 
int mGridXZ
 
int mGridX
 
int mGridZ
 
int mCloseNodeCounter
 
bool mFound
 
sbyte[,] mDirection
 
int mEndLocation
 
int mStartLocation
 
int mNewG
 
byte _weight
 
int index
 
int mx
 
int mz
 

Detailed Description

Definition at line 9 of file PathFinder.cs.

Member Function Documentation

◆ _FindPath()

void Algorithms.PathFinder._FindPath ( PathProgress  path)
inlineprivate

Definition at line 177 of file PathFinder.cs.

178 {
179 lock (this)
180 {
181 Point startPoint = path.startPoint;
182 Point destPoint = path.destPoint;
183 path.nodes.Clear();
184 mFound = (mStop = (mStopped = false));
186 mOpenNodeValue += 2;
187 mCloseNodeValue += 2;
188 mOpen.Clear();
189 mLocation = (mStartLocation = startPoint.z * mGridX + startPoint.x);
190 mEndLocation = destPoint.z * mGridX + destPoint.x;
191 if (mLocation >= mCalcGrid.Length)
192 {
193 if (debug)
194 {
195 Debug.Log("length over");
196 }
197 }
198 else
199 {
200 if (mEndLocation == mLocation)
201 {
202 return;
203 }
204 mCalcGrid[mLocation].G = 0;
206 mCalcGrid[mLocation].PX = (ushort)startPoint.x;
207 mCalcGrid[mLocation].PZ = (ushort)startPoint.z;
210 while (mOpen.Count > 0 && !mStop)
211 {
212 mLocation = mOpen.Pop();
213 if (mCalcGrid[mLocation].Status == mCloseNodeValue)
214 {
215 continue;
216 }
217 mLocationX = (ushort)(mLocation % mGridX);
218 mLocationZ = (ushort)(mLocation % mGridXZ / mGridX);
219 if (mLocation == mEndLocation)
220 {
222 mFound = true;
223 break;
224 }
226 {
227 mStopped = true;
228 if (path.searchLimit > 1000)
229 {
230 Debug.Log("search limit: " + path.startPoint?.ToString() + " " + path.destPoint);
231 }
232 return;
233 }
235 {
237 }
238 for (int i = 0; i < (Diagonals ? 8 : 4); i++)
239 {
240 mNewLocationX = (ushort)(mLocationX + mDirection[i, 0]);
241 mNewLocationZ = (ushort)(mLocationZ + mDirection[i, 1]);
244 {
245 continue;
246 }
248 {
249 _weight = 1;
250 }
251 else
252 {
253 if (i < 4)
254 {
255 index = ((mNewLocationZ >= mLocationZ) ? ((mNewLocationX > mLocationX) ? 1 : ((mNewLocationZ > mLocationZ) ? 2 : 3)) : 0);
257 }
258 else
259 {
260 mx = mLocationX + mDirection[i, 0];
261 mz = mLocationZ;
262 index = ((mz >= mLocationZ) ? ((mx > mLocationX) ? 1 : ((mz > mLocationZ) ? 2 : 3)) : 0);
264 if (weightMap[mx, mz].IsPathBlocked(walker, moveType))
265 {
266 _weight = 0;
267 }
268 if (_weight > 0)
269 {
270 index = ((mz >= mNewLocationZ) ? ((mx > mNewLocationX) ? 1 : ((mz > mNewLocationZ) ? 2 : 3)) : 0);
272 if (_weight > 0)
273 {
274 mx = mLocationX;
275 mz = mLocationZ + mDirection[i, 1];
276 index = ((mz >= mLocationZ) ? ((mx > mLocationX) ? 1 : ((mz > mLocationZ) ? 2 : 3)) : 0);
278 if (weightMap[mx, mz].IsPathBlocked(walker, moveType))
279 {
280 _weight = 0;
281 }
282 if (_weight > 0)
283 {
284 index = ((mz >= mNewLocationZ) ? ((mx > mNewLocationX) ? 1 : ((mz > mNewLocationZ) ? 2 : 3)) : 0);
286 }
287 }
288 }
289 }
290 if (_weight == 0)
291 {
292 continue;
293 }
296 {
297 continue;
298 }
299 }
302 {
303 if (mNewLocationX - mLocationX != 0 && mHoriz == 0)
304 {
305 mNewG += Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
306 }
307 if (mNewLocationZ - mLocationZ != 0 && mHoriz != 0)
308 {
309 mNewG += Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
310 }
311 }
313 {
317 switch (mFormula)
318 {
319 default:
320 mH = mHEstimate * (Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z));
321 break;
322 case HeuristicFormula.MaxDXDY:
323 mH = mHEstimate * Math.Max(Math.Abs(mNewLocationX - destPoint.x), Math.Abs(mNewLocationZ - destPoint.z));
324 break;
325 case HeuristicFormula.DiagonalShortCut:
326 {
327 int num = Math.Min(Math.Abs(mNewLocationX - destPoint.x), Math.Abs(mNewLocationZ - destPoint.z));
328 int num2 = Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
329 mH = mHEstimate * 2 * num + mHEstimate * (num2 - 2 * num);
330 break;
331 }
332 case HeuristicFormula.Euclidean:
333 mH = (int)((double)mHEstimate * Math.Sqrt(Math.Pow(mNewLocationZ - destPoint.x, 2.0) + Math.Pow(mNewLocationZ - destPoint.z, 2.0)));
334 break;
335 case HeuristicFormula.EuclideanNoSQR:
336 mH = (int)((double)mHEstimate * (Math.Pow(mNewLocationX - destPoint.x, 2.0) + Math.Pow(mNewLocationZ - destPoint.z, 2.0)));
337 break;
338 }
339 if (TieBreaker)
340 {
341 int num3 = mLocationX - destPoint.x;
342 int num4 = mLocationZ - destPoint.z;
343 int num5 = startPoint.x - destPoint.x;
344 int num6 = startPoint.z - destPoint.z;
345 int num7 = Math.Abs(num3 * num6 - num5 * num4);
346 mH = (int)((double)mH + (double)num7 * 0.001);
347 }
351 }
352 }
355 }
356 if (mFound)
357 {
358 int x = destPoint.x;
359 int z = destPoint.z;
360 PathFinderNodeFast pathFinderNodeFast = mCalcGrid[destPoint.z * mGridX + destPoint.x];
361 PathFinderNode item = default(PathFinderNode);
362 item.G = pathFinderNodeFast.G;
363 item.PX = pathFinderNodeFast.PX;
364 item.PZ = pathFinderNodeFast.PZ;
365 item.X = destPoint.x;
366 item.Z = destPoint.z;
367 while (item.X != item.PX || item.Z != item.PZ)
368 {
369 path.nodes.Add(item);
370 x = item.PX;
371 z = item.PZ;
372 pathFinderNodeFast = mCalcGrid[z * mGridX + x];
373 item.G = pathFinderNodeFast.G;
374 item.PX = pathFinderNodeFast.PX;
375 item.PZ = pathFinderNodeFast.PZ;
376 item.X = x;
377 item.Z = z;
378 }
379 path.nodes.Add(item);
380 mStopped = true;
381 }
382 else
383 {
384 mStopped = true;
385 }
386 }
387 }
388 }
IPathfindWalker walker
Definition: PathFinder.cs:61
HeuristicFormula mFormula
Definition: PathFinder.cs:57
PathManager.MoveType moveType
Definition: PathFinder.cs:81
PathFinderNodeFast[] mCalcGrid
Definition: PathFinder.cs:75
PriorityQueueB< int > mOpen
Definition: PathFinder.cs:65
WeightCell[,] weightMap
Definition: PathFinder.cs:130
Point startPoint
Definition: PathProgress.cs:18
Point destPoint
Definition: PathProgress.cs:20
List< PathFinderNode > nodes
Definition: PathProgress.cs:16
bool ignoreConnection
Definition: PathProgress.cs:30
Definition: Point.cs:9
override string ToString()
Definition: Point.cs:524
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39

References Algorithms.PathFinder._weight, Algorithms.WeightCell.baseWeight, Algorithms.PriorityQueueB< T >.Clear(), Algorithms.PriorityQueueB< T >.Count, Algorithms.PathFinder.debug, Debug, PathProgress.destPoint, Algorithms.PathFinder.Diagonals, Algorithms.PathFinder.PathFinderNodeFast.F, Algorithms.PathFinder.PathFinderNodeFast.G, PathProgress.ignoreConnection, Algorithms.PathFinder.index, item, Algorithms.PathFinder.mCalcGrid, Algorithms.PathFinder.mCloseNodeCounter, Algorithms.PathFinder.mCloseNodeValue, Algorithms.PathFinder.mDirection, Algorithms.PathFinder.mEndLocation, Algorithms.PathFinder.mFormula, Algorithms.PathFinder.mFound, Algorithms.PathFinder.mGridX, Algorithms.PathFinder.mGridXZ, Algorithms.PathFinder.mGridZ, Algorithms.PathFinder.mH, Algorithms.PathFinder.mHEstimate, Algorithms.PathFinder.mHoriz, Algorithms.PathFinder.mLocation, Algorithms.PathFinder.mLocationX, Algorithms.PathFinder.mLocationZ, Algorithms.PathFinder.mNewG, Algorithms.PathFinder.mNewLocation, Algorithms.PathFinder.mNewLocationX, Algorithms.PathFinder.mNewLocationZ, Algorithms.PathFinder.mOpen, Algorithms.PathFinder.mOpenNodeValue, Algorithms.PathFinder.moveType, Algorithms.PathFinder.mReopenCloseNodes, Algorithms.PathFinder.mStartLocation, Algorithms.PathFinder.mStop, Algorithms.PathFinder.mStopped, Algorithms.PathFinder.mx, Algorithms.PathFinder.mz, PathProgress.nodes, Algorithms.PriorityQueueB< T >.Pop(), Algorithms.PathFinder.PunishChangeDirection, Algorithms.PriorityQueueB< T >.Push(), Algorithms.PathFinder.PathFinderNodeFast.PX, Algorithms.PathFinder.PathFinderNodeFast.PZ, PathProgress.searchLimit, PathProgress.startPoint, Algorithms.PathFinder.PathFinderNodeFast.Status, Algorithms.PathFinder.TieBreaker, Point.ToString(), Algorithms.PathFinder.walker, Algorithms.PathFinder.weightMap, Algorithms.WeightCell.weights, Point.x, and Point.z.

Referenced by Algorithms.PathFinder.FindPath().

◆ FindPath()

void Algorithms.PathFinder.FindPath ( PathProgress  path)
inline

Implements IPathfinder.

Definition at line 155 of file PathFinder.cs.

156 {
157 moveType = path.moveType;
158 walker = path.walker;
159 _FindPath(path);
160 if (path.nodes.Count > 0)
161 {
162 PathFinderNode pathFinderNode = path.nodes[path.nodes.Count - 1];
163 if (pathFinderNode.X == path.startPoint.x && pathFinderNode.Z == path.startPoint.z)
164 {
165 path.nodes.RemoveAt(path.nodes.Count - 1);
166 }
167 }
168 if (path.nodes.Count == 0)
169 {
170 path.state = PathProgress.State.Fail;
171 return;
172 }
173 path.state = PathProgress.State.PathReady;
174 path.nodeIndex = path.nodes.Count - 1;
175 }
void _FindPath(PathProgress path)
Definition: PathFinder.cs:177
PathManager.MoveType moveType
Definition: PathProgress.cs:32
IPathfindWalker walker
Definition: PathProgress.cs:14

References Algorithms.PathFinder._FindPath(), Algorithms.PathFinder.moveType, PathProgress.moveType, PathProgress.nodes, PathProgress.startPoint, Algorithms.PathFinder.walker, PathProgress.walker, Algorithms.PathFinderNode.X, Point.x, Algorithms.PathFinderNode.Z, and Point.z.

◆ Init()

void Algorithms.PathFinder.Init ( IPathfindGrid  _grid,
WeightCell  _weightMap[,],
int  size 
)
inline

Implements IPathfinder.

Definition at line 141 of file PathFinder.cs.

142 {
143 grid = _grid;
144 weightMap = _weightMap;
145 mGridX = (ushort)size;
146 mGridZ = (ushort)size;
148 if (mCalcGrid == null || mCalcGrid.Length != mGridXZ)
149 {
150 mCalcGrid = new PathFinderNodeFast[mGridXZ];
151 mOpen = new PriorityQueueB<int>(new ComparePFNodeMatrix(mCalcGrid));
152 }
153 }
IPathfindGrid grid
Definition: PathFinder.cs:59

References Algorithms.PathFinder.grid, Algorithms.PathFinder.mCalcGrid, Algorithms.PathFinder.mGridX, Algorithms.PathFinder.mGridXZ, Algorithms.PathFinder.mGridZ, Algorithms.PathFinder.mOpen, and Algorithms.PathFinder.weightMap.

◆ ZeroMemory()

static unsafe bool Algorithms.PathFinder.ZeroMemory ( byte *  destination,
int  length 
)

Member Data Documentation

◆ _weight

byte Algorithms.PathFinder._weight
private

Definition at line 128 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ debug

bool Algorithms.PathFinder.debug

Definition at line 47 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ Diagonals

bool Algorithms.PathFinder.Diagonals

Definition at line 49 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ grid

IPathfindGrid Algorithms.PathFinder.grid
private

Definition at line 59 of file PathFinder.cs.

Referenced by Algorithms.PathFinder.Init().

◆ HeavyDiagonals

float Algorithms.PathFinder.HeavyDiagonals = 1f

Definition at line 53 of file PathFinder.cs.

◆ index

int Algorithms.PathFinder.index
private

Definition at line 132 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mCalcGrid

PathFinderNodeFast [] Algorithms.PathFinder.mCalcGrid
private

Definition at line 75 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().

◆ mCloseNodeCounter

int Algorithms.PathFinder.mCloseNodeCounter
private

Definition at line 106 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mCloseNodeValue

byte Algorithms.PathFinder.mCloseNodeValue = 2
private

Definition at line 79 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mDirection

sbyte [,] Algorithms.PathFinder.mDirection
private
Initial value:
= new sbyte[8, 2]
{
{ 0, -1 },
{ 1, 0 },
{ 0, 1 },
{ -1, 0 },
{ -1, -1 },
{ 1, -1 },
{ -1, 1 },
{ 1, 1 }
}

Definition at line 110 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mEndLocation

int Algorithms.PathFinder.mEndLocation
private

Definition at line 122 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mFormula

HeuristicFormula Algorithms.PathFinder.mFormula = HeuristicFormula.Manhattan

Definition at line 57 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mFound

bool Algorithms.PathFinder.mFound
private

Definition at line 108 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mGridX

int Algorithms.PathFinder.mGridX
private

Definition at line 102 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().

◆ mGridXZ

int Algorithms.PathFinder.mGridXZ
private

Definition at line 100 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().

◆ mGridZ

int Algorithms.PathFinder.mGridZ
private

Definition at line 104 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().

◆ mH

int Algorithms.PathFinder.mH
private

Definition at line 86 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mHEstimate

int Algorithms.PathFinder.mHEstimate = 2
private

Definition at line 63 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mHoriz

int Algorithms.PathFinder.mHoriz
private

Definition at line 71 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocation

int Algorithms.PathFinder.mLocation
private

Definition at line 88 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocationX

ushort Algorithms.PathFinder.mLocationX
private

Definition at line 92 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocationZ

ushort Algorithms.PathFinder.mLocationZ
private

Definition at line 94 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewG

int Algorithms.PathFinder.mNewG
private

Definition at line 126 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocation

int Algorithms.PathFinder.mNewLocation
private

Definition at line 90 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocationX

ushort Algorithms.PathFinder.mNewLocationX
private

Definition at line 96 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocationZ

ushort Algorithms.PathFinder.mNewLocationZ
private

Definition at line 98 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mOpen

PriorityQueueB<int> Algorithms.PathFinder.mOpen
private

Definition at line 65 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().

◆ mOpenNodeValue

byte Algorithms.PathFinder.mOpenNodeValue = 1
private

Definition at line 77 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ moveType

PathManager.MoveType Algorithms.PathFinder.moveType
private

◆ mReopenCloseNodes

bool Algorithms.PathFinder.mReopenCloseNodes = true
private

Definition at line 73 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStartLocation

int Algorithms.PathFinder.mStartLocation
private

Definition at line 124 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStop

bool Algorithms.PathFinder.mStop
private

Definition at line 67 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStopped

bool Algorithms.PathFinder.mStopped = true
private

Definition at line 69 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mx

int Algorithms.PathFinder.mx
private

Definition at line 134 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mz

int Algorithms.PathFinder.mz
private

Definition at line 136 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ PunishChangeDirection

bool Algorithms.PathFinder.PunishChangeDirection

Definition at line 51 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ TieBreaker

bool Algorithms.PathFinder.TieBreaker

Definition at line 55 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ total

int Algorithms.PathFinder.total

Definition at line 84 of file PathFinder.cs.

◆ walker

IPathfindWalker Algorithms.PathFinder.walker
private

◆ weightMap

WeightCell [,] Algorithms.PathFinder.weightMap

Definition at line 130 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath(), and Algorithms.PathFinder.Init().


The documentation for this class was generated from the following file: