From 85c617e5c7109bf9979c769484b89340881c0405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 6 May 2014 21:57:55 +0200 Subject: [PATCH] Wegfindungs-Dll wird jetzt zu 100% korrekt eingebunden --- src/Pathfinder.cs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Pathfinder.cs b/src/Pathfinder.cs index f8b7fda..6414261 100644 --- a/src/Pathfinder.cs +++ b/src/Pathfinder.cs @@ -14,7 +14,7 @@ namespace WorldOfPeacecraft public uint Y; } - public static LinkedList FindPath (Coordinate posFrom, Coordinate posTo, ITile[,] map) + public static unsafe LinkedList FindPath (Coordinate posFrom, Coordinate posTo, ITile[,] map) { PathNode nFrom; nFrom.X = (uint) posFrom.X; @@ -24,17 +24,13 @@ namespace WorldOfPeacecraft 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 = stackalloc bool[(int)(mapWidth * mapHeight)]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { boolMap [x + y * mapWidth] = map [x, y].IsWalkable (); } } - PathNode[] result = new PathNode[mapHeight * mapWidth]; - for (int i = 0;i < result.Length;i++) - { - result[i] = new PathNode(); - } + PathNode* result = stackalloc PathNode[(int) (mapHeight * mapWidth)]; uint noSteps = findPath (nFrom, nTo, mapWidth, mapHeight, boolMap, result); LinkedList mappedResult = new LinkedList(); for (int i = 0; i < noSteps; i++) { @@ -45,12 +41,12 @@ namespace WorldOfPeacecraft [DllImport("pathfinding")] [return: MarshalAs(UnmanagedType.U4)] - private static extern uint findPath( - PathNode posFrom, - PathNode posTo, - [MarshalAs(UnmanagedType.U4)] uint mapWidth, - [MarshalAs(UnmanagedType.U4)] uint mapHeight, - [MarshalAs(UnmanagedType.LPArray)] bool[] map, - [MarshalAs(UnmanagedType.LPArray)] PathNode[] result); + private static extern unsafe uint findPath( + PathNode posFrom, + PathNode posTo, + [MarshalAs(UnmanagedType.U4)] uint mapWidth, + [MarshalAs(UnmanagedType.U4)] uint mapHeight, + bool* map, + PathNode* result); } }