Alle uint zu int geändert
This commit is contained in:
@@ -8,45 +8,45 @@ namespace WorldOfPeacecraft
|
|||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
private struct PathNode
|
private struct PathNode
|
||||||
{
|
{
|
||||||
[MarshalAs(UnmanagedType.U4)]
|
[MarshalAs(UnmanagedType.I4)]
|
||||||
public uint X;
|
public int X;
|
||||||
[MarshalAs(UnmanagedType.U4)]
|
[MarshalAs(UnmanagedType.I4)]
|
||||||
public uint Y;
|
public int Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe LinkedList<Coordinate> FindPath (Coordinate posFrom, Coordinate posTo, Map map)
|
public static unsafe LinkedList<Coordinate> FindPath (Coordinate posFrom, Coordinate posTo, Map map)
|
||||||
{
|
{
|
||||||
PathNode nFrom;
|
PathNode nFrom;
|
||||||
nFrom.X = (uint) posFrom.X;
|
nFrom.X = posFrom.X;
|
||||||
nFrom.Y = (uint) posFrom.Y;
|
nFrom.Y = posFrom.Y;
|
||||||
PathNode nTo;
|
PathNode nTo;
|
||||||
nTo.X = (uint) posTo.X;
|
nTo.X = posTo.X;
|
||||||
nTo.Y = (uint) posTo.Y;
|
nTo.Y = posTo.Y;
|
||||||
Tile[,] tiles = map.GetTiles();
|
Tile[,] tiles = map.GetTiles();
|
||||||
uint mapWidth = (uint) tiles.GetLength (0);
|
int mapWidth = tiles.GetLength (0);
|
||||||
uint mapHeight = (uint) tiles.GetLength (1);
|
int mapHeight = tiles.GetLength (1);
|
||||||
bool* boolMap = stackalloc bool[(int)(mapWidth * mapHeight)];
|
bool* boolMap = stackalloc bool[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] = tiles [x, y].IsWalkable ();
|
boolMap [x + y * mapWidth] = tiles [x, y].IsWalkable ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PathNode* result = stackalloc PathNode[(int) (mapHeight * mapWidth)];
|
PathNode* result = stackalloc PathNode[mapHeight * mapWidth];
|
||||||
uint noSteps = findPath (nFrom, nTo, mapWidth, mapHeight, boolMap, result);
|
int 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++) {
|
||||||
mappedResult.AddLast(new Coordinate((int) result[i].X, (int) result[i].Y));
|
mappedResult.AddLast(new Coordinate(result[i].X, result[i].Y));
|
||||||
}
|
}
|
||||||
return mappedResult;
|
return mappedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("pathfinding")]
|
[DllImport("pathfinding")]
|
||||||
[return: MarshalAs(UnmanagedType.U4)]
|
[return: MarshalAs(UnmanagedType.I4)]
|
||||||
private static extern unsafe uint findPath(
|
private static extern unsafe int findPath(
|
||||||
PathNode posFrom,
|
PathNode posFrom,
|
||||||
PathNode posTo,
|
PathNode posTo,
|
||||||
[MarshalAs(UnmanagedType.U4)] uint mapWidth,
|
[MarshalAs(UnmanagedType.I4)] int mapWidth,
|
||||||
[MarshalAs(UnmanagedType.U4)] uint mapHeight,
|
[MarshalAs(UnmanagedType.I4)] int mapHeight,
|
||||||
bool* map,
|
bool* map,
|
||||||
PathNode* result);
|
PathNode* result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user