Kaynağa Gözat

Updated to newest kNet.

Lasse Öörni 14 yıl önce
ebeveyn
işleme
2e4d006674

+ 1 - 0
CMakeLists.txt

@@ -28,6 +28,7 @@ add_definitions (-DENABLE_PROFILING)
 if (NOT WIN32)
 if (NOT WIN32)
     set (USE_OPENGL 1)
     set (USE_OPENGL 1)
     add_definitions (-DUSE_OPENGL)
     add_definitions (-DUSE_OPENGL)
+    add_definitions (-DUNIX)
 endif ()
 endif ()
 
 
 # Compiler-specific options
 # Compiler-specific options

+ 4 - 4
Engine/Network/Connection.cpp

@@ -548,7 +548,7 @@ void Connection::ProcessIdentity(int msgID, MemoryBuffer& msg)
     eventData[P_ALLOW] = true;
     eventData[P_ALLOW] = true;
     SendEvent(E_CLIENTIDENTITY, eventData);
     SendEvent(E_CLIENTIDENTITY, eventData);
     
     
-    // If connection was denied as a response to the event, disconnect the client now
+    // If connection was denied as a response to the identity event, disconnect now
     if (!eventData[P_ALLOW].GetBool())
     if (!eventData[P_ALLOW].GetBool())
         Disconnect();
         Disconnect();
 }
 }
@@ -630,7 +630,7 @@ void Connection::ProcessRemoteEvent(int msgID, MemoryBuffer& msg)
         Node* receiver = scene_->GetNodeByID(nodeID);
         Node* receiver = scene_->GetNodeByID(nodeID);
         if (!receiver)
         if (!receiver)
         {
         {
-            LOGWARNING("Remote node event's receiver not found, discarding event");
+            LOGWARNING("Missing receiver for remote node event, discarding");
             return;
             return;
         }
         }
         SendEvent(receiver, eventType, eventData);
         SendEvent(receiver, eventType, eventData);
@@ -701,7 +701,7 @@ void Connection::ProcessNewNode(Node* node)
     // Write node's attributes
     // Write node's attributes
     node->WriteInitialDeltaUpdate(msg_, deltaUpdateBits_, newNodeState.attributes_);
     node->WriteInitialDeltaUpdate(msg_, deltaUpdateBits_, newNodeState.attributes_);
     
     
-    // Write node's variable map
+    // Write node's user variables
     const VariantMap& vars = node->GetVars();
     const VariantMap& vars = node->GetVars();
     msg_.WriteVLE(vars.Size());
     msg_.WriteVLE(vars.Size());
     for (VariantMap::ConstIterator i = vars.Begin(); i != vars.End(); ++i)
     for (VariantMap::ConstIterator i = vars.Begin(); i != vars.End(); ++i)
@@ -747,7 +747,7 @@ void Connection::ProcessExistingNode(Node* node)
     
     
     node->PrepareUpdates(deltaUpdateBits_, nodeState.attributes_, deltaUpdate, latestData);
     node->PrepareUpdates(deltaUpdateBits_, nodeState.attributes_, deltaUpdate, latestData);
     
     
-    // Check if variable map has changed. Note: variable removal is not supported
+    // Check if user variables have changed. Note: variable removal is not supported
     changedVars_.Clear();
     changedVars_.Clear();
     const VariantMap& vars = node->GetVars();
     const VariantMap& vars = node->GetVars();
     for (VariantMap::ConstIterator i = vars.Begin(); i != vars.End(); ++i)
     for (VariantMap::ConstIterator i = vars.Begin(); i != vars.End(); ++i)

+ 1 - 1
Engine/Network/Connection.h

@@ -144,7 +144,7 @@ private:
     Map<unsigned, PODVector<unsigned char> > componentLatestData_;
     Map<unsigned, PODVector<unsigned char> > componentLatestData_;
     /// Internal vector for delta update
     /// Internal vector for delta update
     PODVector<unsigned char> deltaUpdateBits_;
     PODVector<unsigned char> deltaUpdateBits_;
-    /// Internal set for node's variable map changes
+    /// Internal set for node's user variable changes
     HashSet<ShortStringHash> changedVars_;
     HashSet<ShortStringHash> changedVars_;
     /// Internal set for already processed nodes during an update
     /// Internal set for already processed nodes during an update
     HashSet<Node*> processedNodes_;
     HashSet<Node*> processedNodes_;

