Эх сурвалжийг харах

ENetCS可以单步调试到C++库中, 修复一些Native包装的bug 主要是一些旧的intptr现在已经改用uint了

tanghai 13 жил өмнө
parent
commit
c4883a10d1

+ 6 - 3
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -30,10 +30,13 @@ namespace Modules.Robot
 
 		public void Start()
 		{
-			var address = new Address {HostName = "192.168.10.246", Port = 8888};
-			var host = new Host(address, Native.ENET_PROTOCOL_MAXIMUM_PEER_ID);
+			Library.Initialize();
+			var host = new Host(null, Native.ENET_PROTOCOL_MAXIMUM_PEER_ID);
+			
+			var address = new Address { HostName = "192.168.10.246", Port = 8888 };
+			var peer = host.Connect(address, 1, 0);
+
 			var e = new Event();
-			var peer = host.Connect(address, 255, 0);
 			while (host.CheckEvents(out e) > 0)
 			{
 				if (e.Type == EventType.Connect)

+ 3 - 0
CSharp/CSharp.sln

@@ -33,6 +33,9 @@ EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaiGua", "App\Modules\WaiGua\WaiGua.csproj", "{5AA48F9A-455D-4CD8-A605-A3AC38283E60}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetCS", "ThirdParty\ENetCS\ENetCS.csproj", "{D0B4CFAC-A368-4742-9863-68776CFA9938}"
+	ProjectSection(ProjectDependencies) = postProject
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {C9992B7C-313E-4C9F-A954-640D01EDFB58}
+	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 4 - 6
CSharp/ThirdParty/ENet/ENet.vcxproj

@@ -56,7 +56,7 @@
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB</PreprocessorDefinitions>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;ENET_DLL;ENET_BUILDING_LIB</PreprocessorDefinitions>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
       <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -67,11 +67,14 @@
       <CallingConvention>Cdecl</CallingConvention>
       <CompileAsManaged>false</CompileAsManaged>
       <DisableSpecificWarnings>4146;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalDependencies>wsock32.lib;Ws2_32.lib;Winmm.lib</AdditionalDependencies>
       <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <RandomizedBaseAddress>false</RandomizedBaseAddress>
+      <CLRSupportLastError>Enabled</CLRSupportLastError>
     </Link>
     <ProjectReference>
       <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
@@ -88,11 +91,6 @@
       <AdditionalDependencies />
     </Link>
   </ItemDefinitionGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
   <ItemGroup>
     <ClCompile Include="callbacks.c" />
     <ClCompile Include="compress.c" />

+ 2 - 2
CSharp/ThirdParty/ENetCS/Address.cs

@@ -60,7 +60,7 @@ namespace ENet
 				var ip = new byte[256];
 				fixed (byte* hostIP = ip)
 				{
-					if (Native.enet_address_get_host_ip(ref this.address, hostIP, (IntPtr) ip.Length) < 0)
+					if (Native.enet_address_get_host_ip(ref this.address, hostIP, (uint)ip.Length) < 0)
 					{
 						return null;
 					}
@@ -76,7 +76,7 @@ namespace ENet
 				var name = new byte[256];
 				fixed (byte* hostName = name)
 				{
-					if (Native.enet_address_get_host(ref this.address, hostName, (IntPtr)name.Length) < 0)
+					if (Native.enet_address_get_host(ref this.address, hostName, (uint)name.Length) < 0)
 					{
 						return null;
 					}

+ 13 - 13
CSharp/ThirdParty/ENetCS/Host.cs

@@ -27,28 +27,28 @@ namespace ENet
 	{
 		private Native.ENetHost* host;
 
-		public Host(ushort port, int peerLimit):
+		public Host(ushort port, uint peerLimit):
 			this(new Address { Port = port }, peerLimit)
 		{
 		}
 
-		public Host(Address? address, int peerLimit):
+		public Host(Address? address, uint peerLimit):
 			this(address, peerLimit, 0)
 		{
 		}
 
-		public Host(Address? address, int peerLimit, int channelLimit):
+		public Host(Address? address, uint peerLimit, uint channelLimit):
 			this(address, peerLimit, channelLimit, 0, 0)
 		{
 		}
 
-		public Host(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth)
+		public Host(Address? address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth)
 		{
 			if (this.host != null)
 			{
 				throw new InvalidOperationException("Already created.");
 			}
-			if (peerLimit < 0 || peerLimit > Native.ENET_PROTOCOL_MAXIMUM_PEER_ID)
+			if (peerLimit > Native.ENET_PROTOCOL_MAXIMUM_PEER_ID)
 			{
 				throw new ArgumentOutOfRangeException("peerLimit");
 			}
@@ -58,13 +58,13 @@ namespace ENet
 			{
 				Native.ENetAddress nativeAddress = address.Value.NativeData;
 				this.host = Native.enet_host_create(
-					ref nativeAddress, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth,
+					ref nativeAddress, peerLimit, channelLimit, incomingBandwidth,
 					outgoingBandwidth);
 			}
 			else
 			{
 				this.host = Native.enet_host_create(
-					null, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth,
+					null, peerLimit, channelLimit, incomingBandwidth,
 					outgoingBandwidth);
 			}
 			if (this.host == null)
@@ -78,9 +78,9 @@ namespace ENet
 			this.Dispose();
 		}
 
-		private static void CheckChannelLimit(int channelLimit)
+		private static void CheckChannelLimit(uint channelLimit)
 		{
-			if (channelLimit < 0 || channelLimit > Native.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
+			if (channelLimit > Native.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
 			{
 				throw new ArgumentOutOfRangeException("channelLimit");
 			}
@@ -134,13 +134,13 @@ namespace ENet
 			return ret;
 		}
 
-		public Peer Connect(Address address, int channelLimit, uint data)
+		public Peer Connect(Address address, uint channelLimit, uint data)
 		{
 			this.CheckCreated();
 			CheckChannelLimit(channelLimit);
 
 			Native.ENetAddress nativeAddress = address.NativeData;
-			Native.ENetPeer* p = Native.enet_host_connect(this.host, ref nativeAddress, (IntPtr) channelLimit, data);
+			Native.ENetPeer* p = Native.enet_host_connect(this.host, ref nativeAddress, channelLimit, data);
 			if (p == null)
 			{
 				throw new ENetException(0, "Host connect call failed.");
@@ -185,11 +185,11 @@ namespace ENet
 			Native.enet_host_bandwidth_limit(this.host, incomingBandwidth, outgoingBandwidth);
 		}
 
-		public void SetChannelLimit(int channelLimit)
+		public void SetChannelLimit(uint channelLimit)
 		{
 			CheckChannelLimit(channelLimit);
 			this.CheckCreated();
-			Native.enet_host_channel_limit(this.host, (IntPtr) channelLimit);
+			Native.enet_host_channel_limit(this.host, channelLimit);
 		}
 	}
 }

+ 13 - 13
CSharp/ThirdParty/ENetCS/Native.cs

@@ -48,16 +48,16 @@ namespace ENet
 		public static extern int enet_address_set_host(ref ENetAddress address, byte[] hostName);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_address_get_host(ref ENetAddress address, byte* hostName, IntPtr nameLength);
+		public static extern int enet_address_get_host(ref ENetAddress address, byte* hostName, uint nameLength);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength);
+		public static extern int enet_address_get_host(ref ENetAddress address, byte[] hostName, uint nameLength);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte* hostIP, IntPtr ipLength);
+		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte* hostIP, uint ipLength);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength);
+		public static extern int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, uint ipLength);
 
 		#endregion
 
@@ -81,18 +81,18 @@ namespace ENet
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern ENetHost* enet_host_create(
-				ENetAddress* address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+				ENetAddress* address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern ENetHost* enet_host_create(
-				ref ENetAddress address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern void enet_host_destroy(ENetHost* host);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern ENetPeer* enet_host_connect(
-				ENetHost* host, ref ENetAddress address, IntPtr channelCount, uint data);
+				ENetHost* host, ref ENetAddress address, uint channelCount, uint data);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern void enet_host_broadcast(ENetHost* host, byte channelID, ENetPacket* packet);
@@ -101,7 +101,7 @@ namespace ENet
 		public static extern void enet_host_compress(ENetHost* host, ENetCompressor* compressor);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern void enet_host_channel_limit(ENetHost* host, IntPtr channelLimit);
+		public static extern void enet_host_channel_limit(ENetHost* host, uint channelLimit);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern void enet_host_bandwidth_limit(ENetHost* host, uint incomingBandwidth, uint outgoingBandwidth);
@@ -110,13 +110,13 @@ namespace ENet
 		public static extern void enet_host_flush(ENetHost* host);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_host_check_events(ENetHost* host, out ENetEvent @event);
+		public static extern int enet_host_check_events(ENetHost* host, out ENetEvent e);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_host_service(ENetHost* host, ENetEvent* @event, uint timeout);
+		public static extern int enet_host_service(ENetHost* host, ENetEvent* e, uint timeout);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_host_service(ENetHost* host, out ENetEvent @event, uint timeout);
+		public static extern int enet_host_service(ENetHost* host, out ENetEvent e, uint timeout);
 
 		#endregion
 
@@ -133,13 +133,13 @@ namespace ENet
 		#region Packet Functions
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern ENetPacket* enet_packet_create(void* data, IntPtr dataLength, PacketFlags flags);
+		public static extern ENetPacket* enet_packet_create(void* data, uint dataLength, PacketFlags flags);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		public static extern void enet_packet_destroy(ENetPacket* packet);
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		public static extern int enet_packet_resize(ENetPacket* packet, IntPtr dataLength);
+		public static extern int enet_packet_resize(ENetPacket* packet, uint dataLength);
 
 		#endregion
 

+ 2 - 2
CSharp/ThirdParty/ENetCS/Packet.cs

@@ -49,7 +49,7 @@ namespace ENet
 			}
 			fixed (byte* bytes = data)
 			{
-				this.packet = Native.enet_packet_create(bytes + offset, (IntPtr)length, flags);
+				this.packet = Native.enet_packet_create(bytes + offset, (uint)length, flags);
 				if (this.packet == null)
 				{
 					throw new ENetException(0, "Packet creation call failed.");
@@ -124,7 +124,7 @@ namespace ENet
 				throw new ArgumentOutOfRangeException("length");
 			}
 			this.CheckCreated();
-			int ret = Native.enet_packet_resize(this.packet, (IntPtr) length);
+			int ret = Native.enet_packet_resize(this.packet, (uint)length);
 			if (ret < 0)
 			{
 				throw new ENetException(ret, "Packet resize call failed.");