Wegfindungs-Dll wird jetzt zu 100% korrekt eingebunden
This commit is contained in:
@@ -14,7 +14,7 @@ namespace WorldOfPeacecraft
|
||||
public uint Y;
|
||||
}
|
||||
|
||||
public static LinkedList<Coordinate> FindPath (Coordinate posFrom, Coordinate posTo, ITile[,] map)
|
||||
public static unsafe LinkedList<Coordinate> FindPath (Coordinate posFrom, Coordinate posTo, ITile[,] map)
|
||||
{
|
||||
PathNode nFrom;
|
||||
nFrom.X = (uint) posFrom.X;
|
||||
@@ -24,17 +24,13 @@ namespace WorldOfPeacecraft
|
||||
nTo.Y = (uint) posTo.Y;
|
||||
uint mapWidth = (uint) map.GetLength (0);
|
||||
uint mapHeight = (uint) map.GetLength (1);
|
||||
bool[] boolMap = new bool[mapHeight * mapWidth];
|
||||
bool* boolMap = stackalloc bool[(int)(mapWidth * mapHeight)];
|
||||
for (int y = 0; y < mapHeight; y++) {
|
||||
for (int x = 0; x < mapWidth; x++) {
|
||||
boolMap [x + y * mapWidth] = map [x, y].IsWalkable ();
|
||||
}
|
||||
}
|
||||
PathNode[] result = new PathNode[mapHeight * mapWidth];
|
||||
for (int i = 0;i < result.Length;i++)
|
||||
{
|
||||
result[i] = new PathNode();
|
||||
}
|
||||
PathNode* result = stackalloc PathNode[(int) (mapHeight * mapWidth)];
|
||||
uint noSteps = findPath (nFrom, nTo, mapWidth, mapHeight, boolMap, result);
|
||||
LinkedList<Coordinate> mappedResult = new LinkedList<Coordinate>();
|
||||
for (int i = 0; i < noSteps; i++) {
|
||||
@@ -45,12 +41,12 @@ namespace WorldOfPeacecraft
|
||||
|
||||
[DllImport("pathfinding")]
|
||||
[return: MarshalAs(UnmanagedType.U4)]
|
||||
private static extern uint findPath(
|
||||
PathNode posFrom,
|
||||
PathNode posTo,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapWidth,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapHeight,
|
||||
[MarshalAs(UnmanagedType.LPArray)] bool[] map,
|
||||
[MarshalAs(UnmanagedType.LPArray)] PathNode[] result);
|
||||
private static extern unsafe uint findPath(
|
||||
PathNode posFrom,
|
||||
PathNode posTo,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapWidth,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapHeight,
|
||||
bool* map,
|
||||
PathNode* result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user