+ 4 - 3
ThirdParty/kNet/CMakeLists.txt

@@ -46,17 +46,18 @@ endmacro()
 # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DKNET_LOGGING_SUPPORT_ENABLED")
 # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DKNET_LOGGING_SUPPORT_ENABLED")
 
 
 # If set, the function GetThreadId is not used, which was introduced to Kernel32.dll only in Windows Vista.
 # If set, the function GetThreadId is not used, which was introduced to Kernel32.dll only in Windows Vista.
+# Affects only Boost threads. When native Win32 threads are used, the id is stored on creation.
 AddCompilationDefine(KNET_ENABLE_WINXP_SUPPORT)
 AddCompilationDefine(KNET_ENABLE_WINXP_SUPPORT)
 
 
 # If set, extra code is inserted in debug mode to assert that certain thread race conditions don't occur.
 # If set, extra code is inserted in debug mode to assert that certain thread race conditions don't occur.
-# AddCompilationDefine(KNET_THREAD_CHECKING_ENABLED)
+#AddCompilationDefine(KNET_THREAD_CHECKING_ENABLED)
 
 
-# Enable internal LOG messaging if this flag is enabled. Comment this out to squeeze the last bit of 
+# Enable internal LOG messaging if this flag is enabled. Comment this out to squeeze the last bit of
 # extra performance by avoiding all logging-related string operations.
 # extra performance by avoiding all logging-related string operations.
 AddCompilationDefine(KNET_LOGGING_SUPPORT_ENABLED)
 AddCompilationDefine(KNET_LOGGING_SUPPORT_ENABLED)
 
 
 # Enable storing profiling data from different network level events.
 # Enable storing profiling data from different network level events.
-AddCompilationDefine(KNET_NETWORK_PROFILING)
+#AddCompilationDefine(KNET_NETWORK_PROFILING)
 
 
 if (USE_BOOST)
 if (USE_BOOST)
    AddCompilationDefine(KNET_USE_BOOST)
    AddCompilationDefine(KNET_USE_BOOST)

+ 1 - 3
ThirdParty/kNet/include/kNet/Alignment.h

@@ -16,13 +16,11 @@
 /** @file Alignment.h
 /** @file Alignment.h
 	@brief Provides functions for working with pointer data alignment computations.*/
 	@brief Provides functions for working with pointer data alignment computations.*/
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cassert>
 #include <cassert>
 
 
 #include "Types.h"
 #include "Types.h"
 
 
-#ifndef WIN32
+#ifdef UNIX
 #include <stdint.h>
 #include <stdint.h>
 #endif
 #endif
 
 

+ 1 - 1
ThirdParty/kNet/include/kNet/DataDeserializer.h

@@ -131,7 +131,7 @@ T DataDeserializer::Read()
 	T value;
 	T value;
 	u8 *data = reinterpret_cast<u8*>(&value);
 	u8 *data = reinterpret_cast<u8*>(&value);
 
 
-	for(int i = 0; i < sizeof(value); ++i)
+	for(size_t i = 0; i < sizeof(value); ++i)
 		data[i] = (u8)ReadBitsToU32(8);
 		data[i] = (u8)ReadBitsToU32(8);
 
 
 	if (iter)
 	if (iter)

+ 1 - 1
ThirdParty/kNet/include/kNet/DataSerializer.h

@@ -157,7 +157,7 @@ void DataSerializer::Add(const T &value)
 #endif
 #endif
 	const u8 *data = reinterpret_cast<const u8*>(&value);
 	const u8 *data = reinterpret_cast<const u8*>(&value);
 
 
-	for(int i = 0; i < sizeof(value); ++i)
+	for(size_t i = 0; i < sizeof(value); ++i)
 		AppendByte(data[i]);
 		AppendByte(data[i]);
 
 
 	if (iter)
 	if (iter)

+ 1 - 3
ThirdParty/kNet/include/kNet/EndPoint.h

@@ -16,9 +16,7 @@
 /** @file EndPoint.h
 /** @file EndPoint.h
 	@brief The class \ref kNet::EndPoint Endpoint. Represents an endpoint of a network connection. */
 	@brief The class \ref kNet::EndPoint Endpoint. Represents an endpoint of a network connection. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
-#ifndef WIN32
+#ifdef UNIX
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/in.h>

