Elin Decompiled Documentation EA 23.102 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
 
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 174 of file PathFinder.cs.

175 {
176 lock (this)
177 {
178 Point startPoint = path.startPoint;
179 Point destPoint = path.destPoint;
180 path.nodes.Clear();
181 mFound = (mStop = (mStopped = false));
183 mOpenNodeValue += 2;
184 mCloseNodeValue += 2;
185 mOpen.Clear();
186 mLocation = (mStartLocation = startPoint.z * mGridX + startPoint.x);
187 mEndLocation = destPoint.z * mGridX + destPoint.x;
188 if (mLocation >= mCalcGrid.Length)
189 {
190 if (debug)
191 {
192 Debug.Log("length over");
193 }
194 }
195 else
196 {
197 if (mEndLocation == mLocation)
198 {
199 return;
200 }
201 mCalcGrid[mLocation].G = 0;
203 mCalcGrid[mLocation].PX = (ushort)startPoint.x;
204 mCalcGrid[mLocation].PZ = (ushort)startPoint.z;
207 while (mOpen.Count > 0 && !mStop)
208 {
209 mLocation = mOpen.Pop();
210 if (mCalcGrid[mLocation].Status == mCloseNodeValue)
211 {
212 continue;
213 }
214 mLocationX = (ushort)(mLocation % mGridX);
215 mLocationZ = (ushort)(mLocation % mGridXZ / mGridX);
216 if (mLocation == mEndLocation)
217 {
219 mFound = true;
220 break;
221 }
223 {
224 mStopped = true;
225 if (path.searchLimit > 1000)
226 {
227 Debug.Log("search limit: " + path.startPoint?.ToString() + " " + path.destPoint);
228 }
229 return;
230 }
232 {
234 }
235 for (int i = 0; i < (Diagonals ? 8 : 4); i++)
236 {
237 mNewLocationX = (ushort)(mLocationX + mDirection[i, 0]);
238 mNewLocationZ = (ushort)(mLocationZ + mDirection[i, 1]);
241 {
242 continue;
243 }
245 {
246 _weight = 1;
247 }
248 else
249 {
250 if (i < 4)
251 {
252 index = ((mNewLocationZ >= mLocationZ) ? ((mNewLocationX > mLocationX) ? 1 : ((mNewLocationZ > mLocationZ) ? 2 : 3)) : 0);
254 }
255 else
256 {
257 mx = mLocationX + mDirection[i, 0];
258 mz = mLocationZ;
259 index = ((mz >= mLocationZ) ? ((mx > mLocationX) ? 1 : ((mz > mLocationZ) ? 2 : 3)) : 0);
261 if (weightMap[mx, mz].IsPathBlocked(moveType))
262 {
263 _weight = 0;
264 }
265 if (_weight > 0)
266 {
267 index = ((mz >= mNewLocationZ) ? ((mx > mNewLocationX) ? 1 : ((mz > mNewLocationZ) ? 2 : 3)) : 0);
269 if (_weight > 0)
270 {
271 mx = mLocationX;
272 mz = mLocationZ + mDirection[i, 1];
273 index = ((mz >= mLocationZ) ? ((mx > mLocationX) ? 1 : ((mz > mLocationZ) ? 2 : 3)) : 0);
275 if (weightMap[mx, mz].IsPathBlocked(moveType))
276 {
277 _weight = 0;
278 }
279 if (_weight > 0)
280 {
281 index = ((mz >= mNewLocationZ) ? ((mx > mNewLocationX) ? 1 : ((mz > mNewLocationZ) ? 2 : 3)) : 0);
283 }
284 }
285 }
286 }
287 if (_weight == 0)
288 {
289 continue;
290 }
293 {
294 continue;
295 }
296 }
299 {
300 if (mNewLocationX - mLocationX != 0 && mHoriz == 0)
301 {
302 mNewG += Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
303 }
304 if (mNewLocationZ - mLocationZ != 0 && mHoriz != 0)
305 {
306 mNewG += Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
307 }
308 }
310 {
314 switch (mFormula)
315 {
316 default:
317 mH = mHEstimate * (Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z));
318 break;
319 case HeuristicFormula.MaxDXDY:
320 mH = mHEstimate * Math.Max(Math.Abs(mNewLocationX - destPoint.x), Math.Abs(mNewLocationZ - destPoint.z));
321 break;
322 case HeuristicFormula.DiagonalShortCut:
323 {
324 int num = Math.Min(Math.Abs(mNewLocationX - destPoint.x), Math.Abs(mNewLocationZ - destPoint.z));
325 int num2 = Math.Abs(mNewLocationX - destPoint.x) + Math.Abs(mNewLocationZ - destPoint.z);
326 mH = mHEstimate * 2 * num + mHEstimate * (num2 - 2 * num);
327 break;
328 }
329 case HeuristicFormula.Euclidean:
330 mH = (int)((double)mHEstimate * Math.Sqrt(Math.Pow(mNewLocationZ - destPoint.x, 2.0) + Math.Pow(mNewLocationZ - destPoint.z, 2.0)));
331 break;
332 case HeuristicFormula.EuclideanNoSQR:
333 mH = (int)((double)mHEstimate * (Math.Pow(mNewLocationX - destPoint.x, 2.0) + Math.Pow(mNewLocationZ - destPoint.z, 2.0)));
334 break;
335 }
336 if (TieBreaker)
337 {
338 int num3 = mLocationX - destPoint.x;
339 int num4 = mLocationZ - destPoint.z;
340 int num5 = startPoint.x - destPoint.x;
341 int num6 = startPoint.z - destPoint.z;
342 int num7 = Math.Abs(num3 * num6 - num5 * num4);
343 mH = (int)((double)mH + (double)num7 * 0.001);
344 }
348 }
349 }
352 }
353 if (mFound)
354 {
355 int x = destPoint.x;
356 int z = destPoint.z;
357 PathFinderNodeFast pathFinderNodeFast = mCalcGrid[destPoint.z * mGridX + destPoint.x];
358 PathFinderNode item = default(PathFinderNode);
359 item.G = pathFinderNodeFast.G;
360 item.PX = pathFinderNodeFast.PX;
361 item.PZ = pathFinderNodeFast.PZ;
362 item.X = destPoint.x;
363 item.Z = destPoint.z;
364 while (item.X != item.PX || item.Z != item.PZ)
365 {
366 path.nodes.Add(item);
367 x = item.PX;
368 z = item.PZ;
369 pathFinderNodeFast = mCalcGrid[z * mGridX + x];
370 item.G = pathFinderNodeFast.G;
371 item.PX = pathFinderNodeFast.PX;
372 item.PZ = pathFinderNodeFast.PZ;
373 item.X = x;
374 item.Z = z;
375 }
376 path.nodes.Add(item);
377 mStopped = true;
378 }
379 else
380 {
381 mStopped = true;
382 }
383 }
384 }
385 }
HeuristicFormula mFormula
Definition: PathFinder.cs:57
PathManager.MoveType moveType
Definition: PathFinder.cs:79
PathFinderNodeFast[] mCalcGrid
Definition: PathFinder.cs:73
PriorityQueueB< int > mOpen
Definition: PathFinder.cs:63
WeightCell[,] weightMap
Definition: PathFinder.cs:128
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:500
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.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 153 of file PathFinder.cs.

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

