Browse Source

sync as of 20190322 1703 hours

Matt Coburn 6 years ago
parent
commit
8dda1e29f4
3 changed files with 52 additions and 37 deletions
  1. 3 1
      README.md
  2. 26 27
      Source/Native/enet.c
  3. 23 9
      Source/Native/enet.h

+ 3 - 1
README.md

@@ -2,9 +2,11 @@
   <img src="https://i.imgur.com/CxkUxTs.png" alt="alt logo">
   <img src="https://i.imgur.com/CxkUxTs.png" alt="alt logo">
 </p>
 </p>
 
 
+[![GitHub release](https://img.shields.io/github/release/nxrighthere/ENet-CSharp.svg)](https://github.com/nxrighthere/ENet-CSharp/releases) [![PayPal](https://drive.google.com/uc?id=1OQrtNBVJehNVxgPf6T6yX1wIysz1ElLR)](https://www.paypal.me/nxrighthere) [![Bountysource](https://drive.google.com/uc?id=19QRobscL8Ir2RL489IbVjcw3fULfWS_Q)](https://salt.bountysource.com/checkout/amount?team=nxrighthere) [![Coinbase](https://drive.google.com/uc?id=1LckuF-IAod6xmO9yF-jhTjq1m-4f7cgF)](https://commerce.coinbase.com/checkout/03e11816-b6fc-4e14-b974-29a1d0886697)
+
 This project is based on collaborative work with [@inlife](https://github.com/inlife) and inherited all features of the custom [fork](https://github.com/zpl-c/enet) where the native library was heavily modified. You can find the most notable changes [here](https://github.com/nxrighthere/ENet-CSharp/issues/22#issuecomment-432982154). This version is extended, optimized, and involves new features that were not available before to boost the development process and run safely in the managed .NET environment with the highest possible performance.
 This project is based on collaborative work with [@inlife](https://github.com/inlife) and inherited all features of the custom [fork](https://github.com/zpl-c/enet) where the native library was heavily modified. You can find the most notable changes [here](https://github.com/nxrighthere/ENet-CSharp/issues/22#issuecomment-432982154). This version is extended, optimized, and involves new features that were not available before to boost the development process and run safely in the managed .NET environment with the highest possible performance.
 
 
-Although the project is called ENet-CSharp, this is not just a C# wrapper for the native C library, but an independent fork which is incompatible with any other ENet implementation including the original one since 2.0 version. Programmers who are using C/C++ languages can utilize this fork as well in any projects.
+Although the project is called ENet-CSharp, this is not just a C# wrapper for the native C library, but an independent fork which is incompatible with any other ENet implementation including the [original](https://github.com/lsalzman/enet) since 2.0.0 version. Programmers who are using C/C++ languages can utilize this fork as well in any projects.
 
 
 Features:
 Features:
 
 

+ 26 - 27
Source/Native/enet.c

@@ -1,27 +1,26 @@
-/*
- *  ENet reliable UDP networking library 
- *  Copyright (c) 2018 Lee Salzman, Vladyslav Hrytsenko, Dominik Madarász, Stanislav Denisov
- *
- *  Permission is hereby granted, free of charge, to any person obtaining a copy
- *  of this software and associated documentation files (the "Software"), to deal
- *  in the Software without restriction, including without limitation the rights
- *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- *  copies of the Software, and to permit persons to whom the Software is
- *  furnished to do so, subject to the following conditions:
- *
- *  The above copyright notice and this permission notice shall be included in all
- *  copies or substantial portions of the Software.
- *
- *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- *  SOFTWARE.
- */
-
-#define _WINSOCK_DEPRECATED_NO_WARNINGS
-#define ENET_IMPLEMENTATION
-#define ENET_DLL
-#include "enet.h"
+/*
+ *  ENet reliable UDP networking library 
+ *  Copyright (c) 2018 Lee Salzman, Vladyslav Hrytsenko, Dominik Madarász, Stanislav Denisov
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to deal
+ *  in the Software without restriction, including without limitation the rights
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ *  copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in all
+ *  copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ *  SOFTWARE.
+ */
+
+#define ENET_IMPLEMENTATION
+#define ENET_DLL
+#include "enet.h"

+ 23 - 9
Source/Native/enet.h

@@ -79,6 +79,10 @@
 		#pragma comment(lib, "winmm.lib")
 		#pragma comment(lib, "winmm.lib")
 	#endif
 	#endif
 
 
+	#if _MSC_VER
+		#define _WINSOCK_DEPRECATED_NO_WARNINGS
+	#endif
+
 	#if _MSC_VER >= 1910
 	#if _MSC_VER >= 1910
 		/* It looks like there were changes as of Visual Studio 2017 and there are no 32/64 bit
 		/* It looks like there were changes as of Visual Studio 2017 and there are no 32/64 bit
 		versions of _InterlockedExchange[operation], only InterlockedExchange[operation]
 		versions of _InterlockedExchange[operation], only InterlockedExchange[operation]
@@ -176,6 +180,7 @@
 
 
 #define ENET_HOST_ANY       in6addr_any
 #define ENET_HOST_ANY       in6addr_any
 #define ENET_PORT_ANY       0
 #define ENET_PORT_ANY       0
+#define ENET_HOST_SIZE      1025
 #define ENET_HOST_BROADCAST 0xFFFFFFFFU
 #define ENET_HOST_BROADCAST 0xFFFFFFFFU
 
 
 #define ENET_HOST_TO_NET_16(value) (htons(value))
 #define ENET_HOST_TO_NET_16(value) (htons(value))
@@ -203,9 +208,9 @@ extern "C" {
 	typedef fd_set ENetSocketSet;
 	typedef fd_set ENetSocketSet;
 
 
 	typedef struct _ENetCallbacks {
 	typedef struct _ENetCallbacks {
-		void*(ENET_CALLBACK *malloc)(size_t size);
-		void(ENET_CALLBACK *free)(void* memory);
-		void(ENET_CALLBACK *noMemory)(void);
+		void* (ENET_CALLBACK *malloc)(size_t size);
+		void (ENET_CALLBACK *free)(void* memory);
+		void (ENET_CALLBACK *noMemory)(void);
 	} ENetCallbacks;
 	} ENetCallbacks;
 
 
 	extern void* enet_malloc(size_t);
 	extern void* enet_malloc(size_t);
@@ -462,6 +467,7 @@ extern "C" {
 	#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0)
 	#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0)
 
 
 	typedef enum _ENetPacketFlag {
 	typedef enum _ENetPacketFlag {
+		ENET_PACKET_FLAG_NONE                = 0,
 		ENET_PACKET_FLAG_RELIABLE            = (1 << 0),
 		ENET_PACKET_FLAG_RELIABLE            = (1 << 0),
 		ENET_PACKET_FLAG_UNSEQUENCED         = (1 << 1),
 		ENET_PACKET_FLAG_UNSEQUENCED         = (1 << 1),
 		ENET_PACKET_FLAG_NO_ALLOCATE         = (1 << 2),
 		ENET_PACKET_FLAG_NO_ALLOCATE         = (1 << 2),
@@ -1021,7 +1027,11 @@ extern "C" {
 // !
 // !
 // =======================================================================//
 // =======================================================================//
 
 
-	static ENetCallbacks callbacks = { malloc, free, abort };
+	static ENetCallbacks callbacks = {
+		malloc,
+		free,
+		abort
+	};
 
 
 	int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks* inits) {
 	int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks* inits) {
 		if (version < ENET_VERSION_CREATE(1, 3, 0))
 		if (version < ENET_VERSION_CREATE(1, 3, 0))
@@ -2632,7 +2642,7 @@ extern "C" {
 			size_t shouldCompress = 0;
 			size_t shouldCompress = 0;
 		#endif
 		#endif
 
 
-		while (host->continueSending)
+		while (host->continueSending) {
 			for (host->continueSending = 0, currentPeer = host->peers; currentPeer < &host->peers[host->peerCount]; ++currentPeer) {
 			for (host->continueSending = 0, currentPeer = host->peers; currentPeer < &host->peers[host->peerCount]; ++currentPeer) {
 				if (currentPeer->state == ENET_PEER_STATE_DISCONNECTED || currentPeer->state == ENET_PEER_STATE_ZOMBIE)
 				if (currentPeer->state == ENET_PEER_STATE_DISCONNECTED || currentPeer->state == ENET_PEER_STATE_ZOMBIE)
 					continue;
 					continue;
@@ -2719,11 +2729,13 @@ extern "C" {
 							host->compressionBufferSize = originalSize;
 							host->compressionBufferSize = originalSize;
 						}
 						}
 
 
-						int totalSize = originalSize, dataSize = 0;
+						size_t totalSize = originalSize, dataSize = 0;
 
 
 						while (totalSize) {
 						while (totalSize) {
-							for (int i = 0; i < host->bufferCount - 1; i++) {
-								int copySize = ENET_MIN(totalSize, (int)buffers[i].dataLength);
+							size_t i;
+
+							for (i = 0; i < host->bufferCount - 1; i++) {
+								size_t copySize = ENET_MIN(totalSize, buffers[i].dataLength);
 
 
 								memcpy(host->compressionBuffer + dataSize, buffers[i].data, copySize);
 								memcpy(host->compressionBuffer + dataSize, buffers[i].data, copySize);
 
 
@@ -2777,6 +2789,7 @@ extern "C" {
 				currentPeer->totalDataSent += sentLength;
 				currentPeer->totalDataSent += sentLength;
 				host->totalSentPackets++;
 				host->totalSentPackets++;
 			}
 			}
+		}
 
 
 		return 0;
 		return 0;
 	}
 	}
@@ -3906,11 +3919,12 @@ extern "C" {
 
 
 	void enet_host_broadcast_selective(ENetHost* host, enet_uint8 channelID, ENetPacket* packet, ENetPeer** peers, size_t length) {
 	void enet_host_broadcast_selective(ENetHost* host, enet_uint8 channelID, ENetPacket* packet, ENetPeer** peers, size_t length) {
 		ENetPeer* currentPeer;
 		ENetPeer* currentPeer;
+		size_t i;
 
 
 		if (host == NULL)
 		if (host == NULL)
 			return;
 			return;
 
 
-		for (int i = 0; i < length; i++) {
+		for (i = 0; i < length; i++) {
 			currentPeer = peers[i];
 			currentPeer = peers[i];
 
 
 			if (currentPeer == NULL || currentPeer->state != ENET_PEER_STATE_CONNECTED)
 			if (currentPeer == NULL || currentPeer->state != ENET_PEER_STATE_CONNECTED)