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