+ 1 - 3
ThirdParty/kNet/include/kNet/Event.h

@@ -16,8 +16,6 @@
 /** @file Event.h
 /** @file Event.h
 	@brief The class \ref kNet::Event Event. Provides a mechanism for inter-thread signalling. */
 	@brief The class \ref kNet::Event Event. Provides a mechanism for inter-thread signalling. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #ifdef WIN32
 #ifdef WIN32
 #include "win32/WS2Include.h"
 #include "win32/WS2Include.h"
 #endif
 #endif
@@ -100,7 +98,7 @@ public:
 
 
 	/// Wraps the given WSAEVENT into this event.
 	/// Wraps the given WSAEVENT into this event.
 	explicit Event(WSAEVENT wsaEvent, EventWaitType eventType);
 	explicit Event(WSAEVENT wsaEvent, EventWaitType eventType);
-#else
+#elif defined(UNIX)
 public:
 public:
 	int fd[2]; // fd[0] is used for reading, fd[1] for writing.
 	int fd[2]; // fd[0] is used for reading, fd[1] for writing.
 
 

+ 1 - 3
ThirdParty/kNet/include/kNet/EventArray.h

@@ -16,8 +16,6 @@
 /** @file EventArray.h
 /** @file EventArray.h
 	@brief The class \ref kNet::EventArray EventArray. Allows listening to multiple events at once.*/
 	@brief The class \ref kNet::EventArray EventArray. Allows listening to multiple events at once.*/
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <vector>
 #include <vector>
 
 
 #include "Event.h"
 #include "Event.h"
@@ -61,7 +59,7 @@ private:
 #ifdef WIN32
 #ifdef WIN32
 	WSAEVENT events[maxEvents]; 
 	WSAEVENT events[maxEvents]; 
 
 
-#else
+#elif defined(UNIX)
 	fd_set readfds;
 	fd_set readfds;
 	fd_set writefds;
 	fd_set writefds;
 	int nfds;
 	int nfds;

+ 15 - 17
ThirdParty/kNet/include/kNet/Lockable.h

@@ -16,8 +16,6 @@
 /** @file Lockable.h
 /** @file Lockable.h
 	@brief The Lock<T> and Lockable<T> template classes. */
 	@brief The Lock<T> and Lockable<T> template classes. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #ifdef KNET_USE_BOOST
 #ifdef KNET_USE_BOOST
 #include <boost/thread/recursive_mutex.hpp>
 #include <boost/thread/recursive_mutex.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/thread.hpp>
@@ -154,10 +152,10 @@ public:
 #ifdef WIN32
 #ifdef WIN32
 		InitializeCriticalSection(&lockObject);
 		InitializeCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutexattr_t attr;
-        pthread_mutexattr_init(&attr);
-        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-        pthread_mutex_init(&mutex, &attr);        
+		pthread_mutexattr_t attr;
+		pthread_mutexattr_init(&attr);
+		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+		pthread_mutex_init(&mutex, &attr);
 #endif
 #endif
 #endif
 #endif
 	}
 	}
@@ -176,12 +174,12 @@ public:
 #ifdef WIN32
 #ifdef WIN32
 		InitializeCriticalSection(&lockObject);
 		InitializeCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutexattr_t attr;
-        pthread_mutexattr_init(&attr);
-        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-        pthread_mutex_init(&mutex, &attr);
-#endif    
-#endif   
+		pthread_mutexattr_t attr;
+		pthread_mutexattr_init(&attr);
+		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+		pthread_mutex_init(&mutex, &attr);
+#endif
+#endif
 	}
 	}
 
 
 	~Lockable()
 	~Lockable()
@@ -190,7 +188,7 @@ public:
 #ifdef WIN32
 #ifdef WIN32
 		DeleteCriticalSection(&lockObject);
 		DeleteCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutex_destroy(&mutex);
+		pthread_mutex_destroy(&mutex);
 #endif
 #endif
 #endif
 #endif
 	}
 	}
@@ -213,7 +211,7 @@ public:
 #elif defined(WIN32)
 #elif defined(WIN32)
 		EnterCriticalSection(&lockObject);
 		EnterCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutex_lock(&mutex);
+		pthread_mutex_lock(&mutex);
 #endif
 #endif
 		return value;
 		return value;
 	}
 	}
@@ -225,7 +223,7 @@ public:
 #elif defined(WIN32)
 #elif defined(WIN32)
 		EnterCriticalSection(&lockObject);
 		EnterCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutex_lock(&mutex);
