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