Просмотр исходного кода

去掉ILRuntime层的寻路IntPtr

tanghai 4 лет назад
Родитель
Сommit
47fd7cc558

+ 37 - 7
Unity/Assets/ThirdParty/ShareLib/Recast/Recast.cs

@@ -13,24 +13,54 @@ namespace ET
         public const int MAX_POLYS = 256;
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern IntPtr RecastLoad(int id, byte[] buffer, int n);
+        private static extern IntPtr RecastLoad(int id, byte[] buffer, int n);
+
+        public static long RecastLoadLong(int id, byte[] buffer, int n)
+        {
+            return RecastLoad(id, buffer, n).ToInt64();
+        }
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern IntPtr RecastGet(int id);
+        private static extern IntPtr RecastGet(int id);
+
+        public static long RecastGetLong(int id)
+        {
+            return RecastGet(id).ToInt32();
+        }
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern void RecastClear();
+        private static extern void RecastClear();
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFind(IntPtr navPtr, float[] extents, float[] startPos, float[] endPos, float[] straightPath);
+        private static extern int RecastFind(IntPtr navPtr, float[] extents, float[] startPos, float[] endPos, float[] straightPath);
+        
+        public static int RecastFind(long navPtr, float[] extents, float[] startPos, float[] endPos, float[] straightPath)
+        {
+            return RecastFind(new IntPtr(navPtr), extents, startPos, endPos, straightPath);
+        }
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindNearestPoint(IntPtr navPtr, float[] extents, float[] pos, float[] nearestPos);
+        private static extern int RecastFindNearestPoint(IntPtr navPtr, float[] extents, float[] pos, float[] nearestPos);
+
+        public static int RecastFindNearestPoint(long navPtr, float[] extents, float[] pos, float[] nearestPos)
+        {
+            return RecastFindNearestPoint(new IntPtr(navPtr), extents, pos, nearestPos);
+        }
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindRandomPointAroundCircle(IntPtr navPtr, float[] extents, float[] centerPos, float radius, float[] randomPos);
+        private static extern int RecastFindRandomPointAroundCircle(IntPtr navPtr, float[] extents, float[] centerPos, float radius, float[] randomPos);
+        
+        public static int RecastFindRandomPointAroundCircle(long navPtr, float[] extents, float[] centerPos, float radius, float[] randomPos)
+        {
+            return RecastFindRandomPointAroundCircle(new IntPtr(navPtr), extents, centerPos, radius, randomPos);
+        }
         
         [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindRandomPoint(IntPtr navPtr, float[] randomPos);
+        private static extern int RecastFindRandomPoint(IntPtr navPtr, float[] randomPos);
+
+        public static int RecastFindRandomPoint(long navPtr, float[] randomPos)
+        {
+            return RecastFindRandomPoint(new IntPtr(navPtr), randomPos);
+        }
     }
 }

+ 3 - 3
Unity/Codes/Hotfix/Module/Recast/NavmeshComponentSystem.cs

@@ -13,9 +13,9 @@ namespace ET
             }
         }
         
-        public static IntPtr Get(this NavmeshComponent self, string name)
+        public static long Get(this NavmeshComponent self, string name)
         {
-            IntPtr ptr;
+            long ptr;
             if (self.Navmeshs.TryGetValue(name, out ptr))
             {
                 return ptr;
@@ -27,7 +27,7 @@ namespace ET
                 throw new Exception($"no nav data: {name}");
             }
 
-            ptr = Recast.RecastLoad(name.GetHashCode(), buffer, buffer.Length);
+            ptr = Recast.RecastLoadLong(name.GetHashCode(), buffer, buffer.Length);
             self.Navmeshs[name] = ptr;
 
             return ptr;

+ 7 - 7
Unity/Codes/Hotfix/Module/Recast/PathfindingComponentSystem.cs

@@ -14,7 +14,7 @@ namespace ET
                 self.Name = name;
                 self.NavMesh = NavmeshComponent.Instance.Get(name);
 
-                if (self.NavMesh == IntPtr.Zero)
+                if (self.NavMesh == 0)
                 {
                     throw new Exception($"nav load fail: {name}");
                 }
@@ -27,13 +27,13 @@ namespace ET
             public override void Destroy(PathfindingComponent self)
             {
                 self.Name = string.Empty;
-                self.NavMesh = IntPtr.Zero;
+                self.NavMesh = 0;
             }
         }
         
         public static void Find(this PathfindingComponent self, Vector3 start, Vector3 target, List<Vector3> result)
         {
-            if (self.NavMesh == IntPtr.Zero)
+            if (self.NavMesh == 0)
             {
                 Log.Debug("寻路| Find 失败 pathfinding ptr is zero");
                 throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
@@ -68,7 +68,7 @@ namespace ET
         
         public static Vector3 FindRandomPointWithRaduis(this PathfindingComponent self, Vector3 pos, float raduis)
         {
-            if (self.NavMesh == IntPtr.Zero)
+            if (self.NavMesh == 0)
             {
                 throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
             }
@@ -100,7 +100,7 @@ namespace ET
         /// <exception cref="Exception"></exception>
         public static Vector3 FindRandomPointWithRectangle(this PathfindingComponent self, Vector3 pos, int width, int height)
         {
-            if (self.NavMesh == IntPtr.Zero)
+            if (self.NavMesh == 0)
             {
                 throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
             }
@@ -120,7 +120,7 @@ namespace ET
         
         public static Vector3 FindRandomPointWithRaduis(this PathfindingComponent self, Vector3 pos, float minRadius, float maxRadius)
         {
-            if (self.NavMesh == IntPtr.Zero)
+            if (self.NavMesh == 0)
             {
                 throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
             }
@@ -143,7 +143,7 @@ namespace ET
 
         public static Vector3 RecastFindNearestPoint(this PathfindingComponent self, Vector3 pos)
         {
-            if (self.NavMesh == IntPtr.Zero)
+            if (self.NavMesh == 0)
             {
                 throw new Exception($"pathfinding ptr is zero: {self.DomainScene().Name}");
             }

+ 1 - 1
Unity/Codes/Model/Module/Recast/NavmeshComponent.cs

@@ -10,6 +10,6 @@ namespace ET
         // 为了区分客户端跟服务端还有机器人的加载方式,客户端是加载ab包,服务端跟机器人是加载bytes
         public Func<string, byte[]> Loader;
         
-        public Dictionary<string, IntPtr> Navmeshs = new Dictionary<string, IntPtr>();
+        public Dictionary<string, long> Navmeshs = new Dictionary<string, long>();
     }
 }

+ 1 - 1
Unity/Codes/Model/Module/Recast/PathfindingComponent.cs

@@ -13,7 +13,7 @@ namespace ET
         
         public string Name;
         
-        public IntPtr NavMesh;
+        public long NavMesh;
 
         [NoMemoryCheck]
         public float[] StartPos = new float[3];