+		pthread_mutex_lock(&mutex);
 #endif
 #endif
 		return value;
 		return value;
 	}
 	}
@@ -237,7 +235,7 @@ public:
 #elif defined(WIN32)
 #elif defined(WIN32)
 		LeaveCriticalSection(&lockObject);
 		LeaveCriticalSection(&lockObject);
 #else
 #else
-        pthread_mutex_unlock(&mutex);
+		pthread_mutex_unlock(&mutex);
 #endif
 #endif
 	}
 	}
 
 
@@ -274,7 +272,7 @@ public:
 #elif defined(WIN32)
 #elif defined(WIN32)
 	mutable CRITICAL_SECTION lockObject;
 	mutable CRITICAL_SECTION lockObject;
 #else
 #else
-    mutable pthread_mutex_t mutex;
+	mutable pthread_mutex_t mutex;
 #endif
 #endif
 
 
 private:
 private:

+ 1 - 3
ThirdParty/kNet/include/kNet/MessageConnection.h

@@ -16,8 +16,6 @@
 /** @file MessageConnection.h
 /** @file MessageConnection.h
 	@brief The MessageConnection and ConnectionStatistics classes. */
 	@brief The MessageConnection and ConnectionStatistics classes. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <vector>
 #include <vector>
 #include <map>
 #include <map>
 #include <utility>
 #include <utility>
@@ -126,7 +124,7 @@ enum ConnectionState
 /// Returns a textual representation of a ConnectionState.
 /// Returns a textual representation of a ConnectionState.
 std::string ConnectionStateToString(ConnectionState state);
 std::string ConnectionStateToString(ConnectionState state);
 
 
-// Urho3D: prevent confusion with Win32 functions
+// Prevent confusion with Win32 functions
 #ifdef SendMessage
 #ifdef SendMessage
 #undef SendMessage
 #undef SendMessage
 #endif
 #endif

+ 1 - 3
ThirdParty/kNet/include/kNet/Network.h

@@ -16,9 +16,7 @@
 /** @file Network.h
 /** @file Network.h
 	@brief The class Network. The root point for creating client and server objects. */
 	@brief The class Network. The root point for creating client and server objects. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
-#ifndef WIN32
+#ifdef UNIX
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/in.h>

+ 1 - 3
ThirdParty/kNet/include/kNet/Socket.h

@@ -16,8 +16,6 @@
 /** @file Socket.h
 /** @file Socket.h
 	@brief The Socket class. */
 	@brief The Socket class. */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #ifdef WIN32
 #ifdef WIN32
 
 
 #include "kNetBuildConfig.h"
 #include "kNetBuildConfig.h"
@@ -31,7 +29,7 @@ namespace kNet
 typedef int socklen_t;
 typedef int socklen_t;
 }
 }
 
 
-#else
+#elif defined(UNIX)
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>

+ 4 - 5
ThirdParty/kNet/include/kNet/Thread.h

@@ -16,8 +16,6 @@
 /** @file Thread.h
 /** @file Thread.h
 	@brief The Thread class. Implements threading either using Boost, native Win32 or pthreads constructs. */
 	@brief The Thread class. Implements threading either using Boost, native Win32 or pthreads constructs. */
 
 
-// Modified by Lasse Öörni for Urho3D
- 
 #include <string>
 #include <string>
 
 
 #ifdef KNET_USE_BOOST
 #ifdef KNET_USE_BOOST
@@ -202,6 +200,7 @@ private:
 	boost::thread thread;
 	boost::thread thread;
 #elif defined(WIN32)
 #elif defined(WIN32)
 	HANDLE threadHandle;
 	HANDLE threadHandle;
+	ThreadId threadId;
 
 
 	/// The entry point that is called from the trampoline. Do not call this function.
 	/// The entry point that is called from the trampoline. Do not call this function.
 	void _ThreadRun();
 	void _ThreadRun();
@@ -210,11 +209,11 @@ private:
 private:
 private:
 	bool threadEnabled;
 	bool threadEnabled;
 #else
 #else
-    pthread_t thread;
-    
+	pthread_t thread;
+
 	void _ThreadRun();
 	void _ThreadRun();
 
 
