From 63b6c66c6ce853154c0712d7999a46f6fe335097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 6 May 2014 19:48:55 +0200 Subject: [PATCH] Some datatype fixes --- src/Pathfinder.cs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Pathfinder.cs b/src/Pathfinder.cs index e1194c6..f8b7fda 100644 --- a/src/Pathfinder.cs +++ b/src/Pathfinder.cs @@ -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 FindPath (uint posFrom, uint posTo, Map map) + public static LinkedList 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 mappedResult = new LinkedList(); 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); } -} \ No newline at end of file +}