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

删除enet c#封装冗余的代码

tanghai 12 лет назад
Родитель
Сommit
c0b4c52b34

+ 1 - 1
CSharp/Platform/ENet/Address.cs

@@ -54,7 +54,7 @@ namespace ENet
 		{
 			get
 			{
-				var address = new ENetAddress { host = this.ip, port = this.port };
+				var address = new ENetAddress { Host = this.ip, Port = this.port };
 				return address;
 			}
 		}

+ 3 - 3
CSharp/Platform/ENet/Event.cs

@@ -42,7 +42,7 @@ namespace ENet
 		{
 			get
 			{
-				return this.Ev.packet;
+				return this.Ev.Packet;
 			}
 		}
 
@@ -50,7 +50,7 @@ namespace ENet
 		{
 			get
 			{
-				return this.Ev.peer;
+				return this.Ev.Peer;
 			}
 		}
 
@@ -58,7 +58,7 @@ namespace ENet
 		{
 			get
 			{
-				return this.Ev.type;
+				return this.Ev.Type;
 			}
 		}
 	}

+ 0 - 36
CSharp/Platform/ENet/NativeMethods.cs

@@ -124,41 +124,5 @@ namespace ENet
 
 		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
-
-		public static bool memcmp(byte[] s1, byte[] s2)
-		{
-			if (s1 == null || s2 == null)
-			{
-				throw new ArgumentNullException();
-			}
-			if (s1.Length != s2.Length)
-			{
-				return false;
-			}
-
-			for (int i = 0; i < s1.Length; i++)
-			{
-				if (s1[i] != s2[i])
-				{
-					return false;
-				}
-			}
-			return true;
-		}
-
-		public static int strlen(byte[] s)
-		{
-			if (s == null)
-			{
-				throw new ArgumentNullException();
-			}
-
-			int i;
-			for (i = 0; i < s.Length && s[i] != 0; i++)
-			{
-				;
-			}
-			return i;
-		}
 	}
 }

+ 28 - 46
CSharp/Platform/ENet/NativeStructs.cs

@@ -38,54 +38,35 @@ namespace ENet
 	[StructLayout(LayoutKind.Sequential)]
 	public struct ENetAddress
 	{
-		public uint host;
-		public ushort port;
+		public uint Host;
+		public ushort Port;
 	}
 
 	[StructLayout(LayoutKind.Sequential)]
 	public struct ENetCallbacks
 	{
 		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate IntPtr malloc_cb(IntPtr size);
+		public delegate IntPtr MallocCb(IntPtr size);
 
 		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate void free_cb(IntPtr memory);
+		public delegate void FreeCb(IntPtr memory);
 
 		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate void no_memory_cb();
+		public delegate void NoMemoryCb();
 
 		private readonly IntPtr malloc;
 		private readonly IntPtr free;
 		private readonly IntPtr no_memory;
 	}
 
-	[StructLayout(LayoutKind.Sequential)]
-	public struct ENetCompressor
-	{
-		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate void compress_cb(
-			IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit, 
-			IntPtr outData, IntPtr outLimit);
-
-		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate void decompress_cb(
-			IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
-
-		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-		public delegate void destroy_cb(IntPtr context);
-
-		public IntPtr context;
-		public IntPtr compress, decompress, destroy;
-	}
-
 	[StructLayout(LayoutKind.Sequential)]
 	public class ENetEvent
 	{
-		public EventType type;
-		public IntPtr peer;
-		public byte channelID;
-		public uint data;
-		public IntPtr packet;
+		public EventType Type;
+		public IntPtr Peer;
+		public byte ChannelID;
+		public uint Data;
+		public IntPtr Packet;
 	}
 
 	[StructLayout(LayoutKind.Sequential)]
@@ -96,8 +77,8 @@ namespace ENet
 	[StructLayout(LayoutKind.Sequential)]
 	public class ENetListNode
 	{
-		public ENetListNode next;
-		public ENetListNode previous;
+		public ENetListNode Next;
+		public ENetListNode Previous;
 	}
 
 	[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -106,25 +87,26 @@ namespace ENet
 	[StructLayout(LayoutKind.Sequential)]
 	public struct ENetPacket
 	{
-		public uint referenceCount;
-		public uint flags;
-		public IntPtr data;
-		public uint dataLength;
-		public ENetPacketFreeCallback freeCallback;
+		public uint ReferenceCount;
+		public uint Flags;
+		public IntPtr Data;
+		public uint DataLength;
+		public ENetPacketFreeCallback FreeCallback;
+		public IntPtr UserData;
 	}
 
 	[StructLayout(LayoutKind.Sequential)]
 	public struct ENetPeer
 	{
-		public ENetListNode dispatchList;
-		public readonly IntPtr host;
-		public readonly ushort outgoingPeerID;
-		public readonly ushort incomingPeerID;
-		public readonly uint connectID;
-		public readonly byte outgoingSessionID;
-		public readonly byte incomingSessionID;
-		public ENetAddress address;
-		public IntPtr data;
-		public readonly PeerState state;
+		public ENetListNode DispatchList;
+		public readonly IntPtr Host;
+		public readonly ushort OutgoingPeerID;
+		public readonly ushort IncomingPeerID;
+		public readonly uint ConnectID;
+		public readonly byte OutgoingSessionID;
+		public readonly byte IncomingSessionID;
+		public ENetAddress Address;
+		public IntPtr Data;
+		public readonly PeerState State;
 	}
 }

+ 3 - 3
CSharp/Platform/ENet/Packet.cs

@@ -79,7 +79,7 @@ namespace ENet
 				{
 					return 0;
 				}
-				return this.Struct.dataLength;
+				return this.Struct.DataLength;
 			}
 		}
 
@@ -88,8 +88,8 @@ namespace ENet
 			get
 			{
 				var enetPacket = this.Struct;
-				var bytes = new byte[enetPacket.dataLength];
-				Marshal.Copy(enetPacket.data, bytes, 0, (int) enetPacket.dataLength);
+				var bytes = new byte[enetPacket.DataLength];
+				Marshal.Copy(enetPacket.Data, bytes, 0, (int) enetPacket.DataLength);
 				return bytes;
 			}
 		}

+ 1 - 1
CSharp/Platform/ENet/Peer.cs

@@ -68,7 +68,7 @@ namespace ENet
 				{
 					return PeerState.Uninitialized;
 				}
-				return this.Struct.state;
+				return this.Struct.State;
 			}
 		}