-    friend void* ThreadEntryPoint(void* data);
+	friend void* ThreadEntryPoint(void* data);
 private:
 private:
 	bool threadEnabled;
 	bool threadEnabled;
 #endif
 #endif

+ 0 - 2
ThirdParty/kNet/src/DataDeserializer.cpp

@@ -15,8 +15,6 @@
 /** @file DataDeserializer.cpp
 /** @file DataDeserializer.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cassert>
 #include <cassert>
 #include <cstring>
 #include <cstring>
 
 

+ 0 - 2
ThirdParty/kNet/src/DataSerializer.cpp

@@ -15,8 +15,6 @@
 /** @file DataSerializer.cpp
 /** @file DataSerializer.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cstring>
 #include <cstring>
 
 
 #include "kNet/DebugMemoryLeakCheck.h"
 #include "kNet/DebugMemoryLeakCheck.h"

+ 1 - 3
ThirdParty/kNet/src/Network.cpp

@@ -15,14 +15,12 @@
 /** @file Network.cpp
 /** @file Network.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <string>
 #include <string>
 #include <sstream>
 #include <sstream>
 
 
 #include <cassert>
 #include <cassert>
 
 
-#ifndef WIN32
+#ifdef UNIX
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/inet.h>

+ 1 - 1
ThirdParty/kNet/src/NetworkLogging.cpp

@@ -33,7 +33,7 @@
 #include "kNet/Lockable.h"
 #include "kNet/Lockable.h"
 #include "kNet/Clock.h"
 #include "kNet/Clock.h"
 
 
-#ifndef WIN32
+#ifdef UNIX
 #define _snprintf snprintf
 #define _snprintf snprintf
 #endif
 #endif
 
 

+ 3 - 5
ThirdParty/kNet/src/Socket.cpp

@@ -15,8 +15,6 @@
 /** @file Socket.cpp
 /** @file Socket.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <string>
 #include <string>
 #include <cassert>
 #include <cassert>
 #include <utility>
 #include <utility>
@@ -36,7 +34,7 @@
 
 
 using namespace std;
 using namespace std;
 
 
-#ifndef WIN32
+#ifdef UNIX
 #include <fcntl.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
@@ -711,7 +709,7 @@ bool Socket::Send(const char *data, size_t numBytes)
 	}
 	}
 
 
 	int bytesSent = 0;
 	int bytesSent = 0;
-    // Urho3D: sendto() to a connected socket causes EISCONN on OS X, so avoid it for client UDP sockets
+	// sendto() to a connected socket causes EISCONN on OSX, so avoid it for client UDP sockets
 	if (transport == SocketOverUDP && type != ClientSocket)
 	if (transport == SocketOverUDP && type != ClientSocket)
 		bytesSent = sendto(connectSocket, data, numBytes, 0, (sockaddr*)&udpPeerAddress, sizeof(udpPeerAddress));
 		bytesSent = sendto(connectSocket, data, numBytes, 0, (sockaddr*)&udpPeerAddress, sizeof(udpPeerAddress));
 	else
 	else
@@ -881,7 +879,7 @@ bool Socket::EndSend(OverlappedTransferBuffer *sendBuffer)
 	}
 	}
 	return true;
 	return true;
 
 
-#else
+#elif defined(UNIX)
 	bool success = Send(sendBuffer->buffer.buf, sendBuffer->buffer.len);
 	bool success = Send(sendBuffer->buffer.buf, sendBuffer->buffer.len);
 	DeleteOverlappedTransferBuffer(sendBuffer);
 	DeleteOverlappedTransferBuffer(sendBuffer);
 	return success;
 	return success;

+ 4 - 5
ThirdParty/kNet/src/Thread.cpp

@@ -121,11 +121,10 @@ void SetThreadName(DWORD dwThreadID, const char *threadName)
 
 
 void Thread::SetName(const char *name)
 void Thread::SetName(const char *name)
 {
 {
-#if defined(WIN32) && !defined(KNET_ENABLE_WINXP_SUPPORT)
-#ifdef KNET_USE_BOOST
-	SetThreadName(GetThreadId(thread.native_handle()), name);
-#else
-	SetThreadName(GetThreadId(threadHandle), name);
+// The thread name can only be set when it is ensured that Thread::Id() returns the proper Win32 thread ID
+#ifdef WIN32
+#if !defined(KNET_USE_BOOST) || !defined(KNET_ENABLE_WINXP_SUPPORT)
+	SetThreadName(Id(), name);
 #endif
 #endif
 #endif
 #endif
 }
 }

+ 2 - 4
ThirdParty/kNet/src/unix/UnixClock.cpp

@@ -15,8 +15,6 @@
 /** @file UnixClock.cpp
 /** @file UnixClock.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cassert>
 #include <cassert>
 
 
 #include <time.h>
 #include <time.h>
@@ -108,7 +106,7 @@ tick_t Clock::Tick()
 	timespec t;
 	timespec t;
 	clock_gettime(CLOCK_MONOTONIC, &t);
 	clock_gettime(CLOCK_MONOTONIC, &t);
     return (tick_t)t.tv_sec * 1000 * 1000 * 1000 + (tick_t)t.tv_nsec;
     return (tick_t)t.tv_sec * 1000 * 1000 * 1000 + (tick_t)t.tv_nsec;
-// Urho3D: OS X does not define _POSIX_C_SOURCE
+//_POSIX_C_SOURCE is not defined on OSX
 #elif defined(_POSIX_C_SOURCE) || defined(__APPLE__)
 #elif defined(_POSIX_C_SOURCE) || defined(__APPLE__)
 	timeval t;
 	timeval t;
 	gettimeofday(&t, NULL);
 	gettimeofday(&t, NULL);
@@ -127,7 +125,7 @@ tick_t Clock::TicksPerSec()
 {
 {
 #ifdef _POSIX_MONOTONIC_CLOCK
 #ifdef _POSIX_MONOTONIC_CLOCK
     return 1000 * 1000 * 1000;
     return 1000 * 1000 * 1000;
-// Urho3D: OS X does not define _POSIX_C_SOURCE
+//_POSIX_C_SOURCE is not defined on OSX
 #elif defined(_POSIX_C_SOURCE) || defined(__APPLE__)
 #elif defined(_POSIX_C_SOURCE) || defined(__APPLE__)
     return 1000 * 1000;
     return 1000 * 1000;
 #else
 #else

+ 11 - 13
ThirdParty/kNet/src/unix/UnixThread.cpp

@@ -15,8 +15,6 @@
 /** @file UnixThread.cpp
 /** @file UnixThread.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cassert>
 #include <cassert>
 #include <exception>
 #include <exception>
 
 
@@ -48,7 +46,7 @@ bool Thread::ShouldQuit() const { return !thread || threadEnabled == false; }
 
 
 bool Thread::IsRunning() const
 bool Thread::IsRunning() const
 { 
 { 
-    return thread != 0;
+	return thread != 0;
 }
 }
 
 
 void Thread::Stop()
 void Thread::Stop()
@@ -70,9 +68,9 @@ void Thread::Stop()
 	kNet::Clock::Sleep(10);
 	kNet::Clock::Sleep(10);
 	assert(thread);
 	assert(thread);
 
 
-    /// \todo Do not block indefinitely while waiting for the thread to terminate
-    pthread_join(thread, 0);
-    thread = 0;
+	/// \todo Do not block indefinitely while waiting for the thread to terminate
+	pthread_join(thread, 0);
+	thread = 0;
 
 
 	LOG(LogInfo, "Thread::Stop() called.");
 	LOG(LogInfo, "Thread::Stop() called.");
 
 
@@ -95,7 +93,7 @@ void* ThreadEntryPoint(void* data)
 		return 0;
 		return 0;
 	}
 	}
 	thread->_ThreadRun();
 	thread->_ThreadRun();
-    pthread_exit((void*)0);
+	pthread_exit((void*)0);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -132,10 +130,10 @@ void Thread::StartThread()
 	threadResumeEvent = CreateNewEvent(EventWaitSignal);
 	threadResumeEvent = CreateNewEvent(EventWaitSignal);
 
 
 	threadEnabled = true;
 	threadEnabled = true;
-    pthread_attr_t type;
-    pthread_attr_init(&type);
-    pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
-    if (pthread_create(&thread, &type, ThreadEntryPoint, this))
+	pthread_attr_t type;
+	pthread_attr_init(&type);
+	pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
+	if (pthread_create(&thread, &type, ThreadEntryPoint, this))
 		throw NetException("Failed to create thread!");
 		throw NetException("Failed to create thread!");
 	else
 	else
 		LOG(LogInfo, "Thread::Run(): Thread created.");
 		LOG(LogInfo, "Thread::Run(): Thread created.");
@@ -151,12 +149,12 @@ void Thread::Sleep(int msecs)
 
 
 ThreadId Thread::Id()
 ThreadId Thread::Id()
 {
 {
-    return thread;
+	return thread;
 }
 }
 
 
 ThreadId Thread::CurrentThreadId()
 ThreadId Thread::CurrentThreadId()
 {
 {
-    return pthread_self();
+	return pthread_self();
 }
 }
 
 
 ThreadId Thread::NullThreadId()
 ThreadId Thread::NullThreadId()

+ 6 - 24
ThirdParty/kNet/src/win32/W32Thread.cpp

@@ -15,8 +15,6 @@
 /** @file W32Thread.cpp
 /** @file W32Thread.cpp
 	@brief */
 	@brief */
 
 