References Algorithms.PathFinder._FindPath(), Algorithms.PathFinder.moveType, PathProgress.moveType, PathProgress.nodes, PathProgress.startPoint, 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 139 of file PathFinder.cs.

140 {
141 grid = _grid;
142 weightMap = _weightMap;
143 mGridX = (ushort)size;
144 mGridZ = (ushort)size;
146 if (mCalcGrid == null || mCalcGrid.Length != mGridXZ)
147 {
148 mCalcGrid = new PathFinderNodeFast[mGridXZ];
149 mOpen = new PriorityQueueB<int>(new ComparePFNodeMatrix(mCalcGrid));
150 }
151 }
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 126 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 130 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mCalcGrid

PathFinderNodeFast [] Algorithms.PathFinder.mCalcGrid
private

Definition at line 73 of file PathFinder.cs.

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

◆ mCloseNodeCounter

int Algorithms.PathFinder.mCloseNodeCounter
private

Definition at line 104 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mCloseNodeValue

byte Algorithms.PathFinder.mCloseNodeValue = 2
private

Definition at line 77 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 108 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mEndLocation

int Algorithms.PathFinder.mEndLocation
private

Definition at line 120 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 106 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mGridX

int Algorithms.PathFinder.mGridX
private

Definition at line 100 of file PathFinder.cs.

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

◆ mGridXZ

int Algorithms.PathFinder.mGridXZ
private

Definition at line 98 of file PathFinder.cs.

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

◆ mGridZ

int Algorithms.PathFinder.mGridZ
private

Definition at line 102 of file PathFinder.cs.

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

◆ mH

int Algorithms.PathFinder.mH
private

Definition at line 84 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mHEstimate

int Algorithms.PathFinder.mHEstimate = 2
private

Definition at line 61 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mHoriz

int Algorithms.PathFinder.mHoriz
private

Definition at line 69 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocation

int Algorithms.PathFinder.mLocation
private

Definition at line 86 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocationX

ushort Algorithms.PathFinder.mLocationX
private

Definition at line 90 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mLocationZ

ushort Algorithms.PathFinder.mLocationZ
private

Definition at line 92 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewG

int Algorithms.PathFinder.mNewG
private

Definition at line 124 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocation

int Algorithms.PathFinder.mNewLocation
private

Definition at line 88 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocationX

ushort Algorithms.PathFinder.mNewLocationX
private

Definition at line 94 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mNewLocationZ

ushort Algorithms.PathFinder.mNewLocationZ
private

Definition at line 96 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mOpen

PriorityQueueB<int> Algorithms.PathFinder.mOpen
private

Definition at line 63 of file PathFinder.cs.

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

◆ mOpenNodeValue

byte Algorithms.PathFinder.mOpenNodeValue = 1
private

Definition at line 75 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 71 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStartLocation

int Algorithms.PathFinder.mStartLocation
private

Definition at line 122 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStop

bool Algorithms.PathFinder.mStop
private

Definition at line 65 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mStopped

bool Algorithms.PathFinder.mStopped = true
private

Definition at line 67 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mx

int Algorithms.PathFinder.mx
private

Definition at line 132 of file PathFinder.cs.

Referenced by Algorithms.PathFinder._FindPath().

◆ mz

int Algorithms.PathFinder.mz
private

Definition at line 134 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 82 of file PathFinder.cs.

◆ weightMap

WeightCell [,] Algorithms.PathFinder.weightMap

Definition at line 128 of file PathFinder.cs.

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


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