Some datatype fixes
This commit is contained in:
@@ -5,6 +5,7 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
class Pathfinder
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct PathNode
|
||||
{
|
||||
[MarshalAs(UnmanagedType.U4)]
|
||||
@@ -13,15 +14,20 @@ namespace WorldOfPeacecraft
|
||||
public uint Y;
|
||||
}
|
||||
|
||||
public static LinkedList<Coordinate> FindPath (uint posFrom, uint posTo, Map map)
|
||||
public static LinkedList<Coordinate> FindPath (Coordinate posFrom, Coordinate posTo, ITile[,] map)
|
||||
{
|
||||
Tile[,] tiles = map.GetTiles ();
|
||||
uint mapWidth = tiles.GetLength (0);
|
||||
uint mapHeight = tiles.GetLength (1);
|
||||
PathNode nFrom;
|
||||
nFrom.X = (uint) posFrom.X;
|
||||
nFrom.Y = (uint) posFrom.Y;
|
||||
PathNode nTo;
|
||||
nTo.X = (uint) posTo.X;
|
||||
nTo.Y = (uint) posTo.Y;
|
||||
uint mapWidth = (uint) map.GetLength (0);
|
||||
uint mapHeight = (uint) map.GetLength (1);
|
||||
bool[] boolMap = new bool[mapHeight * mapWidth];
|
||||
for (int y = 0; y < mapHeight; y++) {
|
||||
for (int x = 0; x < mapWidth; y++) {
|
||||
boolMap [x + y * mapWidth] = tiles [x, y].IsWalkable ();
|
||||
for (int x = 0; x < mapWidth; x++) {
|
||||
boolMap [x + y * mapWidth] = map [x, y].IsWalkable ();
|
||||
}
|
||||
}
|
||||
PathNode[] result = new PathNode[mapHeight * mapWidth];
|
||||
@@ -29,22 +35,22 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
result[i] = new PathNode();
|
||||
}
|
||||
int noSteps = findPath (posFrom, posTo, mapWidth, mapHeight, boolMap, result);
|
||||
uint 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(result[i].X, result[i].Y));
|
||||
mappedResult.AddLast(new Coordinate((int) result[i].X, (int) result[i].Y));
|
||||
}
|
||||
return mappedResult;
|
||||
}
|
||||
|
||||
[DllImport("pathfinding.dll")]
|
||||
[DllImport("pathfinding")]
|
||||
[return: MarshalAs(UnmanagedType.U4)]
|
||||
private static extern uint findPath(
|
||||
[MarshalAs(UnmanagedType.U4)] uint posFrom,
|
||||
[MarshalAs(UnmanagedType.U4)] uint posTo,
|
||||
PathNode posFrom,
|
||||
PathNode posTo,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapWidth,
|
||||
[MarshalAs(UnmanagedType.U4)] uint mapHeight,
|
||||
[MarshalAs(UnmanagedType.LPArray)] bool[] map,
|
||||
[MarshalAs(UnmanagedType.LPArray)] PathNode[] result);
|
||||
[MarshalAs(UnmanagedType.LPArray)] PathNode[] result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user