-// Modified by Lasse Öörni for Urho3D
-
 #include <cassert>
 #include <cassert>
 #include <exception>
 #include <exception>
 
 
@@ -33,6 +31,7 @@ namespace kNet
 
 
 Thread::Thread()
 Thread::Thread()
 :threadHandle(NULL),
 :threadHandle(NULL),
+threadId(0),
 threadEnabled(false),
 threadEnabled(false),
 invoker(0)
 invoker(0)
 {
 {
@@ -96,6 +95,7 @@ void Thread::Stop()
 		else if (exitCode != STILL_ACTIVE)
 		else if (exitCode != STILL_ACTIVE)
 		{
 		{
 			CloseHandle(threadHandle);
 			CloseHandle(threadHandle);
+			threadHandle = NULL;
 			break;
 			break;
 		}
 		}
 		kNet::Clock::Sleep(50);
 		kNet::Clock::Sleep(50);
@@ -111,6 +111,7 @@ void Thread::Stop()
 	LOG(LogInfo, "Thread::Stop() called.");
 	LOG(LogInfo, "Thread::Stop() called.");
 
 
 	threadHandle = NULL;
 	threadHandle = NULL;
+	threadId = 0;
 
 
 	delete invoker;
 	delete invoker;
 	invoker = 0;
 	invoker = 0;
@@ -168,13 +169,13 @@ void Thread::StartThread()
 	threadResumeEvent = CreateNewEvent(EventWaitSignal);
 	threadResumeEvent = CreateNewEvent(EventWaitSignal);
 
 
 	threadEnabled = true;
 	threadEnabled = true;
-	threadHandle = CreateThread(NULL, 0, ThreadEntryPoint, this, 0, NULL);
+	threadHandle = CreateThread(NULL, 0, ThreadEntryPoint, this, 0, &threadId);
 	if (threadHandle == NULL)
 	if (threadHandle == NULL)
 		throw NetException("Failed to create thread!");
 		throw NetException("Failed to create thread!");
 	else
 	else
 		LOG(LogInfo, "Thread::Run(): Thread created.");
 		LOG(LogInfo, "Thread::Run(): Thread created.");
 
 
-    SetName("kNet Thread");
+	SetName("kNet Thread");
 }
 }
 
 
 void Thread::Sleep(int msecs)
 void Thread::Sleep(int msecs)
@@ -185,31 +186,12 @@ void Thread::Sleep(int msecs)
 
 
 ThreadId Thread::Id()
 ThreadId Thread::Id()
 {
 {
-	if (threadHandle == NULL)
-		return NullThreadId();
-
-    // Urho3D: if thread ID's can not be supported, return always null
-    #ifdef KNET_ENABLE_WINXP_SUPPORT
-	return NullThreadId();
-    #else
-    ThreadId id = GetThreadId(threadHandle);
-	if (id == 0)
-	{
-		LOG(LogError, "Thread::Id failed: %s!", Network::GetLastErrorString().c_str());
-		return NullThreadId();
-	}
-	return id;
-    #endif
+	return threadId;
 }
 }
 
 
 ThreadId Thread::CurrentThreadId()
 ThreadId Thread::CurrentThreadId()
 {
 {
-    // Urho3D: if thread ID's can not be supported, return always null
-    #ifdef KNET_ENABLE_WINXP_SUPPORT
-    return NullThreadId();
-    #else
 	return GetCurrentThreadId();
 	return GetCurrentThreadId();
-    #endif
 }
 }
 
 
 ThreadId Thread::NullThreadId()
 ThreadId Thread::NullThreadId()