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